/* self-hosted (Google Fonts is unreachable from mainland China); rebuild with node tools/build-fonts.js */
@font-face { font-family: "Silkscreen"; font-weight: 400; font-display: swap; src: url("fonts/silkscreen-400.woff2") format("woff2"); }
@font-face { font-family: "Silkscreen"; font-weight: 700; font-display: swap; src: url("fonts/silkscreen-700.woff2") format("woff2"); }
@font-face { font-family: "ZCOOL KuaiLe"; font-weight: 400; font-display: swap; src: url("fonts/zcool-kuaile.woff2") format("woff2"); }

:root {
  color-scheme: dark;
  --soil: #1f1710;
  --panel: #33261b;
  --panel-2: #45331f;
  --line: #5e4630;
  --text: #f7ecd9;
  --muted: #c4aa8a;
  --amber: #ffb938;
  --danger: #ff7359;
  --ink: #120b06;
  --px: "Silkscreen", "Courier New", monospace;
  --zh: "ZCOOL KuaiLe", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--soil); color: var(--text); font-family: var(--body); font-size: 14px; overflow: hidden;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
#app { height: 100%; position: relative; }
button { font: inherit; color: inherit; }
a { color: var(--amber); }

.btn {
  appearance: none; border: 2px solid var(--ink); background: var(--panel-2); color: var(--text); padding: 8px 14px; border-radius: 5px;
  cursor: pointer; box-shadow: 0 3px 0 var(--ink), inset 0 2px 0 rgba(255, 255, 255, .1); font-weight: 600; font-size: 14px; line-height: 1.2;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; transition: transform .06s, filter .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.btn[disabled] { opacity: .4; cursor: not-allowed; transform: none; filter: none; }
.btn.go { background: var(--amber); color: #2a1a08; }
.btn.ghost { background: transparent; box-shadow: none; border-color: var(--line); }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ---------- menu ---------- */
#menu { height: 100%; overflow-y: auto; padding-inline: 16px; }
.menu-inner { max-width: 900px; margin: 0 auto; padding-block: 26px 40px; display: flex; flex-direction: column; gap: 18px; }
.brand h1 { margin: 0; font-family: var(--px); font-weight: 700; font-size: clamp(40px, 9vw, 72px); letter-spacing: 3px; line-height: 1; color: var(--amber); text-shadow: 4px 4px 0 var(--ink); }
.brand .tagline { margin: 8px 0 0; font-family: var(--zh); font-size: clamp(18px, 3.4vw, 24px); letter-spacing: 3px; }
.brand .sub { margin: 8px 0 0; color: var(--muted); max-width: 64ch; line-height: 1.75; }
#parade { width: 100%; height: 80px; display: block; border: 2px solid var(--ink); border-radius: 6px; background: #a57d53; }
.progress { display: flex; align-items: center; gap: 10px; font-family: var(--zh); font-size: 18px; letter-spacing: 1px; }
.progress b { font-family: var(--px); font-weight: 400; color: var(--amber); font-size: 16px; }
.progress .btn { font-family: var(--body); }
.progress #contBtn { margin-left: auto; }
.chapter { display: flex; flex-direction: column; gap: 10px; }
.chapter-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 2px dashed var(--line); padding-bottom: 6px; }
.chapter-head h2 { margin: 0; font-family: var(--zh); font-weight: 400; font-size: 22px; letter-spacing: 2px; }
.chapter-head .cn { font-family: var(--px); color: var(--amber); font-size: 12px; letter-spacing: 1px; }
.chapter-head span { color: var(--muted); font-size: 13px; }
.chapter-head .cstars { margin-left: auto; font-family: var(--px); font-weight: 400; font-size: 12px; color: var(--amber); }
.chapter-head .lockhint { color: #8a7560; }
.chapter.folded { opacity: .6; }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px; }
.card {
  appearance: none; text-align: left; border: 2px solid var(--ink); background: var(--panel); border-radius: 6px; padding: 8px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; box-shadow: 0 4px 0 var(--ink); transition: transform .12s;
}
.card:hover:not([disabled]) { transform: translateY(-3px); }
.card:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.card[disabled] { cursor: not-allowed; opacity: .55; }
.card canvas { width: 100%; aspect-ratio: 1; object-fit: contain; image-rendering: pixelated; background: #e8d3a6; border-radius: 3px; display: block; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.card .no { font-family: var(--px); font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.card .nm { font-family: var(--zh); font-size: 16px; letter-spacing: 1px; display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.tag { font-family: var(--body); font-size: 11px; color: #2a0f06; border-radius: 3px; padding: 1px 5px; flex: none; }
.t-intro { --tier: #9cc45a; } .t-normal { --tier: #b9a58c; } .t-adv { --tier: #ffb938; }
.t-hard { --tier: #ff7359; } .t-expert { --tier: #c77dff; } .t-master { --tier: #4fd1ff; }
.tag { background: var(--tier); }
.card.t-hard, .card.t-expert, .card.t-master { border-color: var(--tier); box-shadow: 0 4px 0 color-mix(in srgb, var(--tier) 55%, #000); }
.stars { font-family: var(--px); color: var(--amber); letter-spacing: 2px; font-size: 12px; }
.stars .off { color: #5d4a38; }
.how-title { margin: 8px 0 0; font-family: var(--zh); font-weight: 400; font-size: 22px; letter-spacing: 2px; }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.how div { background: var(--panel); border: 2px solid var(--ink); border-radius: 6px; padding: 10px 12px; line-height: 1.65; color: var(--muted); }
.how b { display: block; color: var(--text); font-family: var(--zh); font-weight: 400; font-size: 17px; letter-spacing: 1px; margin-bottom: 2px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- game ---------- */
#game { height: 100%; display: flex; flex-direction: column; align-items: center; }
.hud { width: 100%; max-width: 560px; box-sizing: border-box; display: flex; align-items: center; gap: 8px; padding: 10px 14px 4px; }
.hud .title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.hud .no, .hud .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .no { font-family: var(--px); font-size: 11px; letter-spacing: 1px; color: var(--tier, var(--muted)); }
.hud .nm { font-family: var(--zh); font-size: 20px; letter-spacing: 2px; line-height: 1.2; }
.hud .left { font-size: 12px; color: var(--muted); text-align: right; display: flex; flex-direction: column; line-height: 1.2; }
.hud .left b { color: var(--text); font-family: var(--px); font-weight: 400; font-size: 15px; font-variant-numeric: tabular-nums; }
.speed { font-family: var(--px); font-size: 13px; padding: 7px 10px; background: #3a8fc8; color: #fff; min-width: 44px; }
@media (max-width: 360px) { .hud { gap: 5px; padding-inline: 8px; } .hud .btn { padding: 6px 8px; } }
.stagewrap { flex: 1; min-height: 0; width: 100%; display: flex; align-items: flex-end; justify-content: center; position: relative; }
#board { display: block; touch-action: manipulation; }
.toast {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%) translateY(-8px); background: var(--danger); color: #2a0f06; font-weight: 600;
  padding: 6px 12px; border-radius: 4px; border: 2px solid var(--ink); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  width: max-content; max-width: calc(100% - 32px); box-sizing: border-box; text-align: center; z-index: 5;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.info { background: var(--amber); }

#tray { width: 100%; max-width: 400px; box-sizing: border-box; padding: 6px 16px 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 18px; position: relative; }
#tray svg.links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 4; }
.tcol { display: flex; flex-direction: column; gap: 7px; align-items: stretch; position: relative; }
.box {
  appearance: none; position: relative; height: 44px; border-radius: 8px; border: 2px solid var(--ink); cursor: pointer; font-family: var(--px); font-weight: 700;
  font-size: 18px; padding: 0; display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .22), inset 0 3px 0 rgba(255, 255, 255, .35), 0 3px 0 var(--ink); transition: transform .1s, filter .2s;
}
.box.front { outline: 2px solid rgba(255, 255, 255, .7); outline-offset: 1px; }
.box.front:hover { transform: translateY(-2px); }
.box.front:active { transform: translateY(1px); }
.box.back { filter: brightness(.84); cursor: default; }
.box.back2 { filter: brightness(.68); }
.box.pickable { filter: none; cursor: pointer; animation: wig .5s ease-in-out infinite alternate; }
@keyframes wig { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }
.box.hidden { background: #5b3f78 !important; color: #d8c2f0 !important; text-shadow: none !important; }
.box.empty { visibility: hidden; }
.box.soldier {
  background: radial-gradient(ellipse 30% 18% at 22% 30%, #6cc24a 90%, transparent 100%), radial-gradient(ellipse 28% 16% at 75% 70%, #3f8a2e 90%, transparent 100%),
    radial-gradient(ellipse 26% 16% at 70% 22%, #7fd35a 90%, transparent 100%), #4f9a3a !important;
  color: #fff !important; text-shadow: 0 2px 0 rgba(0, 0, 0, .45) !important;
}
.box.locked { cursor: not-allowed; filter: saturate(.45) brightness(.75); }
.box.locked.back { filter: saturate(.35) brightness(.5); }
.box.locked .num { opacity: .3; }
.box .lock { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.box .lock svg { width: 28px; height: 28px; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .55)); }
.box.unlocking { animation: unl .5s ease-out; }
@keyframes unl { 0% { transform: scale(1); } 40% { transform: scale(1.15) rotate(-4deg); } 100% { transform: scale(1); } }
.more { position: absolute; bottom: -15px; left: 0; right: 0; text-align: center; font-family: var(--px); font-size: 10px; color: var(--muted); letter-spacing: 1px; }
.flykey { position: fixed; left: 0; top: 0; width: 36px; height: 36px; pointer-events: none; z-index: 20; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .45)); }
.flykey svg { width: 100%; height: 100%; }

.boosters { width: 100%; max-width: 440px; box-sizing: border-box; display: flex; justify-content: center; gap: 8px; padding: 20px 16px 14px; }
.boost { position: relative; flex: 1; min-width: 0; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 6px; }
.boost .ic { font-family: var(--px); font-size: 16px; line-height: 1; height: 22px; display: flex; align-items: center; }
.boost .ic svg { width: 22px; height: 22px; }
.boost .lb { font-size: 12px; }
.boost .ct {
  position: absolute; top: -8px; right: -8px; background: var(--amber); color: #2a1a08; border: 2px solid var(--ink); border-radius: 10px;
  font-family: var(--px); font-size: 11px; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.boost.on { background: var(--amber); color: #2a1a08; }

.overlay { position: absolute; inset: 0; background: rgba(15, 10, 6, .74); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; backdrop-filter: blur(2px); }
.card-pop {
  background: var(--panel); border: 3px solid var(--ink); border-radius: 8px; box-shadow: 0 8px 0 var(--ink); padding: 22px; max-width: 360px; width: 100%;
  box-sizing: border-box; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; animation: pop .45s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card-pop .eyebrow { font-family: var(--px); font-size: 12px; color: var(--muted); letter-spacing: 2px; }
.card-pop h2 { margin: 0; font-family: var(--zh); font-weight: 400; font-size: 28px; letter-spacing: 3px; color: var(--amber); }
.card-pop canvas { width: 170px; height: 170px; object-fit: contain; image-rendering: pixelated; border-radius: 4px; }
.big-stars { font-size: 32px; letter-spacing: 6px; color: var(--amber); font-family: var(--px); }
.big-stars .off { color: #5d4a38; }
.card-pop .line { color: var(--muted); line-height: 1.7; font-size: 13px; }
.card-pop .line b { color: var(--text); font-family: var(--px); font-weight: 400; }
.card-pop .acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.lose h2 { color: var(--danger); }
.intro-art { display: flex; gap: 14px; align-items: center; justify-content: center; min-height: 60px; }
.intro-art svg { width: 56px; height: 56px; }
.intro-art .arrow { font-family: var(--px); font-size: 22px; color: var(--muted); }
.mbox {
  width: 54px; height: 40px; border-radius: 7px; border: 2px solid var(--ink); font-family: var(--px); font-weight: 700; color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 17px; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .22);
}

@media (max-height: 720px) { .box { height: 38px; font-size: 16px; } .tcol { gap: 5px; } .boosters { padding: 16px 16px 10px; } .boost { padding: 5px; } }
@media (prefers-reduced-motion: reduce) { .box.pickable, .card-pop { animation: none; } }
