/* Jersey 10 is crisp at multiples of 5px (15, 20, 30, 40); DotGothic16 at multiples of 16px. */
:root {
  --bg: #140c24;
  --bg2: #1f1438;
  --panel: #2a1b4a;
  --panel2: #34225c;
  --edge: #0b0714;
  --hi: #5b3d8f;
  --text: #f4ecff;
  --muted: #b3a6d6;
  --faint: #7a6aa6;
  --gold: #ffd34d;
  --red: #ff4a5a;
  --qi: #5fd8ff;
  --heal: #6dff9c;
  --pink: #ff6fb0;
  --teal: #3fe0d0;
  --px: "Jersey 10", "DotGothic16", "Noto Sans TC", monospace;
  --han: "DotGothic16", "Noto Sans TC", sans-serif;
  --read: var(--px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(var(--bg2) 1px, transparent 1px);
  background-size: 6px 6px;
  color: var(--text);
  font-family: var(--px);
  font-size: 20px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
/* The pixel fonts have one weight; faked bold smears their pixels. */
b, strong, h1, h2, h3 { font-weight: 400; }
.han { font-family: var(--han); }
[hidden] { display: none !important; }
.lbl { font-size: 15px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }

/* A chunky pixel frame: dark edge outside, light edge inside. */
.stage, .pop, .card, .toast { border-radius: 0; box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi); }

#app {
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- HUD ---------- */

.hud { display: flex; align-items: center; gap: 9px; min-height: 36px; }
.depth { display: flex; align-items: baseline; gap: 4px; }
.depth .han { color: var(--gold); font-size: 16px; }
.depth b { font-size: 30px; font-weight: 400; color: var(--gold); text-shadow: 2px 2px 0 var(--edge); }
.vig { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; }
.vig .bar { flex: 1; height: 12px; background: var(--edge); box-shadow: 0 0 0 2px var(--edge); position: relative; }
.vig .bar i { display: block; height: 100%; width: 100%; background: var(--red); box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.25); transition: width 0.2s steps(4); }
.vig.low .bar i { animation: blink 0.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.vig span { font-size: 20px; white-space: nowrap; }
.qi { display: flex; gap: 3px; align-items: center; }
.qi i { width: 9px; height: 9px; background: var(--edge); box-shadow: 0 0 0 1px var(--hi); }
.qi i.on { background: var(--qi); box-shadow: 0 0 0 1px var(--edge), inset -2px -2px 0 #2a9ccf; }
.coins { display: flex; align-items: center; gap: 5px; }
.coins b { font-size: 20px; font-weight: 400; color: var(--gold); }
.cash { width: 12px; height: 12px; background: var(--gold); position: relative; box-shadow: 0 0 0 2px var(--edge); }
.cash::after { content: ""; position: absolute; left: 4px; top: 4px; width: 4px; height: 4px; background: var(--edge); }
.icon {
  all: unset; cursor: pointer; width: 34px; height: 34px; display: grid; place-items: center; flex: none;
  font-family: var(--han); font-size: 16px; color: var(--text); background: var(--panel);
  box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi), 0 4px 0 3px var(--edge);
}
.icon:active { transform: translateY(2px); }

/* ---------- stage ---------- */

.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; background: #0b0714; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.biome {
  position: absolute; left: 8px; top: 8px; font-size: 15px; letter-spacing: 0.08em; color: var(--muted);
  text-shadow: 2px 2px 0 var(--edge); pointer-events: none;
}
.biome .han { color: var(--gold); margin-right: 5px; }
.vs {
  all: unset; box-sizing: border-box; cursor: pointer; position: absolute; left: 8px; right: 8px; top: 34px; z-index: 3;
  padding: 5px 9px; background: rgba(11, 7, 20, 0.86); box-shadow: 0 0 0 2px var(--hi); font-size: 15px; line-height: 1.25;
}
.vs .l1 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 20px; }
.vs .l1 .sep { flex: 1; }
.vs .l2 { color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.good { color: var(--gold); }
.bad { color: var(--red); }
.teal { color: var(--teal); }
.lines button .hint { position: absolute; left: -9px; top: 50%; width: 6px; height: 6px; margin-top: -3px; }
.lines button .hint.s { background: var(--gold); }
.lines button .hint.g { background: var(--teal); }
#phasesBody svg { width: 100%; max-width: 300px; height: auto; font-family: var(--px); }
.phases { text-align: left; padding: 0; margin: 0 0 12px; list-style: none; display: grid; gap: 8px; font-size: 20px; line-height: 1.25; }
.phases b { color: var(--text); }
.trig { text-align: left; display: grid; gap: 4px; font-size: 20px; background: var(--edge); padding: 8px 10px; }
.trig .tg { margin: 0 3px; }
.log {
  position: absolute; left: 10px; right: 10px; bottom: 8px; pointer-events: none;
  display: flex; flex-direction: column; gap: 3px; font-size: 20px; line-height: 1.25; font-weight: 400;
  text-shadow: 2px 0 0 var(--edge), -2px 0 0 var(--edge), 0 2px 0 var(--edge), 0 -2px 0 var(--edge);
}
.log .warn { color: #ffb070; }
.log .good { color: var(--gold); }
.toast {
  position: absolute; left: 50%; top: 110px; transform: translate(-50%, -6px); opacity: 0; pointer-events: none;
  padding: 7px 14px; text-align: center; white-space: nowrap; background: var(--panel);
  transition: opacity 0.2s steps(3), transform 0.2s steps(3);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .zh { font-family: var(--han); font-size: 16px; color: var(--gold); margin-right: 8px; vertical-align: -2px; }
.toast .nm { font-size: 20px; font-weight: 400; }

.pop {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 5; padding: 12px 14px; background: var(--panel);
  max-height: calc(100% - 20px); overflow-y: auto; -webkit-user-select: text; user-select: text;
}
.pop .hd { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pop .hd .han { color: var(--gold); font-size: 16px; }
.pop .tx { white-space: pre-line; font-size: 20px; line-height: 1.4; margin: 6px 0 8px; color: #fff7d6; }
.pop .tx:lang(zh) { font-family: var(--han); }
.pop .to { display: flex; align-items: center; gap: 10px; padding-top: 8px; border-top: 2px dashed var(--hi); }
.pop .to .zh { font-family: var(--han); font-size: 32px; color: var(--gold); }
.pop .to .nm { font-weight: 400; font-size: 20px; line-height: 1.15; }
.pop .to small { display: block; color: var(--muted); font-size: 15px; font-weight: 400; }
.pop .gate { font-size: 15px; color: var(--muted); margin-top: 6px; }
.pop .gate b { color: var(--gold); }
.pop .btns { justify-content: flex-start; margin-top: 12px; }
.pop dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 7px 10px; font-size: 20px; }
.pop dt { color: var(--gold); white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.pop dd { margin: 0; }
.el { font-family: var(--han); }

/* ---------- panel ---------- */

.panel {
  --lh: 22px;
  display: grid; grid-template-columns: 74px 18px 1fr 118px; grid-template-rows: auto auto; gap: 10px 8px;
  padding: 10px; background: var(--panel); box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi);
}
.lines { grid-row: 1; display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 4px; }
.lines button {
  all: unset; box-sizing: border-box; cursor: pointer; height: var(--lh); padding: 5px; position: relative;
  display: flex; gap: 22%; background: var(--edge);
}
.lines button::before, .lines button::after { content: ""; flex: 1; background: var(--text); box-shadow: inset 0 -3px 0 #b3a6d6; }
.lines button.yang::after { display: none; }
.lines button:hover, .lines button:focus-visible { outline: 2px solid var(--hi); }
.lines button.sel { outline: 2px solid var(--gold); }
.lines button.sel::before, .lines button.sel::after { background: var(--gold); box-shadow: inset 0 -3px 0 #c99a1a; }
.lines button.moved::before, .lines button.moved::after { background: var(--teal); box-shadow: none; }
.gatecol { grid-row: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; }
.gatecol .han { font-size: 16px; color: var(--muted); }
.glyph { display: flex; flex-direction: column-reverse; gap: 5px; width: 60px; }
.glyph i { height: 7px; display: flex; gap: 22%; }
.glyph i::before, .glyph i::after { content: ""; flex: 1; background: var(--text); }
.glyph i.yang::after { display: none; }
.glyph i.diff::before, .glyph i.diff::after { background: var(--red); }
.glyph.tiny { width: 16px; gap: 4px; }
.glyph.tiny i { height: var(--lh); gap: 3px; align-items: center; }
.glyph.tiny i::before, .glyph.tiny i::after { height: 4px; background: var(--faint); }
.glyph.tiny i.diff::before, .glyph.tiny i.diff::after { background: var(--red); }
.gatecol.open .glyph.tiny i::before, .gatecol.open .glyph.tiny i::after { background: var(--gold); }

.who { all: unset; cursor: pointer; grid-row: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.who .nm { font-size: 20px; font-weight: 400; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .nm .han { color: var(--gold); font-size: 16px; font-weight: 400; }
.who .tri { display: flex; align-items: center; gap: 6px; font-size: 20px; white-space: nowrap; overflow: hidden; }
.who .tri small { color: var(--muted); font-size: 15px; }
.tg { display: inline-flex; flex-direction: column-reverse; gap: 2px; width: 15px; flex: none; }
.tg i { height: 3px; display: flex; gap: 3px; }
.tg i::before, .tg i::after { content: ""; flex: 1; background: var(--c, var(--text)); }
.tg i.yang::after { display: none; }

.acts { grid-row: 1; display: flex; flex-direction: column; gap: 10px; }
.acts .row { display: flex; gap: 9px; }
.skill {
  all: unset; cursor: pointer; flex: 1; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; position: relative; overflow: hidden; background: var(--panel2); padding: 4px; min-height: 64px;
  box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi), 0 4px 0 3px var(--edge);
}
.skill .tg { width: 24px; gap: 3px; }
.skill .tg i { height: 4px; }
.skill b { font-size: 20px; font-weight: 400; }
.skill .cd { position: absolute; inset: 0; background: rgba(11, 7, 20, 0.75); display: grid; place-items: center; font-size: 30px; font-weight: 400; color: var(--muted); }
.skill.ready { background: #4a2f7a; box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--gold), 0 4px 0 3px var(--edge); }
.skill:active, .minor:active, .btn:active, .pack button:active { transform: translateY(2px); }
.minor {
  all: unset; cursor: pointer; flex: 1; height: 32px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; gap: 1px; color: var(--muted); background: var(--panel2);
  box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi), 0 3px 0 3px var(--edge);
}
.minor .han { font-size: 16px; color: var(--text); }
.pack { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; }
.pack button {
  all: unset; cursor: pointer; flex: 1; max-width: 52px; height: 40px; display: grid; place-items: center; background: var(--edge);
  box-shadow: 0 0 0 2px var(--edge), inset 0 0 0 2px #22163b;
}
.pack button canvas { width: 36px; height: 36px; image-rendering: pixelated; }
.pack button.full { background: var(--panel2); box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi), 0 3px 0 3px var(--edge); }
.pack button:disabled { cursor: default; }
.pack .relic-strip { margin-left: auto; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: 45%; }
.pack .relic-strip span { font-family: var(--han); font-size: 16px; color: var(--gold); background: var(--edge); padding: 2px 4px; }

button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* Longer texts in a plain, very legible face; the pixel font stays for labels. */
.log, .pop .tx, .pop .gate, .pop dd, .judg, .task, .card .sub, .rules li > span:last-child, .relics span.t,
.kept, .place small, .detail .tx, .detail .py, .best, .credit { font-family: var(--read); }
.pop .tx, .judg, .detail .tx { font-size: 20px; line-height: 1.3; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px;
  background: rgba(11, 7, 20, 0.82); overflow-y: auto; overscroll-behavior: contain;
}
.card {
  width: min(100%, 470px); padding: 22px 18px 18px; text-align: center; background: var(--panel);
  -webkit-user-select: text; user-select: text; margin: 6px 0;
}
.card.wide { width: min(100%, 560px); }
.card .mark { font-family: var(--han); font-size: 48px; color: var(--gold); line-height: 1; text-shadow: 4px 4px 0 var(--edge); }
.card .mark.small { font-size: 48px; }
.card h1 { margin: 8px 0 4px; font-size: 40px; font-weight: 400; color: var(--gold); text-shadow: 3px 3px 0 var(--edge); }
.card h2 { margin: 4px 0 12px; font-size: 30px; font-weight: 400; }
.card .sub { color: var(--muted); margin: 0 0 14px; line-height: 1.35; }
.card .sub b { color: var(--gold); }
.rules { text-align: left; margin: 0 0 16px; padding: 0; list-style: none; display: grid; gap: 10px; }
.rules li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.35; font-size: 20px; }
.rules .ic { flex: none; width: 30px; height: 30px; display: grid; place-items: center; font-family: var(--han); color: var(--gold); font-size: 16px; background: var(--edge); }
.btns { display: flex; gap: 14px 12px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.btn {
  all: unset; cursor: pointer; padding: 9px 16px; font-size: 20px; font-weight: 400; text-align: center; background: var(--panel2);
  box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi), 0 4px 0 3px var(--edge);
}
.btn.main { background: var(--gold); color: #2a1630; box-shadow: 0 0 0 3px var(--edge), inset 0 -4px 0 #c99a1a, 0 4px 0 3px var(--edge); }
.btn:disabled { opacity: 0.4; cursor: default; }
.best { color: var(--muted); font-size: 20px; margin: 14px 0 0; min-height: 1em; }
.tsel { display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 20px; color: var(--muted); }
.tsel select { font: inherit; color: var(--text); background: var(--edge); border: 2px solid var(--hi); border-radius: 0; padding: 4px 8px; cursor: pointer; }
.credit { margin-top: 10px; font-size: 15px; color: var(--faint); }

.place { font-size: 20px; color: var(--teal); margin: 6px 0 2px; font-weight: 400; }
.place .han { color: var(--gold); margin-right: 5px; }
.place small { display: block; color: var(--muted); font-size: 15px; margin-top: 4px; font-weight: 400; line-height: 1.3; }
.fhex { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 14px 0 8px; text-align: left; }
.fhex .zh { font-family: var(--han); font-size: 48px; color: var(--gold); line-height: 1; }
.fhex .nm { font-size: 20px; font-weight: 400; line-height: 1.15; }
.fhex .own { color: var(--muted); }
.fhex .own:empty { display: none; }
.judg { white-space: pre-line; line-height: 1.45; text-align: left; margin: 8px 0 12px; max-height: 32vh; overflow-y: auto; color: #fff7d6; font-size: 20px; }
.judg:lang(zh) { font-family: var(--han); }
.judg:empty { display: none; }
.task { margin: 0 0 12px; line-height: 1.4; font-size: 20px; }
.task b { color: var(--gold); }

.relics { display: grid; gap: 14px; margin: 6px 0 10px; }
.relics button {
  all: unset; cursor: pointer; display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px 12px; background: var(--panel2);
  box-shadow: 0 0 0 3px var(--edge), inset 0 0 0 2px var(--hi), 0 4px 0 3px var(--edge);
}
.relics button:disabled { opacity: 0.45; cursor: default; }
.relics .zh { font-family: var(--han); font-size: 32px; color: var(--gold); width: 40px; text-align: center; flex: none; display: grid; place-items: center; }
.relics .zh canvas { width: 36px; height: 36px; image-rendering: pixelated; }
.relics b { display: block; font-size: 20px; }
.relics span.t { color: var(--muted); font-size: 20px; }
.relics small { color: var(--gold); font-size: 15px; margin-left: 6px; }
.relics .price { margin-left: auto; color: var(--gold); font-weight: 400; white-space: nowrap; }

.kept { text-align: left; margin: 0 0 12px; font-size: 20px; display: grid; gap: 5px; }
.kept .none { color: var(--muted); text-align: center; }
.kept div span { font-family: var(--han); color: var(--gold); margin-right: 6px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 4px 0 14px; }
.stats div { padding: 8px 4px; background: var(--edge); }
.stats b { display: block; font-size: 30px; font-weight: 400; color: var(--gold); }
.newbest { color: var(--gold); margin: -4px 0 12px; }
.path { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 6px; margin: 0 0 12px; font-family: var(--han); color: var(--muted); font-size: 16px; }
.path .ar { color: var(--faint); font-size: 15px; }

/* the book */
.bookgrid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; margin: 4px 0 12px; }
.bookgrid button { all: unset; cursor: pointer; aspect-ratio: 1; display: grid; place-items: center; font-size: 15px; color: var(--faint); background: var(--edge); }
.bookgrid button.got { background: var(--panel2); color: var(--text); }
.bookgrid button.got .glyph { width: 58%; gap: 2px; }
.bookgrid button.got .glyph i { height: 3px; }
.bookgrid button.cur { outline: 2px solid var(--gold); }
.detail { text-align: left; border-top: 2px dashed var(--hi); padding-top: 12px; }
.detail .hd { display: flex; gap: 14px; align-items: center; }
.detail .hd .zh { font-family: var(--han); font-size: 48px; color: var(--gold); line-height: 1; }
.detail .hd .nm { font-size: 20px; font-weight: 400; line-height: 1.15; }
.detail .hd .py { color: var(--muted); font-size: 20px; }
.detail h3 { margin: 14px 0 4px; font-size: 15px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--teal); font-weight: 400; }
.detail .tx { white-space: pre-line; line-height: 1.45; font-size: 20px; color: #fff7d6; }
.detail .tx:lang(zh) { font-family: var(--han); }
.detail .ln { display: grid; grid-template-columns: 44px 1fr; gap: 8px 10px; margin-top: 6px; }
.detail .ln .lab { font-family: var(--han); color: var(--gold); font-size: 16px; }
.detail .locked { color: var(--muted); }

@media (min-width: 700px) {
  .panel { grid-template-columns: 84px 20px 1fr 170px; --lh: 24px; }
}
@media (max-height: 640px) {
  .panel { --lh: 17px; padding: 8px; }
  .pack button { height: 34px; }
  .skill { min-height: 50px; }
}
@media (prefers-reduced-motion: reduce) {
  .vig.low .bar i { animation: none; }
}
