/* ============================================================
   Forever Mine — UI shell. Canvas draws the mine; DOM draws the HUD.
   ============================================================ */

/* Display face for the logo, headings, buttons and static panel numbers.
   Latin only: Chinese falls through to the system CJK fonts in the stack.
   It has no tabular figures, so live counters stay on the body face. */
@font-face {
  font-family: "Fredoka";
  font-weight: 600;
  font-display: swap;
  src: url("vendor/fonts/fredoka-5.2.10-latin-600.woff2") format("woff2");
}
@font-face {
  font-family: "Fredoka";
  font-weight: 700;
  font-display: swap;
  src: url("vendor/fonts/fredoka-5.2.10-latin-700.woff2") format("woff2");
}

:root {
  /* Text */
  --ink:        #f2ecff;
  --dim:        #a69cc2;
  --mute:       #6c6288;

  /* Meaning. Gold is score already secured; teal is gems still at risk. */
  --gold:       #ffc95e;
  --carry:      #7ef0d0;
  --earned:     #74e06a;   /* an achievement level already won */
  --danger:     #ff5d5d;
  --danger-soft:#ff8f7d;
  --ember:      #f0a53c;
  --ember-deep: #c96a1f;
  --ember-edge: #6d3510;

  /* Surfaces, darkest to lightest */
  --bg:         #05040a;
  --surface-0:  #0e0b17;
  --surface-1:  #14101f;
  --surface-1b: #191327;
  --surface-2:  rgba(255,255,255,.045);
  --surface-3:  #2a2140;
  --surface-4:  #241a34;
  --edge:       #33294d;
  --edge-soft:  rgba(255,255,255,.08);
  --edge-strong:rgba(255,255,255,.18);

  /* The purple primary */
  --accent:      #6f57b8;
  --accent-deep: #4a3a86;
  --accent-edge: #2c2154;
  /* Red is for leaving: quitting a run, erasing, deleting. */
  --quit:        #e5484d;
  --quit-deep:   #b42328;
  --quit-edge:   #5e1013;

  --medal-gold:   #ffcf4a;
  --medal-silver: #cfd8e6;
  --medal-bronze: #d98a4e;

  /* Type. Nothing on screen goes below --fs-xs. */
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-md: 14px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --font-body: ui-rounded, "Avenir Next", "Segoe UI", system-ui, -apple-system,
               "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC",
               "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --font-display: "Fredoka", var(--font-body);

  /* The Android app shell publishes the insets as --safe-area-inset-* (older
     Android WebViews ignore env()); iOS and browsers use env(). */
  --safe-b: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-t: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-l: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --safe-r: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* Mobile browsers inflate "small" text on their own (iOS in landscape,
     Android's font boosting), so the same card read bigger in the browser
     than in the app. Sizes here are the sizes. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; }
/* Keyboard users get a ring; taps and clicks do not. */
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

#app { position: fixed; inset: 0; overflow: hidden; }

#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------------------------------------------------------- HUD */
#hudScrim {
  position: absolute; left: 0; right: 0; top: 0;
  height: calc(var(--safe-t) + 96px);
  background: linear-gradient(180deg, rgba(5,4,10,.62), rgba(5,4,10,.28) 60%, rgba(5,4,10,0));
  pointer-events: none;
  z-index: 9;
}

#hud {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 10px);
  right: calc(var(--safe-r) + 10px);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
  gap: 10px;
}

