:root {
  --ink: #f4efe6; --ink-dim: #b9c3c4; --panel: rgba(10, 22, 30, 0.78); --panel-solid: #0d1b24; --line: rgba(255,255,255,0.14);
  --accent: #ff7a2f; --accent-2: #ffd166; --good: #5be37d; --bad: #ff5a5a; --left: #4cc3ff; --right: #ff9a3c; --fwd: #5be37d; --back: #ff6262;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d1b24; color: var(--ink); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
#view { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; outline: none; }
#ui { position: fixed; inset: 0; pointer-events: none; user-select: none; -webkit-user-select: none; }
#ui button, #ui .panel, #ui .pad { pointer-events: auto; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: max(12px, env(safe-area-inset-top)) 16px 0 16px; gap: 12px; }
.where { text-shadow: 0 2px 8px rgba(0,0,0,.6); min-width: 0; }
.where-main { font-size: clamp(18px, 2.6vw, 26px); font-weight: 800; letter-spacing: .02em; }
.where-sub { font-size: 13px; color: var(--ink-dim); margin-top: 2px; }
.hud-right { display: flex; gap: 8px; align-items: center; }
.clock { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-variant-numeric: tabular-nums; font-size: 14px; }
.iconbtn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.iconbtn:hover { border-color: var(--accent); }

.meters { position: absolute; left: 16px; top: calc(max(12px, env(safe-area-inset-top)) + 64px); display: grid; gap: 6px; }
.meter { display: flex; align-items: center; gap: 8px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); }
.meter svg { width: 18px; height: 18px; }
.bar { width: 120px; height: 8px; border-radius: 6px; background: rgba(0,0,0,.45); overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #8be0ff, #4cc3ff); transition: width .15s; }
.bar.low i { background: linear-gradient(90deg, #ff5a5a, #ff9a3c); animation: pulse .6s infinite alternate; }
.bar.hull i { background: linear-gradient(90deg, #c49a6c, #e8c79b); }
.meter.flow .bar i { background: linear-gradient(90deg, #ffd166, #ff7a2f); }
.meter.flow.full .bar { box-shadow: 0 0 12px #ffd166; }
.speed { font-size: 12px; color: var(--ink-dim); font-variant-numeric: tabular-nums; padding-left: 26px; }
@keyframes pulse { to { opacity: .55; } }

.banner { position: absolute; top: 22%; left: 50%; transform: translate(-50%, -10px); opacity: 0; transition: .35s; display: flex; gap: 12px; align-items: center; font-size: clamp(22px, 4vw, 40px); font-weight: 900; text-shadow: 0 3px 14px rgba(0,0,0,.7); white-space: nowrap; }
.banner.on { opacity: 1; transform: translate(-50%, 0); }
.cls { font-size: .55em; padding: 4px 10px; border-radius: 8px; background: #2c7; color: #041; }
.cls.c3 { background: #fc3; color: #430; } .cls.c4 { background: #f73; color: #300; } .cls.c5 { background: #e23; color: #fff; }

.lane { position: absolute; left: 50%; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 110px); transform: translateX(-50%); width: min(640px, 92vw); height: 64px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); container-type: inline-size; opacity: 0; transition: opacity .3s; overflow: hidden; }
.lane.on { opacity: 1; }
.gate { position: absolute; left: 12%; top: 6px; bottom: 6px; width: 54px; margin-left: -27px; border-radius: 12px; border: 3px solid var(--accent-2); box-shadow: 0 0 18px rgba(255,209,102,.35) inset; }
.marker { position: absolute; left: 12%; top: 8px; width: 48px; height: 48px; margin-left: -24px; border-radius: 12px; display: grid; place-items: center; background: #222; border: 2px solid #fff3; will-change: transform; }
.marker span { position: absolute; top: -18px; font-size: 11px; font-weight: 800; white-space: nowrap; opacity: 0; }
.marker svg { width: 30px; height: 30px; stroke-width: 3.2; }
.marker.forward { background: #174d27; color: var(--fwd); border-color: var(--fwd); }
.marker.back { background: #4d1717; color: var(--back); border-color: var(--back); }
.marker.left { background: #12384d; color: var(--left); border-color: var(--left); }
.marker.right { background: #4d2e12; color: var(--right); border-color: var(--right); }
.marker.near { box-shadow: 0 0 16px currentColor; }
.marker.gone-hit { transition: .35s; opacity: 0; transform: translateX(0) scale(1.6) !important; }
.marker.gone-miss { transition: .35s; opacity: 0; transform: translateX(-10cqw) translateY(20px) rotate(-30deg) !important; }
.judge { position: absolute; left: 12%; bottom: 70px; transform: translateX(-50%) scale(.8); font-weight: 900; font-size: 22px; opacity: 0; transition: .15s; text-shadow: 0 2px 8px #000; white-space: nowrap; }
.lane { overflow: visible; }
.judge.on { opacity: 1; transform: translateX(-50%) scale(1); }
.judge.perfect { color: var(--accent-2); } .judge.good { color: var(--good); } .judge.late { color: #9bd; } .judge.miss, .judge.wrong { color: var(--bad); }

.flash { position: absolute; top: 34%; left: 50%; transform: translate(-50%, 0) scale(.9); font-size: clamp(18px, 3vw, 28px); font-weight: 800; opacity: 0; transition: .2s; text-shadow: 0 2px 12px #000; text-align: center; max-width: 90vw; }
.flash.on { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toasts { position: absolute; right: 16px; top: calc(max(12px, env(safe-area-inset-top)) + 58px); display: grid; gap: 8px; justify-items: end; max-width: min(380px, 80vw); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 14px; font-size: 14px; transition: .5s; }
.toast.out { opacity: 0; transform: translateX(20px); }
.prompt { position: absolute; left: 50%; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 190px); transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; font-size: 15px; opacity: 0; transition: .25s; pointer-events: auto; text-align: center; }
.prompt.on { opacity: 1; }
.prompt kbd, .panel kbd { background: #fff2; border: 1px solid #fff4; border-bottom-width: 3px; border-radius: 6px; padding: 1px 7px; font-family: var(--font); font-size: 13px; }
.prompt button { margin-left: 8px; }
.vignette { position: absolute; inset: 0; box-shadow: inset 0 0 160px rgba(200,30,30,.9); opacity: 0; transition: opacity .2s; }

.pad { position: absolute; inset: auto 0 0 0; display: none; justify-content: space-between; padding: 0 max(16px, env(safe-area-inset-right)) calc(max(16px, env(safe-area-inset-bottom)) + 4px) max(16px, env(safe-area-inset-left)); pointer-events: none !important; }
.pad.on { display: flex; }
.pad > div { display: flex; gap: 12px; align-items: flex-end; pointer-events: none; }
.pad button { pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; border: 2px solid #fff5; background: rgba(10,22,30,.55); color: #fff; display: grid; place-items: center; touch-action: none; }
.pad button svg { width: 34px; height: 34px; stroke-width: 3; }
.pad button.big { width: 96px; height: 96px; border-color: var(--fwd); color: var(--fwd); }
.pad button.small { width: 64px; height: 64px; border-color: var(--back); color: var(--back); }
.pad button[data-s=left] { border-color: var(--left); color: var(--left); }
.pad button[data-s=right] { border-color: var(--right); color: var(--right); }
.pad button.down { background: rgba(255,255,255,.25); transform: scale(.94); }

/* Panels */
.panel { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(3,10,14,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); padding: 16px; }
.panel.open { display: flex; }
.card { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: min(720px, 100%); max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.card h1 { margin: 0 0 4px; font-size: clamp(30px, 6vw, 52px); font-weight: 900; letter-spacing: .01em; }
.card h2 { margin: 0 0 12px; font-size: 22px; }
.card h3 { margin: 16px 0 8px; font-size: 15px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .08em; }
.card p { line-height: 1.5; color: #dfe6e6; }
.btn { appearance: none; border: 0; border-radius: 12px; padding: 12px 18px; font: 700 16px var(--font); background: var(--accent); color: #1b0d03; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:focus-visible, .iconbtn:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.close { float: right; }
.title-card { text-align: left; background: linear-gradient(160deg, rgba(13,27,36,.96), rgba(30,22,12,.96)); }
.title-card .kicker { color: var(--accent-2); font-weight: 800; letter-spacing: .2em; text-transform: uppercase; font-size: 12px; }
.keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 12px 0 18px; }
.keys div { background: #ffffff0d; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
input[type=text] { font: 16px var(--font); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #0006; color: var(--ink); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile { background: #ffffff0a; border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; font-size: 13px; cursor: pointer; color: var(--ink); font-family: var(--font); }
.tile.locked { opacity: .45; filter: grayscale(1); }
.tile .badge { width: 72px; height: 72px; margin: 4px auto 8px; display: block; }
.tile b { display: block; font-size: 14px; margin-bottom: 2px; }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.mapwrap { position: relative; width: 100%; aspect-ratio: 1; max-height: calc(100dvh - 160px); margin: auto; }
.mapwrap canvas { width: 100%; height: 100%; border-radius: 12px; display: block; touch-action: none; }
.list { display: grid; gap: 8px; }
.list .item { display: flex; justify-content: space-between; gap: 12px; align-items: center; background: #ffffff0a; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.small { font-size: 13px; color: var(--ink-dim); }
.tag { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #fff2; margin-left: 6px; }
.online { color: var(--good); }
@media (max-width: 560px) {
  .meters { top: calc(max(12px, env(safe-area-inset-top)) + 54px); }
  .bar { width: 84px; }
  .iconbtn { width: 38px; height: 38px; }
  .clock { display: none; }
  .lane { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 120px); height: 56px; }
}
@media (prefers-reduced-motion: reduce) { .marker.gone-hit, .marker.gone-miss, .toast, .banner { transition: none; } }
.cardpop { position: absolute; left: 50%; top: 16%; transform: translate(-50%, -12px); opacity: 0; transition: .4s; background: linear-gradient(160deg, #10283a, #2a1d0e); border: 1px solid #ffd16666; border-radius: 16px; padding: 14px 22px; text-align: center; display: grid; gap: 4px; max-width: min(460px, 90vw); box-shadow: 0 12px 40px #0009; }
.cardpop.on { opacity: 1; transform: translate(-50%, 0); }
.cardpop .kicker { color: var(--accent-2); font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.cardpop b { font-size: 22px; }
.cardpop span { font-size: 14px; color: var(--ink-dim); }
