:root {
  --ink: #17213d;
  --muted: #66708f;
  --purple: #6c4ff8;
  --purple-dark: #4a31c9;
  --pink: #ff5ca8;
  --orange: #ff9c3d;
  --yellow: #ffd447;
  --teal: #20c7b7;
  --blue: #3c8cff;
  --green: #36c76f;
  --red: #ff5d68;
  --surface: rgba(255, 255, 255, 0.92);
  --shadow: 0 18px 50px rgba(38, 39, 92, 0.16);
  --radius: 28px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overscroll-behavior: none; }
body {
  font-family: Inter, ui-rounded, "Nunito", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 212, 71, .32), transparent 24%),
    radial-gradient(circle at 90% 18%, rgba(255, 92, 168, .20), transparent 28%),
    radial-gradient(circle at 70% 85%, rgba(32, 199, 183, .20), transparent 28%),
    linear-gradient(145deg, #f7f5ff 0%, #eef8ff 52%, #fff8ee 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow-x: hidden;
}
button, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

#app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  min-height: 72px;
  padding: 10px clamp(14px, 3vw, 36px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(249, 249, 255, 0.78);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(92, 82, 171, .10);
}
.brand-mini { display: flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: -.02em; }
.brand-orb {
  width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--purple), var(--pink)); color: white; box-shadow: 0 8px 18px rgba(108,79,248,.3);
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.volume-control { position: relative; }
.music-btn.is-playing { animation: musicPulse 1.8s ease-in-out infinite; }
.music-volume-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: min(320px, calc(100vw - 28px));
  padding: 16px;
  border-radius: 20px;
  background: rgba(255,255,255,.98);
  border: 1px solid rgba(92,82,171,.13);
  box-shadow: 0 20px 50px rgba(38,39,92,.22);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(.97);
  transform-origin: top right;
  transition: opacity .16s ease, transform .16s ease, visibility .16s;
  z-index: 180;
}
.music-volume-panel.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.track-info { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.track-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: #eeeaff; font-size: 22px; }
.track-info div { min-width: 0; display: grid; gap: 2px; }
.track-info strong { font-size: 14px; }
.track-info small { color: var(--muted); font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.music-volume-panel label { display: grid; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .05em; }
.music-volume-panel label > span { display: flex; justify-content: space-between; gap: 12px; }
.music-volume-panel input { width: 100%; accent-color: var(--purple); cursor: pointer; touch-action: manipulation; }
.icon-btn {
  border: 0; width: 46px; height: 46px; border-radius: 15px; background: white; cursor: pointer;
  box-shadow: 0 7px 20px rgba(60, 52, 124, .12); font-size: 22px; transition: .18s ease;
}
.icon-btn:active { transform: scale(.92); }
.hidden { visibility: hidden; pointer-events: none; }
.class-stars {
  height: 46px; min-width: 84px; padding: 0 14px; border-radius: 15px; display: flex; align-items: center; justify-content: center; gap: 7px;
  background: linear-gradient(145deg, #fff7bf, #ffe46d); box-shadow: 0 7px 20px rgba(171, 121, 0, .14); font-size: 20px;
}

.screen { flex: 1; width: 100%; padding: clamp(14px, 2.2vw, 30px); }
.footer { text-align: center; padding: 15px 20px 20px; color: #6e7491; font-size: 13px; font-weight: 700; }
.glass-card { background: var(--surface); border: 1px solid rgba(255,255,255,.9); box-shadow: var(--shadow); border-radius: var(--radius); }

.home-screen { width: min(1480px, 100%); margin: 0 auto; display: grid; gap: 22px; }
.hero-card { min-height: 330px; display: grid; grid-template-columns: .9fr 1.2fr; overflow: hidden; position: relative; }
.hero-card::before { content: ""; position: absolute; inset: 0; background: linear-gradient(115deg, rgba(108,79,248,.06), transparent 50%); pointer-events: none; }
.hero-visual { min-height: 330px; position: relative; display: grid; place-items: center; background: linear-gradient(145deg, #6d50f8, #a65cff 58%, #ff6eb2); overflow: hidden; }
.hero-visual::before, .hero-visual::after { content: ""; position: absolute; border: 2px solid rgba(255,255,255,.22); border-radius: 50%; }
.hero-visual::before { width: 360px; height: 360px; }
.hero-visual::after { width: 240px; height: 240px; }
.rocket { font-size: clamp(88px, 10vw, 150px); transform: rotate(-8deg); filter: drop-shadow(0 18px 16px rgba(47,20,112,.25)); animation: float 3s ease-in-out infinite; z-index: 2; }
.planet { position: absolute; display: grid; place-items: center; border-radius: 50%; font-weight: 1000; color: white; box-shadow: 0 12px 28px rgba(45,21,105,.25); z-index: 3; }
.p1 { width: 68px; height: 68px; background: var(--orange); left: 14%; top: 18%; transform: rotate(-10deg); }
.p2 { width: 62px; height: 62px; background: var(--teal); right: 13%; bottom: 17%; transform: rotate(9deg); }
.p3 { width: 52px; height: 52px; background: var(--yellow); color: #8b6200; right: 13%; top: 16%; }
.spark { color: white; position: absolute; font-size: 24px; animation: twinkle 1.7s infinite alternate; }
.s1 { left: 16%; bottom: 18%; } .s2 { right: 24%; top: 40%; animation-delay: .5s; } .s3 { left: 31%; top: 11%; animation-delay: .9s; }
.hero-copy { padding: clamp(28px, 4vw, 56px); display: flex; flex-direction: column; justify-content: center; position: relative; }
.eyebrow { font-size: 13px; letter-spacing: .16em; font-weight: 1000; color: var(--purple); }
.hero-copy h1 { margin: 10px 0 14px; font-size: clamp(42px, 5vw, 74px); line-height: .94; letter-spacing: -.055em; }
.hero-copy h1 span { color: var(--purple); }
.hero-copy p { max-width: 720px; margin: 0; color: var(--muted); font-size: clamp(16px, 1.5vw, 20px); line-height: 1.55; font-weight: 600; }
.setup-row { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; }
.select-field { min-width: 180px; display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.select-field select { border: 2px solid #ece9ff; background: #f9f8ff; color: var(--ink); border-radius: 14px; padding: 12px 14px; font-weight: 900; outline: none; }
.select-field select:focus { border-color: var(--purple); }
.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.mode-card {
  min-height: 210px; border: 0; border-radius: 26px; padding: 24px; text-align: left; color: white; cursor: pointer; position: relative; overflow: hidden;
  box-shadow: var(--shadow); transition: transform .18s ease, box-shadow .18s ease; display: flex; gap: 18px; align-items: flex-start;
}
.mode-card::after { content: ""; position: absolute; width: 200px; height: 200px; border-radius: 50%; background: rgba(255,255,255,.12); right: -65px; bottom: -90px; }
.mode-card:hover { transform: translateY(-5px); box-shadow: 0 24px 55px rgba(38,39,92,.23); }
.mode-card:active { transform: scale(.985); }
.tracing-card { background: linear-gradient(145deg, #6b4ef6, #9d5cff); }
.sorting-card { background: linear-gradient(145deg, #13bdae, #42d984); }
.balloon-card { background: linear-gradient(145deg, #ff727d, #ff9b43); }
.mode-icon { font-size: 48px; filter: drop-shadow(0 8px 14px rgba(0,0,0,.16)); }
.mode-number { font-size: 12px; letter-spacing: .14em; font-weight: 1000; opacity: .82; }
.mode-card h2 { margin: 6px 0 8px; font-size: clamp(23px, 2.2vw, 34px); letter-spacing: -.035em; }
.mode-card p { margin: 0; font-weight: 650; line-height: 1.45; opacity: .9; }
.play-pill { position: absolute; right: 20px; bottom: 18px; z-index: 2; background: rgba(255,255,255,.20); border: 1px solid rgba(255,255,255,.35); border-radius: 999px; padding: 9px 14px; font-weight: 1000; }
.teacher-tip { padding: 16px 22px; display: flex; gap: 13px; align-items: center; color: var(--muted); }
.teacher-tip span { font-size: 26px; }.teacher-tip p { margin: 0; }

/* Shared game UI */
.game-shell { width: min(1540px, 100%); margin: 0 auto; display: grid; gap: 16px; }
.game-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.game-heading h1 { margin: 0; font-size: clamp(28px, 3vw, 44px); letter-spacing: -.04em; }
.game-heading p { margin: 4px 0 0; color: var(--muted); font-weight: 650; }
.game-controls { display: flex; gap: 10px; flex-wrap: wrap; }
.action-btn {
  border: 0; border-radius: 15px; min-height: 48px; padding: 0 18px; font-weight: 1000; cursor: pointer; box-shadow: 0 8px 20px rgba(60,52,124,.12); transition: .15s ease;
}
.action-btn:active { transform: scale(.95); }
.primary-btn { color: white; background: linear-gradient(145deg, var(--purple), var(--pink)); }
.secondary-btn { color: var(--ink); background: white; }
.success-btn { color: white; background: linear-gradient(145deg, #1db790, #34d46f); }
.status-chip { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; padding: 9px 14px; background: #fff; box-shadow: 0 7px 18px rgba(42,43,91,.10); font-weight: 900; }

/* Tracing */
.tracing-arena { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.trace-panel { background: white; border-radius: 28px; box-shadow: var(--shadow); overflow: hidden; border: 5px solid transparent; position: relative; }
.trace-panel.player-1 { border-color: rgba(108,79,248,.35); }
.trace-panel.player-2 { border-color: rgba(255,92,168,.35); }
.player-strip { padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; font-weight: 1000; }
.player-1 .player-strip { background: #eeeaff; color: #5436dc; }
.player-2 .player-strip { background: #ffe9f3; color: #df3b86; }
.trace-score { min-width: 72px; text-align: center; background: white; border-radius: 999px; padding: 7px 12px; }
.canvas-wrap { min-height: clamp(390px, 56vh, 690px); position: relative; background-image: radial-gradient(#e2e4f0 1.3px, transparent 1.3px); background-size: 24px 24px; touch-action: none; }
.trace-canvas, .trail-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.trail-canvas { pointer-events: none; }
.trace-message { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 10px 16px; border-radius: 999px; background: rgba(255,255,255,.94); box-shadow: 0 8px 22px rgba(45,45,90,.16); font-weight: 1000; opacity: 0; transition: .2s; pointer-events: none; white-space: nowrap; }
.trace-message.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.trace-badge { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; opacity: 0; transform: scale(.5); transition: .35s cubic-bezier(.2,1.6,.3,1); }
.trace-badge.show { opacity: 1; transform: scale(1); }
.trace-badge > div { width: 165px; height: 165px; border-radius: 50%; display: grid; place-items: center; text-align: center; background: rgba(255,255,255,.94); box-shadow: 0 18px 50px rgba(42,43,91,.25); font-size: 26px; font-weight: 1000; }

/* Sorting */
.sorting-arena { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.learning-panel { min-height: 650px; background: white; border-radius: 28px; box-shadow: var(--shadow); padding: clamp(18px, 2vw, 28px); position: relative; overflow: hidden; }
.learning-panel h2 { margin: 0; font-size: clamp(26px, 2.7vw, 40px); letter-spacing: -.035em; }
.learning-panel .instruction { margin: 7px 0 18px; color: var(--muted); font-weight: 700; }
.picture-drop {
  min-height: 270px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 4px dashed #d8d2ff; border-radius: 24px; background: #f9f8ff; transition: .2s;
}
.picture-drop.hover { transform: scale(1.02); border-color: var(--purple); background: #f0edff; }
.big-emoji { font-size: clamp(95px, 11vw, 155px); filter: drop-shadow(0 12px 10px rgba(80,60,120,.13)); }
.picture-name { font-size: 28px; font-weight: 1000; }
.letter-tray { margin-top: 22px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.letter-card {
  min-height: 100px; border: 0; border-radius: 20px; color: white; font-size: 48px; font-weight: 1000; box-shadow: 0 10px 20px rgba(57,45,113,.16); touch-action: none; cursor: grab;
}
.letter-card:nth-child(4n+1) { background: linear-gradient(145deg, #6c4ff8, #9d6aff); }
.letter-card:nth-child(4n+2) { background: linear-gradient(145deg, #ff5ca8, #ff83bc); }
.letter-card:nth-child(4n+3) { background: linear-gradient(145deg, #22bfae, #41d58d); }
.letter-card:nth-child(4n+4) { background: linear-gradient(145deg, #ff963c, #ffc142); }
.draggable-active { position: fixed !important; z-index: 1000; pointer-events: none; transform: scale(1.12) rotate(-4deg); box-shadow: 0 24px 45px rgba(34,30,72,.28) !important; }
.bounce { animation: bounceBack .48s ease; }
.correct-pulse { animation: correctPulse .75s ease; }

.number-task { display: flex; align-items: center; gap: 14px; padding: 15px 18px; border-radius: 20px; background: #edfff6; margin-bottom: 14px; }
.target-number { width: 82px; height: 82px; border-radius: 24px; display: grid; place-items: center; color: white; background: linear-gradient(145deg, #13bdae, #42d984); font-size: 48px; font-weight: 1000; box-shadow: 0 12px 24px rgba(24,182,148,.25); }
.number-task strong { font-size: 22px; }
.tree-area { height: 330px; border-radius: 26px; background: linear-gradient(#bfeaff 0 48%, #9be16b 48% 100%); position: relative; overflow: hidden; }
.tree-trunk { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: 80px; height: 180px; background: #925330; border-radius: 20px 20px 0 0; }
.tree-crown { position: absolute; width: 300px; height: 220px; left: 50%; top: 15px; transform: translateX(-50%); background: #35b967; border-radius: 48% 52% 45% 55%; box-shadow: inset -18px -12px rgba(0,0,0,.06); }
.apple { position: absolute; width: 58px; height: 58px; border: 0; background: none; display: grid; place-items: center; font-size: 48px; cursor: grab; touch-action: none; filter: drop-shadow(0 7px 5px rgba(57,45,113,.2)); }
.apple.in-basket { position: static !important; transform: none !important; }
.basket-zone { min-height: 125px; margin-top: 14px; border: 4px dashed #ffc667; border-radius: 22px; background: #fff8e7; padding: 12px; display: flex; gap: 4px; align-items: center; justify-content: center; flex-wrap: wrap; transition: .2s; }
.basket-zone.hover { border-color: #ff9135; background: #fff1cf; transform: scale(1.01); }
.basket-icon { font-size: 62px; }
.basket-count { font-weight: 1000; font-size: 20px; }

/* Balloons */
.balloon-game { min-height: calc(100vh - 150px); display: grid; grid-template-rows: auto auto 1fr; gap: 12px; }
.command-board { background: linear-gradient(145deg, #5d43dc, #9d5cff); color: white; border-radius: 24px; padding: 18px clamp(18px, 3vw, 34px); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.command-board .speaker { font-size: 38px; }
.command-text { font-size: clamp(21px, 2.7vw, 38px); font-weight: 1000; line-height: 1.15; flex: 1; }
.timer-ring { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.18); border: 4px solid rgba(255,255,255,.4); font-weight: 1000; font-size: 22px; }
.player-scoreboard { display: grid; gap: 10px; }
.player-score {
  min-height: 62px; border-radius: 18px; padding: 10px 16px; display: flex; align-items: center; justify-content: center; gap: 10px; color: white; box-shadow: 0 8px 20px rgba(40,40,90,.15); font-size: 20px; font-weight: 1000;
}
.balloon-field { min-height: 610px; position: relative; overflow: hidden; border-radius: 28px; background:
  linear-gradient(rgba(255,255,255,.2), rgba(255,255,255,.2)),
  linear-gradient(#a8ddff 0%, #eaf8ff 74%, #bfe58d 74% 100%); box-shadow: var(--shadow); touch-action: none;
}
.balloon-field::before { content: "☁️　　　　☁️　　　　　　　　☁️"; position: absolute; top: 24px; left: 4%; right: 4%; font-size: 62px; opacity: .72; white-space: nowrap; }
.lane-divider { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.45); border-left: 2px dashed rgba(75,102,157,.18); pointer-events: none; }
.balloon {
  --balloon-color: #ff5d68;
  position: absolute; width: 92px; height: 112px; border: 0; border-radius: 52% 48% 48% 52% / 55% 55% 45% 45%;
  background: radial-gradient(circle at 32% 25%, rgba(255,255,255,.8), transparent 18%), var(--balloon-color);
  box-shadow: inset -12px -13px rgba(0,0,0,.08), 0 14px 24px rgba(46,63,104,.19); color: white; font-weight: 1000; font-size: 38px; cursor: pointer; touch-action: none;
  display: grid; place-items: center; will-change: transform;
}
.balloon::after { content: ""; position: absolute; width: 2px; height: 58px; background: rgba(73,80,105,.55); top: 105px; left: 50%; }
.balloon::before { content: ""; position: absolute; width: 17px; height: 13px; background: var(--balloon-color); bottom: -7px; left: 50%; transform: translateX(-50%) rotate(45deg); }
.balloon.wrong { animation: shake .4s ease; filter: grayscale(.4); }
.pop-particle { position: absolute; pointer-events: none; font-size: 25px; animation: particleBurst .8s ease-out forwards; z-index: 10; }
.feedback-toast { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(.8); border-radius: 24px; padding: 20px 32px; background: rgba(255,255,255,.95); box-shadow: 0 20px 60px rgba(40,40,90,.24); font-size: 28px; font-weight: 1000; opacity: 0; pointer-events: none; z-index: 20; transition: .25s; }
.feedback-toast.show { opacity: 1; transform: translate(-50%,-50%) scale(1); }

/* Celebration */
.celebration-overlay { position: fixed; inset: 0; z-index: 5000; display: grid; place-items: center; background: rgba(46,37,105,.34); backdrop-filter: blur(8px); animation: fadeIn .25s ease; }
.celebration-card { width: min(560px, 90vw); background: white; border-radius: 34px; padding: 34px; text-align: center; box-shadow: 0 30px 90px rgba(34,28,83,.36); position: relative; overflow: hidden; }
.celebration-card .cup { font-size: 110px; animation: float 1.5s ease-in-out infinite; }
.celebration-card h2 { margin: 6px 0; font-size: 42px; letter-spacing: -.04em; }
.celebration-card p { color: var(--muted); font-weight: 700; font-size: 18px; }
.star-award { font-size: 32px; letter-spacing: 6px; }

@keyframes float { 0%,100% { transform: translateY(0) rotate(-8deg);} 50% { transform: translateY(-13px) rotate(-3deg);} }
@keyframes twinkle { from { opacity: .35; transform: scale(.7);} to { opacity: 1; transform: scale(1.25);} }
@keyframes bounceBack { 0%{transform:scale(1)} 35%{transform:scale(.82) rotate(-5deg)} 68%{transform:scale(1.12) rotate(4deg)} 100%{transform:scale(1)} }
@keyframes correctPulse { 0%,100%{transform:scale(1)} 45%{transform:scale(1.08); box-shadow:0 0 0 18px rgba(54,199,111,.16)} }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-9px)} 40%{transform:translateX(8px)} 60%{transform:translateX(-5px)} 80%{transform:translateX(4px)} }
@keyframes particleBurst { from { opacity:1; transform:translate(0,0) scale(.4) rotate(0)} to { opacity:0; transform:translate(var(--dx),var(--dy)) scale(1.4) rotate(320deg)} }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

@media (max-width: 1000px) {
  .hero-card { grid-template-columns: 1fr; }
  .hero-visual { min-height: 230px; }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card { min-height: 170px; }
  .sorting-arena { grid-template-columns: 1fr; }
  .tracing-arena { grid-template-columns: 1fr; }
  .canvas-wrap { min-height: 520px; }
}
@media (max-width: 680px) {
  .brand-mini span:last-child { display: none; }
  .screen { padding: 10px; }
  .topbar { min-height: 62px; padding: 8px 10px; }
  .icon-btn { width: 42px; height: 42px; }
  .class-stars { height: 42px; min-width: 70px; }
  .hero-copy { padding: 25px 20px; }
  .mode-card { padding: 20px; }
  .mode-icon { font-size: 40px; }
  .letter-tray { grid-template-columns: repeat(2,1fr); }
  .learning-panel { min-height: 560px; }
  .balloon { width: 72px; height: 90px; font-size: 30px; }
  .balloon::after { top: 85px; }
}

@keyframes musicPulse {
  0%, 100% { box-shadow: 0 7px 20px rgba(60,52,124,.12); transform: scale(1); }
  50% { box-shadow: 0 9px 24px rgba(108,79,248,.28); transform: scale(1.04); }
}