.hud-left  { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
.hud-right { display: flex; gap: 8px; align-items: flex-start; }

.hearts { display: flex; gap: 3px; }
.heart {
  width: 17px; height: 17px;
  background: var(--danger);
  clip-path: polygon(50% 100%, 6% 42%, 6% 22%, 27% 8%, 50% 24%, 73% 8%, 94% 22%, 94% 42%);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.7));
  transition: transform .12s ease;
}
.heart.empty { background: #40304a; }
.heart.pop { transform: scale(1.45); }

/* Hard-hat dents: one pip per charge the helmet can still absorb. */
.helmet { display: flex; gap: 3px; }
.helmet.hidden { display: none; }
.hardhat {
  width: 16px; height: 14px;
  background: var(--gold);
  clip-path: polygon(2% 100%, 2% 78%, 20% 78%, 20% 40%, 32% 18%, 68% 18%, 80% 40%, 80% 78%, 98% 78%, 98% 100%);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.7));
  transition: transform .12s ease;
}
.hardhat.empty { background: #3c3450; }

.depth {
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: .1em;
  color: var(--dim);
  text-shadow: 0 1px 3px #000;
}

/* Eruption clock, as a chip. Neutral for most of a run, amber at the first
   real warning, red and pulsing at the last one — the colour is the alarm. */
.timer {
  font-size: var(--fs-xs); font-weight: 900; letter-spacing: .1em;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  padding: 4px 9px;
  border-radius: 100px;
  background: rgba(12,9,20,.6);
  border: 1px solid var(--edge-soft);
}
.timer.hidden { display: none; }
.timer.soon { color: var(--gold); background: rgba(255,201,94,.12); border-color: rgba(255,201,94,.4); }
.timer.warn { color: #fff; background: rgba(255,93,93,.28); border-color: rgba(255,93,93,.7); animation: tick .9s steps(1, end) infinite; }
@keyframes tick { 0%, 55% { opacity: 1 } 56%, 100% { opacity: .45 } }

/* Wallet chips: icon, label and number in one pill, so each label sits on
   its number instead of across a gap. */
.wallets { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }
.wallet {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 100px;
  background: rgba(12,9,20,.6);
  border: 1px solid var(--edge-soft);
}
.wallet .gem { width: 11px; height: 11px; flex-shrink: 0; }
.wallet .lbl {
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: .08em; color: var(--dim);
}
.wallet .val {
  font-size: var(--fs-md); font-weight: 900; font-variant-numeric: tabular-nums;
  transition: transform .1s ease;
  min-width: 28px; text-align: right;
}
.w-carry { border-color: rgba(126,240,208,.3); }
.w-carry .gem { color: var(--carry); }
.w-carry .val { font-size: var(--fs-lg); }
.w-score .gem { color: var(--gold); }
.v-score  { color: var(--gold); }
.v-carry  { color: var(--carry); }
.val.bump { transform: scale(1.3); }
.val.lose { color: var(--danger) !important; transform: scale(.8); }

.pause-btn {
  pointer-events: auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--edge-strong);
  background: rgba(12,9,20,.6);
  color: var(--ink);
  cursor: pointer;
  transition: transform .07s ease, background .12s ease;
}
.pause-btn svg { width: 20px; height: 20px; }
.pause-btn:active { transform: scale(.92); background: rgba(111,87,184,.5); }
.pause-btn.hidden { display: none; }

/* ------------------------------------------------------ Feedback */
.toast {
  position: absolute;
  top: 22%; left: 50%;
  transform: translate(-50%, -6px);
  padding: 8px 16px;
  background: rgba(12,9,20,.86);
  border: 1px solid var(--edge);
  border-radius: 100px;
  font-size: var(--fs-sm); font-weight: 800; letter-spacing: .07em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Achievement pop-up: sits under the toast so the two never collide. */
.achieve {
  position: absolute;
  top: 30%; left: 50%;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 12px;
  background: rgba(12,9,20,.9);
  border: 1px solid rgba(255, 207, 74, .45);
  border-radius: 14px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 0);
  pointer-events: none;
  z-index: 21;
}
.achieve.show { animation: achieveIn 2.6s ease forwards; }
.achieve .lv-badge { align-self: center; flex-shrink: 0; }
.achieve-txt { display: flex; flex-direction: column; line-height: 1.25; }
.achieve-k { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .1em; color: var(--earned); }
.achieve-v { font-size: var(--fs-md); font-weight: 800; color: var(--ink); }
@keyframes achieveIn {
  0%   { opacity: 0; transform: translate(-50%, 8px) scale(.92); }
  10%  { opacity: 1; transform: translate(-50%, 0) scale(1); }
  85%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

/* First-encounter hazard card, just under the HUD: it must not sit over the
   miner, where the danger it describes is. */
.hint {
  position: absolute;
  top: calc(var(--safe-t) + 88px); left: 50%;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: min(86vw, 340px);
  padding: 9px 16px 10px;
  background: rgba(12,9,20,.9);
  border: 1px solid rgba(255, 110, 80, .55);
  border-radius: 14px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 0);
  pointer-events: none;
  z-index: 21;
}
.hint.show { animation: hintIn 5.5s ease forwards; }
.hint-k { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .1em; color: #ff8a6a; }
.hint-t { font-size: var(--fs-md); font-weight: 800; color: var(--ink); }
.hint-b { font-size: var(--fs-sm); font-weight: 600; color: #d8cfe8; line-height: 1.35; }
/* The tutorial's coach card: where the hint sits, but it stays up.
   The mine scales with the screen (a tile is 1/13.5 of its short side), so
   the card does too: a phone's 12.5px, growing on a tablet or desktop window
   instead of shrinking to a footnote under 80px tiles. Everything inside is
   in em off this one size. */
.coach {
  position: absolute;
  top: calc(var(--safe-t) + 88px); left: 50%;
  display: flex; flex-direction: column; align-items: center; gap: .25em;
  font-size: clamp(var(--fs-sm), 3.2vmin, 19px);
  width: min(88vw, 28.8em);
  padding: .72em 1.28em .8em;
  background: rgba(12,9,20,.9);
  border: 1px solid rgba(255, 201, 94, .55);
  border-radius: 14px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: opacity .25s ease, transform .25s ease, border-color .2s ease;
  pointer-events: none;
  z-index: 21;
}
.coach.show { opacity: 1; transform: translate(-50%, 0); }
.coach.done { border-color: #7ef0d0; }
.coach-k { font-size: max(var(--fs-xs), .88em); font-weight: 800; letter-spacing: .1em; color: #ffc95e; }
.coach.done .coach-k { color: #7ef0d0; }
.coach.done .coach-k::before { content: '✓ '; }
.coach-b { font-size: 1em; font-weight: 600; color: #e6ddf4; line-height: 1.4; }
.coach-b b { color: var(--ink); }
/* The tutorial's closing panel: the three rules a real mine adds. */
.tut-recap { list-style: none; margin: 12px 0 4px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tut-recap li { position: relative; padding-left: 22px; font-size: var(--fs-sm); line-height: 1.4; color: #d8cfe8; text-align: left; }
.tut-recap li::before { content: '✓'; position: absolute; left: 2px; color: #7ef0d0; font-weight: 800; }
.tut-recap b { color: var(--ink); }
@keyframes hintIn {
  0%   { opacity: 0; transform: translate(-50%, 8px) scale(.94); }
  6%   { opacity: 1; transform: translate(-50%, 0) scale(1); }
  90%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

.banner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  z-index: 25;
}
.banner.show { animation: bannerIn 2.6s ease forwards; }
.banner h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 9.5vw, 58px);
  font-weight: 700; letter-spacing: .04em; line-height: 1;
  color: #ffd08a;
  text-shadow: 0 0 24px #ff5a1e, 0 0 60px #ff2d00, 0 4px 0 #6b1200;
}
.banner p { font-size: var(--fs-md); font-weight: 800; letter-spacing: .16em; color: #ffb3a0; }
@keyframes bannerIn {
  0%   { opacity: 0; transform: scale(.7); }
  14%  { opacity: 1; transform: scale(1.06); }
  22%  { transform: scale(1); }
  78%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05); }
}

.hurt {
  position: absolute; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 90px 20px rgba(255,40,40,.75);
  opacity: 0;
  z-index: 15;
  transition: opacity .35s ease;
}
.hurt.show { opacity: 1; transition: opacity .05s ease; }

/* ------------------------------------------------------ Controls */
#controls {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
}

#stickzone {
  position: absolute;
  left: 0; bottom: 0;
  width: 52%; height: 62%;
  pointer-events: auto;
}
/* The stick is drawn here at all times, held or not, so the player can always
   see which way they are pointing. A touch anywhere in the zone steers it from
   wherever the thumb lands; the drawing itself never moves under the thumb. */
#stickbase {
  position: absolute;
  width: 116px; height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.07), rgba(255,255,255,.03));
  border: 2px solid rgba(255,255,255,.16);
  opacity: .4;
  transition: opacity .14s ease;
  left: calc(var(--safe-l) + 92px);
  bottom: calc(var(--safe-b) + 74px);
}
#stickbase.on { opacity: .95; }

/* Cardinal ticks — a quiet reference for "where is straight down". */
#stickring {
  position: absolute; inset: 12px;
  border-radius: 50%;
  background:
    linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,.16)) 50% 0 / 2px 9px no-repeat,
    linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,.16)) 50% 100% / 2px 9px no-repeat,
    linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,.16)) 0 50% / 9px 2px no-repeat,
    linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,.16)) 100% 50% / 9px 2px no-repeat;
}

