/*
 * Segfaultdle — terminal skin.
 *
 * Styles the markup of public/index.html plus the nodes app.js builds (code lines, choices,
 * transcript, leaderboard rows). Dark phosphor-green CRT; amber is reserved for the second
 * guess and red for a burnt snippet, so colour always means the same thing.
 *
 * No external font, no CDN, no image: the only assets are the two files next to this one.
 */

/* ------------------------------------------------------------------ *
 * Tokens                                                              *
 * ------------------------------------------------------------------ */

:root {
  --bg: #060a07;
  --bg-panel: #0a1009;
  --bg-inset: #050906;
  --bg-raised: #0e1610;

  --line: rgba(78, 240, 138, 0.14);
  --line-strong: rgba(78, 240, 138, 0.32);

  --green: #4ef08a;
  --green-dim: #2aa864;
  --green-glow: rgba(78, 240, 138, 0.28);
  --amber: #ffb454;
  --amber-dim: #a8722c;
  --red: #ff5f56;
  --red-dim: #a8352f;

  /* Contrast on --bg: text ~12:1, muted ~6.9:1, faint ~4.2:1 (line numbers, meta). */
  --text: #cfe8d6;
  --muted: #7fa38c;
  --faint: #5d7d68;

  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas,
    "DejaVu Sans Mono", "Liberation Mono", monospace;

  --radius: 10px;
  --gutter: clamp(0.85rem, 3.5vw, 1.5rem);
  --page: 48rem;

  --accent: var(--green);
  --accent-dim: var(--green-dim);
}

/* ------------------------------------------------------------------ *
 * Reset and base                                                      *
 * ------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The markup toggles `hidden`; component rules must never win over it. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--green-dim) transparent;
}

body {
  margin: 0;
  overflow-x: clip;
  background:
    radial-gradient(90rem 40rem at 50% -18rem, rgba(78, 240, 138, 0.08), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100dvh;
  padding:
    env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right))
    env(safe-area-inset-bottom) max(var(--gutter), env(safe-area-inset-left));
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0;
  font-weight: 600;
}

p {
  margin: 0;
}

ol,
ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

kbd {
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05em 0.4em;
  font: inherit;
  font-size: 0.85em;
  color: var(--text);
  background: var(--bg-raised);
}

em {
  color: var(--green);
  font-style: normal;
  text-decoration: underline dotted var(--green-dim);
  text-underline-offset: 3px;
}

::selection {
  background: var(--green);
  color: #04120a;
}

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ *
 * Utilities                                                           *
 * ------------------------------------------------------------------ */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 200;
  transform: translateY(-200%);
  background: var(--green);
  color: #04120a;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

/* CRT overlay: scanlines plus a vignette. Purely decorative, never interactive. */
.crt {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.26) 0 1px, transparent 1px 3px),
    radial-gradient(130% 95% at 50% 0%, transparent 42%, rgba(0, 0, 0, 0.6) 100%);
  opacity: 0.55;
}

/* ------------------------------------------------------------------ *
 * Top bar                                                             *
 * ------------------------------------------------------------------ */

.topbar {
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.1rem 0 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: clamp(1.15rem, 5vw, 1.5rem);
  letter-spacing: -0.02em;
  color: var(--green);
  text-shadow: 0 0 18px var(--green-glow);
  display: flex;
  align-items: baseline;
  gap: 0.15em;
}

.brand-sign {
  color: var(--green-dim);
}

.caret {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  translate: 0 0.12em;
  background: var(--green);
  animation: blink 1.1s steps(2, start) infinite;
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 2.2rem;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.chip-sep {
  color: var(--faint);
}

.chip #puzzle-number {
  color: var(--green);
}

.chip-time time {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.chip-time.is-done time {
  color: var(--amber);
}

.chip-button {
  position: relative;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}

/* The chip stays visually small, but the thumb gets a 44px target. */
.chip-button::after {
  content: "";
  position: absolute;
  inset: -0.4rem -0.2rem;
}

.chip-button:hover {
  border-color: var(--line-strong);
  color: var(--green);
}

/* ------------------------------------------------------------------ *
 * Layout                                                              *
 * ------------------------------------------------------------------ */

main {
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.25rem 0 2.5rem;
  display: block;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.banner {
  border: 1px solid var(--red-dim);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: rgba(255, 95, 86, 0.08);
  color: #ffc9c5;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: clamp(0.9rem, 3.5vw, 1.4rem);
}

.boot {
  margin: 0;
  padding: 2.5rem 0;
  text-align: center;
  color: var(--muted);
  font: inherit;
}

.boot::after {
  content: "_";
  color: var(--green);
  animation: blink 1s steps(2, start) infinite;
}

/* ------------------------------------------------------------------ *
 * Buttons                                                             *
 * ------------------------------------------------------------------ */

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 2.9rem;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--accent);
  color: #04120a;
  border-color: var(--accent);
  box-shadow: 0 0 22px -6px var(--green-glow);
}

