@font-face { font-family: Display; src: url('/fonts/ChakraPetch-600.woff2') format('woff2'); font-weight: 400 650; font-display: swap; }
@font-face { font-family: Display; src: url('/fonts/ChakraPetch-700.woff2') format('woff2'); font-weight: 651 900; font-display: swap; }

:root {
  --bg: #090b0a; --bg2: #101311; --panel: rgba(16, 19, 17, .92); --line: #262c27; --line2: #343b35;
  --ink: #eef3e8; --mute: #a3ab9f; --dim: #727a70;
  --lime: #c3ff5c; --lime-ink: #0b1000; --lav: #b9a7ff; --coral: #ff7a6b; --ember: #ff8a2b;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body {
  font: 500 15px/1.4 Display, system-ui, sans-serif; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; position: fixed; inset: 0;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--lime); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

#app { position: fixed; inset: 0; display: flex; }
.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; outline: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--dim); font-size: 13px; letter-spacing: .12em; text-transform: uppercase; pointer-events: none; transition: opacity .25s; }
.ready .loading { opacity: 0; }

/* Top bar */
.top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 12px) 0 calc(var(--safe-l) + 14px); pointer-events: none; z-index: 3; }
.top > * { pointer-events: auto; }
.brand { display: block; padding: 8px 0; }
.mark { display: block; width: 132px; height: 21px; }
.mark rect { fill: var(--lime); }
.mark rect.b { fill: var(--ink); }
.tools { display: flex; gap: 8px; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: rgba(12, 14, 13, .72);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); padding: 0; transition: transform .15s var(--ease), border-color .15s; }
.icon:active { transform: scale(.92); }
.holder-btn.on { border-color: var(--lime); padding: 0; overflow: hidden; }
.holder-btn img, .avatar img, .avatar canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.holder-btn.on img { width: 36px; height: 36px; }
.playing .top .brand, .playing .tools { opacity: 0; pointer-events: none; }
.top .brand, .tools { transition: opacity .2s; }