/* Aim arrow: rotated to the snapped 8-way direction the pickaxe will swing. */
#stickaim {
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity .1s ease;
}
#stickaim.on { opacity: 1; }
#stickaim i {
  position: absolute; left: 50%; top: -23px;
  width: 17px; height: 14px; margin-left: -8.5px;
  background: var(--gold);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  filter: drop-shadow(0 0 4px rgba(255,201,94,.5));
}

#stickknob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b9a8ff, #6a53c9);
  border: 2px solid rgba(255,255,255,.4);
  box-shadow: 0 4px 14px rgba(0,0,0,.55);
}

#buttons {
  position: absolute;
  right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + 22px);
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: auto;
}

/* Three verbs, one press each. MINE is the thumb-resting primary; JUMP and
   DYNAMITE sit beside it, smaller, in their own colours so they read apart. */
.act {
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.22);
  color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  font-family: var(--font-display);
  font-weight: 700; letter-spacing: .08em;
  box-shadow: 0 6px 20px rgba(0,0,0,.55);
  cursor: pointer;
  transition: transform .07s ease, background .12s ease, opacity .12s ease;
}
.act svg { width: 22px; height: 22px; opacity: .92; }
.act:active, .act.held { transform: scale(.93); }
.act.small { width: 74px; height: 74px; font-size: var(--fs-xs); margin-bottom: 8px; }

#action {
  width: 100px; height: 100px;
  font-size: var(--fs-md);
  background: radial-gradient(circle at 38% 32%, #4a3a72, #241a3c);
}
#action:active, #action.held {
  background: radial-gradient(circle at 38% 32%, #6d55a8, #33265a);
}

#jump {
  color: var(--carry);
  background: radial-gradient(circle at 38% 32%, #2f6a58, #17392f);
}
#jump:active, #jump.held {
  background: radial-gradient(circle at 38% 32%, #46997e, #1f5445);
}

#dynamite {
  position: relative;
  color: #ffb59f;
  background: radial-gradient(circle at 38% 32%, #6d3227, #3a1a14);
}
#dynamite:active, #dynamite.held {
  background: radial-gradient(circle at 38% 32%, #a04a37, #5a271d);
}
#dynamite.depleted { opacity: .42; }
/* DYNAMITE is the longest label on a small button: tighten it to fit. */
#dynamite > span[data-i18n] { letter-spacing: .02em; }
#dynamite .count {
  position: absolute; right: -3px; top: -3px;
  min-width: 21px; height: 21px; padding: 0 4px;
  border-radius: 11px;
  background: var(--surface-4); border: 1.5px solid rgba(255,255,255,.2);
  font-family: var(--font-body);
  font-size: var(--fs-xs); font-weight: 900; line-height: 18px; text-align: center;
  color: var(--ink); letter-spacing: 0;
}