.btn-primary:hover {
  background: #6dffa4;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-strong);
}

.btn-ghost:hover {
  color: var(--green);
  border-color: var(--green-dim);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ *
 * Intro and identity form                                             *
 * ------------------------------------------------------------------ */

.intro-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.intro-title {
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  color: var(--green);
}

.intro-lede {
  color: var(--text);
}

.intro-proof {
  border-left: 3px solid var(--green-dim);
  background: var(--bg-inset);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.75rem 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.proof-tag,
.footer-tag,
.evidence-badge {
  display: inline-block;
  margin-right: 0.5rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--green-dim);
  border-radius: 999px;
  color: var(--green);
  background: rgba(78, 240, 138, 0.08);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

#identity-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  color: var(--green);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.field-optional {
  color: var(--faint);
}

.field input {
  font: inherit;
  font-size: max(1rem, 16px); /* keeps iOS from zooming on focus */
  min-height: 3rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg-inset);
  color: var(--text);
  caret-color: var(--green);
  width: 100%;
}

.field input::placeholder {
  color: var(--faint);
}

.field input:focus {
  border-color: var(--green);
}

.field-help {
  color: var(--muted);
  font-size: 0.78rem;
}

.form-error {
  color: #ffc9c5;
  font-size: 0.85rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.form-actions .btn {
  flex: 1 1 10rem;
}

/* ------------------------------------------------------------------ *
 * Progress                                                            *
 * ------------------------------------------------------------------ */

.progress {
  display: flex;
  gap: 0.4rem;
}

.progress-step {
  flex: 1 1 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-panel);
  color: var(--faint);
  text-align: center;
  padding: 0.3rem 0;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  position: relative;
  overflow: hidden;
}

.step-mark {
  display: block;
  font-variant-numeric: tabular-nums;
}

.progress-step::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: currentColor;
  opacity: 0.5;
}

.progress-step[data-state="current"] {
  color: var(--green);
  border-color: var(--green-dim);
}

.progress-step[data-state="won"] {
  color: var(--green);
  background: rgba(78, 240, 138, 0.1);
  border-color: var(--green-dim);
}

.progress-step[data-state="half"] {
  color: var(--amber);
  background: rgba(255, 180, 84, 0.1);
  border-color: var(--amber-dim);
}

.progress-step[data-state="lost"] {
  color: var(--red);
  background: rgba(255, 95, 86, 0.1);
  border-color: var(--red-dim);
}

/* ------------------------------------------------------------------ *
 * Editor + code                                                       *
 * ------------------------------------------------------------------ */

.editor {
  padding: 0;
  overflow: hidden;
  background: var(--bg-inset);
}

.editor-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  font-size: 0.78rem;
  color: var(--muted);
}

.lights {
  display: inline-flex;
  gap: 0.3rem;
  flex: 0 0 auto;
}

.light {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  display: block;
}

.light-red {
  background: var(--red);
}

.light-amber {
  background: var(--amber);
}

.light-green {
  background: var(--green);
}

.editor-file {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-flags {
  color: var(--faint);
  margin-left: auto;
  white-space: nowrap;
}

.difficulty {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.difficulty-dots {
  display: inline-flex;
  gap: 0.22rem;
}

.difficulty .dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  border: 1px solid var(--faint);
  display: block;
}

.difficulty .dot.is-on {
  background: var(--amber);
  border-color: var(--amber);
}

.code {
  margin: 0;
  padding: 0.85rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: pre;
  font-size: clamp(0.78rem, 3.1vw, 0.92rem);
  line-height: 1.7;
  tab-size: 4;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.code-line {
  display: flex;
  width: max-content;
  min-width: 100%;
}

.code-line:hover {
  background: rgba(78, 240, 138, 0.04);
}

/* Sticky so the numbers survive a horizontal scroll. */
.code-gutter {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: 0 0 auto;
  width: 2.9em;
  padding-right: 0.9em;
  text-align: right;
  color: var(--faint);
  background: var(--bg-inset);
  user-select: none;
  -webkit-user-select: none;
}

.code-text {
  flex: 1 1 auto;
  padding-right: 1rem;
  white-space: pre;
  color: var(--text);
}

.hl-comment {
  color: #5f8570;
  font-style: italic;
}

.hl-preproc {
  color: #c792ea;
}

.hl-string {
  color: #ffb454;
}

.hl-char {
  color: #ffd08a;
}

.hl-number {
  color: #ff9d7a;
}

.hl-keyword {
  color: #4ef08a;
  font-weight: 600;
}

.hl-type {
  color: #6fd7ff;
}

.hl-constant {
  color: #ff7ab2;
}

.hl-function {
  color: #e8f5ec;
}

.hl-operator {
  color: #8fb8a0;
}

.hl-punct {
  color: #67856f;
}

/* ------------------------------------------------------------------ *
 * Question + choices                                                  *
 * ------------------------------------------------------------------ */

.question {
  font-size: clamp(1rem, 4vw, 1.15rem);
  color: var(--text);
}

.choices {
  display: grid;
  gap: 0.55rem;
}

.choice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 3.4rem;
  padding: 0.7rem 0.9rem;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
}

.choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-raised);
}

