:root {
  --bg: #0b0d10;
  --bg-2: #12161b;
  --panel: #161b22;
  --line: #2a323c;
  --text: #dfe6ee;
  --muted: #8794a3;
  --accent: #ff5a52;
  --accent-soft: rgba(255, 90, 82, 0.14);
  --good: #4fd08a;
  --bad: #ff5a52;
  --stage-bg: radial-gradient(circle at 50% 55%, #2a0f10 0%, #150909 55%, #0b0d10 100%);
  --glow: rgba(255, 90, 82, 0.55);
  --font: "Oxanium", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}
body[data-tint="cyan"] { --accent: #4cc3ff; --accent-soft: rgba(76,195,255,.14); --glow: rgba(76,195,255,.55);
  --stage-bg: radial-gradient(circle at 50% 55%, #0c2233 0%, #08141d 55%, #0b0d10 100%); }
body[data-tint="green"] { --accent: #5be38f; --accent-soft: rgba(91,227,143,.14); --glow: rgba(91,227,143,.5);
  --stage-bg: radial-gradient(circle at 50% 55%, #0e2a1a 0%, #091710 55%, #0b0d10 100%); }
body[data-tint="white"] { --accent: #e9eef5; --accent-soft: rgba(233,238,245,.1); --glow: rgba(233,238,245,.45);
  --stage-bg: radial-gradient(circle at 50% 55%, #23272d 0%, #14171b 55%, #0b0d10 100%); }
body[data-tint="shadow"] { --accent: #ffcc33; --accent-soft: rgba(255,204,51,.14); --glow: transparent;
  --stage-bg: radial-gradient(circle at 50% 50%, #fff7d6 0%, #ffd75e 60%, #e6a700 100%); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font-family: var(--mono); font-size: .7em; padding: 1px 5px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.brand { color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: .12em; font-size: 15px; white-space: nowrap; }
.brand b { color: var(--accent); letter-spacing: .22em; }
.brand-sub { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .18em; margin-left: 6px; }
.top nav { display: flex; gap: 4px; }
.top nav button { background: none; border: 1px solid transparent; padding: 6px 10px; border-radius: 4px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; font-size: 13px; }
.top nav button:hover, .top nav button[aria-current="page"] { color: var(--text); border-color: var(--line); }

main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; }
.view > h1 { font-size: clamp(26px, 5vw, 40px); line-height: 1.1; margin: 4px 0 12px; max-width: 22ch; }
.kicker { color: var(--accent); text-transform: uppercase; letter-spacing: .18em; font-size: 12px; margin: 0; }
.lede { color: var(--muted); max-width: 60ch; margin: 0 0 24px; }
.meta { color: var(--muted); font-size: 13px; font-family: var(--mono); }
.sub { margin-top: 32px; font-size: 14px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.row.small { margin: 8px 0 0; }

.primary, .ghost {
  border-radius: 4px; padding: 10px 18px; letter-spacing: .06em; text-transform: uppercase; font-size: 14px; font-weight: 600;
}
.primary { background: var(--accent); color: #111; border: 1px solid var(--accent); }
.primary:hover { filter: brightness(1.1); }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.ghost:hover { border-color: var(--accent); }
.ghost:disabled { opacity: .4; cursor: default; border-color: var(--line); }
.danger:hover { border-color: var(--bad); color: var(--bad); }

/* Menu */
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.mode {
  text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 18px;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s;
}
.mode:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-name { font-weight: 700; font-size: 20px; letter-spacing: .04em; }
.mode-desc { color: var(--muted); font-size: 14px; }
.mode:disabled { opacity: .45; transform: none; border-color: var(--line); cursor: default; }
.active-settings { margin-top: 20px; color: var(--muted); font-size: 14px; }
.active-settings b { color: var(--text); font-weight: 600; }

/* Game HUD */
.hud-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.hud-cell {
  flex: 1 1 80px; border: 1px solid var(--line); border-radius: 4px; padding: 6px 10px; background: var(--bg-2);
  display: flex; flex-direction: column;
}
.hud-cell span { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.hud-cell b { font-family: var(--mono); font-size: 20px; }

.target { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.sigs { display: flex; flex-direction: column; gap: 8px; }
.sig {
  border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 6px 10px; background: var(--bg-2);
  display: flex; flex-direction: column; min-height: 50px;
}
.sig span { font-size: 11px; letter-spacing: .14em; color: var(--muted); }
.sig b { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.sig b.on { color: var(--text); }

.reticle {
  position: relative; aspect-ratio: 1; width: 100%; max-width: 520px; justify-self: center;
  border-radius: 50%; background: var(--stage-bg); overflow: hidden;
}
.ring { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.ring circle { fill: none; }
.ring-a { stroke: var(--accent); stroke-opacity: .5; stroke-width: 3; stroke-dasharray: 70 18 4 18; }
.ring-b { stroke: var(--accent); stroke-opacity: .2; stroke-width: 1; }
.ring-timer { stroke: var(--accent); stroke-width: 6; stroke-dasharray: 100 100; stroke-dashoffset: 0; transform: rotate(-90deg); transform-origin: center; opacity: 0; }
.ring-timer.run { opacity: .9; }
.label {
  position: absolute; top: 13%; left: 0; right: 0; text-align: center; z-index: 3;
  font-weight: 700; letter-spacing: .16em; font-size: clamp(12px, 2.6vw, 18px); color: var(--text); text-shadow: 0 0 8px var(--glow);
}
body[data-tint="shadow"] .label { color: #2a2100; text-shadow: none; }
.stage {
  position: absolute; inset: 16%; display: grid; place-items: center; z-index: 1;
}
.stage::after { /* scanlines */
  content: ""; position: absolute; inset: -30%; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 2px, transparent 2px 4px);
}
body[data-tint="shadow"] .stage::after { display: none; }
#ship-img, #pix {
  max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; user-select: none;
  filter: url(#tint) drop-shadow(0 0 6px var(--glow));
  transition: transform .2s, filter .2s;
}
#ship-img.cap { filter: none; border-radius: 4px; }
#pix { image-rendering: pixelated; }
.flash-cover {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center;
  font-family: var(--mono); letter-spacing: .3em; color: var(--accent); background: rgba(0,0,0,.82);
}

.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 18px; }
.choice {
  text-align: left; padding: 12px 14px; border-radius: 4px; background: var(--panel); border: 1px solid var(--line);
  display: flex; gap: 10px; align-items: baseline; min-height: 48px;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.choice kbd { flex: none; }
.choice.right { border-color: var(--good); background: rgba(79,208,138,.15); }
.choice.wrong { border-color: var(--bad); background: rgba(255,90,82,.15); }
.choice:disabled { cursor: default; }
.actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; flex-wrap: wrap; }

.reveal { margin-top: 18px; border: 1px solid var(--line); border-radius: 6px; padding: 16px; background: var(--bg-2); }
.reveal-head h2 { margin: 2px 0 4px; font-size: 24px; }
.reveal-head p { margin: 0; color: var(--muted); font-size: 14px; font-family: var(--mono); white-space: pre-line; }
.verdict { font-size: 12px; letter-spacing: .2em; text-transform: uppercase; font-weight: 700; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.reveal-views { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 12px; }
.reveal-views figure { margin: 0; background: var(--stage-bg); border-radius: 4px; aspect-ratio: 1; display: grid; place-items: center; padding: 6px; position: relative; }
.reveal-views img { width: 100%; height: 100%; object-fit: contain; filter: url(#tint); }
.reveal-views figcaption { position: absolute; bottom: 4px; left: 6px; font-size: 10px; letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }

/* Results */
.share { font-family: var(--mono); background: var(--panel); border: 1px solid var(--line); padding: 12px; border-radius: 4px; white-space: pre-wrap; }
.log { padding-left: 20px; font-family: var(--mono); font-size: 14px; }
.log li { margin: 4px 0; }
.log .ok { color: var(--good); }
.log .no { color: var(--bad); }
.log small { color: var(--muted); }

/* Study */
.study-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.study-bar input[type=search] { flex: 1 1 200px; }
input[type=search], select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; text-align: left; padding: 0; }
.card:hover { border-color: var(--accent); }
.card .pic { aspect-ratio: 1; background: var(--stage-bg); display: grid; place-items: center; padding: 10px; }
.card img { width: 100%; height: 100%; object-fit: contain; filter: url(#tint); }
.card .cap-line { padding: 8px 10px; font-size: 13px; }
.card .cap-line small { display: block; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.grid.hide-names .card:not(.peek) .cap-line .nm { filter: blur(6px); }

/* Settings */
.settings { display: grid; gap: 16px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px 16px; margin: 0; display: grid; gap: 10px; }
legend { padding: 0 6px; letter-spacing: .12em; text-transform: uppercase; font-size: 13px; color: var(--accent); }
legend small { color: var(--muted); text-transform: none; letter-spacing: 0; }
fieldset > label:not(.chk) { display: grid; grid-template-columns: 130px 1fr; align-items: center; gap: 10px; }
.chk { display: flex; gap: 8px; align-items: center; }
.chk em { color: var(--muted); font-style: normal; font-family: var(--mono); font-size: 12px; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
.mfrs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }

footer { padding: 16px; text-align: center; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

@media (max-width: 640px) {
  .target { grid-template-columns: 1fr; }
  .sigs { flex-direction: row; flex-wrap: wrap; order: 2; }
  .sig { flex: 1 1 30%; min-height: 0; }
  .choices { grid-template-columns: 1fr; }
  .reveal-views { grid-template-columns: repeat(3, 1fr); }
  fieldset > label:not(.chk) { grid-template-columns: 1fr; gap: 4px; }
  .top nav button { padding: 6px 6px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Leaderboard + share */
.mode-best { font-family: var(--mono); font-size: 12px; color: var(--accent); min-height: 1em; }
#res-sub.hi { color: #e8c547; font-weight: 700; }
.callsign { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.callsign input { text-transform: none; letter-spacing: normal; font-size: 16px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; width: min(260px, 100%); }
.callsign input:focus, input[type=search]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.share-box { margin-top: 8px; }
.card-preview { display: block; width: 100%; max-width: 600px; height: auto; aspect-ratio: 1200 / 630; border: 1px solid var(--line); border-radius: 6px; background: #0b0d10; }
.share-box .share { max-width: 600px; margin: 10px 0 0; font-size: 13px; overflow-x: auto; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 8px 14px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.tab[aria-selected="true"] { border-color: var(--accent); color: var(--accent); }
#score-board, #res-board { overflow-x: auto; }
table.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
.scores th { text-align: left; font-weight: 600; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.scores td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.scores td.n { font-family: var(--mono); text-align: right; }
.scores th:nth-child(n+3):nth-child(-n+6) { text-align: right; }
.scores tr.me td { background: var(--accent-soft); color: var(--text); }
.scores tr.me td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.scores td.empty { color: var(--muted); text-align: center; padding: 20px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 10px 16px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.5); }