/* --------------------------------------------------------- Panel */
.panel {
  position: absolute; inset: 0;
  z-index: 40;
  display: grid; place-items: center;
  /* minmax(0, …): a long unbreakable line (a player's name) must shrink and
     ellipsize instead of widening the panel past the screen. */
  grid-template-columns: minmax(0, 1fr);
  padding: calc(var(--safe-t) + 14px) 14px calc(var(--safe-b) + 14px);
  background: rgba(4,3,9,.84);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: fade .2s ease;
}
.panel.hidden { display: none; }
/* The title sits low and lets the demo mine show through above it: a plain
   gradient instead of the blur, which would have to be re-run every frame. */
.panel.demo {
  align-items: end;
  background: linear-gradient(180deg, rgba(4,3,9,.05) 0%, rgba(4,3,9,.2) 35%, rgba(4,3,9,.82) 72%);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.panel.demo .panel-inner { background: linear-gradient(180deg, rgba(25,19,39,.94), rgba(20,16,31,.97)); }
/* No HUD or controls while the demo miner is playing. */
body.attract #hud, body.attract #hudScrim, body.attract #controls,
body.attract #toast, body.attract #banner, body.attract #hint { display: none; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.panel-inner {
  position: relative;      /* anchors the language chip */
  width: 100%; max-width: 420px;
  background: linear-gradient(180deg, var(--surface-1b), var(--surface-1));
  border: 1px solid var(--edge);
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,.6);
}

