:root {
  --bg-cream: #fff9f0;
  --bg-mint: #e8f9f5;
  --ink: #1a1625;
  --ink-soft: #5a5568;
  --ink-lighter: #8b8595;
  --coral: #ff6b5e;
  --coral-light: #ff8f85;
  --sun: #ffb84d;
  --sea: #4db8a8;
  --sea-light: #6dd4c4;
  --sky: #6b9fff;
  --sky-light: #8fb5ff;
  --card: #ffffff;
  --card-alt: #fefdfb;
  --border-soft: #f0e8dc;
  --border-medium: #e5d9c8;
  --shadow-sm: 0 2px 8px rgba(26, 22, 37, 0.04);
  --shadow-md: 0 8px 24px rgba(26, 22, 37, 0.08);
  --shadow-lg: 0 16px 48px rgba(26, 22, 37, 0.12);
  --shadow-xl: 0 24px 64px rgba(26, 22, 37, 0.16);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --transition-fast: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 280ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 380ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 12% 8%, rgba(255, 239, 202, 0.5) 0%, transparent 40%),
    radial-gradient(ellipse at 88% 12%, rgba(207, 233, 255, 0.4) 0%, transparent 38%),
    radial-gradient(ellipse at 50% 95%, rgba(201, 244, 232, 0.45) 0%, transparent 35%),
    linear-gradient(165deg, var(--bg-cream) 0%, var(--bg-mint) 100%);
  color: var(--ink);
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.bg-shape {
  position: fixed;
  z-index: 0;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(80px);
  opacity: 0.6;
  animation: float-shape 20s ease-in-out infinite;
}

.shape-a {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(255, 125, 110, 0.25), transparent 70%);
  top: 65%;
  left: -120px;
  animation-delay: 0s;
}

.shape-b {
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(126, 166, 255, 0.22), transparent 70%);
  top: 4%;
  right: -100px;
  animation-delay: -7s;
}

.shape-c {
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(86, 196, 181, 0.2), transparent 70%);
  top: 42%;
  right: 6%;
  animation-delay: -14s;
}

@keyframes float-shape {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(20px, -15px) scale(1.05); }
  66% { transform: translate(-15px, 10px) scale(0.95); }
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
}

.logo-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  color: var(--ink);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
  cursor: pointer;
}

.logo-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(255, 255, 255, 1);
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ffd88d 0%, #ff9367 100%);
  font-size: 1.1rem;
  box-shadow: 0 4px 12px rgba(255, 147, 103, 0.3);
}

.logo-text {
  font-family: "Baloo 2", cursive;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.01em;
}

.top-nav-note {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-lighter);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.card {
  background: var(--card);
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 40px;
  animation: float-in var(--transition-slow);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--coral-light), var(--sky-light), var(--sea-light));
  opacity: 0.6;
}

.setup-card {
  display: grid;
  gap: 32px;
}

.hero h1 {
  font-family: "Baloo 2", cursive;
  margin: 0 0 16px;
  font-size: clamp(2.25rem, 5vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--ink) 0%, #3d3850 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.125rem;
  line-height: 1.65;
  max-width: 720px;
}

.hero-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.highlight-pill {
  background: linear-gradient(135deg, rgba(237, 248, 255, 0.9), rgba(239, 252, 245, 0.9));
  backdrop-filter: blur(8px);
  border: 1.5px solid rgba(216, 235, 234, 0.8);
  color: #2a5470;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: all var(--transition-fast);
}

.highlight-pill:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: rgba(216, 235, 234, 1);
}

.eyebrow {
  display: inline-block;
  margin: 0 0 12px;
  font-size: 0.8125rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--coral);
  font-weight: 800;
}

.story-form {
  display: grid;
  gap: 20px;
}

.story-form label {
  display: grid;
  gap: 10px;
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--ink);
}

textarea,
input,
select,
button {
  font: inherit;
}

