:root {
  color-scheme: light;
  --ink: #2a2440;
  --muted: #7b7392;
  --paper: #fef6ec;
  --accent: #ef6b4d;
  --accent-dark: #c8462c;
  --gold: #f4a93b;
  --green: #46a86b;
  --blue: #4a8fd4;
  --card: #ffffff;
  --radius: 22px;
  --shadow: 0 16px 40px rgba(60, 45, 90, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 10% 0%, rgba(244, 169, 59, 0.18), transparent 45%),
    radial-gradient(120% 90% at 100% 10%, rgba(74, 143, 212, 0.16), transparent 50%),
    var(--paper);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", "STKaiti", "KaiTi", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow: hidden;
}

button { font: inherit; border: 0; cursor: pointer; color: inherit; }

/* ---------- layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) clamp(12px, 3vw, 28px) calc(12px + var(--safe-bottom));
  gap: clamp(8px, 1.4vh, 16px);
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.round-btn {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-dark);
  transition: transform 0.12s ease;
}
.round-btn:active { transform: scale(0.92); }

.title-block { text-align: center; min-width: 0; }
.title-block h1 {
  margin: 0;
  font-size: clamp(26px, 4.4vw, 40px);
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 2px;
}
#poemMeta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: clamp(13px, 1.8vw, 16px);
}
.grade-tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- stage ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}
.scene-host {
  position: relative;
  flex: 1;
  border-radius: var(--radius);
  background: #dceff6;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.scene-host svg {
  display: block;
  width: 100%;
  height: 100%;
}
.scene-host.replay { animation: sceneFlash 0.6s ease; }

/* per-line focus linkage */
.scene-host [data-line] {
  transition: opacity 0.6s ease, filter 0.6s ease;
}
.focus-dim { opacity: 0.3; filter: blur(0.6px) saturate(0.8); }
.focus-on {
  animation: focusPop 1.4s ease;
  transform-box: fill-box;
  transform-origin: center;
  filter: drop-shadow(0 0 10px rgba(255, 244, 188, 0.85));
}

