/* ============================================
   Storyteller — Warm Storybook Theme
   ============================================ */

/* ---------- 1. Base / Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: #f5f0e8;
  font-family: 'Lora', Georgia, serif;
  color: #3b2a1a;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #ece5d8;
}

::-webkit-scrollbar-thumb {
  background: #b8a48a;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #5c4033;
}

/* ---------- 2. Language Selection Screen ---------- */
#language-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 2rem;
}

#language-screen[hidden] {
  display: none;
}

#language-screen h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 3.5rem;
  color: #5c4033;
  margin-bottom: 0.25rem;
}

#language-screen p {
  font-size: 1.1rem;
  color: #8a7560;
  margin-bottom: 2.5rem;
}

.language-buttons {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.lang-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  border: none;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(92, 64, 51, 0.12);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.lang-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(92, 64, 51, 0.22);
}

.lang-btn .lang-flag {
  width: 60px;
  height: 40px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.lang-btn .lang-label {
  font-size: 0.85rem;
  color: #5c4033;
  margin-top: 0.5rem;
  font-family: 'Lora', Georgia, serif;
  font-weight: 600;
}

/* ---------- 2b. Story Setup Wizard ---------- */
#wizard-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(210, 180, 140, 0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(184, 150, 120, 0.25) 0%, transparent 50%),
    #f5f0e8;
}

#wizard-screen[hidden] {
  display: none;
}

.wizard-inner {
  background: #fffdf8;
  border-radius: 24px;
  box-shadow:
    0 8px 40px rgba(92, 64, 51, 0.12),
    0 1px 3px rgba(92, 64, 51, 0.08);
  padding: 3rem 2.5rem 2.5rem;
  max-width: 640px;
  width: 100%;
  text-align: center;
  position: relative;
  border: 1px solid rgba(210, 190, 165, 0.4);
  animation: wizardAppear 0.5s ease both;
}

@keyframes wizardAppear {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.wizard-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.4rem;
  color: #5c4033;
  margin-bottom: 1.5rem;
  letter-spacing: -0.5px;
}

/* Step indicators */
.wizard-steps-indicator {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 2rem;
}

.step-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e0d5c3;
  transition: background 0.3s ease, transform 0.3s ease;
}

.step-dot.active {
  background: #5c4033;
  transform: scale(1.2);
}

/* Step containers */
.wizard-step {
  animation: stepFadeIn 0.35s ease both;
}

.wizard-step[hidden] {
  display: none;
}

@keyframes stepFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.wizard-step-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.5rem;
  color: #6b4c3b;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

/* Tag buttons — large, child-friendly */
.wizard-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-bottom: 1.5rem;
}

.wizard-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 16px 28px;
  font-family: 'Lora', Georgia, serif;
  font-size: 1.15rem;
  font-weight: 500;
  color: #5c4033;
  background: linear-gradient(135deg, #fff9f0 0%, #f5ede0 100%);
  border: 2px solid #e0d1be;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.25s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 56px;
  line-height: 1.3;
}

.wizard-tag:hover {
  background: linear-gradient(135deg, #f5ede0 0%, #ecdcc6 100%);
  border-color: #c4a882;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(92, 64, 51, 0.15);
}

.wizard-tag:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(92, 64, 51, 0.12);
  background: linear-gradient(135deg, #ecdcc6 0%, #e4d0b6 100%);
}

/* Back button */
.wizard-back {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 10px 20px;
  background: none;
  border: none;
  color: #9a8472;
  font-family: 'Lora', Georgia, serif;
  font-size: 1rem;
  cursor: pointer;
  transition: color 0.2s;
}

.wizard-back:hover {
  color: #5c4033;
}

/* Wizard mic area */
#wizard-mic-area {
  animation: stepFadeIn 0.35s ease both;
}

#wizard-mic-area[hidden] {
  display: none;
}

.wizard-summary {
  font-family: 'Lora', Georgia, serif;
  font-size: 1.1rem;
  color: #6b4c3b;
  line-height: 1.6;
  margin-bottom: 1.75rem;
  font-style: italic;
}

