/*
 * Highscores admin: a Game & Watch faceplate around LCD leaderboards.
 *
 * Fonts are self-hosted (SIL Open Font License): Chakra Petch (display), Atkinson Hyperlegible Next (body),
 * Martian Mono (names, URLs, code), DSEG7 Classic (seven-segment score digits).
 */

@font-face { font-family: "Chakra Petch"; font-weight: 600; font-display: swap; src: url("/assets/chakra-petch-600-0b5f70d2.woff2") format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-weight: 700; font-display: swap; src: url("/assets/chakra-petch-700-1769cc45.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible Next"; font-weight: 400; font-display: swap; src: url("/assets/atkinson-hyperlegible-next-400-987ed25c.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible Next"; font-weight: 700; font-display: swap; src: url("/assets/atkinson-hyperlegible-next-700-f8c47b13.woff2") format("woff2"); }
@font-face { font-family: "Martian Mono"; font-weight: 400; font-display: swap; src: url("/assets/martian-mono-400-5817b560.woff2") format("woff2"); }
@font-face { font-family: "DSEG7"; font-weight: 700; font-display: block; src: url("/assets/dseg7-classic-bold-77ee7dcc.woff2") format("woff2"); }

:root {
  /* Faceplate */
  --steel: #d8dbde;
  --steel-light: #e6e8ea;
  --steel-edge: #b9bec3;
  --ink: #1f2328;
  --ink-muted: #5d636a;

  /* Screen */
  --bezel: #2b2f33;
  --lcd: #b3bd9b;
  --lcd-shade: #a5b08c;
  --segment: #1c2216;
  --segment-ghost: rgb(28 34 22 / 0.08);

  /* The action-button red */
  --signal: #c7372f;
  --signal-deep: #a42a23;

  --font-display: "Chakra Petch", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible Next", system-ui, sans-serif;
  --font-mono: "Martian Mono", ui-monospace, monospace;
  --font-lcd: "DSEG7", ui-monospace, monospace;

  --radius: 6px;
  --gutter: clamp(1rem, 4vw, 2.5rem);

  color-scheme: light;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--steel);
  color: var(--ink);
  font: 400 1rem/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: var(--font-display); font-weight: 700; line-height: 1.1; margin: 0; }
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); letter-spacing: -0.01em; }
h2 { font-size: 0.8125rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-muted); }
p { margin: 0; }
code { font-family: var(--font-mono); font-size: 0.8125em; }

a { color: inherit; text-underline-offset: 0.2em; }
a:hover { color: var(--signal-deep); }

:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* --- Masthead --- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem var(--gutter);
  border-bottom: 1px solid var(--steel-edge);
  background: var(--steel-light);
}

.masthead form { margin: 0; }

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-decoration: none;
}

.wordmark span { color: var(--signal); }

.page {
  max-width: 72rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3rem) var(--gutter) 4rem;
}

.page-narrow { max-width: 26rem; box-sizing: content-box; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 2rem;
}

.page-header .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.page-header .actions form { margin: 0; }

.eyebrow {
  display: inline-block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--ink-muted);
  text-decoration: none;
}

/* --- Buttons --- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 2.5rem;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--steel-edge);
  border-radius: 999px;
  background: var(--steel-light);
  color: var(--ink);
  font: 700 0.875rem/1 var(--font-body);
  text-decoration: none;
  cursor: pointer;
}

.button:hover { border-color: var(--ink-muted); color: var(--ink); }

.button-primary {
  border-color: var(--signal-deep);
  background: var(--signal);
  color: #fff;
  box-shadow: inset 0 -2px 0 var(--signal-deep), 0 1px 2px rgb(0 0 0 / 0.2);
}

.button-primary:hover { background: var(--signal-deep); border-color: var(--signal-deep); color: #fff; }
.button-primary:active { box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.3); }

.button-quiet { border-color: transparent; background: none; color: var(--ink-muted); }
.button-quiet:hover { border-color: transparent; color: var(--signal-deep); }

/* --- Flash --- */

.flash {
  max-width: 72rem;
  margin: 1.25rem auto 0;
  padding: 0 var(--gutter);
}

.flash div {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--ink);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--steel-light);
  font-size: 0.9375rem;
}

.flash .alert { border-left-color: var(--signal); }

/* --- The screen: a dark bezel around an LCD panel --- */

.screen {
  padding: clamp(0.625rem, 1.5vw, 1rem);
  border-radius: calc(var(--radius) * 2);
  background: var(--bezel);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.6), 0 6px 16px -8px rgb(0 0 0 / 0.5);
}

.lcd {
  position: relative;
  border-radius: var(--radius);
  background: linear-gradient(170deg, var(--lcd) 40%, var(--lcd-shade));
  box-shadow: inset 0 2px 8px rgb(0 0 0 / 0.35);
  color: var(--segment);
}

/* A number drawn in seven-segment digits, with the unlit "8"s showing behind it. */
.lcd-number {
  display: inline-grid;
  justify-items: end;
  font-family: var(--font-lcd);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.lcd-number > * { grid-area: 1 / 1; }
.lcd-number .ghost { color: var(--segment-ghost); }

/* --- Games index --- */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.game-card { display: block; text-decoration: none; }
.game-card:focus-visible { outline: none; }

.game-card .screen { transition: transform 120ms ease-out, box-shadow 120ms ease-out; }

.game-card:hover .screen,
.game-card:focus-visible .screen {
  transform: translateY(-2px);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.6), 0 12px 20px -10px rgb(0 0 0 / 0.55);
}

.game-card:focus-visible .screen { outline: 2px solid var(--signal); outline-offset: 3px; }

.game-card .lcd {
  display: grid;
  gap: 0.625rem;
  padding: 1rem 1rem 0.875rem;
}

