:root {
  color-scheme: dark;
  --void: #07090e;
  --chassis: #11151d;
  --panel: #171d27;
  --panel-alt: #121821;
  --line: #2d3748;
  --bone: #f2ead9;
  --muted: #b6b9c4;
  --gold: #e3bf72;
  --emerald: #78d69a;
  --crimson: #e83e63;
  --blood: #a8121a;
  --cyan: #7fc7e8;
  --font-disp: 'Oswald', Impact, sans-serif;
  --font-serif: 'Cinzel', Georgia, serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: radial-gradient(circle at 75% 0%, #162328 0%, var(--void) 55%);
  color: var(--bone);
  font-family: var(--font-body);
  line-height: 1.5;
}

a {
  color: var(--gold);
}

code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -80px;
  background: var(--gold);
  color: #08090f;
  padding: 10px 14px;
  font-weight: 700;
  z-index: 9999;
}
.skip-link:focus {
  top: 10px;
}

/* Topbar */
.topbar {
  background: rgba(7, 9, 14, 0.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.topbar-inner {
  width: min(1140px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.portal-back {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--bone);
}
.portal-back:hover {
  border-color: var(--gold);
  color: var(--gold);
}
.brand-title strong {
  display: block;
  font-family: var(--font-disp);
  font-size: 20px;
  letter-spacing: 0.08em;
  line-height: 1;
}
.brand-title span {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--emerald);
}
.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.util-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--bone);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.util-btn:hover, .util-btn:focus-visible {
  border-color: var(--gold);
  color: var(--gold);
  outline: none;
}

/* Main Shell */
.shell {
  width: min(1140px, calc(100% - 24px));
  margin: 18px auto 48px;
}

/* Hero Card */
.hero-card {
  margin: 0 0 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--chassis);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.hero-card img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 410px;
  object-fit: cover;
}
.hero-meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #0c1017;
  border-top: 1px solid var(--line);
}
.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
}
.hero-stats strong {
  color: var(--emerald);
}
.difficulty-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.diff-btn {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--bone);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.diff-btn.active {
  background: var(--gold);
  color: #090b10;
  border-color: var(--gold);
}

/* Daily Banner */
.daily-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  margin-bottom: 24px;
  border: 1px solid rgba(227, 191, 114, 0.5);
  border-left: 5px solid var(--gold);
  border-radius: 8px;
  background: linear-gradient(110deg, #171a24 0%, #1b1520 100%);
}
.badge-gold {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--gold);
  margin-bottom: 4px;
}
.daily-copy h2 {
  margin: 0 0 4px;
  font-family: var(--font-disp);
  font-size: 24px;
  letter-spacing: 0.04em;
}
.daily-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  max-width: 64ch;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--emerald);
  border-radius: 6px;
  background: var(--emerald);
  color: #07120c;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn-primary:hover {
  background: #9bf0b8;
}
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--bone);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.btn-ghost:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* Section Head + Track Grid */
.section-head {
  margin-bottom: 14px;
}
.section-head h2 {
  margin: 0 0 4px;
  font-family: var(--font-disp);
  font-size: 26px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.track-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.track-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--track-accent, var(--emerald));
  border-radius: 8px;
  min-width: 0;
}
.track-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.track-freq {
  color: var(--track-accent, var(--emerald));
  font-weight: 700;
}
.track-bpm {
  color: var(--muted);
}
.track-card h3 {
  margin: 0;
  font-family: var(--font-disp);
  font-size: 22px;
  letter-spacing: 0.03em;
}
.track-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}
.track-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.track-best strong {
  color: var(--gold);
}
.track-card-actions {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.intensity-bars {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--track-accent, var(--gold));
  letter-spacing: 2px;
}

/* Gameplay Console */
.console-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
}
.now-playing {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.freq-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 4px;
  background: rgba(120, 214, 154, 0.14);
  border: 1px solid var(--emerald);
  color: var(--emerald);
  white-space: nowrap;
}
.now-playing strong {
  display: block;
  font-family: var(--font-disp);
  font-size: 20px;
  line-height: 1.1;
}
.now-playing small {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--gold);
  letter-spacing: 0.1em;
}
.console-actions {
  display: flex;
  gap: 8px;
}

.console-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(270px, 0.78fr);
  gap: 14px;
  align-items: start;
}

.crt-stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.crt-bezel {
  position: relative;
  border: 3px solid #3c475a;
  border-radius: 12px;
  overflow: hidden;
  background: #060d0a;
  box-shadow: inset 0 0 36px rgba(0, 0, 0, 0.9), 0 12px 32px rgba(0, 0, 0, 0.55);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.crt-bezel.bypass-on {
  border-color: var(--crimson);
  box-shadow: inset 0 0 36px rgba(210, 31, 36, 0.35), 0 0 24px rgba(232, 62, 99, 0.35);
}
#highway-canvas {
  display: block;
  width: 100%;
  height: clamp(340px, 56vh, 520px);
  touch-action: none;
}