/* Headings leave room for the language chip in the corner. */
.panel h2 {
  font-family: var(--font-display);
  font-size: var(--fs-xl); font-weight: 700; letter-spacing: .03em;
  margin-bottom: 4px; padding-right: 64px;
}
/* Sentences read in sentence case; spaced capitals are for short labels. */
.panel .sub {
  font-size: var(--fs-sm); font-weight: 600; line-height: 1.4;
  color: var(--dim); margin-bottom: 16px;
}
/* The one-visit warning on a cave lantern — it has to read before the buttons. */
.panel .note {
  font-size: var(--fs-sm); font-weight: 700; line-height: 1.4;
  color: var(--gold);
  background: rgba(255, 201, 94, .1);
  border: 1px solid rgba(255, 201, 94, .32);
  border-radius: 10px;
  padding: 8px 10px; margin: -6px 0 14px;
}
.panel .logo {
  font-family: var(--font-display);
  font-size: clamp(34px, 11vw, 56px);
  font-weight: 700; letter-spacing: .05em; line-height: .95;
  background: linear-gradient(180deg, #9ff4ff, #4f9ee8 55%, #3b5fd0);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
  margin: 8px 0 2px;
}
.panel .logo-sub {
  font-family: var(--font-display);
  text-align: center; font-size: clamp(15px, 4.4vw, 20px); font-weight: 700;
  letter-spacing: .36em; color: var(--gold); margin: 6px 0 6px;
}
.panel .tagline {
  text-align: center; font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: .2em; color: var(--dim); margin-bottom: 18px;
}

/* Language chip: top-right of every panel, instead of a full-width button. */
.lang-chip {
  position: absolute; top: 14px; right: 14px;
  display: flex; align-items: center; gap: 5px;
  padding: 6px 10px 6px 8px;
  border-radius: 100px;
  border: 1px solid var(--edge);
  background: rgba(255,255,255,.03);
  color: var(--dim);
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: .04em;
  cursor: pointer;
  z-index: 2;
}
.lang-chip svg { width: 14px; height: 14px; }
.lang-chip:active { background: var(--surface-3); color: var(--ink); }
.music-chip { right: auto; left: 14px; padding: 6px 9px; }
.music-chip.off { color: var(--mute); }

/* The title: a little headroom for the corner chips, and nothing below the
   doors but two quiet links. */
.panel-inner.title { padding-top: 34px; }
.title-links { display: flex; justify-content: center; gap: 6px; margin-top: 12px; }
.title-links .link-btn { margin: 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.stat {
  background: var(--surface-2);
  border: 1px solid var(--edge-soft);
  border-radius: 12px; padding: 9px 11px;
  min-width: 0;
}
.stat .k { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .08em; color: var(--dim); }
.stat .v {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stat .v.gold { color: var(--gold); }
.stat .v.carry { color: var(--carry); }
/* An odd stat out sits across the whole row rather than leaving a hole. */
.stat.wide { grid-column: 1 / -1; }

/* ---------------------------------------------------- Highscore board
   One row per banked haul. The row a run just set is highlighted, so the
   summary answers "where did that land?" without any extra copy. */
.scores {
  background: var(--surface-2);
  border: 1px solid var(--edge-soft);
  border-radius: 12px;
  padding: 9px 11px; margin-bottom: 16px;
}
.score-head {
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: .1em;
  color: var(--dim); margin-bottom: 6px;
}
.score-empty { font-size: var(--fs-sm); font-weight: 600; color: var(--dim); }
.score-row {
  display: flex; align-items: baseline; gap: 9px;
  padding: 3px 5px; margin: 0 -5px;
  border-radius: 7px;
  font-variant-numeric: tabular-nums;
}
.score-row .rk {
  flex-shrink: 0; min-width: 14px;
  font-size: var(--fs-xs); font-weight: 900; color: var(--dim);
}
.score-row .vv { flex: 1; font-size: var(--fs-md); font-weight: 900; color: var(--gold); }
.score-row .dd { font-size: var(--fs-xs); font-weight: 700; color: var(--dim); }
.score-row.you { background: rgba(126, 240, 208, .11); }
.score-row.you .rk { color: var(--carry); }
.score-row.you .vv { color: var(--carry); }

/* ------------------------------------------------------------ Shop
   The shop is a column: header and the way out stay put, only the list
   scrolls, so the carried balance is in view at every purchase. */
.panel-inner.shop {
  display: flex; flex-direction: column;
  max-height: calc(100vh - var(--safe-t) - var(--safe-b) - 28px);
  max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 28px);
  padding-bottom: 14px;
}
.shop .shop-head { flex-shrink: 0; }
.shop .shop-head .stats { margin-bottom: 10px; }
.shop .shop-scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  touch-action: pan-y;
  margin: 0 -6px; padding: 2px 6px 6px;
  /* fade the list edges so it reads as scrollable */
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 10px, #000 calc(100% - 14px), transparent);
          mask-image: linear-gradient(180deg, transparent 0, #000 10px, #000 calc(100% - 14px), transparent);
}
.shop .shop-foot { flex-shrink: 0; padding-top: 4px; }
.shop .shop-foot .btn:first-child { margin-top: 6px; }

.shop-section {
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: .12em;
  color: var(--dim); margin: 6px 2px 7px;
}
.shop-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.shop-item {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface-2);
  border: 1px solid var(--edge-soft);
  border-radius: 13px; padding: 10px 11px;
}
.shop-item .ico {
  flex-shrink: 0;
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--surface-4);
  border: 1px solid var(--edge-soft);
}
.shop-item .ico svg { width: 24px; height: 24px; }
.shop-item .info { flex: 1; min-width: 0; }
.shop-item .nm-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.shop-item .nm { font-size: var(--fs-md); font-weight: 800; }
.shop-item .lv {
  font-size: var(--fs-xs); font-weight: 800; color: var(--dim);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.shop-item .ds { font-size: var(--fs-sm); color: var(--dim); font-weight: 600; line-height: 1.35; }
/* A maxed upgrade folds to one slim line: nothing left to decide there. */
.shop-item.maxed { padding: 6px 11px; opacity: .7; }
.shop-item.maxed .ico { width: 28px; height: 28px; border-radius: 8px; }
.shop-item.maxed .ico svg { width: 18px; height: 18px; }
.shop-item.maxed .nm { font-size: var(--fs-sm); }
.shop-item .maxed-tag {
  flex-shrink: 0; font-size: var(--fs-xs); font-weight: 900;
  letter-spacing: .06em; color: var(--gold);
}
.shop-item .new-tag {
  font-size: var(--fs-xs); font-weight: 900; letter-spacing: .08em;
  color: #1a1030; background: var(--gold);
  border-radius: 6px; padding: 1px 6px;
}
/* What deeper lanterns still hold: one line, not a wall of greyed rows. */
.shop-locked {
  font-size: var(--fs-sm); font-weight: 700; color: var(--dim);
  text-align: center; padding: 8px 6px 4px;
}
.pips { display: flex; gap: 3px; margin-top: 6px; }
.pip { width: 15px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.18); }
.pip.on { background: var(--gold); }

/* Buy buttons. The price is paid from carried gems, so it wears the carry
   colour and the gem mark. Four states, each readable at a glance:
   affordable · too dear (red price) · FULL (supply already topped up) · MAX. */
.buy {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  min-width: 74px; padding: 9px 10px;
  border-radius: 11px; border: 1px solid rgba(126,240,208,.35);
  background: var(--surface-3); color: var(--carry);
  font-size: var(--fs-sm); font-weight: 900; font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform .07s ease, background .12s ease;
}
.buy .gem { width: 10px; height: 10px; flex-shrink: 0; }
.buy:active { transform: scale(.95); background: #3a2e5a; }
.buy:disabled { cursor: default; transform: none; }
.buy.poor { color: var(--danger-soft); border-color: rgba(255,93,93,.25); background: rgba(255,93,93,.06); }
.buy.full, .buy.max { color: var(--dim); border-color: var(--edge-soft); background: transparent; letter-spacing: .06em; }

.btn {
  display: block; width: 100%;
  padding: 15px; margin-top: 9px;
  border-radius: 14px; border: none;
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-family: var(--font-display);
  font-size: 16px; font-weight: 700; letter-spacing: .08em;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--accent-edge);
  transition: transform .07s ease, box-shadow .07s ease, background .12s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-edge); }
