/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --cream:      #e8dcb8;
  --cream-dim:  #cdbfa0;
  --banner:     #c0392b;
  --banner-dk:  #8e2820;
  --steel:      #8a8d96;
  --steel-dk:   #4a4d56;
  --steel-line: #2a2a30;
  --ink:        #1b1410;
  --led:        #ff5a3a;
  --led-bg:     #1a0d0a;
  --gold:       #e8b020;
  --night:      #120c08;
  --night-2:    #1e160f;

  --paper: var(--cream);
  --bloff-overlay-bg: var(--cream);
}

html, body {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--night);
  color: var(--cream);
}

body {
  min-height: 100dvh;
}

/* ===== CANVAS ===== */
#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  z-index: 0;
  background: var(--night);
  filter: drop-shadow(1px 0 0 rgba(255,40,40,0.35)) drop-shadow(-1px 0 0 rgba(40,220,255,0.35));
}

/* ===== CRT OVERLAY ===== */
#crt {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 120px 20px rgba(0,0,0,0.55);
}
#crt::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, rgba(255,0,40,0.03) 0 2px, transparent 2px 4px);
}

/* ===== HUD (top, 3-cell PB/LIVE/WR split) ===== */
#hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  display: none;
  gap: 2px;
  z-index: 10;
}
body[data-state="charge"] #hud,
body[data-state="flight"] #hud,
body[data-state="paused"] #hud { display: flex; }

.hud-cell {
  background: var(--led-bg);
  border: 2px solid var(--steel-line);
  box-shadow: 2px 2px 0 #000;
  padding: 4px 8px;
  display: flex;
  align-items: baseline;
  gap: 4px;
  font: 900 11px/1 ui-monospace, "SF Mono", Menlo, "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--cream);
}
.hud-k { color: var(--cream-dim); font-size: 9px; letter-spacing: 0.18em; }
.hud-v { color: var(--led); font-size: 15px; text-shadow: 0 0 6px rgba(255,90,58,0.5); }
.hud-u { color: var(--cream-dim); font-size: 9px; }
body[data-pb="1"] .hud-pb .hud-v { color: var(--gold); }
.hud-wr .hud-v { color: var(--gold); }
.hud-live { justify-content: center; }
.hud-dot {
  width: 6px; height: 6px;
  background: var(--led);
  border-radius: 50%;
  animation: blink 1s steps(2) infinite;
  align-self: center;
}
.hud-live .hud-v { font-size: 10px; letter-spacing: 0.16em; }
@keyframes blink { 50% { opacity: 0.2; } }

/* ===== METER (lower-left speed gauge / height) ===== */
#meter {
  position: fixed;
  bottom: max(76px, env(safe-area-inset-bottom));
  left: max(8px, env(safe-area-inset-left));
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 10;
}
body[data-state="charge"] #meter,
body[data-state="flight"] #meter,
body[data-state="paused"] #meter { display: flex; }

.meter-row {
  background: var(--led-bg);
  border: 2px solid var(--steel-line);
  box-shadow: 2px 2px 0 #000;
  padding: 4px 8px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font: 900 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--cream);
}
.meter-k { color: var(--cream-dim); font-size: 9px; letter-spacing: 0.18em; }
.meter-v { color: var(--led); font-size: 18px; text-shadow: 0 0 6px rgba(255,90,58,0.5); }
.meter-u { color: var(--cream-dim); font-size: 9px; }
body[data-state="flight"] .meter-row:not(.meter-h) { display: none; }
body[data-state="charge"] .meter-row.meter-h { display: none; }

.meter-speed { align-items: center; }
.speed-gauge {
  width: 64px;
  height: 10px;
  background: var(--ink);
  border: 1px solid var(--steel-line);
  overflow: hidden;
}
.speed-gauge__fill {
  height: 100%;
  width: 0%;
  background: var(--led);
  box-shadow: 0 0 6px rgba(255,90,58,0.6);
  transition: width 60ms linear;
}
.speed-gauge__fill.is-maxed { background: var(--gold); box-shadow: 0 0 6px rgba(232,176,32,0.7); }

/* ===== DISTANCE-TO-VAULT (right edge) ===== */
#dist {
  position: fixed;
  top: 50%;
  right: max(8px, env(safe-area-inset-right));
  transform: translateY(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: var(--led-bg);
  border: 2px solid var(--steel-line);
  box-shadow: 2px 2px 0 #000;
  padding: 6px 9px;
  z-index: 10;
  font-variant-numeric: tabular-nums;
}
body[data-state="charge"] #dist { display: flex; }
.dist-k { color: var(--cream-dim); font: 900 8px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.14em; }
.dist-v { color: var(--led); font: 900 28px/1 ui-monospace, "SF Mono", Menlo, monospace; text-shadow: 0 0 6px rgba(255,90,58,0.5); }
.dist-u { color: var(--cream-dim); font: 900 9px/1 ui-monospace, "SF Mono", Menlo, monospace; }
#dist.is-close { border-color: var(--gold); }
#dist.is-close .dist-v { color: var(--gold); text-shadow: 0 0 8px rgba(232,176,32,0.7); animation: distpulse 0.28s ease-in-out infinite alternate; }
@keyframes distpulse { to { transform: scale(1.12); } }

