/* CoreDump — terminal / cyberpunk shell */

:root {
  --bg: #03050a;
  --panel: rgba(8, 14, 24, 0.85);
  --line: rgba(0, 229, 255, 0.25);
  --blue: #00e5ff;
  --blue-dim: #3b8ea0;
  --amber: #ffb000;
  --red: #ff3d6e;
  --text: #cfeaf2;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
}

body {
  background:
    radial-gradient(ellipse at 50% 35%, rgba(0, 120, 160, 0.16), transparent 65%),
    var(--bg);
  overflow-x: hidden;
}

canvas { display: block; max-width: 100%; height: auto; }

/* ---- CRT treatment ---------------------------------------------------- */

.crt {
  position: relative;
  min-height: 100vh;
  /* The unzoomed stage can be wider than a phone while it's being measured;
     clip it so mobile browsers don't widen the whole page to fit. */
  overflow: hidden;
  max-width: 100vw;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Everything visible lives in .stage, which main.js zooms to fit the window.
   It keeps its natural size (columns never shrink); the zoom does the scaling. */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: max-content;
}
.rig > * { flex-shrink: 0; }
.board-frame canvas { max-width: none; }

.crt::before { /* scanlines */
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.025) 0px,
    rgba(255, 255, 255, 0.025) 1px,
    rgba(0, 0, 0, 0.18) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
  animation: flicker 6s infinite steps(1);
}

.crt::after { /* vignette */
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 51;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.65) 100%);
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  47% { opacity: 0.85; }
  48% { opacity: 1; }
  82% { opacity: 0.92; }
}

/* ---- header / footer ---------------------------------------------------- */

.topbar {
  width: min(720px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.brand {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.18em;
  color: var(--blue);
  text-shadow: 0 0 8px rgba(0, 229, 255, 0.7), 0 0 22px rgba(0, 229, 255, 0.35);
}
.brand .slash { color: var(--amber); text-shadow: 0 0 8px rgba(255, 176, 0, 0.7); }
.brand .cursor { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* GAME / BUILD LOG tabs (game page and log page) */
.tabs { display: flex; gap: 4px; }
.tab {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--blue-dim);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 4px 10px;
}
.tab:hover { color: var(--blue); border-color: var(--blue); }
.tab.active { color: #03050a; background: var(--blue); border-color: var(--blue); box-shadow: 0 0 10px rgba(0, 229, 255, 0.45); }

.sys { font-size: 11px; color: var(--blue-dim); letter-spacing: 0.1em; text-transform: uppercase; }
#mode-label { color: var(--amber); }

.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  font-size: 11px;
  color: var(--blue-dim);
  max-width: 720px;
}
kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  margin-right: 2px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--blue);
  background: rgba(0, 229, 255, 0.05);
}

/* ---- layout ------------------------------------------------------------- */

.rig {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
}

.panel { display: flex; flex-direction: column; gap: 14px; width: 130px; }

.module {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 10px 10px;
  position: relative;
}
.module::before { /* corner tick */
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  width: 10px;
  height: 10px;
  border-top: 2px solid var(--blue);
  border-left: 2px solid var(--blue);
}
.module h2 {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.25em;
  color: var(--blue-dim);
}
.module canvas { margin: 0 auto; }