#wizard-mic-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, #6b4c3b, #5c4033);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px rgba(92, 64, 51, 0.3);
  transition: all 0.25s ease;
  margin-bottom: 1rem;
}

#wizard-mic-btn:hover {
  background: linear-gradient(145deg, #5c4033, #4a3328);
  transform: scale(1.08);
  box-shadow: 0 8px 30px rgba(92, 64, 51, 0.4);
}

#wizard-mic-btn svg {
  width: 36px;
  height: 36px;
  fill: #fff;
}

.wizard-mic-hint {
  font-family: 'Lora', Georgia, serif;
  font-size: 0.95rem;
  color: #9a8472;
  margin-bottom: 0.5rem;
}

/* ---------- 3. Main App ---------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#app[hidden] {
  display: none;
}

/* ---------- 4. Header ---------- */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: #f5f0e8;
  box-shadow: 0 2px 8px rgba(92, 64, 51, 0.15);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  z-index: 200;
}

#header h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.4rem;
  color: #5c4033;
  flex: 1;
  text-align: center;
}

/* Icon base */
.icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

#sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  color: #5c4033;
  transition: background 0.2s;
}

#sidebar-toggle:hover {
  background: rgba(92, 64, 51, 0.08);
}

#sidebar-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  color: #5c4033;
  transition: background 0.2s;
}

#sidebar-close:hover {
  background: rgba(92, 64, 51, 0.08);
}

/* ---------- 5. Sidebar ---------- */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: #f5f0e8;
  box-shadow: 2px 0 12px rgba(92, 64, 51, 0.15);
  z-index: 550;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow-y: auto;
}

#sidebar.open {
  transform: translateX(0);
}

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 540;
}

#sidebar.open ~ #sidebar-overlay {
  display: block;
}

#new-story-btn {
  background: #c9a84c;
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 0.6rem 1.2rem;
  font-family: 'Lora', Georgia, serif;
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: background 0.2s;
  width: 100%;
}

#new-story-btn:hover {
  background: #b8962f;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.sidebar-header h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.2rem;
  color: #5c4033;
}

#story-list {
  list-style: none;
}

#story-list li {
  padding: 0.75rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

#story-list li:hover {
  background: rgba(92, 64, 51, 0.07);
}

.story-list li .story-title {
  font-weight: 600;
  color: #5c4033;
  font-size: 0.95rem;
}

.story-list li .story-date {
  font-size: 0.78rem;
  color: #8a7560;
  margin-top: 2px;
}

/* ---------- 6. Story Canvas ---------- */
#story-canvas {
  flex: 1;
  overflow-y: auto;
  padding: 72px 1rem 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.welcome-message {
  text-align: center;
  margin-top: 30vh;
  color: #8a7560;
  font-size: 1.1rem;
  line-height: 1.6;
  max-width: 420px;
  padding: 0 1rem;
}

.story-content {
  width: 100%;
  max-width: 700px;
}

/* ---------- 7. Story Step ---------- */
.story-step {
  background: #fffcf5;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(92, 64, 51, 0.08);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  animation: fadeIn 0.5s ease both;
}

.story-step .story-text {
  font-family: 'Lora', Georgia, serif;
  font-size: 1.1rem;
  line-height: 1.7;
  color: #3b2a1a;
}

.story-step .story-image {
  width: 100%;
  border-radius: 8px;
  margin-top: 1rem;
  border: 1px solid rgba(92, 64, 51, 0.1);
}

/* ---------- 7b. Fullscreen Story Image Overlay ---------- */
#fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
}

#fullscreen-overlay[hidden] {
  display: none;
}

#fullscreen-img {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  object-fit: contain;
  display: block;
}

/* Hover zone in top-left corner to reveal menu button */
#fullscreen-menu-zone {
  position: fixed;
  top: 0;
  left: 0;
  width: 80px;
  height: 80px;
  z-index: 510;
}