.game-card .lcd-number { font-size: 1.75rem; }

.game-card .lcd-caption {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
}

.game-card .lcd-caption span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.game-card .label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.25rem 0;
}

.game-card .label strong { font-family: var(--font-display); font-size: 1.25rem; overflow-wrap: anywhere; }
.game-card .label span { font-size: 0.8125rem; color: var(--ink-muted); white-space: nowrap; }
.game-card:hover .label strong { color: var(--signal-deep); }

.empty {
  padding: 3rem 1.5rem;
  border: 1px dashed var(--steel-edge);
  border-radius: calc(var(--radius) * 2);
  text-align: center;
}

.empty p { margin-bottom: 1.25rem; color: var(--ink-muted); }

/* --- Game page --- */

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2.5rem;
}

@media (min-width: 62rem) {
  .game-layout { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; }
  .game-layout .api { position: sticky; top: 1.5rem; }
}

.game-layout section > h2 { margin-bottom: 0.875rem; }

.leaderboard .lcd { padding: 0.5rem clamp(0.75rem, 2vw, 1.25rem); }

.leaderboard table { width: 100%; border-collapse: collapse; }

.leaderboard th {
  padding: 0.75rem 0 0.5rem;
  font: 400 0.625rem/1 var(--font-mono);
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

.leaderboard td {
  padding: 0.45rem 0;
  border-top: 1px solid rgb(28 34 22 / 0.12);
  vertical-align: middle;
}

.leaderboard .rank { width: 2.75rem; font-size: 0.875rem; }
.leaderboard .score { width: 1%; text-align: right; }
.leaderboard td.score { font-size: clamp(0.875rem, 2.4vw, 1.375rem); }

.leaderboard .name {
  max-width: 0;
  padding-right: 1rem;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard .remove { width: 2.25rem; text-align: right; }
.leaderboard .remove form { margin: 0; }

.leaderboard .remove button {
  width: 1.75rem;
  height: 1.75rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: rgb(28 34 22 / 0.4);
  font: 400 1.125rem/1 var(--font-body);
  cursor: pointer;
}

.leaderboard .remove button:hover,
.leaderboard .remove button:focus-visible { background: var(--signal); color: #fff; }

.leaderboard .lcd-empty {
  padding: 2.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  text-align: center;
}

.leaderboard .lcd-empty .lcd-number { display: grid; justify-items: center; margin-bottom: 1rem; font-size: 2.5rem; }

.leaderboard-footnote { margin-top: 0.75rem; font-size: 0.8125rem; color: var(--ink-muted); }

/* --- API reference --- */

.api { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.75rem; }

.endpoint { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem; }

.endpoint-line {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  overflow-wrap: anywhere;
}

.endpoint-line code { font-size: 0.75rem; }

.method {
  flex: none;
  padding: 0.2rem 0.45rem;
  border-radius: 3px;
  background: var(--ink);
  color: var(--steel-light);
  font: 700 0.6875rem/1.2 var(--font-mono);
  letter-spacing: 0.05em;
}

.endpoint p { font-size: 0.9375rem; color: var(--ink-muted); }

.endpoint h3 { margin: 0; font: 700 1rem/1.3 var(--font-display); }
.endpoint form { margin: 0; }

.api-key {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  border-radius: var(--radius);
  background: var(--bezel);
  color: #dfe3d2;
}

.api-key details { min-width: 0; padding-top: 0.15rem; }

.api-key summary {
  font: 700 0.8125rem/1.4 var(--font-body);
  cursor: pointer;
}

.api-key details[open] .when-closed,
.api-key details:not([open]) .when-open { display: none; }

.api-key code {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}

.api-key .copy,
.snippet .copy {
  padding: 0.3rem 0.6rem;
  border: 1px solid rgb(255 255 255 / 0.2);
  border-radius: 999px;
  background: var(--bezel);
  color: #dfe3d2;
  font: 700 0.6875rem/1 var(--font-body);
  cursor: pointer;
}

.api-key .copy:hover,
.snippet .copy:hover { border-color: rgb(255 255 255 / 0.5); }

.snippet {
  position: relative;
  border-radius: var(--radius);
  background: var(--bezel);
  color: #dfe3d2;
}

.snippet pre {
  margin: 0;
  padding: 0.875rem 1rem;
  overflow-x: auto;
  font: 400 0.6875rem/1.7 var(--font-mono);
}

.snippet .copy {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
}

.api-key .copy { flex: none; }

/* --- Forms --- */

.form { display: grid; gap: 1.25rem; }

.field { display: grid; gap: 0.375rem; }
.field label { font-weight: 700; font-size: 0.9375rem; }

.field input {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--steel-edge);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: 400 1rem/1.4 var(--font-body);
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.08);
}

.field input.mono { font-family: var(--font-mono); font-size: 0.9375rem; }
.field input:focus-visible { outline: 2px solid var(--signal); outline-offset: 0; border-color: var(--signal); }
.field .field_with_errors { display: contents; }
.field .field_with_errors input { border-color: var(--signal); }

.hint { font-size: 0.875rem; color: var(--ink-muted); }

.form-error {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--signal);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: #fff;
  font-size: 0.9375rem;
}

.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; padding-top: 0.25rem; }

.panel {
  padding: clamp(1.25rem, 4vw, 2rem);
  border: 1px solid var(--steel-edge);
  border-radius: calc(var(--radius) * 2);
  background: var(--steel-light);
}

.panel h1 { margin-bottom: 0.5rem; font-size: 1.75rem; }
.panel > p { margin-bottom: 1.5rem; color: var(--ink-muted); }

.below-panel { margin-top: 1.25rem; text-align: center; font-size: 0.9375rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