.readouts { margin: 0; display: grid; gap: 6px; }
.readouts div { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.readouts dt { font-size: 10px; color: var(--blue-dim); letter-spacing: 0.12em; }
.readouts dd {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  text-shadow: 0 0 6px rgba(0, 229, 255, 0.5);
  font-variant-numeric: tabular-nums;
}
.readouts div[hidden] { display: none; }
.readouts.big div { flex-direction: column; align-items: flex-start; gap: 0; }
.readouts.big dd { font-size: 17px; }

.amber { color: var(--amber) !important; text-shadow: 0 0 8px rgba(255, 176, 0, 0.6) !important; }

/* ---- gauges ---------------------------------------------------------------- */

.gauge {
  position: relative;
  height: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.gauge::after { /* segment ticks */
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to right, transparent 0 9px, rgba(3, 5, 10, 0.9) 9px 11px);
}
.gauge-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
}
.gauge-mark {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 2px;
  background: rgba(255, 255, 255, 0.55);
  z-index: 1;
}
.gauge.oc .gauge-fill { background: linear-gradient(90deg, #0088a8, var(--blue)); box-shadow: 0 0 10px var(--blue); }
.gauge.heat .gauge-fill { background: linear-gradient(90deg, #1d6fa8, var(--amber) 70%, var(--red)); background-size: var(--heat-span, 100%) 100%; }

.gauge-status {
  margin-top: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--blue-dim);
}

#oc-module.ready .gauge-status { color: var(--blue); text-shadow: 0 0 8px var(--blue); animation: blink 0.8s steps(1) infinite; }
#oc-module.active { border-color: var(--amber); }
#oc-module.active .gauge.oc .gauge-fill { background: linear-gradient(90deg, #a86a00, var(--amber)); box-shadow: 0 0 12px var(--amber); }
#oc-module.active .gauge-status { color: var(--amber); text-shadow: 0 0 8px var(--amber); }

#heat-module.hot .gauge-status { color: var(--amber); text-shadow: 0 0 8px var(--amber); }
#heat-module.throttled { border-color: var(--red); animation: jitter 0.12s steps(2) infinite; }
#heat-module.throttled .gauge-status { color: var(--red); text-shadow: 0 0 8px var(--red); }

@keyframes jitter {
  0% { transform: translate(0, 0); }
  50% { transform: translate(1px, -1px); }
  100% { transform: translate(-1px, 1px); }
}

/* ---- board ---------------------------------------------------------------- */

.board-frame {
  position: relative;
  border: 1px solid rgba(0, 229, 255, 0.55);
  box-shadow:
    0 0 0 1px rgba(0, 229, 255, 0.12),
    0 0 24px rgba(0, 229, 255, 0.25),
    inset 0 0 30px rgba(0, 229, 255, 0.08);
  transition: border-color 0.3s, box-shadow 0.3s;
}
.board-frame.hot {
  border-color: rgba(255, 176, 0, 0.7);
  box-shadow: 0 0 0 1px rgba(255, 176, 0, 0.15), 0 0 26px rgba(255, 140, 0, 0.3), inset 0 0 30px rgba(255, 140, 0, 0.1);
}
.board-frame.overclock {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px rgba(255, 176, 0, 0.3), 0 0 34px rgba(255, 176, 0, 0.45), inset 0 0 40px rgba(255, 176, 0, 0.12);
}
.board-frame.throttled {
  border-color: var(--red);
  box-shadow: 0 0 0 1px rgba(255, 61, 110, 0.3), 0 0 30px rgba(255, 61, 110, 0.45), inset 0 0 40px rgba(255, 61, 110, 0.12);
  animation: jitter 0.1s steps(2) infinite;
}

#fx {
  position: absolute;
  pointer-events: none;
  z-index: 1;
}
#snd.off { color: var(--red); }

#overlay {
  z-index: 3;
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(3, 5, 10, 0.82);
  text-align: center;
  padding: 16px;
}
#overlay[hidden] { display: none; }
.ov-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--blue);
  text-shadow: 0 0 10px rgba(0, 229, 255, 0.8);
}
.ov-hint { font-size: 11px; color: var(--amber); letter-spacing: 0.1em; animation: blink 1.2s steps(1) infinite; }
.ov-content:empty { display: none; }
.ov-content { width: 100%; }

