* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --border: #E5E5EA;
  --text: #1D1D1F;
  --text-muted: #86868B;
  --primary: #007AFF;
  --primary-hover: #0056CC;
  --danger: #FF3B30;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, #F5F5F7 0%, #EEEEF0 100%);
  color: var(--text);
  min-height: 100dvh;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.header-row h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.btn-icon {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--surface);
  color: var(--text);
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

.reads-counter {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.4rem;
  border: none;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.btn:active {
  opacity: 0.8;
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #F0F0F2;
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  border-radius: 10px;
}

/* Cost display */
#cost-display {
  text-align: center;
  margin-bottom: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Camera */
#camera-container {
  position: relative;
  margin-bottom: 1rem;
  border-radius: 20px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  max-height: 60dvh;
}

#camera-preview {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 60dvh;
  object-fit: cover;
  border-radius: 20px;
}

#shutter-btn {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#shutter-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

.shutter-icon {
  display: block;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
}

/* Preview */
#snapshot-canvas {
  display: block;
  width: 100%;
  border-radius: 16px;
  margin-bottom: 1rem;
}

.preview-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* Progress */
#progress-section {
  text-align: center;
  padding: 2rem 0;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}

#progress-status {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Result */
#result-section {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 6rem);
}

#text-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  min-height: 80px;
  flex: 1 1 auto;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
  outline: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

#text-output .word {
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s;
}

#text-output .word:hover {
  background: rgba(0, 122, 255, 0.1);
}

#text-output:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

/* Playback controls */
.playback-controls {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.btn-round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  padding: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.btn-round:hover {
  background: #F0F0F2;
}

.btn-round:active {
  transform: scale(0.93);
}

.btn-round.btn-play {
  width: 72px;
  height: 72px;
  font-size: 1.4rem;
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.25);
}

.btn-round.btn-play:hover {
  background: var(--primary-hover);
}

.result-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

/* Voice settings (hidden, kept for JS) */
#voice-settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 0.75rem;
  align-items: center;
  font-size: 0.9rem;
}

#voice-settings label {
  color: var(--text-muted);
}

#voice-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
  font-size: 0.85rem;
}

#rate-slider {
  width: 100%;
  accent-color: var(--primary);
}

#rate-value {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: right;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Highlight currently spoken word */
.spoken-word {
  background: #FFF3C4;
  color: #1D1D1F;
  border-radius: 4px;
  padding: 1px 4px;
  font-weight: 700;
}

/* ===== Character Stage ===== */
#character-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 0.25rem;
  flex-shrink: 0;
}

#active-character {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#active-character svg {
  width: 100%;
  height: 100%;
}

#character-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 0.1rem;
}

/* ===== Welcome Character ===== */
#welcome-character {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}

#welcome-character svg {
  width: 100px;
  height: 100px;
}

/* ===== Mouth Animation ===== */
.mouth-closed { display: block; }
.mouth-open { display: none; }

.speaking .mouth-closed { display: none; }
.speaking .mouth-open { display: block; }

@keyframes speak-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.speaking {
  animation: speak-bounce 0.18s ease-in-out;
}

/* ===== Idle Blink Animation ===== */
@keyframes blink {
  0%, 90%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

.char-eyes {
  animation: blink 4s ease-in-out infinite;
  transform-origin: center;
}

/* ===== Modal Overlay ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  max-width: 400px;
  width: 100%;
  position: relative;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
}

.modal h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
  text-align: center;
}

.modal p {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--text);
}

/* Auth form styles */
.modal form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal form label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.modal form input[type="email"],
.modal form input[type="password"] {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.modal form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.modal form button[type="submit"] {
  margin-top: 0.75rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  padding: 0.25rem 0;
}

.form-toggle {
  font-size: 0.85rem;
  text-align: center;
  margin-top: 1rem;
  color: var(--text-muted);
}

.form-toggle a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.form-toggle a:hover {
  text-decoration: underline;
}

/* ===== Install Banner ===== */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  z-index: 900;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  font-size: 0.85rem;
}

.install-banner-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ===== SW Update Banner ===== */
.sw-update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--primary);
  color: #fff;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  z-index: 950;
  font-size: 0.85rem;
  font-weight: 500;
}

.sw-update-banner .btn {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.sw-update-banner .btn:hover {
  background: rgba(255, 255, 255, 0.3);
}
