:root {
  --bg: #000;
  --panel: rgba(8, 12, 18, 0.82);
  --panel-solid: #0a0e14;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #e8eef5;
  --dim: #8a97a6;
  --faint: #56616e;
  --accent: #20e0ff;
  --danger: #ff3b5c;
  --ui: "Tektur", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui); overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#game { position: fixed; inset: 0; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
.off { display: none !important; }

/* ---------- menu ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 10;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,12,18,.35) 0%, rgba(0,6,10,.82) 65%, rgba(0,0,0,.94) 100%); }
#loading { z-index: 30; background: #000; transition: opacity .45s ease; }
#loading.fade { opacity: 0; pointer-events: none; }
.load-inner { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.loadbar { position: relative; width: 240px; height: 2px; background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 1px; }
.loadbar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); box-shadow: 0 0 10px var(--accent); transition: width .3s ease; }
.loadbar i::after { content: ""; position: absolute; right: -3px; top: -2px; width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 8px #fff, 0 0 16px var(--accent); }
#load-text { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); height: 14px; }

.menu-bar { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; pointer-events: none; }
#status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--dim); letter-spacing: .06em; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: rgba(4,8,12,.6); }
#status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
#status.online .dot { background: #3dff8a; box-shadow: 0 0 8px #3dff8a; }
#status.offline .dot { background: #ffb020; }
#best { font-size: 12.5px; color: var(--dim); letter-spacing: .06em; }
#best b { color: #fff; font-weight: 600; margin-left: 6px; font-variant-numeric: tabular-nums; }

.menu-inner { display: flex; flex-direction: column; align-items: center; gap: 26px; padding: 0 16px; width: 100%; max-width: 440px; }
.title { position: relative; width: min(640px, 92vw); display: flex; justify-content: center; padding: 6px 0 20px; }
.wordmark { margin: 0; font-weight: 900; font-stretch: 100%; font-size: clamp(50px, 11.5vw, 104px); line-height: .95; letter-spacing: .06em;
  padding-left: .08em; white-space: nowrap; }
.wordmark span { background: linear-gradient(180deg, #ffffff 0%, color-mix(in srgb, var(--accent) 18%, #fff) 55%, color-mix(in srgb, var(--accent) 60%, #fff) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 65%, transparent)) drop-shadow(0 0 26px color-mix(in srgb, var(--accent) 35%, transparent)); }
.wordmark.sm { font-size: 40px; }
.trace { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.trace path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.trace-bed { stroke: color-mix(in srgb, var(--accent) 14%, transparent); stroke-width: 2; }
.trace-run { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 140 860; animation: run 3.2s linear infinite;
  filter: drop-shadow(0 0 4px var(--accent)) drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 70%, transparent)); }
@keyframes run { from { stroke-dashoffset: 1000; } to { stroke-dashoffset: 0; } }

.play-card { width: 100%; display: flex; flex-direction: column; padding: 14px 18px 18px; background: rgba(6,12,18,.92);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
#preview { width: 100%; height: 64px; display: block; margin-bottom: 10px; border-radius: 10px; background: #001923; }
.field-label { font-size: 10.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .14em; margin: 10px 0 7px; }
#name { height: 46px; padding: 0 14px; background: rgba(0,0,0,.45); border: 1px solid var(--line-2); border-radius: 10px;
  color: #fff; font: 600 18px var(--ui); outline: none; transition: border-color .15s, box-shadow .15s; }
#name:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
#name::placeholder { color: #3c4651; }
#swatches { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; }
#swatches button { aspect-ratio: 1; border-radius: 7px; border: 0; padding: 0; opacity: .5; transition: opacity .12s, transform .12s, box-shadow .12s; }
#swatches button:hover { opacity: .9; }
#swatches button.sel { opacity: 1; transform: scale(1.12); box-shadow: 0 0 0 2px #000, 0 0 0 3.5px #fff, 0 0 16px currentColor; }
#hue { width: 100%; height: 14px; margin: 4px 0 4px;
  background: linear-gradient(90deg, hsl(0,100%,60%), hsl(60,100%,60%), hsl(120,100%,60%), hsl(180,100%,60%), hsl(240,100%,60%), hsl(300,100%,60%), hsl(360,100%,60%)); }
.primary { position: relative; height: 52px; margin-top: 16px; padding: 0 28px; border: 0; border-radius: 12px; background: var(--accent); color: #00090d;
  font-weight: 800; font-size: 19px; letter-spacing: .12em; text-transform: uppercase; display: flex; align-items: center; justify-content: center; gap: 12px;
  box-shadow: 0 0 28px color-mix(in srgb, var(--accent) 45%, transparent); transition: transform .08s, box-shadow .15s, filter .15s; }
.primary:hover { filter: brightness(1.08); box-shadow: 0 0 40px color-mix(in srgb, var(--accent) 65%, transparent); }
.primary:active { transform: scale(.98); }
.primary kbd { font: 600 10.5px var(--mono); letter-spacing: .04em; text-transform: none; padding: 3px 6px; border-radius: 5px; background: rgba(0,0,0,.18); color: rgba(0,9,13,.7); }
.menu-nav { display: flex; gap: 8px; }
.menu-nav button, .dead-actions button:not(.primary), #next-track { background: transparent; border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 18px; color: var(--dim); font-size: 13.5px; font-weight: 500; letter-spacing: .04em; transition: color .12s, border-color .12s; }
.menu-nav button:hover, .dead-actions button:not(.primary):hover, #next-track:hover { color: #fff; border-color: rgba(255,255,255,.3); }
#nowplaying { position: fixed; left: 20px; bottom: 16px; font-size: 12px; color: var(--faint); }
@media (max-height: 700px) { .menu-inner { gap: 14px; } .title { padding-bottom: 8px; } .wordmark { font-size: 56px; } #preview { height: 44px; } }

/* ---------- death ---------- */
.dead-card { width: min(500px, calc(100vw - 32px)); padding: 28px 28px 20px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; text-align: center; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
#dead-title { font-size: 22px; font-weight: 600; margin-bottom: 20px; }
#dead-title b { color: var(--danger); font-weight: 700; }
.dead-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 22px; }
.dead-stats div { display: flex; flex-direction: column; gap: 2px; }
.dead-stats b { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dead-stats span { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; }
.dead-actions { display: flex; gap: 8px; justify-content: center; }
.dead-actions button { height: 44px; }
.hint { margin-top: 12px; font-size: 12px; color: var(--faint); }

/* ---------- panels ---------- */
.panel { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); }
.panel-card { width: min(500px, calc(100vw - 32px)); max-height: calc(100vh - 48px); display: flex; flex-direction: column;
  background: #070b10; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; animation: rise .18s ease-out;
  box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.panel-card header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; }
