:root {
  --gold: #f2c14e; --gold-2: #ffd98a; --cyan: #6fe3ff; --violet: #c890ff; --red: #ff5a6e;
  --ink: #eef3f8; --muted: #9fb0bf; --glass: rgba(10, 16, 24, 0.72); --line: rgba(190, 210, 230, 0.14);
  --display: 'Barlow Condensed', 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  --ui: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { background: #0b1018; color: var(--ink); font-family: var(--ui); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#world, #world canvas, #shade { position: fixed; inset: 0; width: 100%; height: 100%; }
#world canvas { display: block; cursor: crosshair; }
#shade { pointer-events: none; z-index: 1; background: linear-gradient(180deg, rgba(5, 9, 14, 0.45), transparent 22%, transparent 74%, rgba(5, 9, 14, 0.6)); }
#speed-lines, #damage-vignette { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
#speed-lines { opacity: 0; transition: opacity .35s; background: repeating-conic-gradient(from 1deg at 50% 49%, transparent 0deg 15deg, rgba(164, 228, 255, .17) 15.3deg 15.5deg, transparent 15.8deg 30deg); mask-image: radial-gradient(circle at 50% 49%, transparent 0 26%, #000 82%); animation: rush .55s linear infinite; }
body.boosting #speed-lines { opacity: .75; }
#damage-vignette { opacity: 0; background: radial-gradient(ellipse at center, transparent 38%, rgba(255, 45, 70, .72) 100%); }
@keyframes rush { from { transform: scale(.75); } to { transform: scale(1.25); } }

button { cursor: pointer; font: 600 10px var(--ui); letter-spacing: 0.08em; color: var(--ink); border: 1px solid var(--line); background: rgba(12, 20, 30, 0.78); padding: 11px 14px; border-radius: 6px; transition: background 0.15s, border-color 0.15s; }
button:hover { background: rgba(40, 56, 72, 0.9); border-color: rgba(242, 193, 78, 0.4); }
button:disabled { opacity: 0.5; cursor: wait; }
button:focus-visible, summary:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
kbd { font: 600 9px var(--ui); border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 3px; padding: 3px 5px; margin-left: 4px; color: #dce6ee; }

.hud { opacity: 0; pointer-events: none; transition: opacity 0.4s; }
body.hud-on .hud { opacity: 1; }
body.hud-on header.hud, body.hud-on #mission-panel { pointer-events: auto; }
header { position: absolute; top: max(20px, env(safe-area-inset-top)); left: 28px; right: 28px; display: flex; justify-content: space-between; align-items: center; z-index: 4; }
header.hud { opacity: 1; pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand > b { font: 800 36px var(--display); color: var(--gold); letter-spacing: 0.02em; }
.brand > b span { color: rgba(160, 180, 200, 0.4); font-weight: 500; }
.brand > div { font: 700 19px var(--display); letter-spacing: 0.12em; }
.brand small { display: block; font: 600 8px var(--ui); letter-spacing: 0.24em; color: var(--muted); margin-top: 4px; }
.header-actions { display: flex; gap: 8px; }

#mission-panel { position: absolute; top: 96px; left: 28px; width: 252px; padding: 16px 18px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 10px; z-index: 3; }
.eyebrow { font-size: 9px; letter-spacing: 0.22em; color: var(--gold); font-weight: 700; }
.eyebrow i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); margin: 0 5px 1px 0; box-shadow: 0 0 8px var(--gold); }
h2 { font: 700 26px var(--display); margin: 10px 0 6px; letter-spacing: 0.01em; }
p { font-size: 11.5px; line-height: 1.65; color: #b6c5d1; }
.bar { height: 4px; background: rgba(255, 255, 255, 0.1); border-radius: 4px; overflow: hidden; }
.bar i { display: block; background: var(--gold); height: 100%; width: 0; transition: width 0.18s; }
.mission-foot { display: flex; justify-content: space-between; font-size: 8.5px; letter-spacing: 0.12em; color: #c4d2dc; margin-top: 10px; }
#navigation { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 11px; color: var(--gold); font: 700 10px var(--ui); letter-spacing: 0.1em; }

#settings { position: absolute; top: 86px; right: 28px; width: 236px; background: var(--glass); padding: 13px 14px; border: 1px solid var(--line); border-radius: 10px; z-index: 5; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
summary { cursor: pointer; list-style: none; font-size: 9px; font-weight: 700; letter-spacing: 0.18em; color: #c8d6e0; }
summary::-webkit-details-marker { display: none; }
summary span { float: right; }
#settings label { display: block; font-size: 8px; font-weight: 700; color: #a9bccb; letter-spacing: 0.18em; margin: 15px 2px 7px; }
#settings label span { float: right; color: var(--gold); }
.seg { display: flex; background: rgba(255, 255, 255, 0.05); border-radius: 6px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; font-size: 10px; padding: 8px 4px; border-radius: 4px; color: #c5d3dd; letter-spacing: 0.02em; }
.seg button.selected { background: var(--gold); color: #111; }
#settings input[type=range] { width: 100%; accent-color: var(--gold); }
#settings p { font-size: 10px; margin: 12px 2px 6px; }
#performance { font: 600 9.5px ui-monospace, Menlo, Consolas, monospace; color: var(--cyan); line-height: 1.5; }

#reticle { position: fixed; left: 50%; top: 47%; width: 40px; height: 40px; transform: translate(-50%, -50%); pointer-events: none; z-index: 3; opacity: 0; transition: opacity 0.3s; }
body.hud-on #reticle { opacity: 1; }
#reticle span { position: absolute; inset: 0; border: 1.5px solid rgba(255, 230, 170, 0.85); border-radius: 50%; box-shadow: 0 0 10px rgba(242, 193, 78, 0.45); }
#reticle i::before, #reticle i::after { content: ''; position: absolute; background: rgba(255, 240, 200, 0.95); left: 50%; top: 50%; transform: translate(-50%, -50%); }
#reticle i::before { width: 2px; height: 14px; } #reticle i::after { width: 14px; height: 2px; }
#hit { position: fixed; left: 50%; top: 47%; transform: translate(-50%, -50%); color: var(--red); font-size: 30px; font-weight: 800; pointer-events: none; z-index: 3; opacity: 0; text-shadow: 0 0 12px var(--red); }
#lock-readout { position: fixed; top: 148px; right: 28px; width: 220px; z-index: 3; pointer-events: none; opacity: 0; padding: 11px 13px; color: #b9cbd8; font: 700 10px var(--ui); letter-spacing: .12em; background: rgba(7, 16, 26, .68); border: 1px solid var(--line); border-radius: 7px; backdrop-filter: blur(10px); transition: opacity .25s, border-color .2s; }
body.hud-on #lock-readout { opacity: 1; }
#lock-readout.active { border-color: rgba(242, 193, 78, .5); color: var(--gold-2); }
#lock-readout.solid { box-shadow: inset 0 0 20px rgba(242, 193, 78, .08), 0 0 24px rgba(242, 193, 78, .12); }
#lock-readout .bar { margin: 9px 0 7px; }
#lock-readout .bar i { background: var(--cyan); }
#lock-readout.solid .bar i { background: var(--gold); }
#lock-readout small { display: block; color: #a1b8c7; font-size: 8px; letter-spacing: .12em; }

#markers { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.target { position: absolute; left: 0; top: 0; --s: 1; }
.target .box { position: absolute; width: calc(36px * var(--s)); height: calc(36px * var(--s)); transform: translate(-50%, -50%); border: 2px solid var(--red); border-radius: 4px; box-shadow: 0 0 12px rgba(255, 90, 110, 0.5); }
.target .label { position: absolute; transform: translate(-50%, calc(-100% - 18px * var(--s) - 10px)); white-space: nowrap; font: 700 9.5px var(--ui); letter-spacing: 0.1em; color: #ffd7dc; text-shadow: 0 1px 3px #000; }
.target .bar { position: absolute; width: 46px; transform: translate(-50%, calc(18px * var(--s) + 6px)); height: 3px; }
.target .bar i { background: var(--red); width: 100%; }
.target .arrow { display: none; }
.target.offscreen .box, .target.offscreen .bar { display: none; }
.target.offscreen .arrow { display: block; position: absolute; width: 0; height: 0; transform-origin: 0 0; }
.target.offscreen .arrow::before { content: ''; position: absolute; left: -2px; top: -11px; border-left: 22px solid var(--red); border-top: 11px solid transparent; border-bottom: 11px solid transparent; filter: drop-shadow(0 0 6px rgba(255, 90, 110, 0.8)); }
.target.offscreen .label { transform: translate(-50%, 18px); background: rgba(40, 8, 14, 0.75); padding: 3px 6px; border-radius: 3px; }

#toast { position: fixed; left: 50%; top: 27%; transform: translate(-50%, 0); font: 700 clamp(18px, 2.6vw, 30px) var(--display); letter-spacing: 0.08em; color: var(--gold-2); text-shadow: 0 2px 18px rgba(0, 0, 0, 0.75), 0 0 24px rgba(242, 193, 78, 0.35); pointer-events: none; z-index: 3; opacity: 0; transition: opacity 0.25s; text-align: center; width: 90vw; }
#toast.show { opacity: 1; }
#boundary { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); padding: 8px 14px; border: 1px solid var(--red); color: #ffd2d8; font: 700 11px var(--ui); letter-spacing: 0.16em; background: rgba(60, 10, 18, 0.6); border-radius: 4px; z-index: 3; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#boundary.show { opacity: 1; }

footer { position: absolute; left: 28px; right: 28px; bottom: 62px; display: flex; align-items: flex-end; gap: 42px; z-index: 3; }
footer small { display: block; font-size: 8px; font-weight: 700; letter-spacing: 0.2em; color: #b4c4d0; margin-bottom: 6px; }
.health-line { display: flex; align-items: center; gap: 12px; }
.health-line b, .score b, .weapon b { font: 700 30px var(--display); letter-spacing: 0.02em; }
.health-line .bar { width: 140px; }
#health.low { background: var(--red); }
.weapon b[data-w=laser] { color: var(--cyan); } .weapon b[data-w=plasma] { color: var(--violet); }
#boost-hud { display: inline-block; margin-left: 10px; font: 700 9px var(--ui); letter-spacing: 0.18em; color: #5e6f7d; border: 1px solid #2d3b47; padding: 3px 6px; border-radius: 3px; vertical-align: 6px; }
#boost-hud.on { color: #111; background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 12px var(--cyan); }
.speed { margin-left: auto; text-align: right; }
.speed b { font: 700 60px var(--display); line-height: 0.9; }
.speed small { margin-top: 6px; }
#keys { position: absolute; left: 28px; right: 28px; bottom: 18px; display: flex; flex-wrap: wrap; gap: 16px; font-size: 10px; color: #b8c7d2; z-index: 3; }
#keys kbd { margin: 0 5px 0 0; }
body.in-cockpit #keys { display: none; }
body.in-cockpit footer { bottom: 22px; }
body.in-cockpit #shade { background: linear-gradient(180deg, rgba(5, 9, 14, 0.25), transparent 18%); }

#touch { display: none; }
body.touch.hud-on #touch { display: block; }
body.touch #keys { display: none; }
body.touch footer { bottom: 186px; }
body.touch footer .score b, body.touch .health-line b { font-size: 24px; }
#stick { position: fixed; left: max(24px, env(safe-area-inset-left)); bottom: max(28px, env(safe-area-inset-bottom)); width: 140px; height: 140px; border-radius: 50%; border: 1.5px solid rgba(242, 193, 78, 0.45); background: rgba(10, 16, 24, 0.45); z-index: 6; touch-action: none; }
#stick i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: rgba(242, 193, 78, 0.85); box-shadow: 0 0 16px rgba(242, 193, 78, 0.5); }
#stick small { position: absolute; bottom: -18px; width: 100%; text-align: center; font-size: 8px; letter-spacing: 0.2em; color: var(--muted); }
.touch-right { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 50px); gap: 8px; z-index: 6; touch-action: none; }
.touch-right button { height: 42px; padding: 0; font-size: 11px; font-weight: 700; touch-action: none; background: rgba(10, 16, 24, 0.6); }
.touch-right button.big { grid-column: span 2; height: 64px; font-size: 13px; letter-spacing: 0.16em; }
.touch-right button.fire { background: rgba(242, 193, 78, 0.85); color: #111; }
.touch-right button.on { background: var(--cyan); color: #111; }

#overlay { position: fixed; inset: 0; display: flex; align-items: center; padding: 0 8vw; background: linear-gradient(90deg, rgba(6, 10, 16, 0.86) 0%, rgba(6, 10, 16, 0.5) 45%, rgba(6, 10, 16, 0.05) 75%); z-index: 8; }
#overlay[hidden] { display: none; }
.intro { max-width: 560px; }
h1 { font: 800 clamp(54px, 8.4vw, 112px) var(--display); line-height: 0.88; margin: 14px 0 18px; letter-spacing: -0.005em; }
h1 em { font-style: normal; color: var(--gold); }
#intro-copy { font-size: 14px; max-width: 440px; color: #c8d5df; }
.start-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 26px 0 18px; }
.start-actions button { padding: 15px 20px; font-size: 11px; }
#start { background: var(--gold); color: #111; border-color: var(--gold); }
#start:hover { background: var(--gold-2); }
.hint { font-size: 9px; letter-spacing: 0.2em; color: var(--muted); }
.hint span { color: var(--gold); margin: 0 6px; }
#loaderror { color: var(--red); }
.brief { position: absolute; right: 6vw; bottom: 7vh; display: flex; gap: 22px; font: 700 10px var(--ui); letter-spacing: 0.16em; color: #c6d3dc; }
.brief b { color: var(--gold); margin-right: 6px; }
.version { position: absolute; left: 8vw; bottom: 5vh; font-size: 9px; letter-spacing: 0.24em; color: #6d7f8d; }

dialog { width: min(640px, 92vw); max-height: 86vh; background: #0d141d; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px; }
dialog::backdrop { background: rgba(3, 6, 10, 0.72); backdrop-filter: blur(4px); }
.registry-head { display: flex; justify-content: space-between; align-items: flex-start; }
.registry-head h2 { margin-top: 6px; }
#scores-close { padding: 8px 11px; }
#score-entry { border: 1px solid rgba(242, 193, 78, 0.35); border-radius: 8px; padding: 12px 14px; margin: 10px 0; background: rgba(242, 193, 78, 0.05); }
#score-entry label { font-size: 8px; letter-spacing: 0.2em; color: var(--gold); font-weight: 700; }
.score-input { display: flex; gap: 8px; margin-top: 6px; }
.score-input input { flex: 1; background: #070c12; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; font: 600 13px var(--ui); -webkit-user-select: text; user-select: text; }
#save-score { background: var(--gold); color: #111; }
.score-scroll { max-height: 46vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; font-size: 8.5px; letter-spacing: 0.18em; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #0d141d; }
td { padding: 9px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
td:nth-child(3) { font-weight: 700; color: var(--gold-2); }
#bench-out { position: fixed; left: 20px; bottom: 20px; z-index: 20; max-width: 560px; max-height: 60vh; overflow: auto; background: rgba(5, 9, 14, 0.9); color: var(--cyan); font-size: 11px; padding: 12px; border-radius: 8px; border: 1px solid var(--line); }

@media (max-width: 760px) {
  header { left: 14px; right: 14px; top: 12px; }
  .brand > b { font-size: 28px; } .brand > div { font-size: 15px; }
  .header-actions button { padding: 9px 9px; font-size: 9px; }
  #scores-open { display: none; }
  .brand small { display: none; }
  .header-actions { gap: 6px; }
  #mission-panel { top: 64px; left: 14px; width: calc(52vw - 20px); padding: 10px 12px; }
  #mission-panel h2 { font-size: 19px; margin: 6px 0 4px; }
  #mission-panel p, .mission-foot span:last-child { display: none; }
  #navigation { margin-top: 8px; padding-top: 8px; }
  #settings { top: 64px; right: 14px; width: calc(46vw - 14px); padding: 10px 11px; }
  #lock-readout { top: 116px; right: 14px; width: min(46vw, 190px); padding: 8px; font-size: 8px; }
  #lock-readout small { font-size: 7px; }
  #toast { top: 34%; }
  footer { left: 14px; right: 14px; gap: 14px; }
  .speed b { font-size: 30px; }
  .health-line .bar { width: 70px; }
  footer small { letter-spacing: 0.12em; }
  .weapon { display: none; }
  .brief { display: none; }
  #overlay { padding: 0 6vw; background: rgba(6, 10, 16, 0.72); }
}

/* Target lock */
#assist-ring { position: fixed; left: 50%; top: 47%; transform: translate(-50%, -50%); border-radius: 50%; border: 1px dashed rgba(255, 230, 170, 0.22); pointer-events: none; z-index: 2; opacity: 0; transition: opacity 0.3s, border-color 0.2s; }
body.hud-on #assist-ring { opacity: 1; }
body:not(.touch):not(.show-assist) #assist-ring { display: none; }
#assist-ring.active { border-color: rgba(242, 193, 78, 0.5); }
.target .lockmark { display: none; position: absolute; width: calc(56px * var(--s)); height: calc(56px * var(--s)); transform: translate(-50%, -50%); border: 2px solid var(--gold); border-radius: 50%; border-left-color: transparent; border-right-color: transparent; }
.target.locking .lockmark { display: block; animation: lockspin 0.5s linear infinite; opacity: 0.7; }
.target.locked .lockmark { display: block; animation: lockspin 2.4s linear infinite; box-shadow: 0 0 14px rgba(242, 193, 78, 0.6); }
.target.locked .box { border-color: var(--gold); box-shadow: 0 0 14px rgba(242, 193, 78, 0.6); }
.target.locked .label { color: var(--gold-2); }
.target.locked .label::before { content: 'LOCK · '; }
@keyframes lockspin { from { transform: translate(-50%, -50%) rotate(0deg); } to { transform: translate(-50%, -50%) rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .target .lockmark { animation: none !important; } }
@media (prefers-reduced-motion: reduce) { #speed-lines { animation: none; display: none; } }
.diff-pick { margin: 22px 0 0; max-width: 420px; }
.diff-pick small { display: block; font-size: 9px; letter-spacing: 0.2em; color: var(--muted); margin-bottom: 7px; font-weight: 700; }
.diff-pick .seg button { font-size: 11px; padding: 10px 4px; }
.diff-pick p { margin: 6px 2px 0; font-size: 10.5px; min-height: 2.6em; }
.seg button:disabled { opacity: 0.45; cursor: not-allowed; }
td.lvl { font-size: 10px; letter-spacing: 0.12em; color: var(--muted); }