/* ===== TICKER (bottom) ===== */
#ticker {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 22px;
  background: var(--ink);
  border-top: 2px solid var(--banner);
  overflow: hidden;
  z-index: 9;
  display: none;
}
body[data-state="charge"] #ticker,
body[data-state="flight"] #ticker,
body[data-state="paused"] #ticker { display: block; }

#ticker-track {
  white-space: nowrap;
  display: inline-block;
  padding-left: 100%;
  animation: tickerScroll 22s linear infinite;
  font: 11px/22px ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--cream);
  letter-spacing: 0.06em;
}
@keyframes tickerScroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}

/* ===== BUG (corner logo) ===== */
#bug {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 9;
  display: none;
  font: 900 14px/1 Impact, "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.06em;
  color: var(--cream);
  background: var(--steel-line);
  border: 2px solid var(--steel-line);
  padding: 5px 7px;
  box-shadow: 2px 2px 0 #000;
}
body[data-state="charge"] #bug,
body[data-state="flight"] #bug,
body[data-state="paused"] #bug { display: block; }
.bug-sub { font-size: 9px; color: var(--banner); margin-left: 2px; }

/* ===== MASH PROMPT OVERLAY ===== */
#prompt {
  position: fixed;
  left: 0; right: 0;
  top: 38%;
  text-align: center;
  z-index: 8;
  display: none;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
body[data-state="idle"] #prompt,
body[data-state="charge"] #prompt { display: flex; }

#prompt-main {
  font: 900 38px/1 Impact, "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.1em;
  color: var(--banner);
  text-shadow: 3px 3px 0 #000, 0 0 12px rgba(192,57,43,0.6);
  animation: pulse 0.7s ease-in-out infinite alternate;
}
#prompt-sub {
  font: 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--cream);
  letter-spacing: 0.12em;
}
@keyframes pulse { to { transform: scale(1.08); } }

body[data-state="charge"] #prompt {
  top: 20%;
  bottom: auto;
}
body[data-state="charge"] #prompt-main { font-size: 20px; }

/* ===== VAULT BUTTON (mobile only) ===== */
#btn-vault {
  position: fixed;
  bottom: max(34px, env(safe-area-inset-bottom));
  right: max(12px, env(safe-area-inset-right));
  z-index: 12;
  display: none;
  min-width: 96px;
  min-height: 64px;
  font: 900 22px/1 Impact, "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--banner);
  border: 3px solid var(--steel-line);
  box-shadow: 4px 4px 0 #000;
  touch-action: manipulation;
  padding: 14px 24px;
}
#btn-vault:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #000;
}
body.touch[data-state="charge"].is-moving #btn-vault { display: block; }

/* ===== PAUSE PILL ===== */
#pause-pill {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  display: none;
  font: 900 28px/1 Impact, "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.2em;
  color: var(--led);
  background: var(--led-bg);
  border: 2px solid var(--steel-line);
  padding: 12px 22px;
  box-shadow: 4px 4px 0 #000;
}
body[data-state="paused"] #pause-pill { display: block; }

/* ===== PANELS (start, result) ===== */
.panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(18, 12, 8, 0.86);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.panel[hidden] { display: none; }

.panel-inner {
  background: var(--cream);
  color: var(--ink);
  border: 4px solid var(--steel-line);
  box-shadow: 8px 8px 0 #000, 0 0 0 2px var(--banner) inset;
  max-width: 380px;
  width: 100%;
  padding: 28px 22px;
  text-align: center;
}

.title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 16px;
}
.t-row {
  font: 900 44px/0.9 Impact, "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.04em;
  transform: skewX(-6deg);
}
.t-row-1 { color: var(--banner); text-shadow: 3px 3px 0 var(--steel-line); }
.t-row-2 { color: var(--ink); text-shadow: 3px 3px 0 var(--banner); }

.pitch {
  font: 13px/1.5 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--ink);
  margin: 0 0 14px;
}
.pitch strong { color: var(--banner); }
.pitch .warn { color: var(--banner-dk); font-weight: 700; }

.legend {
  font: 10px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--steel-dk);
  margin-top: 14px;
  letter-spacing: 0.04em;
}

/* ===== BUTTONS ===== */
button {
  font: 900 18px/1 Impact, "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.12em;
  color: #fff;
  background: var(--banner);
  border: 3px solid var(--steel-line);
  box-shadow: 5px 5px 0 #000;
  padding: 14px 32px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 60ms ease, box-shadow 60ms ease;
}
button:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 #000;
}
button.secondary { background: var(--steel-dk); }
button:focus-visible { outline: 2px solid var(--led); outline-offset: 3px; }

/* ===== RESULT CARD ===== */
.panel-inner.finish {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  max-width: 380px;
}