.panel-card h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .04em; }
.x { background: none; border: 0; color: var(--dim); font-size: 15px; width: 32px; height: 32px; border-radius: 8px; }
.x:hover { color: #fff; background: rgba(255,255,255,.06); }
.tabs { display: flex; gap: 4px; margin: 0 20px; padding: 4px; background: rgba(255,255,255,.04); border-radius: 11px; }
.tab { flex: 1; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--dim); font-size: 13.5px; font-weight: 600; letter-spacing: .04em; transition: background .12s, color .12s; }
.tab:hover { color: #fff; }
.tab.on { background: rgba(255,255,255,.09); color: #fff; }
.panel-body { padding: 16px 20px 20px; overflow-y: auto; min-height: 260px; }
.pane { display: flex; flex-direction: column; gap: 12px; }
.group { background: rgba(255,255,255,.025); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row small { display: block; font-size: 12px; color: var(--faint); margin-top: 2px; }
.row.vol { padding: 8px 0 12px; }
.row.vol span { font-size: 13px; color: var(--dim); }
.row.track { cursor: default; }
.row.track em { font-style: normal; font-size: 13.5px; color: #fff; }
#next-track { padding: 6px 14px; font-size: 12.5px; }
.row input[type=checkbox] { appearance: none; width: 48px; height: 14px; border-radius: 2px; background: #2a333d; position: relative; flex: none;
  cursor: pointer; transition: background .15s; margin: 0 4px 0 0; overflow: visible; }
.row input[type=checkbox]::after { content: ""; position: absolute; top: -5px; left: -2px; width: 24px; height: 24px; border-radius: 3px; background: #6b7682;
  border: 2px solid #070b10; box-sizing: border-box; transition: transform .14s ease, background .14s; }
.row input[type=checkbox]:checked { background: var(--accent); }
.row input[type=checkbox]:checked::after { transform: translateX(28px); background: #fff; }
.row input[type=checkbox]:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 6px; }
.row input:focus:not(:focus-visible) { outline: none; }
/* sliders: a long flat bar with a big square knob */
.row input[type=range], #hue { -webkit-appearance: none; appearance: none; height: 10px; border-radius: 2px; outline: none; cursor: pointer; }
.row input[type=range] { width: 60%; margin: 0; background: linear-gradient(90deg, var(--accent) 0 var(--v, 50%), #1c242d var(--v, 50%) 100%); }
.row input[type=range]::-webkit-slider-thumb, #hue::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 3px; background: #fff;
  border: 2px solid #070b10; box-shadow: none; }
.row input[type=range]::-moz-range-thumb, #hue::-moz-range-thumb { width: 18px; height: 18px; border-radius: 3px; background: #fff; border: 2px solid #000;
  box-shadow: 0 0 12px var(--accent); }
.krow { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14px; color: var(--dim); }
.krow:last-child { border-bottom: 0; }
.keys { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.keys i { font-style: normal; font-size: 12px; color: var(--faint); margin: 0 4px; }
kbd { font: 600 12px var(--mono); color: #fff; min-width: 26px; height: 26px; padding: 0 6px; display: inline-grid; place-items: center;
  background: linear-gradient(#1a222b, #11171e); border: 1px solid rgba(255,255,255,.12); border-bottom-width: 2px; border-radius: 6px; }
kbd.wide { min-width: 46px; font-family: var(--ui); letter-spacing: .04em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; color: var(--accent); padding: 4px 8px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.rules { margin: 0; padding: 0; list-style: none; counter-reset: r; display: flex; flex-direction: column; gap: 10px; }
.rules li { counter-increment: r; position: relative; padding: 10px 12px 10px 42px; font-size: 13.5px; line-height: 1.5; color: var(--dim);
  background: rgba(255,255,255,.025); border: 1px solid var(--line); border-radius: 10px; }
.rules li::before { content: counter(r); position: absolute; left: 12px; top: 10px; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  font: 700 11px var(--ui); color: #001018; background: var(--accent); }
.rules b { color: #fff; font-weight: 700; }
.crow { display: grid; grid-template-columns: 56px 1fr; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.crow:last-child { border-bottom: 0; }
.crow span { font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .12em; padding-top: 2px; }
.crow p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--dim); }
.note { margin: 0; font-size: 12px; color: var(--faint); }
#colour-hint { margin-left: 8px; text-transform: none; letter-spacing: .02em; font-weight: 500; color: var(--accent); animation: hint 1.6s ease-in-out infinite; }
@keyframes hint { 50% { opacity: .45; } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#topleft { position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; pointer-events: auto; }
.chip { width: 34px; height: 34px; display: grid; place-items: center; background: rgba(8,12,18,.6); border: 1px solid var(--line); border-radius: 9px; padding: 0; }
.chip svg { width: 18px; height: 18px; fill: none; stroke: var(--dim); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chip:hover svg, .chip.on svg { stroke: var(--accent); }
#feed { position: absolute; top: 56px; left: 14px; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
#feed div { color: var(--dim); transition: opacity .4s; }
#feed b { font-weight: 600; }
#toast { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); font-size: 22px; font-weight: 700; letter-spacing: .02em;
  text-shadow: 0 0 12px rgba(0,0,0,.8); opacity: 0; transition: opacity .25s; white-space: nowrap; }
#toast.show { opacity: 1; }
#lb { position: absolute; top: 12px; right: 12px; width: 206px; padding: 10px 12px 8px; background: rgba(8,12,18,.55); border: 1px solid var(--line);
  border-radius: 10px; font-size: 13px; }
.lb-head { display: flex; justify-content: space-between; font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase;
  letter-spacing: .1em; margin-bottom: 6px; }
#lb ol { list-style: none; margin: 0; padding: 0; }
#lb li { display: grid; grid-template-columns: 22px 1fr auto; gap: 4px; padding: 1.5px 0; font-variant-numeric: tabular-nums; }
#lb li .r { color: var(--faint); }
#lb li .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb li .v { color: var(--dim); }
#lb li.me { color: #fff; font-weight: 600; }
#lb li.me .v { color: #fff; }
#lb li.gap { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
#stats { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 18px; align-items: flex-end; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 24px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .1em; margin-top: 3px; }
#charge { position: absolute; left: 0; bottom: 48px; width: 150px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.08); overflow: hidden; opacity: 0; transition: opacity .2s; }
#charge.on { opacity: 1; }
#charge i { display: block; height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
#minimap { position: absolute; right: 12px; bottom: 12px; width: 150px; height: 150px; border-radius: 8px; background: rgba(8,12,18,.55); border: 1px solid var(--line); }
#debug { position: absolute; top: 56px; left: 14px; margin: 0; padding: 10px 12px; min-width: 250px; background: rgba(4,6,10,.82); border: 1px solid var(--line);
  border-radius: 8px; font: 11.5px/1.55 var(--mono); color: #b9c4d0; white-space: pre; }
#hud.debug #feed { top: auto; bottom: 90px; }

@media (max-width: 640px) {
  #lb { width: 150px; font-size: 11.5px; padding: 8px 9px 6px; }
  #minimap { width: 96px; height: 96px; }
  .stat b { font-size: 19px; }
  .dead-stats b { font-size: 21px; }
}

.dead-actions .primary { margin-top: 0; height: 44px; font-size: 15px; }

.row.mine { cursor: default; align-items: flex-start; }
#mine-list { font-size: 13px; color: var(--dim); display: flex; flex-direction: column; gap: 4px; }
#mine-list button { background: none; border: 0; color: var(--faint); margin-left: 6px; padding: 0 4px; }
#mine-list button:hover { color: #fff; }
.filebtn { flex: none; font-size: 12.5px; color: var(--dim); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.filebtn:hover { color: #fff; border-color: rgba(255,255,255,.3); }