/* mode select */
.mode-list { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.mode-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--mono);
  color: var(--text);
  background: rgba(0, 229, 255, 0.03);
  border: 1px solid rgba(0, 229, 255, 0.18);
  padding: 7px 9px;
  cursor: pointer;
}
.mode-item:hover { border-color: rgba(0, 229, 255, 0.5); }
.mode-item.selected {
  border-color: var(--blue);
  background: rgba(0, 229, 255, 0.1);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.3), inset 0 0 12px rgba(0, 229, 255, 0.08);
}
.mode-item .mi-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.mode-item .mi-name { font-size: 12px; font-weight: 800; letter-spacing: 0.12em; color: var(--blue); }
.mode-item.selected .mi-name::before { content: '> '; color: var(--amber); }
.mode-item .mi-best { font-size: 10px; color: var(--amber); font-variant-numeric: tabular-nums; }
.mode-item .mi-blurb { font-size: 10px; color: var(--blue-dim); margin-top: 3px; line-height: 1.35; }

/* results */
.ov-content .mode-list { margin-top: 10px; }
.result-main { font-size: 26px; font-weight: 800; color: var(--amber); text-shadow: 0 0 12px rgba(255, 176, 0, 0.7); font-variant-numeric: tabular-nums; }
.result-sub { font-size: 10px; letter-spacing: 0.15em; color: var(--blue-dim); margin-top: 2px; }
.result-new { font-size: 11px; font-weight: 800; letter-spacing: 0.2em; color: var(--blue); text-shadow: 0 0 8px var(--blue); margin-top: 6px; animation: blink 0.6s steps(1) infinite; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin: 12px auto 0; max-width: 220px; font-size: 10px; text-align: left; }
.result-grid dt { color: var(--blue-dim); letter-spacing: 0.1em; }
.result-grid dd { margin: 0; color: var(--blue); text-align: right; font-variant-numeric: tabular-nums; }

#callout {
  z-index: 2;
  position: absolute;
  left: 0;
  right: 0;
  top: 32%;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
#callout.show { animation: callout 1.1s ease-out forwards; }
@keyframes callout {
  0% { opacity: 0; transform: translateY(8px) scale(0.92); }
  12% { opacity: 1; transform: translateY(0) scale(1.04); }
  25% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}
.co-main { font-size: 18px; font-weight: 800; letter-spacing: 0.12em; color: #fff; text-shadow: 0 0 10px var(--blue), 0 0 22px var(--blue); }
.co-sub { font-size: 12px; font-weight: 600; letter-spacing: 0.15em; color: var(--blue); }
.co-pts { font-size: 12px; color: var(--blue-dim); margin-top: 2px; }
.co-main.red, .co-sub.red { color: var(--red); text-shadow: 0 0 10px var(--red); }
.co-main.amber { text-shadow: 0 0 10px var(--amber), 0 0 22px var(--amber); }

/* ---- settings modal -------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40; /* under the CRT scanlines (50) so they still sweep over it */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 4, 8, 0.78);
}
.modal[hidden] { display: none; }

.modal-box {
  width: min(600px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: #060b14;
  border: 1px solid rgba(0, 229, 255, 0.55);
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.25);
}
.modal-head, .modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-foot { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.modal-head h2 { margin: 0; font-size: 14px; letter-spacing: 0.25em; color: var(--blue); text-shadow: 0 0 8px var(--blue); }
.modal-body { overflow-y: auto; padding: 4px 14px 14px; }
.modal-body section { margin-top: 14px; }
.modal-body h3 { margin: 0 0 8px; font-size: 10px; letter-spacing: 0.25em; color: var(--blue-dim); font-weight: 600; }

.btn {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--blue);
  background: rgba(0, 229, 255, 0.06);
  border: 1px solid var(--line);
  padding: 5px 10px;
  cursor: pointer;
}
.btn:hover, .btn:focus-visible { border-color: var(--blue); outline: none; box-shadow: 0 0 8px rgba(0, 229, 255, 0.4); }
.btn.reset { color: var(--amber); }