.card {
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--steel-line);
  padding: 20px 18px 16px;
  position: relative;
  text-align: center;
  box-shadow: 0 0 0 2px var(--banner) inset, 6px 6px 0 #000;
}
.card::before, .card::after {
  content: "";
  position: absolute;
  top: 12px;
  width: 10px;
  height: 10px;
  background: var(--steel-line);
  border-radius: 50%;
}
.card::before { left: 10px; }
.card::after  { right: 10px; }

.card-top {
  font: 900 20px/1 Impact, "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.2em;
  color: var(--banner);
  margin-bottom: 6px;
}
.grade-sub {
  display: block;
  margin-top: 4px;
  font: 400 10px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.1em;
  color: var(--steel-dk);
  text-transform: lowercase;
}
.card-num {
  font: 900 64px/1 Impact, "Arial Black", system-ui, sans-serif;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.card-unit {
  font: 900 12px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.3em;
  color: var(--steel-dk);
  margin-top: 2px;
}
.card-rule {
  height: 3px;
  background: var(--steel-line);
  margin: 14px 0;
}
.card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font: 11px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  text-align: left;
}
.card-stats .muted {
  color: var(--steel-dk);
  font-size: 9px;
  letter-spacing: 0.16em;
}
.card-stats span:not(.muted) {
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
}
.card-sus {
  margin-top: 10px;
  font: 900 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.18em;
  color: var(--gold);
  background: var(--ink);
  border: 2px dashed var(--gold);
  padding: 6px;
}
.card-sus[hidden] { display: none; }
.card-footer {
  margin-top: 12px;
  font: 9px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.16em;
  color: var(--steel-dk);
}

/* ===== SCOREBOARD ===== */
.scoreboard {
  margin-top: 18px;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--steel-line);
  padding: 12px;
  text-align: left;
}
.scoreboard__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font: 900 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.1em;
  color: var(--banner-dk);
  border-bottom: 2px solid var(--steel-line);
  padding-bottom: 6px;
  margin-bottom: 8px;
}
.scoreboard__status { color: var(--led); font-weight: 400; }
.scoreboard__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.scoreboard__row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: baseline;
  font: 12px/1.2 ui-monospace, "SF Mono", Menlo, monospace;
  padding: 3px 4px;
  color: var(--ink);
}
.scoreboard__row.is-current {
  background: var(--banner);
  color: #fff;
}
.scoreboard__empty {
  font: 11px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--steel-dk);
  text-align: center;
  padding: 12px;
}
.initials-form {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.initials-form[hidden] { display: none; }
.initials-form label {
  font: 9px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.16em;
  color: var(--steel-dk);
}
.initials-form__row { display: flex; gap: 6px; }
.initials-form__row input {
  flex: 1;
  min-width: 0;
  font: 14px/1 ui-monospace, "SF Mono", Menlo, monospace;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--led);
  border: 2px solid var(--steel-line);
  padding: 8px;
  letter-spacing: 0.2em;
  text-align: center;
}
.initials-form__row input:focus { outline: 2px solid var(--led); outline-offset: 1px; }
.initials-form__save {
  padding: 8px 14px;
  font-size: 13px;
}
.initials-form__skip {
  align-self: flex-end;
  background: transparent;
  color: var(--steel-dk);
  border: none;
  box-shadow: none;
  font: 10px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.12em;
  padding: 4px;
  text-decoration: underline;
}
.initials-form__skip:active {
  transform: none;
  box-shadow: none;
}

.finish-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.finish-actions button { flex: 1; }

/* ===== BACK-LINK HIDE EXTENSION ===== */
body[data-state="charge"] #bloff-back,
body[data-state="flight"] #bloff-back,
body[data-state="paused"] #bloff-back { display: none !important; }

/* ===== COPIED-CONFIRMATION TOAST ===== */
#copied-toast {
  position: fixed;
  bottom: max(86px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--led-bg);
  border: 2px solid var(--led);
  color: var(--led);
  font: 900 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.12em;
  padding: 10px 16px;
  box-shadow: 3px 3px 0 #000;
  pointer-events: none;
  animation: toastFade 1.6s ease forwards;
}
@keyframes toastFade {
  0%   { opacity: 0; transform: translate(-50%, 8px); }
  15%  { opacity: 1; transform: translateX(-50%); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== MOBILE REFLOW ===== */
@media (max-width: 560px) {
  .panel-inner { max-width: 100%; padding: 20px 16px; }
  .t-row { font-size: 36px; }
  .card-num { font-size: clamp(48px, 18vw, 64px); }
  #hud { gap: 1px; }
  .hud-cell { padding: 3px 5px; }
  .hud-v { font-size: 12px; }
  .hud-k { font-size: 8px; }
  .hud-live .hud-v { display: none; }
  #bug { display: none !important; }
  #meter { bottom: max(64px, env(safe-area-inset-bottom)); }
  #ticker { height: 18px; }
  #ticker-track { font-size: 10px; line-height: 18px; }
  #prompt-main { font-size: 30px; }
  .scoreboard__row { font-size: 11px; }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  #crt { display: none; }
  #game { filter: none; }
  #prompt-main { animation: none; }
  #hud-dot, .hud-dot { animation: none; }
  #ticker-track { animation: none; }
  #dist.is-close .dist-v { animation: none; }
}