.btn.ghost {
  background: transparent; border: 1px solid var(--edge);
  box-shadow: none; color: var(--dim); font-size: var(--fs-md); padding: 12px;
}
.btn.ghost:active { transform: none; background: var(--surface-3); color: var(--ink); }
.btn.daily {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: linear-gradient(180deg, var(--ember), var(--ember-deep)); box-shadow: 0 5px 0 var(--ember-edge);
}
.btn.daily:active { box-shadow: 0 2px 0 var(--ember-edge); }
.btn.daily .daily-k { font-size: 17px; }
.btn.daily .daily-v {
  font-family: var(--font-body);
  font-size: var(--fs-sm); font-weight: 700; letter-spacing: .02em; color: rgba(255,255,255,.88);
}
.btn.daily .daily-v.best { color: #fff3c4; }
/* Hardcore: the endless button's darker twin, two lines like the daily's. */
.btn.hardcore {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 11px 15px;
  background: linear-gradient(180deg, var(--quit), var(--quit-deep)); box-shadow: 0 5px 0 var(--quit-edge);
}
.btn.hardcore:active { box-shadow: 0 2px 0 var(--quit-edge); }
.btn.hardcore .daily-v {
  font-family: var(--font-body);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em; color: rgba(255,255,255,.85);
}
.revive-count {
  font-family: var(--font-display);
  text-align: center; font-size: 48px; font-weight: 700; color: var(--gold);
  margin: 4px 0 2px;
}
.link-btn {
  display: block; margin: 14px auto 0; padding: 6px 10px;
  background: none; border: none; cursor: pointer;
  color: var(--dim); font-size: var(--fs-xs); font-weight: 700; text-decoration: underline;
}
.link-btn:active { color: var(--ink); }
.credits { font-size: var(--fs-xs); font-weight: 600; line-height: 1.5; color: var(--mute); margin: 6px 0 4px; }
.acct .name-rules { margin: 0 0 8px; }
.sso {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px; border-radius: 12px; cursor: pointer;
  font: inherit; font-size: 15px; font-weight: 700; letter-spacing: 0;
}
.sso.apple  { background: #fff; color: #000; border: none; }
.sso.google { background: #fff; color: #1f1f1f; border: 1px solid #747775; }
.sso:disabled { opacity: .6; cursor: default; }
.sso-logo { width: 18px; height: 18px; flex-shrink: 0; }
.sso-logo.apple { width: auto; height: auto; font-size: 19px; line-height: 1; }
.acct-linked { font-size: var(--fs-md); font-weight: 800; color: var(--carry); }
.acct-email { display: block; color: var(--dim); font-weight: 600; font-size: var(--fs-xs); margin-top: 2px; overflow-wrap: anywhere; }
.btn.quit { background: linear-gradient(180deg, var(--quit), var(--quit-deep)); box-shadow: 0 5px 0 var(--quit-edge); }
.btn.quit:active { box-shadow: 0 2px 0 var(--quit-edge); }
.btn.ghost.quit { background: transparent; box-shadow: none; color: #ff8a8d; border-color: rgba(229, 72, 77, .5); }
.btn.ghost.quit:active { background: rgba(229, 72, 77, .14); color: #ffb3b5; }

.help { font-size: var(--fs-sm); line-height: 1.6; color: var(--dim); font-weight: 600; }
.help b { color: var(--ink); font-weight: 800; }
.help .row { display: flex; gap: 10px; margin-bottom: 6px; }
.help .row span:first-child { flex-shrink: 0; min-width: 84px; color: var(--gold); font-weight: 800; font-size: var(--fs-xs); letter-spacing: .06em; padding-top: 1px; }
/* Sprite pictures above a rule's text, each in a little window of mine floor. */
.help-pics { display: flex; flex-wrap: wrap; gap: 10px; margin: 2px 0 4px; }
.help-pics figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.help-pics canvas { display: block; border-radius: 6px; outline: 1px solid rgba(255,255,255,.08); }
.help-pics figcaption { font-size: var(--fs-xs); font-weight: 700; color: var(--mute); }

/* ------------------------------------------------- online panels */
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-row .btn { margin-top: 9px; }
.btn-row.one { grid-template-columns: 1fr; }
.btn.small { width: auto; display: inline-block; margin: 0; padding: 7px 12px; font-size: var(--fs-sm); }
.btn:disabled { opacity: .5; cursor: default; }

/* Two rows: the all-time boards (three) over the dailies (two). */
.tabs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-bottom: 10px; }
.tabs .tab { grid-column: span 2; }
.tabs .tab:nth-child(n+4) { grid-column: span 3; }
.tab {
  padding: 9px 4px; border-radius: 10px;
  border: 1px solid var(--edge); background: transparent;
  color: var(--dim); font-size: var(--fs-xs); font-weight: 800; letter-spacing: .04em;
  cursor: pointer;
}
.tab:active { background: var(--surface-3); }
.tab.on { background: var(--surface-3); color: var(--gold); border-color: rgba(255, 201, 94, .4); }

.board { min-height: 120px; }
.board-row { align-items: center; padding: 5px; }
.board-row .rk { min-width: 22px; text-align: center; }
.board-row .nm {
  flex: 1; min-width: 0; font-size: var(--fs-sm); font-weight: 800; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.board-row .vv { flex: 0 0 auto; min-width: 58px; text-align: right; }
.board-row .dd { flex: 0 0 auto; min-width: 46px; text-align: right; }
.board-row .hs { color: #ff7a3c; }
.board-row.pinned { margin-top: 6px; border-top: 1px dashed rgba(255,255,255,.14); border-radius: 0 0 7px 7px; }
.board-stale { font-size: var(--fs-xs); font-weight: 700; color: var(--gold); margin-bottom: 6px; }
.score-row .dd.wide { flex: 1; }

.medal {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  vertical-align: -1px; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25);
}
.medal.gold   { background: var(--medal-gold); }
.medal.silver { background: var(--medal-silver); }
.medal.bronze { background: var(--medal-bronze); }
.medal.none   { background: rgba(255,255,255,.12); box-shadow: inset 0 0 0 1px rgba(255,255,255,.14); }
/* A daily-medal tally beside a name: the disc, then "×N" in the medal's own
   colour. The count never sits on the disc, where it would read as a placing. */
.medals { margin-left: 6px; font-size: var(--fs-xs); font-weight: 900; }
.medal-count { margin-left: 5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.medal-count .medal { width: 9px; height: 9px; margin-right: 2px; vertical-align: 0; }
.medal-count.gold   { color: var(--medal-gold); }
.medal-count.silver { color: var(--medal-silver); }
.medal-count.bronze { color: var(--medal-bronze); }
/* The medal board: the tally is the score, three fixed columns of it. */
.board-row .vv.medal-cols { display: flex; font-size: var(--fs-sm); }
.medal-cols .medal-count { display: inline-block; min-width: 34px; margin-left: 4px; text-align: left; }
.medal-cols .medal-count.zero { opacity: .35; }

.medal-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.medal-big {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 0; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--edge-soft);
  font-family: var(--font-display);
  font-size: var(--fs-lg); font-weight: 700;
}
.medal-big span { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.medal-big.gold span   { background: var(--medal-gold); }
.medal-big.silver span { background: var(--medal-silver); }
.medal-big.bronze span { background: var(--medal-bronze); }

.name-show { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
.name-show .nm { font-size: 20px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-edit input {
  width: 100%; box-sizing: border-box; padding: 12px 13px;
  border-radius: 12px; border: 1px solid var(--edge);
  background: var(--surface-0); color: var(--ink);
  font: inherit; font-size: 16px; font-weight: 800;   /* 16px stops iOS zooming in */
  user-select: text; -webkit-user-select: text;
}
.name-edit input:focus { outline: none; border-color: var(--gold); }
.name-rules { font-size: var(--fs-xs); color: var(--dim); font-weight: 600; margin-top: 6px; line-height: 1.45; }
.name-err { font-size: var(--fs-sm); color: #ff7d7d; font-weight: 800; margin-top: 6px; }
.note.danger { color: #ff9d8a; background: rgba(224, 98, 60, .1); border-color: rgba(224, 98, 60, .35); }
.online-line { font-size: var(--fs-sm); font-weight: 800; color: var(--carry); text-align: center; margin: -6px 0 12px; }

/* The end-of-campaign ledger: labels left, signed amounts right, total ruled off. */
.ledger { margin-bottom: 16px; font-size: var(--fs-sm); }
.ledger .row { justify-content: space-between; margin-bottom: 3px; }
.ledger .row span:first-child { min-width: 0; font-size: var(--fs-sm); letter-spacing: 0; color: var(--dim); font-weight: 700; padding-top: 0; }
.ledger .row span:last-child { color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.ledger .row span.total { color: var(--gold); font-size: var(--fs-md); }
.ledger .row:last-child { border-top: 1px solid rgba(255,255,255,.14); padding-top: 4px; margin-top: 4px; }

/* ------------------------------------------------- Achievements & stats */
.ach-list { display: flex; flex-direction: column; gap: 14px; margin: 12px 0 20px; }
.ach-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.ach-nm { font-size: var(--fs-md); font-weight: 800; }
.ach-lv { flex-shrink: 0; font-size: var(--fs-xs); font-weight: 800; letter-spacing: .06em; color: var(--dim); }
.ach.done .ach-lv { color: var(--earned); }

/* One achievement's levels, side by side. Cards are narrower than the row so
   the next one always peeks in: the row reads as something to swipe. */
.lv-strip {
  position: relative;
  display: flex; gap: 8px;
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  touch-action: pan-x pan-y;
  scrollbar-width: none;
}
.lv-strip::-webkit-scrollbar { display: none; }
.lv-card {
  flex: 0 0 74%;
  scroll-snap-align: start;
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 11px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--edge-soft);
}
.lv-card.done { border-color: rgba(116, 224, 106, .38); background: rgba(116, 224, 106, .06); }
.lv-card.now { border-color: var(--edge-strong); }
.lv-card.locked { opacity: .5; }
.lv-ds { font-size: var(--fs-sm); font-weight: 700; line-height: 1.35; color: var(--ink); }
.lv-card.locked .lv-ds { color: var(--dim); }
.lv-pg { font-size: var(--fs-xs); font-weight: 800; color: var(--dim); font-variant-numeric: tabular-nums; }
.lv-card.done .lv-pg { color: var(--earned); }
.ach-bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,.12); overflow: hidden; }
.ach-bar span { display: block; height: 100%; border-radius: 3px; background: var(--gold); }

/* The level itself, in Roman numerals. Filled once earned, outlined while
   being worked on, grey while locked. */
.lv-badge {
  align-self: flex-start;
  min-width: 30px; height: 22px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
  font-size: 13px; font-weight: 700; letter-spacing: .06em; line-height: 1;
}
.lv-badge.done { background: linear-gradient(180deg, #a8f29a, #4fb845); color: #0f2a0b; box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.lv-badge.now { color: var(--gold); box-shadow: inset 0 0 0 1.5px var(--gold); }
.lv-badge.locked { color: var(--dim); box-shadow: inset 0 0 0 1px var(--edge-strong); }

/* Profile: the way into achievements, and the save's two red buttons. */
.btn.ach-btn { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 16px; }
.ach-count { font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 800; color: var(--earned); font-variant-numeric: tabular-nums; }
.danger-zone { margin-top: 4px; }

.stats-h { margin-bottom: 10px; }
.score-head.split { display: flex; justify-content: space-between; }
.score-head.split span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-list { margin-bottom: 0; }
.stat-list .row:last-child { border-top: 0; padding-top: 0; margin-top: 0; }

/* ------------------------------------------------- CJK typography
   The wide Latin letter-spacing used across the HUD looks broken on Chinese,
   which is already generously spaced by its own glyph metrics. */
body.lang-cjk .depth,
body.lang-cjk .timer,
body.lang-cjk .score-head,
body.lang-cjk .wallet .lbl,
body.lang-cjk .toast,
body.lang-cjk .hint-k,
body.lang-cjk .coach-k,
body.lang-cjk .banner p,
body.lang-cjk .panel h2,
body.lang-cjk .panel .tagline,
body.lang-cjk .stat .k,
body.lang-cjk .shop-section,
body.lang-cjk .tab,
body.lang-cjk .btn,
body.lang-cjk .act { letter-spacing: .02em; }
body.lang-cjk .help { line-height: 1.75; }
body.lang-cjk .help .row span:first-child { min-width: 64px; font-size: var(--fs-sm); letter-spacing: 0; }
body.lang-cjk .banner h1 { letter-spacing: .06em; }
body.lang-cjk .panel .logo-sub { letter-spacing: .3em; }

/* Wider layout: keep the thumbs where they belong on tablets/desktop. */
@media (min-width: 720px) and (min-height: 520px) {
  #stickzone { width: 40%; }
  #action { width: 88px; height: 88px; }
  .act.small { width: 68px; height: 68px; }
}

/* Short screens: lift the parked stick clear of the action cluster. */
@media (max-height: 700px) {
  #stickbase { bottom: calc(var(--safe-b) + 106px); }
}

/* Landscape phones: too short for a pinned shop header, so the whole panel
   scrolls as one again. */
@media (max-height: 520px) {
  .panel-inner.shop { display: block; max-height: none; }
  .shop .shop-scroll { overflow: visible; -webkit-mask-image: none; mask-image: none; }
}

/* Narrow phones: three control clusters have to share one thumb's width. */
@media (max-width: 400px) {
  #buttons { gap: 8px; right: calc(var(--safe-r) + 10px); }
  #action { width: 84px; height: 84px; }
  .act.small { width: 62px; height: 62px; }
  .act svg { width: 19px; height: 19px; }
}
@media (hover: hover) and (pointer: fine) {
  #controls { opacity: .55; transition: opacity .2s ease; }
  #controls:hover { opacity: 1; }
  .btn:hover:not(:disabled) { filter: brightness(1.08); }
  .btn.ghost:hover:not(:disabled), .lang-chip:hover, .tab:hover { color: var(--ink); border-color: var(--edge-strong); }
  .buy:hover:not(:disabled) { background: #3a2e5a; }
  .pause-btn:hover { background: rgba(111,87,184,.4); }
  /* A mouse can't swipe the level strips: widen the panel so every level
     card sits side by side instead. */
  .panel-inner.achievements { max-width: min(860px, 100%); }
  .achievements .lv-strip { overflow-x: visible; scroll-snap-type: none; }
  .achievements .lv-card { flex: 1 1 0; min-width: 0; }
}

/* Reduced motion: keep every message, drop the zoom, bounce and pulse. */
@media (prefers-reduced-motion: reduce) {
  .banner.show { animation: bannerFade 2.6s linear forwards; }
  @keyframes bannerFade { 0% { opacity: 0 } 10%, 80% { opacity: 1 } 100% { opacity: 0 } }
  .toast, .toast.show { transform: translate(-50%, 0); }
  .achieve.show { animation: bannerFade 2.6s linear forwards; }
  .hint.show { animation: bannerFade 5.5s linear forwards; }
  .heart.pop, .val.bump { transform: none; }
  .timer.warn { animation: none; }
  .panel { animation: none; }
}
