/* Full-bleed voxel world; chrome sits in a top rail, leaderboard docks right on desktop and slides up on phones */
:root {
  --ink: #141a2b;
  --paper: #fffaf0;
  --gold: #ffc83d;
  --gold-deep: #c48c12;
  --hot: #ff5a4e;
  --sol: #3cf0a8;
  --violet: #9b6bff;
  --panel: rgba(18, 24, 42, .88);
  --panel-line: rgba(255, 250, 240, .14);
  --muted: rgba(255, 250, 240, .66);
  --display: 'Bungee', 'Arial Black', Impact, sans-serif;
  --ui: 'Chakra Petch', 'Trebuchet MS', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: #22304a; color: var(--paper); font-family: var(--ui);
  overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none;
}
#game { position: fixed; inset: 0; }
#game canvas { display: block; width: 100%; height: 100%; }
button { font-family: var(--ui); color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* top rail */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 0; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { font-family: var(--display); font-size: 22px; text-shadow: 0 3px 0 var(--ink); display: flex; align-items: center; gap: 8px; }
.net { font-family: var(--ui); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  background: var(--violet); color: var(--paper); padding: 2px 7px; border-radius: 6px; text-shadow: none; }
.round {
  display: flex; align-items: baseline; gap: 10px; background: var(--panel); border: 2px solid var(--panel-line);
  border-radius: 999px; padding: 7px 16px;
}
.round .lbl { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.sol { font-family: var(--display); font-weight: 400; font-size: 20px; color: var(--sol); font-variant-numeric: tabular-nums; }
.timer { font-family: var(--display); font-size: 16px; font-variant-numeric: tabular-nums; min-width: 4.2ch; }
.timer.hot { color: var(--hot); }
.tb-right { display: flex; gap: 8px; justify-content: flex-end; }
.chip {
  background: var(--panel); border: 2px solid var(--panel-line); border-radius: 10px; padding: 8px 12px;
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap;
}
.chip:hover { border-color: rgba(255, 250, 240, .35); }
.chip.wallet.on { color: var(--sol); }
#lbToggle { display: none; }

/* leaderboard */
.lb {
  position: fixed; z-index: 4; right: 16px; top: calc(env(safe-area-inset-top, 0px) + 72px); width: 272px;
  max-height: calc(100% - 100px); overflow: auto; background: var(--panel); border: 2px solid var(--panel-line);
  border-radius: 16px; padding: 14px;
}
.lb-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.lb h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 18px; }
.entries { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .06em; }
.lb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lb-list li {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px; background: rgba(255, 250, 240, .05); font-variant-numeric: tabular-nums;
}
.lb-list li:first-child { background: rgba(255, 200, 61, .16); }
.lb-list li:first-child .rk { color: var(--gold); }
.lb-list li.me { outline: 2px solid var(--sol); }
.rk { font-family: var(--display); font-size: 14px; color: var(--muted); }
.addr { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pts { font-family: var(--display); font-size: 16px; }
.lb-empty { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.prev { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--panel-line); font-size: 13px; color: var(--muted); line-height: 1.45; }
.prev b { color: var(--paper); font-weight: 700; }
.prev a { color: var(--sol); }

/* in-game hud */
.hud { position: fixed; left: 16px; top: calc(env(safe-area-inset-top, 0px) + 54px); z-index: 3; pointer-events: none; display: grid; gap: 4px; }
#score { font-family: var(--display); font-size: clamp(48px, 9vw, 76px); line-height: 1; text-shadow: 0 4px 0 var(--ink), 0 8px 0 rgba(0,0,0,.2); font-variant-numeric: tabular-nums; }
.mode-badge { justify-self: start; font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px; background: var(--panel); }
.mode-badge.ranked { background: var(--gold); color: var(--ink); }

#toast { position: fixed; left: 50%; top: 30%; z-index: 6; transform: translate(-50%, 0); font-family: var(--display);
  font-size: clamp(22px, 5vw, 34px); color: var(--gold); text-shadow: 0 3px 0 var(--ink); pointer-events: none; opacity: 0; white-space: nowrap; }
#toast.show { animation: pop .9s ease-out forwards; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(.7); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -10px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -24px) scale(1); }
}