/* ---------- verse ---------- */
.verse {
  text-align: center;
  padding: 4px 8px;
  min-height: clamp(56px, 11vh, 96px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.verse-line {
  font-size: clamp(26px, 5.4vw, 46px);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: 3px;
}
.verse-line .ch {
  display: inline-block;
  animation: charPop 0.5s ease both;
  animation-delay: calc(var(--i) * 0.07s);
}
.verse-line .blank {
  color: var(--accent);
  opacity: 0.55;
}
.verse-cue {
  font-size: clamp(14px, 2.2vw, 19px);
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- controls ---------- */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.4vh, 14px);
}

.steps {
  display: flex;
  gap: 10px;
  align-items: center;
}
.step {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 4px 12px rgba(60, 45, 90, 0.08);
  color: var(--muted);
  font-size: clamp(13px, 1.8vw, 16px);
  font-weight: 700;
  transition: all 0.2s ease;
}
.step .dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e7e0f0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.step.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(239, 107, 77, 0.4);
}
.step.active .dot { background: rgba(255, 255, 255, 0.32); color: #fff; }
.step.done .dot { background: var(--green); color: #fff; }

.main-action {
  width: min(560px, 100%);
  min-height: clamp(64px, 10vh, 86px);
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--accent), var(--gold));
  color: #fff;
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow: 0 14px 30px rgba(239, 107, 77, 0.4);
  transition: transform 0.12s ease, filter 0.2s ease;
}
.main-action:active { transform: scale(0.97); }
.main-action.is-busy {
  filter: grayscale(0.2) brightness(0.96);
  pointer-events: none;
}
.main-action.is-go { background: linear-gradient(160deg, var(--green), #6fc88a); box-shadow: 0 14px 30px rgba(70, 168, 107, 0.4); }

.mini-nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.mini-btn {
  min-height: 50px;
  padding: 0 18px;
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 6px 14px rgba(60, 45, 90, 0.1);
  font-size: clamp(15px, 2.2vw, 18px);
  font-weight: 700;
  color: var(--ink);
  transition: transform 0.12s ease;
}
.mini-btn:active { transform: scale(0.94); }
.mini-btn[disabled] { opacity: 0.4; pointer-events: none; }

.hint-text {
  margin: 0;
  min-height: 22px;
  color: var(--muted);
  font-size: clamp(13px, 2vw, 17px);
  text-align: center;
}
.hint-text.error { color: var(--accent-dark); font-weight: 700; }

/* ---------- 看图背诵版 (simple.html) ---------- */
.s-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) clamp(12px, 3vw, 28px) calc(10px + var(--safe-bottom));
  gap: clamp(8px, 1.4vh, 14px);
}
a.round-btn { text-decoration: none; }
.s-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.s-bg { position: absolute; inset: 0; }
.s-bg svg { display: block; width: 100%; height: 100%; }
.s-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: clamp(14px, 4vh, 40px) clamp(16px, 5vw, 60px);
  overflow: auto;
  text-align: center;
}
.s-title {
  font-size: clamp(24px, 4.4vw, 38px);
  font-weight: 900;
  letter-spacing: 2px;
  color: #2a2440;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.85);
}
.s-by {
  font-size: clamp(13px, 2vw, 17px);
  color: #4a4360;
  text-shadow: 0 2px 8px rgba(255, 255, 255, 0.85);
  margin-bottom: 6px;
}
.s-body {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.4vh, 14px);
  background: rgba(255, 255, 255, 0.34);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border-radius: 18px;
  padding: clamp(12px, 3vh, 26px) clamp(16px, 4vw, 40px);
}
.s-line {
  font-size: clamp(22px, 4.6vw, 40px);
  font-weight: 800;
  line-height: 1.5;
  letter-spacing: 3px;
  color: #211c36;
  text-shadow: 0 2px 12px rgba(255, 255, 255, 0.9);
}
.s-ch { display: inline-block; }
.s-ch.box {
  min-width: 1em;
  margin: 0 1px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 0 0 2px rgba(239, 107, 77, 0.5);
  color: transparent;
  cursor: pointer;
}
.s-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.s-btn {
  flex: 1 1 0;
  max-width: 280px;
  min-height: clamp(60px, 9vh, 80px);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: clamp(20px, 3.6vw, 28px);
  font-weight: 900;
  color: var(--ink);
  transition: transform 0.12s ease;
}
.s-btn:active { transform: scale(0.97); }
.s-btn.nav { flex: 0 0 auto; max-width: 160px; font-size: clamp(16px, 2.6vw, 22px); color: var(--blue); }
.s-btn.nav:disabled { opacity: 0.35; pointer-events: none; }
.s-btn.primary { background: linear-gradient(160deg, var(--accent), var(--gold)); color: #fff; }
.s-btn.active { background: var(--blue); color: #fff; }
.ver-link {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  text-decoration: none;
  white-space: nowrap;
}

/* ---------- drawer ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
}
.drawer[hidden] { display: none; }
.drawer-mask {
  position: absolute;
  inset: 0;
  background: rgba(40, 30, 60, 0.45);
  animation: fadeIn 0.2s ease;
}
.drawer-panel {
  position: absolute;
  inset: 0 0 0 auto;
  width: min(440px, 88vw);
  background: var(--paper);
  box-shadow: -12px 0 40px rgba(40, 30, 60, 0.3);
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideIn 0.25s ease;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-head h2 { margin: 0; font-size: 24px; }
.poem-grid {
  display: block;
  overflow: auto;
  padding: 2px;
}
.grade-group { margin-bottom: 18px; }
.grade-head {
  position: sticky;
  top: 0;
  margin: 0 0 10px;
  padding: 6px 2px;
  background: var(--paper);
  font-size: 15px;
  color: var(--accent-dark);
  font-weight: 800;
  z-index: 1;
}
.grade-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.ptag {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent-soft, #e8f2ff);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  vertical-align: middle;
}
.poem-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 6px 16px rgba(60, 45, 90, 0.1);
  text-align: left;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
.poem-card:active { transform: scale(0.96); }
.poem-card.active { outline: 3px solid var(--accent); }
.poem-card strong { font-size: 19px; font-weight: 900; }
.poem-card small { color: var(--muted); font-size: 13px; }
.poem-card .stars { font-size: 14px; letter-spacing: 2px; color: var(--gold); }

/* ---------- celebrate ---------- */
.celebrate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(40, 30, 60, 0.5);
}
.celebrate[hidden] { display: none; }
.celebrate-card {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 14px;
  padding: 32px 40px;
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
  animation: popIn 0.4s ease;
}
.celebrate-emoji { font-size: 64px; animation: cheer 0.8s ease infinite alternate; }
.celebrate-card h2 { margin: 0; font-size: 28px; }
.celebrate-actions { display: flex; gap: 12px; justify-content: center; }
.text-btn {
  min-height: 56px;
  padding: 0 24px;
  border-radius: 16px;
  background: #eee6f3;
  font-size: 18px;
  font-weight: 800;
}
.text-btn.primary { background: var(--accent); color: #fff; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -10%;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  animation: fall linear forwards;
}

/* ---------- scene animation classes ---------- */
.float-slow { animation: floatSlow 5s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
.boat-move { animation: boatMove 9s ease-in-out infinite alternate; transform-box: fill-box; }
.water-line { animation: waterDrift 6s linear infinite; }
.sun-glow { animation: sunGlow 4s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
.moon-pulse { animation: moonPulse 5s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
.bird-fly { animation: birdFly 6s ease-in-out infinite alternate; transform-box: fill-box; }
.butterfly { animation: butterflyPath 6s ease-in-out infinite alternate; transform-box: fill-box; }
.firework-a { animation: firework 2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.firework-b { animation: firework 2.4s ease-in-out 0.5s infinite; transform-box: fill-box; transform-origin: center; }
.sway { animation: sway 4s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: bottom center; }
.twinkle { animation: twinkle 2.6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
.twinkle.d1 { animation-delay: 0.6s; }
.twinkle.d2 { animation-delay: 1.2s; }
.twinkle.d3 { animation-delay: 1.8s; }
.petal { animation: petalFall 7s linear infinite; transform-box: fill-box; }
.petal.d1 { animation-delay: 1.5s; }
.petal.d2 { animation-delay: 3s; }
.petal.d3 { animation-delay: 4.5s; }
.candle { animation: candle 1.2s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: bottom center; }
.mist { animation: mistDrift 16s ease-in-out infinite alternate; }
.shimmer { animation: shimmer 3.4s ease-in-out infinite alternate; }
.firefly {
  animation: fireflyFloat 6s ease-in-out infinite alternate, twinkle 2.4s ease-in-out infinite alternate;
  transform-box: fill-box;
  transform-origin: center;
}
.firefly.d1 { animation-delay: -2s, -1s; }
.firefly.d2 { animation-delay: -4s, -1.6s; }
.snowflake { animation: snowFall linear infinite; }
.cloud-drift { animation: cloudDrift 22s ease-in-out infinite alternate; }
.fall-leaf { animation: leafFall linear infinite; transform-box: fill-box; }
@keyframes snowFall {
  0% { transform: translate(0, -30px); opacity: 0; }
  12% { opacity: 0.95; }
  100% { transform: translate(26px, 500px); opacity: 0.2; }
}
@keyframes cloudDrift { from { transform: translateX(-26px); } to { transform: translateX(40px); } }
@keyframes leafFall {
  0% { transform: translate(0, -20px) rotate(0deg); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translate(-50px, 500px) rotate(320deg); opacity: 0.2; }
}

@keyframes charPop {
  0% { opacity: 0; transform: translateY(10px) scale(0.8); color: var(--accent); }
  60% { opacity: 1; transform: translateY(-2px) scale(1.05); color: var(--accent); }
  100% { opacity: 1; transform: translateY(0) scale(1); color: inherit; }
}
@keyframes focusPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.14); }
  100% { transform: scale(1.05); }
}
@keyframes sceneFlash { 0% { transform: scale(0.995); } 100% { transform: scale(1); } }
@keyframes floatSlow { from { transform: translateY(0); } to { transform: translateY(-12px); } }
@keyframes boatMove { from { transform: translateX(-22px) translateY(5px); } to { transform: translateX(34px) translateY(-4px); } }
@keyframes waterDrift { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -120; } }
@keyframes sunGlow { from { opacity: 0.75; transform: scale(0.97); } to { opacity: 1; transform: scale(1.05); } }
@keyframes moonPulse { from { opacity: 0.78; transform: scale(0.97); } to { opacity: 1; transform: scale(1.05); } }
@keyframes birdFly { from { transform: translateX(-30px) translateY(6px); } to { transform: translateX(46px) translateY(-22px); } }
@keyframes butterflyPath { from { transform: translateX(-30px) translateY(14px) rotate(-8deg); } to { transform: translateX(60px) translateY(-30px) rotate(10deg); } }
@keyframes firework { 0% { opacity: 0.1; transform: scale(0.3); } 45% { opacity: 1; transform: scale(1); } 100% { opacity: 0.05; transform: scale(1.5); } }
@keyframes sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@keyframes twinkle { from { opacity: 0.25; transform: scale(0.7); } to { opacity: 1; transform: scale(1.15); } }
@keyframes petalFall {
  0% { transform: translate(0,0) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  100% { transform: translate(-40px, 260px) rotate(220deg); opacity: 0; }
}
@keyframes candle { from { transform: scaleY(0.86) translateY(2px); opacity: 0.8; } to { transform: scaleY(1.05); opacity: 1; } }
@keyframes mistDrift { from { transform: translateX(-44px); } to { transform: translateX(44px); } }
@keyframes shimmer { from { opacity: 0.25; } to { opacity: 0.7; } }
@keyframes fireflyFloat { from { transform: translate(0, 0); } to { transform: translate(22px, -18px); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes popIn { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes cheer { from { transform: rotate(-10deg) scale(1); } to { transform: rotate(10deg) scale(1.1); } }
@keyframes fall { to { transform: translateY(120vh) rotate(540deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; }
}

/* landscape phones / short screens: shrink verse + scene a touch */
@media (max-height: 540px) {
  .verse { min-height: 44px; }
  .main-action { min-height: 56px; }
}