#fullscreen-menu-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(4px);
}

#fullscreen-menu-zone:hover #fullscreen-menu-btn,
#fullscreen-menu-btn:focus {
  opacity: 1;
}

#fullscreen-menu-btn .icon {
  stroke: #fff;
}

/* ---------- 8. Microphone Area ---------- */
#mic-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  padding: 1.25rem 1rem 1.75rem;
  z-index: 520;
  pointer-events: none;
}

/* ---------- 9. Mic Button ---------- */
#mic-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: #5c4033;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(92, 64, 51, 0.35);
  transition: background 0.2s, transform 0.15s;
  pointer-events: auto;
}

#mic-btn:hover {
  background: #4a3328;
  transform: scale(1.05);
}

#mic-btn svg {
  width: 32px;
  height: 32px;
  fill: #fff;
}

#mic-btn.recording {
  background: #8b2500;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(139, 37, 0, 0.7); }
  70%  { box-shadow: 0 0 0 20px rgba(139, 37, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(139, 37, 0, 0); }
}

/* ---------- 10. Subtitle Bar ---------- */
#subtitle-bar {
  position: fixed;
  bottom: 110px;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  text-align: center;
  padding: 0.6rem 1.5rem;
  font-size: 1.1rem;
  z-index: 530;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#subtitle-bar.visible {
  opacity: 1;
}

/* ---------- 11. Loading Indicator ---------- */
#loading {
  position: fixed;
  inset: 0;
  background: rgba(245, 240, 232, 0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 600;
}

#loading:not([hidden]) {
  display: flex;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e0d5c3;
  border-top-color: #5c4033;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading p {
  margin-top: 1rem;
  color: #5c4033;
  font-size: 1rem;
  text-align: center;
}

/* ---------- 13. Animations ---------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.5s ease both;
}

/* ---------- 14. Toast Notifications ---------- */
.toast {
  position: fixed;
  top: 24px;
  right: 24px;
  max-width: 400px;
  padding: 14px 20px;
  border-radius: 8px;
  font-family: 'Merriweather', Georgia, serif;
  font-size: 0.95rem;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateX(40px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 9999;
  pointer-events: auto;
}

.toast.visible {
  opacity: 1;
  transform: translateX(0);
}

.toast + .toast {
  margin-top: 8px;
}

.toast-info {
  background: #e8f4f8;
  color: #1a5276;
  border-left: 4px solid #3498db;
}

.toast-warning {
  background: #fef9e7;
  color: #7d6608;
  border-left: 4px solid #f1c40f;
}

.toast-error {
  background: #fdedec;
  color: #922b21;
  border-left: 4px solid #e74c3c;
}

.toast-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.toast-close:hover {
  opacity: 1;
}

/* ---------- 12. Responsive ---------- */
@media (max-width: 600px) {
  #language-screen h1 {
    font-size: 2.5rem;
  }

  .lang-btn {
    width: 96px;
    height: 96px;
  }

  .lang-btn .flag {
    font-size: 2.4rem;
  }

  #header h1 {
    font-size: 1.2rem;
  }

  .story-step {
    padding: 1rem;
  }

  .story-step .story-text {
    font-size: 1rem;
  }

  #story-canvas {
    padding: 64px 0.75rem 140px;
  }

  #mic-btn {
    width: 68px;
    height: 68px;
  }

  #mic-btn svg {
    width: 28px;
    height: 28px;
  }

  #subtitle-bar {
    bottom: 96px;
    font-size: 1rem;
  }

  /* Wizard responsive */
  .wizard-inner {
    padding: 2rem 1.25rem 1.75rem;
    border-radius: 18px;
  }

  .wizard-title {
    font-size: 1.8rem;
  }

  .wizard-step-title {
    font-size: 1.25rem;
  }

  .wizard-tag {
    padding: 14px 22px;
    font-size: 1.05rem;
    min-height: 50px;
  }

  #wizard-mic-btn {
    width: 76px;
    height: 76px;
  }
}