.crt-status-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 9, 14, 0.86);
  backdrop-filter: blur(5px);
  padding: 16px;
}
.crt-status-overlay[hidden] {
  display: none;
}
.overlay-card {
  width: min(320px, 100%);
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 8px;
  text-align: center;
}
.overlay-card h3 {
  margin: 4px 0 14px;
  font-family: var(--font-disp);
  font-size: 26px;
}
.overlay-actions {
  display: grid;
  gap: 8px;
}

/* Tactile Touch Pads */
.pad-deck {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.lane-pad {
  min-height: 62px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #1c2432 0%, #10151e 100%);
  color: var(--bone);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.lane-pad .pad-key {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
}
.lane-pad small {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}
.lane-pad.pressed {
  transform: translateY(2px);
  border-color: var(--emerald);
  background: rgba(120, 214, 154, 0.24);
}

/* Parish Bypass Switch */
.bypass-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border: 2px solid #524250;
  border-radius: 8px;
  background: linear-gradient(90deg, #1b161f 0%, #141923 100%);
  color: var(--bone);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.bypass-switch.active {
  border-color: var(--crimson);
  background: linear-gradient(90deg, #4b1224 0%, #2a0d1c 100%);
  box-shadow: 0 0 18px rgba(232, 62, 99, 0.35);
}
.bypass-led {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #3d333c;
  border: 2px solid #7c6f7a;
  flex: 0 0 auto;
}
.bypass-switch.active .bypass-led {
  background: #ff4e72;
  border-color: #ffd7e0;
  box-shadow: 0 0 12px #ff4e72;
}
.bypass-copy strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.06em;
}
.bypass-copy small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

/* Side Telemetry */
.telemetry-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.stat-box {
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.stat-box small {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.stat-box strong {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--bone);
}

.scope-box, .meter-box, .teleprinter-box {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.panel-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  color: var(--gold);
  margin-bottom: 8px;
}
#scope-canvas {
  display: block;
  width: 100%;
  height: 82px;
  border-radius: 5px;
  border: 1px solid #23332c;
}

.meter-track {
  height: 12px;
  background: #0a0d13;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  transition: width 0.12s linear;
}
.threat-fill {
  background: linear-gradient(90deg, #78d69a 0%, #e3bf72 52%, #e83e63 100%);
}
.progress-fill {
  background: var(--emerald);
}
.meter-hint {
  margin: 7px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

.teleprinter-lines {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 84px;
}
.teleprinter-lines p {
  margin: 0;
  padding: 6px 8px;
  background: #0b1015;
  border-left: 3px solid var(--emerald);
  color: #daf3e2;
}
.teleprinter-lines p.tp-wait {
  border-left-color: var(--line);
  color: var(--muted);
}

/* Result Card */
.result-card {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--gold);
  border-radius: 10px;
}
.eyebrow {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--gold);
  text-transform: uppercase;
}
.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.result-top h2 {
  margin: 0;
  font-family: var(--font-disp);
  font-size: 32px;
}
.res-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}
.grade-badge {
  width: 78px;
  height: 78px;
  border-radius: 10px;
  border: 2px solid var(--gold);
  background: #0d121a;
  display: grid;
  place-items: center;
  font-family: var(--font-disp);
  font-size: 42px;
  color: var(--gold);
  flex: 0 0 auto;
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.result-stats > div {
  padding: 12px;
  background: #0e131b;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.result-stats small {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}
.result-stats strong {
  font-family: var(--font-mono);
  font-size: 20px;
}
.judgement-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}
.judgement-breakdown strong {
  color: var(--bone);
}
.reward-banner {
  padding: 12px 14px;
  border-left: 4px solid var(--emerald);
  background: rgba(120, 214, 154, 0.1);
  color: #e4f8eb;
  font-size: 13.5px;
  margin-bottom: 18px;
}
.decoded-archive h3 {
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}
#res-transcript p {
  margin: 0 0 6px;
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: #0b1015;
  border-left: 3px solid var(--emerald);
}
#res-transcript p.locked-line {
  border-left-color: var(--line);
  color: #6b7280;
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 6, 10, 0.85);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  padding: 14px;
}
.modal-backdrop[hidden] {
  display: none;
}
.modal-card {
  width: min(520px, 100%);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 10px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.modal-head h2 {
  margin: 0;
  font-family: var(--font-disp);
  font-size: 24px;
}
.setting-row {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
.setting-row label small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.setting-row select, .setting-row input[type="range"] {
  width: 100%;
  font-family: var(--font-body);
  padding: 8px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: #0c1018;
  color: var(--bone);
}
.checkbox-row label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
}
.cal-tester {
  padding: 12px;
  margin-bottom: 14px;
  background: #0d121a;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.cal-status {
  width: 100%;
  margin: 4px 0 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--gold);
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 18px 14px 28px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

/* Responsive Breakpoints (Zero horizontal overflow at 320/390/500/900/1280) */
@media (max-width: 860px) {
  .console-layout {
    grid-template-columns: 1fr;
  }
  .score-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .track-grid {
    grid-template-columns: 1fr;
  }
  .score-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #highway-canvas {
    height: clamp(290px, 48vh, 420px);
  }
}

@media (max-width: 420px) {
  .shell, .topbar-inner {
    width: calc(100% - 16px);
  }
  .lane-pad {
    min-height: 54px;
  }
  .lane-pad .pad-key {
    font-size: 16px;
  }
}