.slider {
  display: grid;
  grid-template-columns: 64px 1fr 72px;
  align-items: center;
  gap: 2px 10px;
  margin-bottom: 8px;
}
.sl-label { font-size: 11px; font-weight: 600; letter-spacing: 0.12em; color: var(--text); }
.sl-val { font-size: 11px; color: var(--amber); text-align: right; font-variant-numeric: tabular-nums; }
.sl-hint { grid-column: 2 / 4; font-size: 9px; color: var(--blue-dim); margin-top: -2px; }
.slider input[type='range'] { width: 100%; accent-color: var(--blue); }

.check { font-size: 11px; letter-spacing: 0.12em; display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { accent-color: var(--blue); }

.pad-status { font-weight: 400; letter-spacing: 0.08em; color: var(--blue-dim); }
.pad-status.on { color: var(--amber); }

.binds-wrap { overflow-x: auto; }
.binds { width: 100%; border-collapse: collapse; font-size: 10px; }
.binds th { text-align: left; font-weight: 600; color: var(--blue-dim); letter-spacing: 0.1em; padding: 3px 6px 3px 0; white-space: nowrap; }
.binds thead th { font-size: 9px; }
.binds td { padding: 2px 3px; }
.slot {
  width: 100%;
  min-width: 58px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--blue);
  background: rgba(0, 229, 255, 0.04);
  border: 1px solid rgba(0, 229, 255, 0.18);
  padding: 4px 4px;
  cursor: pointer;
}
.slot.empty { color: rgba(59, 142, 160, 0.6); }
.slot:hover { border-color: var(--blue); }
.slot.listening { color: var(--amber); border-color: var(--amber); animation: blink 0.6s steps(1) infinite; }
.note { font-size: 9px; color: var(--blue-dim); margin: 8px 0 0; line-height: 1.5; }

.mode-item.config .mi-name { color: var(--amber); }

/* ---- global leaderboard ------------------------------------------------------ */

#overlay { overflow-y: auto; justify-content: safe center; }

.lb-slot { width: 100%; margin-top: 10px; }
.lb-msg { font-size: 10px; letter-spacing: 0.15em; color: var(--blue-dim); margin: 4px 0 6px; }
.lb-msg.amber { color: var(--amber); }
.lb-msg.red { color: var(--red); }
.lb-tabs { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 800; letter-spacing: 0.12em; color: var(--blue); }
.lb-arrow { font-family: var(--mono); font-size: 18px; color: var(--amber); background: none; border: 1px solid var(--line); width: 32px; cursor: pointer; }
.lb-arrow:hover { border-color: var(--amber); }

.lb-list { list-style: none; margin: 0; padding: 0; font-size: 11px; text-align: left; }
.lb-list li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 3px 6px; border-bottom: 1px solid rgba(0, 229, 255, 0.08); }
.lb-list li:nth-child(-n + 3) .lb-rank { color: var(--amber); }
.lb-list li.me { background: rgba(255, 176, 0, 0.12); outline: 1px solid var(--amber); }
.lb-rank { color: var(--blue-dim); text-align: right; font-variant-numeric: tabular-nums; }
.lb-name { color: var(--text); white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.lb-val { color: var(--blue); font-variant-numeric: tabular-nums; }

.lb-form { display: flex; gap: 6px; margin-bottom: 4px; }
.lb-input {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.15em;
  color: var(--amber);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--amber);
  padding: 5px 8px;
  text-transform: uppercase;
}
.lb-input:focus { outline: none; box-shadow: 0 0 10px rgba(255, 176, 0, 0.4); }
.lb-status { font-size: 10px; color: var(--amber); min-height: 12px; margin-bottom: 4px; }

/* ---- v0.2: versus, banner, toasts, touch ------------------------------------ */

/* Incoming-garbage meter on the board's left edge. */
.pending {
  position: absolute;
  left: -7px;
  bottom: 0;
  width: 4px;
  height: 0;
  background: linear-gradient(to top, var(--red), #ff9db4);
  box-shadow: 0 0 10px var(--red);
  transition: height 0.15s;
  z-index: 2;
}

#banner {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
  padding: 6px 8px;
  font-size: 10px;
  letter-spacing: 0.08em;
  line-height: 1.4;
  color: #03050a;
  background: rgba(255, 176, 0, 0.92);
  text-align: center;
}
#banner[hidden] { display: none; }

