:root {
  --ink: #fff6df;
  --soft: #ecd8b0;
  --gold: #e6b54a;
  --font: "Noto Sans SC", "PingFang SC", sans-serif;
  --display: "Fredoka", "Noto Sans SC", sans-serif;
  --ipa: "Andika", "Noto Sans SC", serif;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #16120c;
}

button { font-family: inherit; cursor: pointer; border: 0; }

.hidden { display: none !important; }

.app {
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
  background: #1a1610;
}

.app[data-world="1"] { background: #2a1c12; }
.app[data-world="2"] { background: #143044; }
.app[data-world="3"] { background: #1a2038; }

.sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(70% 40% at 50% 0%, rgba(255, 196, 110, 0.16), transparent 55%),
    linear-gradient(180deg, #2a1c12, #14100c 72%);
}

.app[data-world="1"] .sky {
  background:
    radial-gradient(55% 40% at 80% 8%, rgba(255, 186, 110, 0.28), transparent 50%),
    linear-gradient(180deg, #c47a3a, #7a4a22 46%, #2a1810 100%);
}

.app[data-world="2"] .sky {
  background:
    radial-gradient(50% 36% at 20% 8%, rgba(160, 220, 255, 0.24), transparent 48%),
    linear-gradient(180deg, #3d8ab4, #2a6a58 48%, #143040 100%);
}

.app[data-world="3"] .sky {
  background:
    radial-gradient(40% 30% at 70% 6%, rgba(255, 220, 140, 0.2), transparent 46%),
    linear-gradient(180deg, #3a4a88, #2a3868 42%, #141828 100%);
}

.screen {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
}

.panel {
  background:
    linear-gradient(180deg, rgba(255, 230, 170, 0.12), transparent 42%),
    #2a2216;
  border: 3px solid #1a120a;
  box-shadow: 0 10px 0 #0c0806, inset 0 1px 0 rgba(255, 230, 180, 0.16);
}

.kicker,
.title-en {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
}

.title-stack {
  position: absolute;
  left: 28px;
  top: 28px;
  width: min(460px, calc(100% - 180px));
  padding: 22px 24px 20px;
  border-radius: 24px;
}

.home-art {
  position: absolute;
  right: 4vw;
  top: 12vh;
  width: min(46vw, 620px);
  border-radius: 28px;
  overflow: hidden;
  border: 4px solid #3d2412;
  box-shadow: 0 14px 0 #0c0806;
}

.home-art img {
  display: block;
  width: 100%;
  height: auto;
}

.title-stack h1,
.panel h2,
.board h2 {
  margin: 8px 0 0;
  font-family: var(--display);
  line-height: 1.1;
}

.title-stack h1 {
  font-size: clamp(34px, 6vw, 58px);
  text-shadow: 0 4px 0 #2a1a0c;
}

.title-en { margin-top: 10px; font-size: 16px; }

.home-progress {
  position: absolute;
  top: 26px;
  right: 28px;
  z-index: 3;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 800;
  color: #3d220c;
  background: linear-gradient(180deg, #ffe08a, #d7a03c);
  border: 3px solid #7a4814;
}

.home-panel {
  position: absolute;
  left: 50%;
  bottom: 5vh;
  transform: translateX(-50%);
  width: min(720px, calc(100% - 36px));
  padding: 22px 24px 24px;
  text-align: center;
  border-radius: 24px;
}

.lede,
.tip,
.seek-hint {
  margin: 8px 0 0;
  color: var(--soft);
  line-height: 1.55;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.primary,
.ghost,
.back,
.listen,
.link-btn {
  padding: 12px 22px;
  font-size: 18px;
  font-weight: 800;
  border-radius: 999px;
}

.primary {
  color: #fff8e8;
  background: linear-gradient(180deg, #2f8d62, #1f6046);
  border: 3px solid #123818;
  box-shadow: 0 6px 0 #0a1c0e;
}

.primary.big { padding: 15px 36px; font-size: 24px; }
.primary:hover,
.ghost:hover,
.back:hover { transform: translateY(1px); }

.ghost,
.back,
.link-btn {
  color: #3d220c;
  text-decoration: none;
  background: linear-gradient(180deg, #ffe7a8, #e2b24a);
  border: 3px solid #7a4814;
  box-shadow: 0 6px 0 #4a2a08;
}

.link-btn { display: inline-block; }

.listen {
  color: #fff8e8;
  background: linear-gradient(180deg, #2a7a6e, #145248);
  border: 3px solid #083830;
  box-shadow: 0 4px 0 #042420;
}

.panel-wrap {
  min-height: 100dvh;
  padding: 28px 22px;
}

.panel.wide {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 22px;
  border-radius: 28px;
}

.panel header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.help-grid,
.world-grid,
.stage-grid {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

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

.help-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(20, 10, 6, 0.28);
  border: 2px solid rgba(232, 195, 106, 0.28);
}

.help-card strong { display: block; margin-bottom: 6px; }

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

.world-card,
.stage-node {
  position: relative;
  overflow: hidden;
  text-align: left;
  padding: 0;
  border-radius: 20px;
  color: #fff6df;
  border: 3px solid #5a3010;
  box-shadow: 0 8px 0 #2a1406;
}

.world-card { min-height: 320px; }

.world-card img,
.stage-node img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.world-copy,
.stage-copy {
  position: relative;
  z-index: 1;
  min-height: inherit;
  padding: 16px;
  background: linear-gradient(180deg, rgba(12, 8, 5, 0.15), rgba(12, 8, 5, 0.88) 62%);
}

.world-card h3 {
  margin: 8px 0 0;
  font-family: var(--display);
  font-size: 26px;
}

.world-card p { margin: 6px 0 0; color: #f0d7b0; }

.world-card.open:hover,
.stage-node.open:hover { transform: translateY(-3px); }

.world-card .done {
  display: inline-block;
  margin-top: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(20, 12, 8, 0.45);
  font-weight: 800;
}

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

.stage-node { min-height: 168px; }

.stage-node .stage-num {
  font-family: var(--display);
  font-size: 28px;
}

.stage-node strong { display: block; margin-top: 4px; font-size: 16px; }

.stage-node .meta {
  margin-top: 8px;
  font-size: 13px;
  color: #f0d7b0;
}

.stage-node.done { box-shadow: 0 8px 0 #16381c, 0 0 0 3px #8fce6e inset; }

.play {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px 20px;
}

.play-hud {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.board {
  border-radius: 16px;
  padding: 8px 12px 10px;
  background:
    linear-gradient(180deg, rgba(255, 230, 170, 0.12), transparent 40%),
    #2a2216;
  border: 3px solid #1a120a;
  box-shadow: 0 6px 0 #0c0806;
}

.board.compact h2 {
  margin: 4px 0 0;
  font-size: 18px;
}

.status {
  min-width: 148px;
  text-align: right;
  color: #3d220c;
  background: linear-gradient(180deg, #ffe08a, #d7a03c);
  border-color: #7a4814;
}

.status p { margin: 0 0 4px; font-weight: 800; font-size: 14px; }

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 14px;
  align-items: start;
}

.scene-board {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  border: 4px solid #3d2412;
  box-shadow: 0 12px 0 #0c0806;
  background: #1a120c;
  cursor: pointer;
  aspect-ratio: 16 / 9;
}

.scene-board img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.character {
  --rel-x: 12px;
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0;
  background: none;
  max-width: 14%;
  max-height: 22%;
  filter: drop-shadow(0 8px 10px rgba(20, 10, 4, 0.35));
  z-index: 3;
}

.character img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  pointer-events: none;
}

.character.peeking { filter: drop-shadow(0 6px 8px rgba(20, 10, 4, 0.28)) brightness(0.96); }
.character.air:not(.rel-play) { animation: floaty 1.6s ease-in-out infinite; }

.character.hint:not(.rel-play) {
  animation: pulse 0.7s ease-in-out infinite;
  z-index: 4;
}

.character.found {
  filter: drop-shadow(0 0 16px rgba(255, 224, 120, 0.85));
}

.character.found:not(.rel-play) { animation: hop 0.55s ease; }

.character.rel-play[data-rel="in"],
.character.rel-play[data-rel="behind"] { z-index: 1; }

.character.rel-play[data-rel="on"] { animation: rel-on 1.45s ease-in-out infinite; }
.character.rel-play[data-rel="in"] { animation: rel-in 1.7s ease-in-out infinite; }
.character.rel-play[data-rel="under"] { animation: rel-under 1.7s ease-in-out infinite; }
.character.rel-play[data-rel="next-to"] { animation: rel-next 1.55s ease-in-out infinite; }
.character.rel-play[data-rel="in-front-of"] { animation: rel-front 1.5s ease-in-out infinite; }
.character.rel-play[data-rel="behind"] { animation: rel-behind 1.8s ease-in-out infinite; }
.character.rel-play[data-rel="opposite"] { animation: rel-opposite 1.6s ease-in-out infinite; }
.character.rel-play[data-rel="between"] { animation: rel-between 2s ease-in-out infinite; }
.character.rel-play[data-rel="above"] { animation: rel-above 1.7s ease-in-out infinite; }
.character.rel-play[data-rel="below"] { animation: rel-below 1.55s ease-in-out infinite; }
.character.rel-play[data-rel="over"] { animation: rel-over 1.8s ease-in-out infinite; }
.character.rel-play[data-rel="in-the-front-of"] { animation: rel-in-front 1.7s ease-in-out infinite; }

.character.rel-play[data-rel="on"]::after,
.character.rel-play[data-rel="above"]::after,
.character.rel-play[data-rel="over"]::after,
.character.rel-play[data-rel="under"]::before,
.character.rel-play[data-rel="below"]::before {
  content: "";
  position: absolute;
  left: 50%;
  pointer-events: none;
}

.character.rel-play[data-rel="on"]::after,
.character.rel-play[data-rel="above"]::after,
.character.rel-play[data-rel="over"]::after {
  bottom: -8%;
  width: 92%;
  height: 12px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(242, 208, 106, 0.72), transparent 72%);
}

.character.rel-play[data-rel="under"]::before,
.character.rel-play[data-rel="below"]::before {
  bottom: 90%;
  width: 170%;
  height: 28px;
  transform: translateX(-50%);
  border-radius: 50%;
  border-bottom: 2px dashed rgba(242, 208, 106, 0.8);
  background: radial-gradient(ellipse, rgba(242, 208, 106, 0.28), transparent 70%);
}

.rel-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.rel-layer[hidden] { display: none !important; }

.rel-occluder,
.rel-svg,
.rel-marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.rel-occluder { z-index: 1; }
.rel-svg { z-index: 2; }
.rel-marks { z-index: 3; }

.rel-svg { overflow: visible; }

.rel-path-bg,
.rel-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rel-path-bg {
  stroke: rgba(32, 16, 6, 0.72);
  stroke-width: 8;
}

.rel-path {
  stroke: #ffe27a;
  stroke-width: 4;
  stroke-dasharray: 9 7;
  animation: rel-dash 0.85s linear infinite;
  filter: drop-shadow(0 0 5px rgba(255, 220, 110, 0.7));
}

.rel-layer.strong .rel-path { stroke-width: 5.5; }
.rel-layer.strong .rel-path-bg { stroke-width: 10; }

.rel-mark {
  position: absolute;
  width: 15%;
  height: 24%;
  transform: translate(-50%, -50%);
}

.rel-mark .rel-ring {
  position: absolute;
  inset: 8%;
  border: 4px solid #ffe27a;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(32, 16, 6, 0.45), 0 0 18px rgba(255, 220, 110, 0.55);
  animation: rel-ring 1.5s ease-in-out infinite;
}

.rel-mark.surface { width: 20%; height: 16%; }
.rel-mark.surface .rel-ring { border-radius: 50%; inset: 22% 4%; }

.rel-mark.contain { width: 18%; height: 28%; }
.rel-mark.contain .rel-ring { border-style: dashed; }

.rel-mark.slab .rel-ring {
  background: radial-gradient(ellipse at 50% 40%, rgba(18, 10, 6, 0.22), transparent 68%);
}

.rel-mark small {
  position: absolute;
  left: 50%;
  top: calc(100% - 6%);
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
  color: #3d220c;
  background: linear-gradient(180deg, #ffe08a, #d7a03c);
  border: 2px solid #7a4814;
}

.rel-mark.caption-up small {
  top: auto;
  bottom: calc(100% - 8%);
}

.rel-layer.strong .rel-ring {
  box-shadow: 0 0 28px rgba(255, 224, 120, 0.95);
}

@keyframes floaty {
  0%, 100% { transform: translate(-50%, -56%); }
  50% { transform: translate(-50%, -44%); }
}

@keyframes pulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 224, 120, 0)); }
  50% { filter: drop-shadow(0 0 18px rgba(255, 224, 120, 0.95)); }
}

@keyframes hop {
  0% { transform: translate(-50%, -50%) scale(1); }
  40% { transform: translate(-50%, -62%) scale(1.08); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes rel-on {
  0%, 100% { transform: translate(-50%, -50%); }
  30% { transform: translate(-50%, -70%); }
  52% { transform: translate(-50%, -44%); }
  68% { transform: translate(-50%, -56%); }
}

@keyframes rel-in {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  40% { transform: translate(calc(-50% + var(--rel-x) * 0.2), -48%) scale(0.84); }
  70% { transform: translate(-50%, -56%) scale(1.04); }
}

@keyframes rel-under {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -66%) scale(0.9); }
}

@keyframes rel-next {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(calc(-50% + var(--rel-x)), -54%); }
}

@keyframes rel-front {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -40%) scale(1.1); }
}

@keyframes rel-behind {
  0%, 100% { transform: translate(-50%, -50%) scale(0.94); }
  40% { transform: translate(calc(-50% + var(--rel-x)), -58%) scale(0.98); }
  72% { transform: translate(-50%, -48%) scale(0.92); }
}

@keyframes rel-opposite {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(-50%, -60%); }
}

@keyframes rel-between {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
  25% { transform: translate(calc(-50% - 12px), -54%) rotate(-7deg); }
  75% { transform: translate(calc(-50% + 12px), -54%) rotate(7deg); }
}

@keyframes rel-above {
  0%, 100% { transform: translate(-50%, -58%); }
  50% { transform: translate(-50%, -40%); }
}

@keyframes rel-below {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(-50%, -40%); }
}

@keyframes rel-over {
  0%, 100% { transform: translate(-50%, -50%); }
  35% { transform: translate(calc(-50% + var(--rel-x)), -80%); }
  70% { transform: translate(-50%, -48%); }
}

@keyframes rel-in-front {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  45% { transform: translate(-50%, -42%) scale(0.9); }
  70% { transform: translate(-50%, -56%) scale(1.04); }
}

@keyframes rel-dash {
  to { stroke-dashoffset: -16; }
}

@keyframes rel-ring {
  0%, 100% { transform: scale(0.92); opacity: 0.75; }
  50% { transform: scale(1.06); opacity: 1; }
}

.prompt-panel {
  padding: 16px;
  border-radius: 22px;
}

.sentence {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  font-family: var(--ipa);
  font-size: clamp(22px, 3vw, 30px);
}

.sentence-zh {
  margin: 10px 0 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.5;
  color: #f0d7b0;
}

.word,
.blank {
  padding: 4px 8px;
  border-radius: 10px;
}

.word {
  color: #fff6df;
  background: rgba(255, 246, 223, 0.08);
  border: 2px dashed rgba(232, 195, 106, 0.45);
}

.word:hover { background: rgba(255, 224, 138, 0.18); }

.blank {
  min-width: 4.5em;
  text-align: center;
  color: #ffe08a;
  background: rgba(20, 10, 6, 0.35);
  border: 2px solid #c9a056;
}

.blank.filled {
  color: #16381c;
  background: #b6e38a;
  border-color: #2d6b38;
}

.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.choice {
  min-height: 72px;
  padding: 10px;
  border-radius: 16px;
  color: #3d220c;
  background: linear-gradient(180deg, #fff4d2, #e8c36a);
  border: 3px solid #5a3010;
  box-shadow: 0 5px 0 #2a1406;
}

.choice strong {
  display: block;
  font-family: var(--ipa);
  font-size: 22px;
}

.choice:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.choice.right {
  background: linear-gradient(180deg, #dff6c8, #8fce6e);
  border-color: #16381c;
}

.choice.wrong {
  animation: shake 0.35s ease;
  background: linear-gradient(180deg, #ffd0c4, #d45454);
  color: #fff8e8;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 20;
  margin: 0;
  padding: 10px 20px;
  border-radius: 999px;
  pointer-events: none;
  background: #2a150a;
  border: 2px solid #c9a056;
  font-weight: 800;
}

.word-pop {
  position: fixed;
  z-index: 30;
  min-width: 180px;
  padding: 12px 14px;
  border-radius: 16px;
  color: #3d220c;
  background: #fff8e4;
  border: 3px solid #7a4814;
  box-shadow: 0 10px 0 #2a1406;
}

.word-en {
  margin: 0;
  font-family: var(--ipa);
  font-size: 26px;
}

.word-ipa {
  margin: 4px 0 0;
  color: #7a4814;
}

.word-zh { margin: 6px 0 0; }

.word-pop button {
  margin-top: 10px;
  padding: 7px 12px;
  border-radius: 999px;
  color: #fff8e8;
  background: #2a7a6e;
}

.result-card {
  position: absolute;
  left: 50%;
  bottom: 8vh;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 36px));
  text-align: center;
  padding: 24px;
  border-radius: 28px;
}

.result-words {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.result-words span {
  min-width: 92px;
  padding: 8px 10px;
  border-radius: 12px;
  font-family: var(--ipa);
  font-weight: 800;
  background: #2d6b38;
  border: 2px solid #123818;
}

.result-score {
  margin: 8px 0 0;
  font-family: var(--display);
  font-size: 42px;
  color: var(--gold);
}

@media (max-width: 980px) {
  .play-layout { grid-template-columns: 1fr; }
  .world-grid { grid-template-columns: 1fr; }
  .stage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .help-grid { grid-template-columns: 1fr; }
  .title-stack { left: 16px; top: 18px; width: calc(100% - 32px); }
  .home-progress { top: auto; bottom: 30vh; right: 18px; }
  .home-art { display: none; }
  .choices { grid-template-columns: 1fr; }
}
