:root {
  --bg-top: #fff3c4;
  --bg-bottom: #cce8ff;
  --card: #fffaf0;
  --card-strong: #ffffff;
  --ink: #24324a;
  --muted: #5d6b80;
  --sun: #ffbf3c;
  --coral: #ff7a59;
  --leaf: #39b56a;
  --berry: #4b74ff;
  --pink: #ff5e96;
  --line: #24324a;
  --shadow: 0 14px 35px rgba(36, 50, 74, 0.16);
  --radius-lg: 32px;
  --radius-md: 22px;
  --radius-sm: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Avenir Next", "Gill Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 30%),
    radial-gradient(circle at bottom right, rgba(255, 255, 255, 0.8), transparent 28%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  opacity: 0.35;
  pointer-events: none;
}

body::before {
  top: -80px;
  right: -50px;
  background: radial-gradient(circle, #fff 0%, #ffdca4 60%, transparent 72%);
}

body::after {
  bottom: -100px;
  left: -40px;
  background: radial-gradient(circle, #fff 0%, #b6f5cf 58%, transparent 72%);
}

.app-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--coral);
}

h1 {
  margin: 0;
  font-family: "Georgia", "Palatino Linotype", serif;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 0.95;
}

.progress-wrap {
  min-width: 180px;
  padding: 16px 18px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
}

.progress-wrap span {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
  text-align: center;
}

.progress-track {
  width: 100%;
  height: 16px;
  border: 3px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--coral), var(--sun));
  transition: width 240ms ease;
}

.lesson-card {
  border: 4px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.scene {
  padding: 28px;
  animation: scene-in 420ms ease;
}

.scene-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 22px;
}

.scene-header-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.scene-header-art {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border: 4px solid var(--line);
  border-radius: 28px;
  font-size: 2.6rem;
  background: #fff;
  box-shadow: 0 8px 0 rgba(36, 50, 74, 0.08);
  animation: floaty 2.6s ease-in-out infinite;
}

.bubble-button {
  cursor: pointer;
  user-select: none;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.bubble-button:hover,
.bubble-button:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 10px 0 rgba(36, 50, 74, 0.08);
  outline: none;
}

.bubble-button.is-popping {
  animation: badge-pop 360ms ease;
}