textarea,
input,
select {
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--card-alt);
  color: var(--ink);
  font-size: 1rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--sea);
  box-shadow: 0 0 0 4px rgba(77, 184, 168, 0.12), var(--shadow-md);
  background: var(--card);
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

button {
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 24px;
  font-weight: 700;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--coral) 0%, #ffa044 100%);
  color: white;
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-md), 0 4px 16px rgba(255, 107, 94, 0.3);
  position: relative;
  overflow: hidden;
}

button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

button:hover::before {
  left: 100%;
}

button:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: var(--shadow-lg), 0 8px 24px rgba(255, 107, 94, 0.4);
}

button:active {
  transform: translateY(0) scale(0.98);
}

.secondary-btn {
  background: linear-gradient(135deg, #faf7f0 0%, #f5f0e6 100%);
  border: 1.5px solid var(--border-medium);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.secondary-btn:hover {
  background: linear-gradient(135deg, #ffffff 0%, #faf7f0 100%);
  border-color: var(--border-soft);
  box-shadow: var(--shadow-md);
}

.feature-list {
  margin: 0;
  padding: 20px 24px;
  background: linear-gradient(135deg, rgba(255, 252, 245, 0.6), rgba(250, 247, 240, 0.6));
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-soft);
  color: var(--ink-soft);
  display: grid;
  gap: 10px;
  list-style: none;
}

.feature-list li {
  padding-left: 28px;
  position: relative;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.feature-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--sea);
  font-weight: 800;
  font-size: 1.1rem;
}

.progress-wrap {
  width: 100%;
  border-radius: 999px;
  height: 12px;
  background: var(--border-soft);
  overflow: hidden;
  margin: 20px 0 16px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
  position: relative;
}

.progress-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.3) 50%, transparent 100%);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.progress-bar {
  width: 0%;
  height: 100%;
  transition: width 400ms cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(90deg, var(--sea) 0%, var(--sky) 100%);
  box-shadow: 0 0 12px rgba(77, 184, 168, 0.4);
  position: relative;
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4));
  animation: progress-shine 1.5s ease-in-out infinite;
}

@keyframes progress-shine {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

.game-wrap {
  margin-top: 28px;
  background: linear-gradient(135deg, rgba(255, 248, 239, 0.8), rgba(255, 242, 223, 0.8));
  backdrop-filter: blur(8px);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  border: 2px dashed rgba(245, 185, 119, 0.5);
  display: grid;
  justify-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.subtle {
  margin: 0;
  color: var(--ink-lighter);
  font-size: 0.9375rem;
}

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 10px;
}

.ttt-cell {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-md);
  border: 2px solid #ffd19b;
  font-family: "Baloo 2", cursive;
  font-size: 2.25rem;
  background: white;
  color: var(--coral);
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.ttt-cell:hover:not(:disabled) {
  transform: scale(1.05);
  border-color: var(--sun);
  box-shadow: var(--shadow-md);
}

.ttt-cell:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.storybook-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--border-soft);
}

.storybook-header h2 {
  margin: 0;
  font-family: "Baloo 2", cursive;
  font-size: clamp(2rem, 3.5vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--ink) 0%, #3d3850 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.chip {
  background: linear-gradient(135deg, #eef8f3, #e8f5f0);
  color: #2d5850;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 700;
  border: 1.5px solid rgba(56, 105, 95, 0.15);
  box-shadow: var(--shadow-sm);
}

.read-mode-prompt {
  background: linear-gradient(135deg, rgba(255, 248, 216, 0.9), rgba(255, 242, 200, 0.9));
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 229, 155, 0.6);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.read-mode-prompt p {
  margin: 0 0 12px;
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--ink);
}

.read-mode-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.page-card {
  min-height: 500px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(255, 254, 251, 0.95), rgba(255, 246, 234, 0.95));
  backdrop-filter: blur(8px);
  border: 2px solid var(--border-soft);
  padding: 28px;
  display: grid;
  gap: 20px;
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition-base);
}

