:root {
  --cyan: #7fe9ff;
  --orange: #ffb347;
  --bg: #03050c;
  --panel: rgba(6, 10, 24, 0.86);
  --text: #e8f4ff;
  --muted: rgba(200, 220, 255, 0.55);
  --display: 'Orbitron', 'Segoe UI', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  display: block;
  position: fixed;
  inset: 0;
  cursor: crosshair;
}

/* HUD ------------------------------------------------------------------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  padding: 12px 18px;
  pointer-events: none;
  font-family: var(--display);
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px rgba(127, 233, 255, 0.5);
}
.hud-left { text-align: left; }
.hud-center { text-align: center; }
.hud-right { text-align: right; }
.hud-big { font-size: 20px; font-weight: 700; }
.hud-row { font-size: 12px; margin-top: 4px; display: flex; gap: 10px; }
.hud-center .hud-row { justify-content: center; }
.hud-right .hud-row { justify-content: flex-end; }
.label { color: var(--muted); }
.status { font-size: 14px; margin-top: 6px; min-height: 18px; color: #cdf6ff; letter-spacing: 0.2em; }
.status.on { text-shadow: 0 0 14px #cdf6ff; animation: pulse 0.5s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.6; } to { opacity: 1; } }
.lives { color: var(--cyan); letter-spacing: 0.2em; }
.small { font-size: 11px; }
.muted { color: var(--muted); }
.bar {
  margin: 6px 0 0 auto;
  width: 180px;
  height: 6px;
  border: 1px solid rgba(127, 233, 255, 0.4);
  border-radius: 3px;
  overflow: hidden;
}
.hud-btn {
  pointer-events: auto;
  font-size: 14px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid rgba(127, 233, 255, 0.4);
  background: rgba(127, 233, 255, 0.08);
  color: var(--text);
  letter-spacing: 0;
}
#hud-speed-bar {
  height: 100%;
  width: 100%;
  transform-origin: left;
  transform: scaleX(0);
  background: linear-gradient(90deg, #4ee1ff, #ff4fd8);
  transition: transform 80ms linear;
}

/* Countdown -------------------------------------------------------------- */
#countdown {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 140px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px var(--cyan), 0 0 80px var(--cyan);
  pointer-events: none;
  animation: pop 1s ease-out infinite;
}
@keyframes pop {
  0% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.4; }
}