.scene-header-art-teach {
  background: linear-gradient(180deg, #eff8ff, #d9f0ff);
}

.scene-header-art-quiz {
  background: linear-gradient(180deg, #fff2ea, #ffe0ce);
}

.scene-header-art-finish {
  background: linear-gradient(180deg, #f1ffe9, #ddf7ca);
}

.scene-title {
  margin: 0 0 6px;
  font-family: "Georgia", "Palatino Linotype", serif;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.scene-kind {
  display: inline-flex;
  align-items: center;
  margin-bottom: 10px;
  padding: 6px 12px;
  border: 3px solid var(--line);
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: #fff;
}

.scene-kind-teach {
  background: #dff2ff;
}

.scene-kind-quiz {
  background: #ffe7d8;
}

.scene-kind-finish {
  background: #e5f8dc;
}

.scene-prompt {
  margin: 0;
  font-size: clamp(1rem, 2.6vw, 1.35rem);
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  padding: 10px 14px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
}

.bubble-burst {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 20;
}

.bubble-pop {
  position: absolute;
  left: -10px;
  top: -10px;
  width: 20px;
  height: 20px;
  border: 3px solid var(--line);
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  animation: bubble-burst-out 760ms ease-out forwards;
  animation-delay: var(--delay, 0ms);
}

.bubble-burst-teach .bubble-pop {
  background: #dff2ff;
}

.bubble-burst-quiz .bubble-pop {
  background: #ffe7d8;
}

.bubble-burst-finish .bubble-pop {
  background: #e5f8dc;
}

.stage {
  display: grid;
  gap: 20px;
}

.stage.welcome {
  grid-template-columns: 1.2fr 0.8fr;
  align-items: center;
}

.support-box,
.feedback-box,
.machine-card,
.item-card,
.answer-card {
  border: 3px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--card-strong);
}

.support-box {
  padding: 20px;
  font-size: 1.08rem;
  line-height: 1.4;
  animation: rise-in 420ms ease both;
}

.scene-teach .support-box {
  background: linear-gradient(180deg, #f6fcff, #e8f5ff);
}

.scene-quiz .support-box,
.scene-quiz .feedback-box {
  background: linear-gradient(180deg, #fff9f4, #ffeede);
}

.scene-finish .support-box,
.scene-finish .feedback-box {
  background: linear-gradient(180deg, #f7fff2, #e7f7dd);
}

.scene-teach .badge {
  background: #e4f4ff;
}

.scene-quiz .badge {
  background: #fff0e4;
}

.scene-finish .badge {
  background: #ebf9df;
}

.hero-machine {
  position: relative;
  min-height: 320px;
  padding: 28px;
  background:
    linear-gradient(180deg, #ffe5a9, #ffd479 48%, #ffc44c 100%);
  overflow: hidden;
  animation: rise-in 520ms ease both 60ms;
}

.hero-machine::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 3px dashed rgba(36, 50, 74, 0.25);
  border-radius: 26px;
}

.machine-face {
  position: absolute;
  top: 50px;
  right: 40px;
  width: 132px;
  height: 132px;
  border: 4px solid var(--line);
  border-radius: 30px;
  background: #fff7d6;
  animation: floaty 2.8s ease-in-out infinite;
}

.machine-face::before,
.machine-face::after {
  content: "";
  position: absolute;
  top: 42px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--line);
}

.machine-face::before {
  left: 28px;
}

.machine-face::after {
  right: 28px;
}

.machine-smile {
  position: absolute;
  left: 34px;
  bottom: 24px;
  width: 56px;
  height: 26px;
  border-bottom: 5px solid var(--line);
  border-radius: 0 0 50px 50px;
}

.machine-beam {
  position: absolute;
  left: 118px;
  right: 112px;
  top: 102px;
  height: 74px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.92), rgba(140, 209, 255, 0.95), rgba(255, 255, 255, 0));
  opacity: 0.7;
  filter: blur(5px);
  animation: beam-pulse 1.8s ease-in-out infinite;
}

.pipe {
  position: absolute;
  top: 124px;
  width: 100px;
  height: 26px;
  border: 4px solid var(--line);
  border-radius: 20px;
  background: #fff;
}

.pipe.left {
  left: -14px;
}

.pipe.right {
  right: -14px;
}

.hero-item {
  position: absolute;
  display: grid;
  place-items: center;
  width: 108px;
  height: 108px;
  z-index: 2;
}

.hero-item .item-emoji-wrap {
  margin-bottom: 0;
  min-height: auto;
}

.hero-item .item-emoji {
  font-size: 5.2rem;
}

.hero-item .item-illustration {
  width: 92px;
  height: 92px;
}

.hero-item.input {
  left: 18px;
  top: 82px;
  animation: item-in 2.8s ease-in-out infinite;
}

.hero-item.output {
  right: -8px;
  top: 58px;
  animation: item-out 2.8s ease-in-out infinite;
}

.sparkles {
  position: absolute;
  left: 50%;
  top: 36px;
  transform: translateX(-50%);
  font-size: 2rem;
  letter-spacing: 6px;
  animation: twinkle 1.6s ease-in-out infinite;
}

.visual-grid,
.choice-grid,
.answer-grid,
.mini-machine-row,
.chain-walkthrough {
  display: grid;
  gap: 18px;
}

.visual-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.machine-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.visual-sentence {
  display: grid;
  grid-template-columns: minmax(160px, 220px) auto minmax(180px, 240px) auto minmax(180px, 240px);
  gap: 16px;
  align-items: center;
  justify-content: center;
}

.number-sentence {
  align-items: stretch;
}

.number-chain-result {
  display: grid;
  grid-template-columns: minmax(150px, 200px) auto minmax(120px, 170px) auto minmax(120px, 170px) auto minmax(150px, 200px);
  gap: 16px;
  align-items: center;
  justify-content: center;
}

.arrow {
  font-size: 2rem;
  font-weight: 800;
  color: var(--coral);
  animation: arrow-bop 1.4s ease-in-out infinite;
}

.machine-card,
.item-card,
.answer-card {
  padding: 16px;
  min-height: 156px;
  animation: rise-in 480ms ease both;
}

.machine-card {
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #fff6d5, #ffe087);
  text-align: center;
  position: relative;
}

.machine-icon {
  display: inline-grid;
  place-items: center;
  width: 82px;
  height: 82px;
  margin-bottom: 10px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: #fff;
  font-size: 2.2rem;
  animation: wiggle 3s ease-in-out infinite;
}

.machine-name {
  font-weight: 900;
  font-size: 1.1rem;
}

.machine-label {
  font-size: 0.98rem;
  color: var(--muted);
}

.item-card,
.answer-card,
.choice-card {
  text-align: center;
}

.result-card {
  background: linear-gradient(180deg, #fffdf5, #fff4c8);
  position: relative;
}

.result-card.is-empty {
  border-style: dashed;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.95), rgba(255, 247, 198, 0.95)),
    linear-gradient(180deg, #fffef8, #fff5d4);
}

.result-card.is-correct {
  background: linear-gradient(180deg, #f2fff6, #dff7e8);
}

.result-card.is-wrong {
  background: linear-gradient(180deg, #fff2ef, #ffe1db);
}

.item-emoji-wrap {
  display: grid;
  place-items: center;
  min-height: 86px;
  margin-bottom: 10px;
}

.item-emoji-wrap.is-big {
  min-height: 106px;
}

.item-emoji {
  display: block;
  font-size: 4rem;
}

.item-illustration {
  display: block;
  width: 76px;
  height: 76px;
}

.item-illustration-apple {
  overflow: visible;
}

.item-illustration-circle {
  overflow: visible;
}

.item-illustration-heart {
  overflow: visible;
}

.item-illustration-hat-cat {
  overflow: visible;
}

.item-emoji-wrap.is-big .item-emoji {
  font-size: 5rem;
}

.item-emoji-wrap.is-big .item-illustration {
  width: 92px;
  height: 92px;
}

.item-emoji.is-blue {
  filter: hue-rotate(170deg) saturate(1.7) brightness(1.05);
}

.result-mark {
  display: block;
  margin: 14px 0 10px;
  font-size: 4.8rem;
  font-weight: 900;
  color: var(--berry);
  animation: bubble-pulse 1.6s ease-in-out infinite;
}

.item-name {
  display: block;
  font-weight: 900;
  font-size: 1.1rem;
}

.number-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 10px;
}

.number-dots {
  display: grid;
  grid-template-columns: repeat(3, 22px);
  gap: 10px;
  justify-content: center;
  min-height: 54px;
  margin-top: 8px;
}

.number-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ff8f73, #ff6d54);
  border: 3px solid var(--line);
}

.number-value {
  font-size: 3rem;
  font-weight: 900;
  line-height: 1;
}

.item-tags {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tag {
  padding: 6px 10px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 0.9rem;
  font-weight: 800;
}

.choice-grid,
.answer-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.chain-step {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
  gap: 14px;
  align-items: center;
  padding: 18px;
  border: 3px solid var(--line);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #fff9de, #fff3bf);
  animation: rise-in 480ms ease both;
}

.machine-chip {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.machine-chip .machine-icon {
  margin-bottom: 0;
}

.choice-card {
  width: 100%;
  padding: 18px 14px;
  border: 3px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 8px 0 rgba(36, 50, 74, 0.1);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
  animation: rise-in 440ms ease both;
}

.choice-grid .choice-card:nth-child(1) {
  animation-delay: 40ms;
}

.choice-grid .choice-card:nth-child(2) {
  animation-delay: 100ms;
}

.choice-grid .choice-card:nth-child(3) {
  animation-delay: 160ms;
}

.choice-card:hover,
.choice-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 12px 0 rgba(36, 50, 74, 0.1);
  outline: none;
}

.choice-card.is-correct {
  background: #dff7e8;
  animation: correct-pop 420ms ease;
}

.choice-card.is-wrong {
  background: #ffe1db;
  animation: wrong-shake 380ms ease;
}

.feedback-box {
  padding: 18px 20px;
  background: #fff;
  animation: rise-in 440ms ease both 120ms;
}

.feedback-box strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1.1rem;
}

.controls {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 22px;
}

.controls.compact {
  justify-content: end;
}

.control-button {
  min-width: 120px;
  padding: 14px 18px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
  box-shadow: 0 8px 0 rgba(36, 50, 74, 0.1);
}

.control-button.primary {
  background: linear-gradient(180deg, #ff8f73, #ff6d54);
  color: #fff;
}

.control-button:hover,
.control-button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 10px 0 rgba(36, 50, 74, 0.1);
  outline: none;
}

.control-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.mini-machine-row {
  grid-template-columns: repeat(5, minmax(0, auto));
  align-items: center;
  justify-content: center;
}

.celebration {
  display: grid;
  gap: 18px;
  text-align: center;
}

.celebration-burst {
  padding: 24px;
  border: 4px solid var(--line);
  border-radius: 30px;
  background:
    radial-gradient(circle at top, #fff 0%, #fff5d3 22%, #ffd678 68%, #ffb86b 100%);
  animation: pop-in 480ms ease both;
}

.celebration-burst .big {
  display: block;
  margin-bottom: 10px;
  font-size: clamp(3rem, 8vw, 4.8rem);
  animation: bouncey 1.8s ease-in-out infinite;
}

.recap-list {
  display: grid;
  gap: 14px;
  text-align: left;
}

.recap-list .support-box {
  background: #fff;
}

@keyframes scene-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes pop-in {
  0% {
    opacity: 0;
    transform: scale(0.86);
  }
  70% {
    opacity: 1;
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes badge-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes beam-pulse {
  0%,
  100% {
    opacity: 0.2;
    transform: scaleX(0.9);
  }
  50% {
    opacity: 0.95;
    transform: scaleX(1.05);
  }
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.35;
    transform: translateX(-50%) scale(0.94);
  }
  50% {
    opacity: 1;
    transform: translateX(-50%) scale(1.08);
  }
}

@keyframes item-in {
  0%,
  100% {
    transform: translateX(0) rotate(-4deg);
    opacity: 1;
  }
  28% {
    transform: translateX(28px) rotate(-2deg) scale(1);
    opacity: 1;
  }
  52% {
    transform: translateX(92px) scale(0.82);
    opacity: 0;
  }
}

@keyframes item-out {
  0%,
  48% {
    transform: translateX(-56px) scale(0.7);
    opacity: 0;
  }
  58% {
    transform: translateX(-8px) scale(0.9);
    opacity: 1;
  }
  78% {
    transform: translateX(18px) scale(1.04) rotate(5deg);
    opacity: 1;
  }
  100% {
    transform: translateX(18px) scale(1.04) rotate(5deg);
    opacity: 1;
  }
}

@keyframes floaty {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes wiggle {
  0%,
  100% {
    transform: rotate(0deg);
  }
  10% {
    transform: rotate(-6deg);
  }
  20% {
    transform: rotate(6deg);
  }
  30% {
    transform: rotate(-4deg);
  }
  40% {
    transform: rotate(0deg);
  }
}

@keyframes correct-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes wrong-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-4px);
  }
}

@keyframes bouncey {
  0%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
  55% {
    transform: translateY(0);
  }
  70% {
    transform: translateY(-4px);
  }
}

@keyframes bubble-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes bubble-burst-out {
  0% {
    transform: translate(0, 0) scale(0.35);
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(1.15);
    opacity: 0;
  }
}

@keyframes arrow-bop {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(6px);
  }
}

@media (max-width: 900px) {
  .topbar,
  .scene-header,
  .stage.welcome,
  .visual-grid,
  .visual-sentence,
  .number-chain-result,
  .choice-grid,
  .answer-grid,
  .chain-walkthrough {
    grid-template-columns: 1fr;
  }

  .topbar,
  .scene-header {
    display: grid;
    align-items: start;
  }

  .scene-header-main {
    display: grid;
    grid-template-columns: 1fr;
  }

  .scene-header-art {
    width: 70px;
    height: 70px;
    font-size: 2.1rem;
  }

  .machine-row,
  .mini-machine-row {
    justify-content: start;
  }

  .visual-sentence {
    justify-items: stretch;
  }

  .number-chain-result {
    justify-items: stretch;
  }

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

  .visual-sentence .arrow,
  .number-chain-result .arrow {
    justify-self: center;
    transform: rotate(90deg);
    animation: none;
  }

  .controls {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .control-button {
    width: 100%;
  }

  .machine-beam {
    left: 96px;
    right: 88px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