.choice:active:not(:disabled) {
  transform: translateY(1px);
}

.choice:disabled {
  cursor: default;
}

.choice-key {
  flex: 0 0 auto;
  width: 1.6rem;
  height: 1.6rem;
  display: grid;
  place-items: center;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.8rem;
}

.choice-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.choice-mark {
  flex: 0 0 auto;
  font-size: 1.1rem;
  line-height: 1;
}

.choice[data-state="wrong"] {
  border-color: var(--amber-dim);
  border-left-color: var(--amber);
  background: rgba(255, 180, 84, 0.08);
  color: var(--amber);
}

.choice[data-state="wrong"] .choice-mark {
  color: var(--amber);
}

.choice[data-state="right"] {
  border-color: var(--green-dim);
  border-left-color: var(--green);
  background: rgba(78, 240, 138, 0.1);
  color: var(--green);
}

.choice[data-state="right"] .choice-mark {
  color: var(--green);
}

/* Second guess: the whole panel switches to amber. Failure switches to red. */
#screen-play[data-state="second"] {
  --accent: var(--amber);
  --accent-dim: var(--amber-dim);
}

#screen-play[data-state="second"] .choice[data-state="wrong"] {
  opacity: 0.75;
}

#screen-play[data-state="lost"] {
  --accent: var(--red);
  --accent-dim: var(--red-dim);
}

#screen-play[data-state="lost"] .choice[data-state="wrong"] {
  border-color: var(--red-dim);
  border-left-color: var(--red);
  background: rgba(255, 95, 86, 0.08);
  color: var(--red);
}

#screen-play[data-state="lost"] .choice[data-state="wrong"] .choice-mark {
  color: var(--red);
}

.choice:disabled:not([data-state]) {
  opacity: 0.45;
}

.hint {
  color: var(--faint);
  font-size: 0.8rem;
}

.feedback {
  min-height: 1.5rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.feedback[data-tone="ok"] {
  color: var(--green);
}

.feedback[data-tone="warn"] {
  color: var(--amber);
}

.feedback[data-tone="bad"] {
  color: var(--red);
}

/* Coarse pointers have no number row to press. */
@media (pointer: coarse) {
  .hint {
    display: none;
  }
}

/* ------------------------------------------------------------------ *
 * Reveal + gcc evidence                                               *
 * ------------------------------------------------------------------ */

.reveal {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: clamp(0.9rem, 3.5vw, 1.3rem);
}

.reveal[data-tone="ok"] {
  --accent: var(--green);
}

.reveal[data-tone="warn"] {
  --accent: var(--amber);
}

.reveal[data-tone="bad"] {
  --accent: var(--red);
}

.reveal-title {
  color: var(--accent);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.reveal-answer {
  color: var(--muted);
  font-size: 0.92rem;
}

.reveal-answer-text {
  color: var(--green);
  font-weight: 600;
}

.reveal-explanation {
  color: var(--text);
  font-size: 0.95rem;
}

.evidence {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-inset);
  overflow: hidden;
}

.evidence-head {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
}

.evidence-title {
  color: var(--muted);
  font-size: 0.8rem;
}

.transcript {
  margin: 0;
  padding: 0.75rem;
  overflow-x: auto;
  white-space: pre;
  font: inherit;
  font-size: clamp(0.75rem, 3vw, 0.85rem);
  line-height: 1.65;
  color: var(--text);
  overscroll-behavior-x: contain;
}

.tr-line {
  display: block;
  min-width: max-content;
}

.tr-cmd {
  color: var(--green);
}

.tr-out {
  color: #e8f5ec;
}

.tr-err {
  color: #ffa39d;
}

.tr-muted {
  color: var(--faint);
}

.tr-status {
  margin-top: 0.15rem;
  font-weight: 600;
}

.tr-status.is-ok {
  color: var(--green);
}

.tr-status.is-bad {
  color: var(--red);
}

.evidence-meta {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.72rem;
  overflow-wrap: anywhere;
}

.reveal-actions {
  display: flex;
  justify-content: flex-end;
}

.reveal-actions .btn {
  flex: 1 1 auto;
}

/* ------------------------------------------------------------------ *
 * Result                                                              *
 * ------------------------------------------------------------------ */

.result-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  text-align: center;
}