.opponent { display: flex; flex-direction: column; gap: 8px; width: 214px; }
.opponent[hidden] { display: none; }
.opp-head { display: flex; flex-direction: column; gap: 2px; }
.opp-label { font-size: 10px; letter-spacing: 0.25em; color: var(--blue-dim); }
#opp-name { font-size: 13px; font-weight: 800; letter-spacing: 0.1em; color: var(--red); text-shadow: 0 0 8px rgba(255, 61, 110, 0.6); }
.opp-frame { position: relative; border: 1px solid rgba(255, 61, 110, 0.55); box-shadow: 0 0 18px rgba(255, 61, 110, 0.2); }
#board2 { width: 212px !important; height: auto; }
.opp-score { font-size: 12px; color: var(--amber); font-variant-numeric: tabular-nums; }

.mode-item.daily .mi-name { color: #39ff88; }
.lb-msg.small { font-size: 9px; margin-top: 8px; }
.lb-list a.lb-name { color: var(--text); text-decoration: none; }
.lb-list a.lb-name:hover { color: var(--blue); text-decoration: underline; }
.lb-watch {
  font-family: var(--mono);
  margin-left: 6px;
  font-size: 9px;
  color: var(--amber);
  background: none;
  border: 1px solid rgba(255, 176, 0, 0.4);
  padding: 0 4px;
  cursor: pointer;
}
.lb-watch:hover { background: rgba(255, 176, 0, 0.15); }
.lb-list.ach li { grid-template-columns: 22px auto 1fr; }
.lb-list.ach li.locked { opacity: 0.45; }
.ach-desc { color: var(--blue-dim) !important; font-size: 10px; text-align: right; }
.room-code { font-size: 18px; letter-spacing: 0.3em; color: var(--blue); }

#toasts { position: fixed; top: 14px; right: 14px; z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  min-width: 220px;
  max-width: 300px;
  padding: 10px 12px;
  background: rgba(6, 11, 20, 0.95);
  border: 1px solid var(--amber);
  box-shadow: 0 0 18px rgba(255, 176, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: toast-in 0.3s ease-out;
  transition: opacity 0.5s, transform 0.5s;
}
.toast b { font-size: 12px; letter-spacing: 0.12em; color: var(--amber); }
.toast span { font-size: 11px; color: var(--text); }
.toast.out { opacity: 0; transform: translateX(20px); }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } }

/* Touch controls */
#touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(3, 5, 10, 0.98) 70%, rgba(3, 5, 10, 0));
  display: flex;
  flex-direction: column;
  gap: 8px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#touch[hidden] { display: none; }
.t-row { display: flex; gap: 8px; }
#touch button {
  flex: 1;
  min-height: 42px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--blue);
  background: rgba(0, 229, 255, 0.07);
  border: 1px solid rgba(0, 229, 255, 0.35);
  border-radius: 8px;
  touch-action: none;
}
#touch button.big { min-height: 58px; font-size: 22px; }
#touch button.hard { color: var(--amber); border-color: rgba(255, 176, 0, 0.5); background: rgba(255, 176, 0, 0.08); }
#touch button.amber { color: var(--amber); }
#touch button.on { background: rgba(0, 229, 255, 0.3); box-shadow: 0 0 12px rgba(0, 229, 255, 0.5); }

/* Touch layout: lean side panels, no keyboard hints, room for the control bar. */
body.touch .keys,
body.touch .telemetry,
body.touch .sys { display: none; }
body.touch .panel { width: 76px; gap: 8px; }
body.touch .rig { gap: 8px; }
body.touch .module h2 { font-size: 9px; letter-spacing: 0.12em; }
body.touch .module { padding: 6px; }
body.touch .crt { justify-content: flex-start; padding-top: 8px; }
body.touch .board-frame { touch-action: none; }