.page-card:hover {
  box-shadow: var(--shadow-lg);
}

.page-images {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.page-images[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.page-images[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.story-image-frame {
  margin: 0;
  width: 100%;
  background: linear-gradient(135deg, #fffdf9, #f8f6f0);
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-md);
  overflow: hidden;
  padding: 10px;
  aspect-ratio: 1 / 1;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
}

.story-image-frame:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
  border-color: var(--border-soft);
}

.page-images[data-count="1"] .story-image-frame {
  aspect-ratio: 4 / 3;
  max-width: 800px;
  justify-self: center;
}

.page-images[data-count="2"] .story-image-frame {
  aspect-ratio: 4 / 3;
}

.story-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  display: block;
  background: linear-gradient(135deg, #faf8f2, #f7f3ea);
}

.page-text {
  margin: 0;
  padding: 20px 24px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border: 2px solid var(--border-soft);
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.choice-wrap {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 20px 0;
}

.choice-btn {
  background: linear-gradient(135deg, var(--sea) 0%, var(--sky) 100%);
  flex: 1;
  min-width: 200px;
  box-shadow: var(--shadow-md), 0 4px 16px rgba(77, 184, 168, 0.3);
}

.choice-btn:hover {
  box-shadow: var(--shadow-lg), 0 8px 24px rgba(77, 184, 168, 0.4);
}

.story-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  margin-top: 12px;
  padding-top: 20px;
  border-top: 2px solid var(--border-soft);
}

.speaker-btn {
  margin-left: auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sun) 0%, #ff9f45 100%);
  font-size: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md), 0 4px 16px rgba(255, 184, 77, 0.4);
  transition: all var(--transition-base);
}

.speaker-btn:hover {
  transform: scale(1.08) rotate(5deg);
  box-shadow: var(--shadow-lg), 0 8px 24px rgba(255, 184, 77, 0.5);
}

.speaker-btn.muted {
  background: linear-gradient(135deg, #f5f1e8, #ebe7dd);
  box-shadow: var(--shadow-sm);
  opacity: 0.7;
}

.speaker-btn.muted:hover {
  opacity: 1;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  background: linear-gradient(135deg, #2d2a3f, #1a1625);
  color: white;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  animation: toast-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.hidden {
  display: none !important;
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 24px 20px 60px;
  }

  .top-nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .top-nav-note {
    font-size: 0.8125rem;
  }

  .card {
    padding: 32px 24px;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .storybook-header {
    flex-direction: column;
  }

  .page-images {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-images[data-count="1"],
  .page-images[data-count="2"] {
    grid-template-columns: 1fr;
  }

  .speaker-btn {
    margin-left: 0;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 20px 16px 48px;
  }

  .card {
    padding: 24px 20px;
    border-radius: var(--radius-lg);
  }

  .logo-btn {
    padding: 10px 16px;
  }

  .logo-text {
    font-size: 1.15rem;
  }

  .hero h1 {
    font-size: 2rem;
    margin-bottom: 12px;
  }

  .hero p {
    font-size: 1.0625rem;
  }

  .hero-highlights {
    gap: 8px;
  }

  .highlight-pill {
    width: 100%;
    text-align: center;
    padding: 12px 16px;
  }

  .page-card {
    padding: 20px;
    min-height: 420px;
  }

  .page-text {
    padding: 16px 18px;
    font-size: 1.0625rem;
  }

  .story-controls {
    gap: 10px;
  }

  .story-controls .secondary-btn {
    flex: 1 1 45%;
  }

  .speaker-btn {
    width: 56px;
    height: 56px;
  }

  .ttt-board {
    grid-template-columns: repeat(3, 72px);
  }

  .ttt-cell {
    width: 72px;
    height: 72px;
    font-size: 2rem;
  }
}