/* Overlay ---------------------------------------------------------------- */
#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(3, 5, 12, 0.35), rgba(3, 5, 12, 0.92));
  padding: 16px;
  overflow: auto;
}
.panel {
  width: min(920px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 1px solid rgba(127, 233, 255, 0.35);
  box-shadow: 0 0 40px rgba(127, 233, 255, 0.15), inset 0 0 60px rgba(127, 233, 255, 0.04);
  border-radius: 12px;
  padding: 28px 32px;
  text-align: center;
}
.panel h1 {
  font-family: var(--display);
  letter-spacing: 0.12em;
  margin: 0 0 6px;
  font-size: 30px;
}
.panel h1.title {
  font-size: clamp(40px, 8vw, 72px);
  font-weight: 900;
  letter-spacing: 0.18em;
  background: linear-gradient(90deg, #7fe9ff, #ffffff, #ffb347);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(127, 233, 255, 0.5));
}
/* The mark: each glyph is a span so readings can light up independently. */
.panel h1.mark {
  background: none;
  color: var(--text);
  filter: none;
  font-size: clamp(26px, 5.6vw, 60px);
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.mark .g {
  display: inline-block;
  transition: opacity 220ms ease, text-shadow 220ms ease, color 220ms ease;
  opacity: 0.85;
}
.mark .g.p { opacity: 0.5; font-weight: 500; color: var(--cyan); }
.mark .g.full.l { opacity: 0.9; text-shadow: 0 0 14px rgba(127, 233, 255, 0.5); }
.mark .g.full.p { opacity: 0.55; }
.mark .g.lit {
  opacity: 1;
  color: #ffffff;
  text-shadow: 0 0 12px #7fe9ff, 0 0 28px rgba(127, 233, 255, 0.8), 0 0 48px rgba(255, 179, 71, 0.5);
  animation: strike 220ms ease-out;
}
.mark .g.dim { opacity: 0.14; text-shadow: none; }
@keyframes strike {
  0% { opacity: 0.3; }
  35% { opacity: 1; }
  55% { opacity: 0.55; }
  100% { opacity: 1; }
}
.version {
  display: inline-block;
  margin-left: 12px;
  padding: 2px 9px;
  border: 1px solid rgba(255, 179, 71, 0.5);
  border-radius: 999px;
  color: var(--orange);
  font-size: 10px;
  letter-spacing: 0.2em;
  vertical-align: middle;
}
.tagline {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: var(--display);
  letter-spacing: 0.3em;
  font-size: 12px;
}
.eyebrow {
  font-family: var(--display);
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--orange);
}
.bulletin {
  max-width: 620px;
  margin: 0 auto 14px;
  padding: 10px 16px 12px;
  text-align: left;
  border-left: 2px solid var(--cyan);
  border-radius: 0 8px 8px 0;
  background: rgba(127, 233, 255, 0.05);
}
.bulletin .eyebrow { color: var(--cyan); font-size: 11px; }
.bulletin p { margin: 6px 0 0; font-size: 13px; line-height: 1.55; color: rgba(232, 244, 255, 0.85); }
.bulletin .you { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-family: var(--display); font-size: 13px; letter-spacing: 0.12em; color: #fff; }
.bulletin a { color: var(--cyan); text-decoration: none; }
.bulletin a:hover { text-decoration: underline; }
.level-card .record { margin: 8px 0 0; font-size: 13px; line-height: 1.5; color: var(--muted); font-style: italic; }
.level-card .record b { font-style: normal; font-family: var(--display); font-size: 10px; letter-spacing: 0.25em; color: var(--orange); margin-right: 8px; }
.level-card .stopped, .residents li.stopped .res-status { color: var(--orange); }
.record { text-align: left; max-width: 680px; margin: 12px auto 0; }
.record .chapter { margin: 0 0 18px; }
.mark-sm { font-family: var(--display); font-weight: 900; font-size: 20px; letter-spacing: 0.08em; white-space: nowrap; color: var(--text); }
.record .chapter p { margin: 6px 0 0; font-size: 14px; line-height: 1.6; color: rgba(232, 244, 255, 0.85); }
.record h3 { margin: 22px 0 8px; }
.residents { list-style: none; margin: 0; padding: 0; }
.residents li { padding: 8px 0; border-top: 1px solid rgba(127, 233, 255, 0.12); }
.residents li p { margin: 4px 0 0 30px; font-size: 13px; line-height: 1.5; color: var(--muted); font-style: italic; }
.res-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.res-num { font-family: var(--display); font-size: 11px; width: 22px; color: var(--muted); }
.res-head b { color: #fff; }
.res-status { margin-left: auto; font-family: var(--display); font-size: 11px; letter-spacing: 0.25em; color: var(--muted); }
.residents li.stopped b { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(255, 179, 71, 0.6); }
.record-note { margin: 4px 0 0; font-style: italic; }
.level-card {
  border: 1px solid rgba(255, 179, 71, 0.35);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 10px auto 18px;
  max-width: 620px;
  background: rgba(255, 179, 71, 0.05);
}
.level-title {
  font-family: var(--display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.1em;
}
.intro { margin: 8px 0 0; font-size: 14px; color: rgba(232, 244, 255, 0.85); }
.columns.three { grid-template-columns: 1fr 1.15fr 1fr; }
.columns {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 0 28px;
  text-align: left;
  margin-bottom: 16px;
}
.top {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 0 28px;
  text-align: left;
  margin: 4px 0 0;
}
.top .bulletin, .top .level-card { max-width: none; margin-left: 0; margin-right: 0; }
.top .level-card { text-align: left; margin-bottom: 8px; }
.panel h3 {
  font-family: var(--display);
  font-size: 12px;
  letter-spacing: 0.25em;
  color: var(--cyan);
  margin: 12px 0 6px;
}
.controls, .roster { margin: 0; padding-left: 0; list-style: none; font-size: 14px; line-height: 1.7; }
.controls b { color: #fff; }
.roster li { color: var(--muted); }
.roster li span { display: inline-block; width: 30px; font-family: var(--display); font-size: 11px; }
.roster li.now { color: #fff; }
.roster li.ready { color: rgba(232, 244, 255, 0.85); cursor: pointer; }
.roster li.ready:hover, .roster li.now:hover { color: var(--cyan); }
.roster li.now { cursor: pointer; }
.roster li.ready::after { content: ' · play'; font-size: 11px; color: var(--cyan); opacity: 0.8; }
.roster li.conduit { font-size: 12px; opacity: 0.8; padding-left: 10px; }
.roster li.conduit span { width: 20px; }
.roster li.locked::after { content: ' · locked'; font-size: 11px; opacity: 0.6; }
.roster li.now::after { content: ' · ready'; font-size: 11px; color: var(--orange); }
.small { font-size: 13px; line-height: 1.55; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
button {
  font-family: var(--display);
  letter-spacing: 0.12em;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 8px;
  border: 1px solid rgba(127, 233, 255, 0.5);
  background: rgba(127, 233, 255, 0.08);
  color: var(--text);
  cursor: pointer;
}
button.primary {
  background: linear-gradient(90deg, rgba(127, 233, 255, 0.35), rgba(255, 179, 71, 0.35));
  border-color: #fff;
  box-shadow: 0 0 20px rgba(127, 233, 255, 0.3);
}
button:hover:not([disabled]) { filter: brightness(1.25); }
button[disabled] { opacity: 0.45; cursor: default; }
.stats { margin: 14px auto; border-collapse: collapse; font-size: 15px; }
.stats td { padding: 5px 16px; }
.stats td:first-child { color: var(--muted); text-align: right; }
.stats td:last-child { font-family: var(--display); text-align: left; }

@media (max-width: 720px) {
  .columns, .columns.three, .top { grid-template-columns: 1fr; }
  .panel { padding: 20px 18px; }
  #hud { grid-template-columns: 1fr 1fr; }
  .hud-center { display: none; }
}

/* Touch controls (shown on coarse pointers only) ------------------------- */
#touch {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: none;
  gap: 10px;
  z-index: 5;
}
@media (pointer: coarse) {
  body.in-game #touch { display: flex; }
}
.tb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 22px;
  padding: 0;
  touch-action: none;
  opacity: 0.85;
}
.tb.big { width: 84px; height: 84px; font-size: 13px; border-color: var(--orange); }

/* Phone-sized landscape screens: keep the HUD out of the way. */
@media (max-height: 520px) {
  #hud { padding: 6px 10px; }
  .hud-big { font-size: 13px; }
  .hud-row { font-size: 9px; margin-top: 2px; }
  .bar { width: 110px; height: 4px; }
  #hud-track, #hud-mute, #hud-fps { display: none; }
  .tb { width: 54px; height: 54px; font-size: 18px; }
  .tb.big { width: 70px; height: 70px; font-size: 11px; }
}

/* Jukebox ---------------------------------------------------------------- */
.jb-now { margin: 4px auto 10px; max-width: 640px; }
.jb-meta { display: flex; justify-content: space-between; gap: 12px; font-family: var(--display); font-size: 12px; letter-spacing: 0.15em; color: var(--muted); min-height: 16px; }
.jb-bar { width: 100%; margin: 6px 0 0; }
#jb-progress { height: 100%; width: 0; background: linear-gradient(90deg, #7fe9ff, #ffb347); }
.jb-sliders { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 28px; margin: 6px 0 14px; font-size: 13px; }
.jb-sliders label { display: flex; align-items: center; gap: 8px; }
.jb-sliders input[type=range] { width: 180px; accent-color: #7fe9ff; }
.jb-sliders span { font-family: var(--display); font-size: 12px; min-width: 52px; text-align: left; }
.jb-columns { grid-template-columns: 1fr 1fr; }
.jb-list { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.jb-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; border: 1px solid transparent; }
.jb-row.now { border-color: rgba(255, 179, 71, 0.5); background: rgba(255, 179, 71, 0.08); }
.jb-num { font-family: var(--display); font-size: 11px; width: 24px; color: var(--muted); }
.jb-title { flex: 1; display: flex; flex-direction: column; line-height: 1.25; }
.jb-title small { color: var(--muted); font-size: 11px; }
.jb-actions { display: flex; gap: 4px; }
.jb-actions button { padding: 4px 9px; font-size: 13px; letter-spacing: 0; }

/* Multiplayer lobby ------------------------------------------------------ */
.mp-field { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.mp-adv { margin-top: 14px; text-align: left; }
.mp-adv summary { cursor: pointer; font-family: var(--display); font-size: 11px; letter-spacing: 0.25em; color: var(--muted); }
.mp-adv summary:hover { color: var(--cyan); }
.opt { display: flex; align-items: center; gap: 10px; font-size: 14px; line-height: 1.4; cursor: pointer; text-align: left; margin: 0 0 8px; }
.opt input { accent-color: var(--cyan); width: 16px; height: 16px; flex: none; cursor: pointer; margin: 0; }
.opt b { flex: none; }
.opt b { color: #fff; }
.mp-field select, .opt select { color-scheme: dark; }
.mp-field option, .opt option { background: #0a1020; color: var(--text); }

.mp-field input, .mp-field select, .opt select {
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.1em;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(127, 233, 255, 0.5);
  background: rgba(127, 233, 255, 0.08);
  color: var(--text);
}
.mp-status { margin-top: 14px; min-height: 24px; font-size: 14px; }
.mp-code {
  font-family: var(--display);
  font-size: clamp(40px, 8vw, 72px);
  font-weight: 900;
  letter-spacing: 0.35em;
  color: #fff;
  text-shadow: 0 0 18px var(--cyan), 0 0 40px rgba(127, 233, 255, 0.5);
  margin: 6px 0;
}
.mp-error { color: #ff7a8a; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--cyan); }

/* Tutorial card ---------------------------------------------------------- */
#tutor {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid rgba(255, 179, 71, 0.45);
  border-radius: 10px;
  padding: 12px 16px 10px;
  text-align: center;
  box-shadow: 0 0 30px rgba(255, 179, 71, 0.12);
  z-index: 4;
}
.tutor-step { font-family: var(--display); font-size: 11px; letter-spacing: 0.3em; color: var(--orange); }
.tutor-title { font-family: var(--display); font-size: 20px; font-weight: 700; letter-spacing: 0.12em; margin: 2px 0 4px; }
.tutor-text { font-size: 14px; line-height: 1.5; color: rgba(232, 244, 255, 0.9); }
.tutor-text b { color: #fff; }
.tutor-progress { font-family: var(--display); font-size: 12px; letter-spacing: 0.15em; color: var(--cyan); min-height: 16px; margin-top: 6px; }
.tutor-row { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.tutor-row button { padding: 7px 14px; font-size: 12px; }
@media (max-height: 520px) {
  #tutor { top: 52px; padding: 8px 12px 6px; }
  .tutor-title { font-size: 15px; }
  .tutor-text { font-size: 12px; }
}

.opt select { padding: 4px 8px; font-size: 12px; letter-spacing: 0.05em; min-width: 0; }

/* Frame picker: four systems, eight cells. */
.frame-card {
  margin-top: 10px; padding: 12px 18px 14px; text-align: left;
  background: linear-gradient(180deg, rgba(12, 20, 38, 0.85), rgba(8, 12, 26, 0.7));
  border: 1px solid rgba(120, 200, 255, 0.18); border-left: 3px solid var(--cyan); border-radius: 10px;
}
.frame-card .eyebrow { margin-bottom: 8px; }
.frame-card .opt { margin-bottom: 10px; }
.frame-card .opt select { width: 100%; font-size: 13px; padding: 5px 8px; }
#frame-panel { margin: 0; }
.frame-grid { display: grid; gap: 3px; }
.frame-row { display: flex; align-items: center; gap: 7px; font-size: 12px; line-height: 1.5; }
.frame-row .fr-name { font-family: var(--display); font-size: 10px; letter-spacing: 0.18em; color: var(--muted); width: 4.4em; flex: none; }
.frame-row .fr-pips { font-size: 13px; letter-spacing: 0.12em; color: rgba(180, 200, 230, 0.35); flex: none; }
.frame-row .fr-pips .on { color: var(--cyan); }
.frame-row .fr-val { color: #fff; font-variant-numeric: tabular-nums; margin-left: auto; white-space: nowrap; }
.frame-row .fr-val i { color: var(--muted); font-style: normal; font-size: 10px; margin-left: 4px; }
.fr-step {
  font: inherit; font-size: 13px; line-height: 1; width: 20px; height: 20px; flex: none; padding: 0;
  background: rgba(120, 200, 255, 0.10); color: var(--cyan); border: 1px solid rgba(120, 200, 255, 0.35);
  border-radius: 5px; cursor: pointer;
}
.fr-step:hover:not(:disabled) { background: rgba(120, 200, 255, 0.22); }
.fr-step:disabled { opacity: 0.28; cursor: default; }
.frame-foot { display: flex; align-items: center; gap: 10px; margin-top: 7px; font-family: var(--display); font-size: 10px; letter-spacing: 0.2em; color: var(--muted); }
.frame-foot .short { color: var(--orange); }
.fr-reset { font: inherit; font-size: 10px; letter-spacing: 0.2em; margin-left: auto; padding: 3px 9px; background: none; color: var(--muted); border: 1px solid rgba(180, 200, 230, 0.28); border-radius: 5px; cursor: pointer; }
.fr-reset:hover { color: #fff; border-color: rgba(180, 200, 230, 0.6); }
.frame-lore { margin: 8px 0 0; font-style: italic; }
.row.menu { gap: 8px; }
.row.menu button { padding: 10px 14px; letter-spacing: 0.06em; }

/* Title screen: heading spacing inside the top grid, and a tighter fit on short (laptop) viewports.
   These sit at the end of the file so they win over the base .panel h3 / .roster rules above. */
.top h3 { margin-top: 0; }
.top .roster + h3 { margin-top: 10px; }
/* Laptop heights: tighter spacing and no dossier line (it is in the Record). */
@media (max-height: 820px) and (min-width: 721px) {
  .panel { padding: 18px 28px; }
  .panel h1.mark { font-size: clamp(26px, 4.4vw, 48px); }
  .tagline { margin-bottom: 8px; }
  .panel h3 { margin: 8px 0 4px; }
  .top h3 { margin-top: 0; }
  .top .roster + h3 { margin-top: 6px; }
  .controls, .roster { line-height: 1.45; }
  .columns { margin-bottom: 10px; }
  .bulletin { padding: 8px 14px 10px; }
  .bulletin p { line-height: 1.45; }
  .level-card { padding: 10px 16px; }
  .level-card .intro, .level-card .record { margin-top: 6px; }
  .level-card .record { display: none; }
  .columns.three .controls { font-size: 13px; }
}
/* Short viewports: the bulletin keeps its heading and the record link only. */
@media (max-height: 760px) and (min-width: 721px) {
  .bulletin > p:not(.you) { display: none; }
}
