: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(210, 180, 255, 0.2), transparent 46%),
    linear-gradient(180deg, #4a3a88, #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(38vw, 420px);
  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: 300px; }

.world-art,
.stage-art {
  position: absolute;
  inset: 0;
}

.world-card[data-world="1"] .world-art,
.stage-node[data-world="1"] .stage-art {
  background:
    radial-gradient(circle at 78% 18%, rgba(255, 210, 120, 0.35), transparent 36%),
    linear-gradient(160deg, #c47a3a, #7a4a22 58%, #2a1810);
}

.world-card[data-world="2"] .world-art,
.stage-node[data-world="2"] .stage-art {
  background:
    radial-gradient(circle at 20% 16%, rgba(160, 230, 255, 0.3), transparent 38%),
    linear-gradient(160deg, #3d8ab4, #2a6a58 58%, #143040);
}

.world-card[data-world="3"] .world-art,
.stage-node[data-world="3"] .stage-art {
  background:
    radial-gradient(circle at 70% 12%, rgba(210, 180, 255, 0.32), transparent 40%),
    linear-gradient(160deg, #4a3a88, #2a3868 58%, #141828);
}

.world-art .seal,
.stage-art .seal {
  position: absolute;
  top: 18px;
  right: 18px;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-family: var(--display);
  font-size: 28px;
  color: #3d220c;
  background: radial-gradient(circle at 35% 30%, #ffe08a, #d7a03c);
  border: 3px solid #7a4814;
  box-shadow: 0 6px 0 #2a1406;
}

.mini-row {
  position: absolute;
  left: 18px;
  top: 88px;
  display: flex;
  gap: 8px;
}

.mini-tile {
  display: grid;
  place-items: center;
  min-width: 54px;
  height: 72px;
  padding: 0 8px;
  border-radius: 10px;
  font-family: var(--ipa);
  font-size: 18px;
  color: #3d220c;
  background: linear-gradient(180deg, #fff4d2, #e8c36a);
  border: 3px solid #5a3010;
  box-shadow: 0 4px 0 #2a1406;
}

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

.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(2, minmax(0, 1fr)); }

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

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

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

.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-main {
  padding: 16px;
  border-radius: 22px;
}

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

.flip-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 920px;
  min-width: 0;
  margin: 16px auto 0;
  padding: 18px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 196, 110, 0.12), transparent 50%),
    linear-gradient(180deg, #4a3018, #2a1a10);
  border: 4px solid #7a4814;
  box-shadow: inset 0 0 0 3px #2a1408;
}

.tile {
  display: block;
  position: relative;
  width: 100%;
  max-width: 160px;
  min-width: 0;
  height: 0;
  padding: 0 0 132%;
  justify-self: center;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.tile-inner {
  position: absolute;
  inset: 0;
}

.tile-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 16px;
  border: 4px solid #8a5a22;
  box-shadow: 0 8px 0 #1a0c06;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.tile-back {
  z-index: 2;
  color: #ffe08a;
  background:
    repeating-linear-gradient(90deg, rgba(90, 48, 16, 0.18) 0 8px, transparent 8px 16px),
    linear-gradient(180deg, #c48a42, #8a4e1c 55%, #5a3010);
}

.tile-back .stamp {
  display: grid;
  place-items: center;
  width: min(58%, 72px);
  aspect-ratio: 1;
  border-radius: 50%;
  font-family: var(--display);
  font-size: clamp(18px, 2.6vw, 28px);
  color: #3d220c;
  background: radial-gradient(circle at 35% 30%, #ffe08a, #d7a03c);
  border: 3px solid #7a4814;
  box-shadow: 0 4px 0 #2a1406;
}

.tile-back .flip-cue {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff4d2;
  text-shadow: 0 1px 0 #2a1406;
}

.app[data-world="2"] .tile-back {
  background:
    repeating-linear-gradient(90deg, rgba(20, 48, 64, 0.2) 0 8px, transparent 8px 16px),
    linear-gradient(180deg, #3d8ab4, #1f5a58 55%, #143040);
}

.app[data-world="3"] .tile-back {
  background:
    repeating-linear-gradient(90deg, rgba(40, 32, 80, 0.22) 0 8px, transparent 8px 16px),
    linear-gradient(180deg, #6a5ab4, #3a2a68 55%, #141828);
}

.tile-front {
  z-index: 1;
  color: #3d220c;
  background:
    repeating-linear-gradient(180deg, rgba(255, 244, 210, 0.35) 0 6px, transparent 6px 12px),
    linear-gradient(180deg, #fff8e4, #f0d08a);
  opacity: 0;
  transform: rotateY(12deg) scale(0.96);
}

.tile.flipped .tile-back,
.tile.matched .tile-back {
  opacity: 0;
  pointer-events: none;
}

.tile.flipped .tile-front,
.tile.matched .tile-front {
  z-index: 3;
  opacity: 1;
  transform: none;
}

.tile-front small,
.prompt-tile small,
.sort-token small {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: #7a4814;
}

.tile-front strong,
.prompt-tile strong,
.sort-token strong,
.choice-card strong,
.sort-box strong {
  font-family: var(--ipa);
  font-size: clamp(20px, 3vw, 32px);
  line-height: 1.1;
}

.tile-front em,
.prompt-tile em,
.choice-card em,
.sort-token em,
.sort-box em {
  font-style: normal;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(122, 72, 20, 0.12);
}

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

.tile.hint .tile-face {
  box-shadow: 0 0 0 4px #ffe08a, 0 6px 0 #2a1406;
}

.choice-board {
  display: grid;
  justify-items: center;
  gap: 18px;
  margin-top: 16px;
}

.prompt-tile {
  width: min(280px, 100%);
  min-height: 168px;
  padding: 18px 16px;
  border-radius: 22px;
  color: #3d220c;
  background: linear-gradient(180deg, #fff6df, #f0d7b0);
  border: 3px solid #5a3010;
  box-shadow: 0 8px 0 #2a1406;
}

.prompt-tile strong { display: block; margin: 8px 0 0; font-size: clamp(28px, 5vw, 42px); }

.choice-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

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

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

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

.sort-board { margin-top: 12px; }

.wave-title {
  margin: 0 0 12px;
  text-align: center;
  font-family: var(--display);
  font-size: 22px;
  color: var(--gold);
}

.sort-token-wrap {
  display: grid;
  place-items: center;
  min-height: 220px;
  margin-bottom: 16px;
}

.sort-token {
  width: min(220px, 70vw);
  min-height: 180px;
  padding: 18px 14px;
  border-radius: 22px;
  touch-action: none;
  user-select: none;
  cursor: grab;
  color: #3d220c;
  background: linear-gradient(180deg, #fff6df, #f0d7b0);
  border: 3px solid #5a3010;
  box-shadow: 0 10px 0 #2a1406;
}

.sort-token strong { display: block; margin: 8px 0; font-size: 40px; }
.sort-token .tile-zh { display: block; }

.sort-token.selected {
  box-shadow: 0 0 0 4px #ffe08a, 0 10px 0 #2a1406;
}

.sort-token.dragging {
  z-index: 12;
  cursor: grabbing;
  pointer-events: none;
}

.sort-boxes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.sort-box {
  min-height: 92px;
  padding: 10px 8px;
  border-radius: 16px;
  color: #fff6df;
  background: rgba(20, 10, 6, 0.28);
  border: 3px dashed rgba(232, 195, 106, 0.55);
}

.sort-box.right {
  border-style: solid;
  background: rgba(45, 107, 56, 0.45);
  border-color: #8fce6e;
}

.sort-box.wrong { animation: shake 0.35s ease; border-color: #d45454; }

.sort-box.hint {
  box-shadow: 0 0 0 4px #ffe08a;
  border-style: solid;
}

@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 button {
  min-width: 92px;
  padding: 8px 10px;
  border-radius: 12px;
  font-family: var(--ipa);
  font-weight: 800;
  color: #fff6df;
  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) {
  .world-grid { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr 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; }
  .flip-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
  }
  .tile { min-height: 0; }
  .tile-front strong { font-size: 22px; }
  .sort-boxes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