/* HUD */
.hud { position: absolute; top: calc(var(--safe-t) + 12px); left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; z-index: 2;
  opacity: 0; transition: opacity .2s; text-shadow: 0 2px 0 #000; }
.playing .hud, .over-state .hud { opacity: 1; }
.over-state .hud { opacity: 0; }
.hud b { display: block; font: 700 40px/1 Display, sans-serif; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.hud-sub { display: inline-flex; align-items: center; gap: 6px; color: var(--mute); font-size: 14px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.hud .em, .over-stats .em { width: 13px; height: 13px; stroke: none; }
.hud .sh { width: 16px; height: 16px; color: var(--lav); margin-left: 4px; }
.dot { width: 3px; height: 3px; background: var(--dim); display: inline-block; }
.pause { position: absolute; z-index: 3; top: calc(var(--safe-t) + 10px); right: calc(var(--safe-r) + 12px); opacity: 0; pointer-events: none; transition: opacity .2s; }
.playing .pause { opacity: .85; pointer-events: auto; }
.hint, .paused { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 18%); margin: 0; padding: 10px 16px; border-radius: 999px;
  background: rgba(10, 12, 11, .8); border: 1px solid var(--line2); color: var(--ink); font-size: 14px; white-space: nowrap; pointer-events: none; z-index: 2;
  animation: hint 3s var(--ease) forwards; }
.paused { animation: none; bottom: 42%; color: var(--lime); }
@keyframes hint { 0% { opacity: 0; transform: translate(-50%, 8px); } 8%, 82% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* Panels (home, over): phone = bottom card above the toolbar */
.panel { position: absolute; z-index: 3; left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px); bottom: calc(var(--safe-b) + 76px);
  margin: 0 auto; max-width: 440px; padding: 14px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  transition: opacity .2s var(--ease), transform .25s var(--ease); }
.playing .panel { opacity: 0; transform: translateY(16px); pointer-events: none; }
.mode { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--bg); border-radius: 14px; border: 1px solid var(--line); }
.mode button { min-height: 48px; border: 0; border-radius: 10px; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; color: var(--mute); transition: background .15s, color .15s; }
.mode button span { font-size: 15px; font-weight: 600; }
.mode button b { font-size: 12px; font-weight: 500; color: var(--dim); }
.mode button[aria-selected="true"] { background: #1b201c; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line2); }
.mode button[aria-selected="true"] b { color: var(--lime); }
.runner-chip { width: 100%; margin-top: 10px; display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 8px; min-height: 60px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); text-align: left; transition: border-color .15s, transform .15s var(--ease); }
.runner-chip:active { transform: scale(.98); }
.runner-chip .chev { color: var(--dim); margin-left: auto; width: 20px; height: 20px; }
.avatar { width: 44px; height: 44px; border-radius: 10px; background: #0d0f0e; border: 1px solid var(--line); overflow: hidden; flex: none; display: block; }
.avatar.big { width: 72px; height: 72px; border-radius: 14px; }
.sk { background: linear-gradient(100deg, #111412 30%, #1b201c 50%, #111412 70%) 0 0 / 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.rc-text { display: flex; flex-direction: column; min-width: 0; }
.rc-text b { font-size: 16px; font-weight: 600; }
.rc-text small { font-size: 12px; color: var(--mute); }
.rc-text small.holder { color: var(--lime); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line2); background: #171b18; font-weight: 600; font-size: 15px; transition: transform .15s var(--ease), background .15s, opacity .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--lime); color: var(--lime-ink); border-color: var(--lime); }
.btn.primary svg { color: var(--lime-ink); }
.go { width: 100%; margin-top: 10px; min-height: 58px; font-size: 19px; letter-spacing: .04em; text-transform: uppercase; border-radius: 16px; box-shadow: 0 8px 30px rgba(195, 255, 92, .18); }
.go svg { width: 24px; height: 24px; }
.best-line { margin: 10px 2px 0; text-align: center; color: var(--mute); font-size: 13px; }
.best-line b { color: var(--ink); font-weight: 600; }

.over { text-align: center; animation: rise .25s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.over-tag { margin: 0; color: var(--mute); font-size: 13px; letter-spacing: .12em; text-transform: uppercase; }
.over-score { margin: 2px 0 0; }
.over-score b { font: 700 56px/1 Display, sans-serif; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.over-score.record b { color: var(--lime); }
.over-stats { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 6px 0 0; color: var(--mute); font-size: 14px; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.over-post { min-height: 20px; margin: 8px 0 0; font-size: 13px; color: var(--mute); }
.over-post b { color: var(--lime); font-weight: 600; }
.over-post button { border: 0; background: none; color: var(--lime); text-decoration: underline; padding: 6px 2px; font-size: 13px; }
.over-actions { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-top: 10px; }
.over-actions .btn.primary { min-height: 54px; font-size: 17px; }
.over-actions .btn:not(.primary) { min-width: 54px; padding: 0 14px; }
.post { width: 100%; margin-top: 8px; }
.post .avatar { width: 28px; height: 28px; border-radius: 7px; }

/* Bottom toolbar */
.bar { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 4px;
  padding: 6px calc(var(--safe-r) + 12px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 12px); transition: opacity .2s, transform .25s var(--ease); }
.bar button { flex: 1; max-width: 140px; min-height: 56px; border: 0; background: none; color: var(--mute); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; font-weight: 600; letter-spacing: .02em; border-radius: 12px; transition: color .15s, background .15s; }
.bar button:active { background: rgba(255, 255, 255, .05); color: var(--ink); }
.playing .bar { opacity: 0; transform: translateY(20px); pointer-events: none; }

/* Sheets */
.sheet { position: fixed; inset: auto 0 0 0; margin: 0 auto; width: 100%; max-width: 520px; max-height: min(84dvh, 720px); padding: 6px 16px calc(var(--safe-b) + 16px);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0; background: #0f1210; color: var(--ink); overflow: auto; overscroll-behavior: contain; }
.sheet[open] { animation: sheet .25s var(--ease); }
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
.sheet::backdrop { background: rgba(0, 0, 0, .6); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 6px; position: sticky; top: -6px; background: #0f1210; z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.close { border-color: transparent; background: transparent; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 4px 0 10px; }
.tabs button { min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: transparent; color: var(--mute); font-weight: 600; }
.tabs button[aria-selected="true"] { background: #1b201c; color: var(--ink); border-color: var(--line2); }

.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.board li { display: grid; grid-template-columns: 30px 36px 1fr auto; align-items: center; gap: 10px; min-height: 48px; padding: 4px 10px 4px 6px; border-radius: 12px; background: var(--bg2); font-variant-numeric: tabular-nums; }
.board li.you { box-shadow: inset 0 0 0 1px var(--lime); }
.board .rank { text-align: center; color: var(--mute); font-weight: 600; }
.board li:nth-child(1) .rank { color: var(--lime); }
.board img { width: 36px; height: 36px; border-radius: 8px; image-rendering: pixelated; background: #0b0d0c; }
.board .addr { color: var(--ink); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .addr small { display: block; color: var(--dim); font-size: 12px; }
.board .sc { font-weight: 700; font-size: 16px; }
.board.skeleton li { background: linear-gradient(100deg, #111412 30%, #181c19 50%, #111412 70%) 0 0 / 200% 100%; animation: sk 1.2s linear infinite; }
.you-row { margin-top: 8px; }
.empty { color: var(--mute); text-align: center; margin: 18px 0; font-size: 14px; }
#board-join { width: 100%; margin-top: 12px; }

.guest-runner { display: flex; gap: 14px; align-items: center; padding: 6px 0 12px; }
.guest-runner p { margin: 0; }
.guest-runner small { color: var(--mute); font-size: 13px; }
.wallets { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.wallet { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); font-weight: 600; text-align: left; }
.wallet img, .wallet svg { width: 32px; height: 32px; border-radius: 8px; }
.wallet svg { padding: 4px; color: var(--lime); }
.fine, .msg, .perk { color: var(--mute); font-size: 13px; margin: 12px 0 0; }
.msg:empty { display: none; }
.addr-line { display: flex; justify-content: space-between; align-items: center; margin: 4px 0; font-variant-numeric: tabular-nums; }
.link { border: 0; background: none; color: var(--coral); min-height: 44px; padding: 0 4px; font-size: 14px; }
.perk { margin-top: 0; color: var(--lime); }
.mine { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.mine button { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); font-size: 12px; color: var(--mute); }
.mine button[aria-pressed="true"] { border-color: var(--lime); color: var(--lime); }
.mine img { width: 64px; height: 64px; image-rendering: pixelated; }
.how { margin: 4px 0 0; padding: 0 0 0 18px; display: grid; gap: 10px; color: var(--mute); }
.how b { color: var(--ink); font-weight: 600; }
.sig { color: var(--dim); font-size: 13px; margin: 16px 0 0; }

.toast { position: fixed; z-index: 20; left: 50%; top: calc(var(--safe-t) + 70px); transform: translate(-50%, -10px); opacity: 0; pointer-events: none; padding: 10px 16px; border-radius: 999px;
  background: #1b201c; border: 1px solid var(--line2); font-size: 14px; transition: opacity .2s, transform .2s var(--ease); white-space: nowrap; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Side panel: tablet landscape and desktop */
.side { display: none; }
@media (min-width: 1024px) and (min-height: 600px) {
  .side { display: flex; flex-direction: column; width: 340px; flex: none; border-left: 1px solid var(--line); background: #0c0e0d; padding: calc(var(--safe-t) + 18px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) 16px; overflow: hidden; }
  .side-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
  .side-head h2 { margin: 0; font-size: 22px; } .side-head h2 span { color: var(--lime); }
  .side-head small { color: var(--mute); font-size: 13px; }
  .side .board { overflow: auto; flex: 1; align-content: start; }
  .side-foot { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
  .keys { color: var(--dim); font-size: 12px; line-height: 2; margin: 0; }
  kbd { font: 600 12px Display, sans-serif; color: var(--ink); background: #171b18; border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; margin-right: 2px; }
  .side .sig { margin-top: 8px; }
  .bar #open-board { display: none; }
  .panel { left: 50%; right: auto; width: 400px; transform: translateX(-50%); bottom: calc(var(--safe-b) + 84px); }
  .playing .panel { transform: translate(-50%, 16px); }
}
@media (min-width: 1440px) { .side { width: 380px; } }

/* Phone landscape and short screens: panel moves to the right edge, toolbar becomes a column */
@media (orientation: landscape) and (max-height: 520px) {
  .panel { left: auto; right: calc(var(--safe-r) + 76px); top: calc(var(--safe-t) + 10px); bottom: calc(var(--safe-b) + 10px); width: min(340px, 46vw); max-width: none; display: flex; flex-direction: column; justify-content: center; padding: 10px 12px; overflow: auto; }
  .go { min-height: 50px; }
  .runner-chip { min-height: 52px; }
  .over-score b { font-size: 44px; }
  .bar { left: auto; top: 0; bottom: 0; width: calc(var(--safe-r) + 72px); flex-direction: column; justify-content: center; padding: 8px calc(var(--safe-r) + 8px) 8px 8px; }
  .bar button { flex: none; width: 56px; }
  .playing .bar { transform: translateX(20px); }
  .top { padding-right: calc(var(--safe-r) + 84px); }
  .pause { right: calc(var(--safe-r) + 12px); }
  .hud b { font-size: 30px; }
  .hint, .paused { bottom: calc(var(--safe-b) + 14px); }
  .paused { bottom: 40%; }
}
@media (max-width: 359px) {
  #share span { display: none; }
  .panel { padding: 12px; left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px); }
  .over-score b { font-size: 48px; }
  .hint { font-size: 13px; padding: 8px 12px; }
}
@media (min-width: 700px) and (min-height: 900px) {
  .panel { max-width: 480px; bottom: calc(var(--safe-b) + 96px); padding: 18px; }
  .hud b { font-size: 52px; }
}

/* 404 */
.lost { min-height: 100dvh; display: grid; place-content: center; gap: 18px; text-align: center; padding: 24px; position: static; }
.lost h1 { margin: 0; font-size: 34px; } .lost h1 span { color: var(--lime); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .12s !important; }
  .hint { animation: none; }
}