/* menus */
.overlay {
  position: fixed; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 92px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
  text-align: center; pointer-events: none;
}
.overlay > * { pointer-events: auto; }
.overlay > .menu-top { pointer-events: none; }
.overlay.center { justify-content: center; background: rgba(12, 16, 30, .4); }
.logo {
  margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(60px, 15vw, 128px); line-height: .9;
  color: var(--gold); text-shadow: 0 6px 0 var(--ink), 0 12px 0 rgba(0,0,0,.25); letter-spacing: .02em;
}
.tag { margin: 14px auto 0; font-weight: 700; font-size: 15px; max-width: 36ch; text-shadow: 0 2px 0 var(--ink); text-wrap: balance; }
.panel {
  width: min(400px, 100%); display: grid; gap: 10px; background: var(--panel); border: 2px solid var(--panel-line);
  border-radius: 20px; padding: 12px;
}
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 14px; }
.seg button {
  border: none; border-radius: 10px; background: none; padding: 9px 6px; font-family: var(--display); font-size: 16px;
  display: grid; gap: 2px; color: var(--muted);
}
.seg button small { font-family: var(--ui); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.seg button[aria-checked="true"] { background: var(--paper); color: var(--ink); }
.seg button[data-mode="ranked"][aria-checked="true"] { background: var(--gold); }
.picker { display: flex; align-items: center; gap: 8px; }
.arrow { width: 44px; height: 44px; flex: none; border-radius: 12px; border: none; background: rgba(255,250,240,.1); font-family: var(--display); font-size: 22px; }
.arrow:hover { background: rgba(255,250,240,.2); }
.cinfo { flex: 1; min-width: 0; text-align: left; padding-left: 4px; }
#cname { font-family: var(--display); font-size: 20px; }
#cstat { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
#cstat.price { color: var(--sol); }
.buy { flex: none; border: none; border-radius: 10px; padding: 10px 12px; background: var(--sol); color: var(--ink); font-weight: 700; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.cta {
  width: 100%; border: none; border-radius: 14px; padding: 15px 18px; background: var(--gold); color: var(--ink);
  font-family: var(--display); font-size: 21px; box-shadow: 0 6px 0 var(--gold-deep); transition: transform .08s;
}
.cta:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--gold-deep); }
.cta:disabled { background: #8a8f9c; box-shadow: 0 6px 0 #5d6270; cursor: not-allowed; }
.note { margin: 2px 4px 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.msg { margin: 0; font-size: 13px; font-weight: 600; color: var(--paper); background: rgba(255, 90, 78, .22); border-radius: 10px; padding: 8px 10px; text-align: left; }

.card { width: min(360px, 100%); background: var(--panel); border-radius: 20px; padding: 22px 20px; display: grid; gap: 12px; border: 2px solid var(--panel-line); }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--hot); }
.big { font-family: var(--display); font-size: 88px; line-height: 1; text-shadow: 0 5px 0 var(--ink); font-variant-numeric: tabular-nums; }
.result { font-size: 15px; font-weight: 600; line-height: 1.45; min-height: 1.45em; }
.result .rank { font-family: var(--display); color: var(--gold); font-size: 20px; display: block; }
.actions { display: grid; gap: 8px; }
.ghost { background: none; border: 2px solid rgba(255,250,240,.3); border-radius: 12px; padding: 10px 16px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; }

.nag { border: none; border-radius: 10px; padding: 8px 10px; background: rgba(255, 200, 61, .18); color: var(--gold); font-size: 13px; font-weight: 700; text-align: left; }

/* wallet sheet */
.modal { position: fixed; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 14, 26, .6); }
.sheet { width: min(440px, 100%); max-height: 100%; overflow: auto; background: #182038; border: 2px solid var(--panel-line); border-radius: 20px; padding: 18px; display: grid; gap: 14px;
  -webkit-user-select: text; user-select: text; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 20px; }
.x { width: 36px; height: 36px; border-radius: 10px; border: none; background: rgba(255,250,240,.1); font-size: 22px; line-height: 1; }
.bal { display: flex; align-items: baseline; gap: 10px; background: rgba(0,0,0,.25); border-radius: 14px; padding: 12px 14px; }
.bal span { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.bal .sol { font-size: 26px; flex: 1; }
.flabel { display: block; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.addrbox { display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.25); border-radius: 10px; padding: 8px 8px 8px 12px; }
.addrbox code { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.mini { flex: none; border: none; border-radius: 8px; padding: 7px 10px; background: rgba(255,250,240,.12); font-weight: 700; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.mini:hover { background: rgba(255,250,240,.22); }
details { border-top: 1px solid var(--panel-line); padding-top: 12px; }
details > *:not(summary) { margin-top: 10px; }
summary { cursor: pointer; font-weight: 700; font-size: 15px; }
.sheet input, .sheet textarea { width: 100%; border: 2px solid var(--panel-line); border-radius: 10px; background: rgba(0,0,0,.3); color: var(--paper); padding: 10px 12px;
  font-family: ui-monospace, Consolas, monospace; font-size: 14px; resize: vertical; }
.sheet input:focus, .sheet textarea:focus { outline: none; border-color: var(--gold); }
.row { display: flex; gap: 8px; }
.cta.small { font-size: 17px; padding: 11px; }
.warn { margin: 0; font-size: 13px; line-height: 1.45; color: var(--gold); }
.msg.ok { background: rgba(60, 240, 168, .18); }

.busy { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(10, 14, 26, .7); text-align: center; padding: 0 24px; }
.busy p { margin: 0; font-family: var(--display); font-size: 22px; }
.busy small { font-size: 13px; color: var(--muted); }
#paused { cursor: pointer; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 5px solid rgba(255,250,240,.2); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  #lbToggle { display: inline-block; }
  .lb { display: none; }
  .lb.open { display: block; }
}
@media (max-width: 860px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .round { justify-self: center; padding: 6px 12px; gap: 8px; }
  .round .lbl { display: none; }
  .lb { left: 16px; right: 16px; width: auto; top: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); max-height: 60%; z-index: 7; display: none; }
  .lb.open { display: block; }
}
@media (max-width: 520px) {
  .brand { font-size: 0; gap: 0; }
  .brand::before { content: 'C'; font-size: 22px; }
  .net { font-size: 10px; margin-left: 6px; }
  .sol { font-size: 17px; }
  .timer { font-size: 14px; }
  .chip { padding: 7px 9px; font-size: 11px; }
  .overlay { padding-top: calc(env(safe-area-inset-top, 0px) + 72px); }
}
@media (prefers-reduced-motion: reduce) { #toast.show { animation-duration: 1.4s; } .spinner { animation-duration: 2s; } }