.result-kicker {
  color: var(--green);
  letter-spacing: 0.04em;
}

.result-grid {
  font-size: clamp(2rem, 12vw, 3rem);
  letter-spacing: 0.15em;
  line-height: 1.2;
}

.result-score {
  font-size: clamp(1.6rem, 8vw, 2.4rem);
  font-weight: 700;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.result-max {
  color: var(--faint);
  font-size: 0.55em;
}

.result-streak {
  color: var(--muted);
  font-size: 0.9rem;
}

.share-block {
  width: 100%;
  margin: 0.3rem 0 0;
  padding: 0.75rem;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--bg-inset);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  width: 100%;
}

.share-actions .btn {
  flex: 1 1 9rem;
}

.copy-status {
  min-height: 1.2rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.copy-status[data-tone="ok"] {
  color: var(--green);
}

.copy-status[data-tone="bad"] {
  color: var(--red);
}

.next-puzzle {
  color: var(--muted);
  font-size: 0.85rem;
}

.next-time {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.new-puzzle {
  width: 100%;
}

.new-puzzle .btn {
  width: 100%;
}

/* ------------------------------------------------------------------ *
 * Stats                                                               *
 * ------------------------------------------------------------------ */

.stats-card,
.board-card {
  margin-top: 0.25rem;
}

.section-title {
  font-size: 1rem;
  color: var(--green);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.8rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 0.5rem;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-inset);
  padding: 0.6rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.stats-sub {
  margin: 1.1rem 0 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.distribution {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.dist-score {
  flex: 0 0 1.2rem;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dist-track {
  flex: 1 1 auto;
  height: 0.85rem;
  border-radius: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  overflow: hidden;
}

.dist-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  background: var(--green-dim);
  transition: width 0.4s ease;
}

.dist-row[data-current="true"] .dist-fill {
  background: var(--green);
}

.dist-row[data-current="true"] .dist-score {
  color: var(--green);
}

.dist-count {
  flex: 0 0 1.6rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ *
 * Leaderboard                                                         *
 * ------------------------------------------------------------------ */

.board-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.2rem;
  margin-bottom: 0.9rem;
}

.filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter label,
.filter-label {
  color: var(--muted);
  font-size: 0.8rem;
}

#promo-filter {
  font: inherit;
  font-size: max(0.9rem, 16px);
  min-height: 2.6rem;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--bg-inset);
  color: var(--text);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
}

.seg {
  font: inherit;
  font-size: 0.82rem;
  min-height: 2.6rem;
  padding: 0.35rem 0.85rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}

.seg + .seg {
  border-left: 1px solid var(--line-strong);
}

.seg[aria-pressed="true"] {
  background: rgba(78, 240, 138, 0.14);
  color: var(--green);
}

.board-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.board {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.board th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

.board td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.board .col-rank {
  width: 2.5rem;
}

.board .col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.board .col-score {
  color: var(--green);
  font-weight: 600;
}

.board .col-name {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank {
  color: var(--faint);
}

.board tr[data-me="true"] {
  background: rgba(78, 240, 138, 0.08);
}

.board tr[data-me="true"] .player-name {
  color: var(--green);
  font-weight: 600;
}

.board tr[data-me="true"] .rank {
  color: var(--green);
}

.board-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding-top: 0.7rem;
}

/* ------------------------------------------------------------------ *
 * Footer                                                              *
 * ------------------------------------------------------------------ */

.footer {
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.2rem 0 2rem;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.75rem;
}

/* ------------------------------------------------------------------ *
 * Motion                                                              *
 * ------------------------------------------------------------------ */

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

@keyframes line-in {
  from {
    opacity: 0;
    transform: translateX(-0.5rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(0.6rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.code-line {
  animation: line-in 0.26s ease both;
  animation-delay: calc(min(var(--row, 0), 24) * 16ms);
}

.reveal.is-in {
  animation: panel-in 0.32s ease both;
}

#screen-result .result-grid {
  animation: pop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

#screen-result .result-score {
  animation: pop-in 0.45s 0.1s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.choice[data-state] {
  animation: pop-in 0.2s ease both;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .caret,
  .boot::after {
    opacity: 1;
  }
}

/* ------------------------------------------------------------------ *
 * Small screens                                                       *
 * ------------------------------------------------------------------ */

@media (max-width: 30rem) {
  .topbar {
    padding-top: 0.85rem;
  }

  .editor-flags {
    display: none;
  }

  .board th,
  .board td {
    padding: 0.4rem 0.35rem;
  }

  .board .col-name {
    max-width: 8rem;
  }
}

@media (min-width: 40rem) {
  .choices {
    grid-template-columns: 1fr 1fr;
  }

  .reveal-actions .btn {
    flex: 0 0 auto;
    min-width: 12rem;
  }
}
