/* rjtstack theme: palette, typography and shared UI primitives.
   Loaded before layout.css and game.css, which consume these variables and
   refine the game-specific components. The docs pages load this file alone.

   The look: a dark neutral ground with a faint piece-outline pattern, and
   every mode coloured from the piece palette (--mode, set per page on body).
   Buttons and panels borrow the glass of the mino tiles: a dark rim, a bright
   bevel inside it, a gloss band over the top half and a soft drop shadow. */

:root {
  color-scheme: dark;

  /* surfaces and text */
  --bg: #0b0b0d;
  --panel: #17181c;
  --text: #e8e8ec;
  --muted: #8f909a;
  --accent: #4fc3f7;
  --accent-strong: #9adcff;
  --accent-ink: #0b0b0d;

  /* strokes */
  --grid: rgba(143, 144, 154, 0.08);
  --line: rgba(143, 144, 154, 0.18);

  /* mino faces, sampled from Archive/public/images/sprites40px.png */
  --mino-I: #12a3e0;
  --mino-J: #203f99;
  --mino-L: #f7931d;
  --mino-O: #dcbf00;
  --mino-S: #38b449;
  --mino-T: #a52ba1;
  --mino-Z: #be1e2d;

  /* The page's colour, from the piece palette. Each mode's body class sets
     --mode (below); body derives the accents from it, so those have to be
     declared on body, not here, to see the page's value. */
  --mode: var(--mino-I);

  /* type */
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  /* The smallest text on any page, and the size of the top bar's links: 14 px
     (CLAUDE.md, "Text size"). Under a size in em, use max(0.9em, var(--text-min)). */
  --text-min: 0.875rem;

  /* radii and elevation */
  --radius-sm: 0.45rem;
  --radius-md: 0.8rem;
  --radius-lg: 0.9rem;
  --shadow-panel:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 0 0 1px rgba(0, 0, 0, 0.55),
    0 24px 48px -18px rgba(0, 0, 0, 0.85),
    0 10px 20px -12px rgba(0, 0, 0, 0.6);
}

/* Mode colours. Replays and the replay player share one. */
body.page-home   { --mode: var(--mino-I); }
body.page-play   { --mode: var(--mino-I); }
body.page-pvcpu  { --mode: var(--mino-Z); }
body.page-zen    { --mode: var(--mino-S); }
body.page-combo  { --mode: var(--mino-L); }
body.page-replays,
body.page-replay { --mode: var(--mino-T); }
body.page-tune   { --mode: var(--mino-O); }

body {
  /* Text on the dark ground needs a lighter cut of the mode colour. */
  --accent: color-mix(in srgb, var(--mode) 62%, #fff);
  --accent-strong: color-mix(in srgb, var(--mode) 40%, #fff);
  --accent-ink: #0b0b0d;
  --mode-text: var(--accent);
  --mode-glow: color-mix(in srgb, var(--mode) 55%, transparent);
  --mode-faint: color-mix(in srgb, var(--mode) 16%, transparent);
  --mode-line: color-mix(in srgb, var(--mode) 45%, rgba(255, 255, 255, 0.12));
  --mode-shadow: color-mix(in srgb, var(--mode) 35%, transparent);
}

/* ------------------------------------------------------------- base page */

* {
  box-sizing: border-box;
  scrollbar-color: rgba(143, 144, 154, 0.45) transparent;
  scrollbar-width: thin;
}

html {
  min-height: 100%;
  background: var(--bg);
}

/* The ground: a soft wash of the mode colour at the top, a fine 24 px grid
   and the piece-outline tile (body::before), faded away from the centre so
   the well sits on plain dark. All of it is static. */
body {
  position: relative;
  /* A stacking context, so the pattern (body::before, z-index -1) paints
     over the body's own background instead of under it. */
  isolation: isolate;
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(1100px 560px at 50% -160px, var(--mode-faint), transparent 70%),
    radial-gradient(700px 420px at 100% 100%, color-mix(in srgb, var(--mode) 7%, transparent), transparent 70%),
    linear-gradient(rgba(255, 255, 255, 0.016) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.016) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: url("/img/bg-pieces.svg") 0 0 / 240px 240px;
  -webkit-mask-image: radial-gradient(70% 80% at 50% 45%, transparent 40%, #000 100%);
  mask-image: radial-gradient(70% 80% at 50% 45%, transparent 40%, #000 100%);
  pointer-events: none;
}

h1, h2, h3, h4 {
  line-height: 1.15;
  text-wrap: balance;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

p {
  margin: 0 0 0.8rem;
}

hr {
  height: 0;
  margin: 1.4rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}

code,
pre,
kbd,
samp {
  font-family: var(--font-mono);
}

code {
  padding: 0.1em 0.32em;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: rgba(143, 144, 154, 0.1);
  font-size: max(0.88em, var(--text-min));
}

/* A key to press, as ui/keys.js draws "[Enter]": the name on a raised cap,
   the brackets either side dimmer than the key. */
kbd.key {
  font-size: max(0.88em, var(--text-min));
  white-space: nowrap;
}

.key-bracket {
  color: #5c5d67;
}

.key-cap {
  display: inline-block;
  margin: 0 0.1em;
  padding: 0.02em 0.4em 0.06em;
  border: 1px solid #5a5b64;
  border-bottom-width: 2px;
  border-radius: 0.3em;
  background: linear-gradient(180deg, #3d3e46, #2a2b31);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  color: #f2f2f6;
  font-weight: 700;
  line-height: 1.15;
}

pre {
  overflow: auto;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(11, 11, 13, 0.65);
  font-size: var(--text-min);
  line-height: 1.5;
}

pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
}

/* Numerals stay monospaced and aligned in HUDs and tables. */
.num,
.mono,
.tabular {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* A board score (public/js/ui/bscore.js): an unlabeled number in a chip of
   clear glass, the same wherever it shows. It takes no hue, since a board
   score is neither a family nor a warning. Sizes are in em so it fits a
   small score line and a step line alike; line-height 1 keeps the line it
   sits in as tall as before. The cost input keeps its field's own box and
   takes only the digits and the ink. */
:root {
  --bscore-ink: #f6f6f9;
  --bscore-rim: rgba(255, 255, 255, 0.2);
}

.bscore {
  padding: 0.05em 0.34em;
  border: 1px solid var(--bscore-rim);
  border-radius: 0.32em;
  background: linear-gradient(180deg,
    rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: var(--bscore-ink);
  font-family: var(--font-mono);
  font-size: max(0.92em, var(--text-min));
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.field input.bscore {
  color: var(--bscore-ink);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

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

.hint {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: var(--text-min);
}

/* Between the keys of a hint: a key with nothing bound hides (ui/controls.js),
   and takes its separator with it. */
.hint [data-control]:not([hidden]) ~ [data-control]:not([hidden])::before {
  content: " \00b7  ";
  white-space: pre;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: var(--text-min);
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* --------------------------------------------------------------- scrollbar */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(143, 144, 154, 0.4);
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(143, 144, 154, 0.62);
  background-clip: padding-box;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* ---------------------------------------------------------- selection/focus */

::selection {
  background: var(--mode-glow);
  color: #fff;
}

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

/* ---------------------------------------------------------------- buttons */

/* A glass tile: --btn-c is the face colour. The face is a vertical gradient
   with a soft light rising from the bottom edge (as on the mino tiles), the
   top half carries the gloss band, the rim is dark with a bright bevel
   inside it, and it casts a shadow in its own colour. */
.btn {
  --btn-c: #3b3e46;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid rgba(0, 0, 0, 0.8);
  border-radius: 0.55rem;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.3) 0%,
      rgba(255, 255, 255, 0.12) 46%,
      rgba(255, 255, 255, 0) 47%),
    radial-gradient(90% 70% at 50% 115%,
      color-mix(in srgb, var(--btn-c) 70%, #fff) 0%,
      transparent 65%),
    linear-gradient(180deg,
      color-mix(in srgb, var(--btn-c) 88%, #fff) 0%,
      var(--btn-c) 50%,
      color-mix(in srgb, var(--btn-c) 78%, #000) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    inset 0 -2px 3px rgba(0, 0, 0, 0.3),
    0 8px 16px -6px rgba(0, 0, 0, 0.8),
    0 2px 3px rgba(0, 0, 0, 0.5);
  color: #fff;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}

.btn:hover:not(:disabled):not([aria-disabled="true"]) {
  color: #fff;
  text-decoration: none;
  filter: brightness(1.14) saturate(1.05);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16),
    inset 0 -2px 3px rgba(0, 0, 0, 0.3),
    0 12px 22px -8px rgba(0, 0, 0, 0.85),
    0 3px 5px rgba(0, 0, 0, 0.5);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
  filter: brightness(0.96);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    inset 0 3px 6px rgba(0, 0, 0, 0.45),
    0 3px 6px -3px rgba(0, 0, 0, 0.8);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: default;
}

/* The page's colour, with a cast shadow in the same colour. */
.btn-primary {
  --btn-c: var(--mode);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16),
    inset 0 -2px 3px rgba(0, 0, 0, 0.3),
    0 10px 22px -8px var(--mode-glow),
    0 8px 16px -6px rgba(0, 0, 0, 0.8),
    0 2px 3px rgba(0, 0, 0, 0.5);
}

.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    inset 0 -2px 3px rgba(0, 0, 0, 0.3),
    0 14px 28px -8px var(--mode-glow),
    0 12px 22px -8px rgba(0, 0, 0, 0.85),
    0 3px 5px rgba(0, 0, 0, 0.5);
}

/* Flat: no glass, just a quiet label that lights up. */
.btn-ghost {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  text-shadow: none;
}

.btn-ghost:hover:not(:disabled):not([aria-disabled="true"]) {
  filter: none;
  transform: none;
  background: rgba(143, 144, 154, 0.12);
  box-shadow: none;
  color: var(--text);
}

.btn-ghost:active:not(:disabled) {
  transform: none;
  box-shadow: none;
}

.btn-small {
  padding: 0.3rem 0.65rem;
  border-radius: 0.45rem;
  font-size: var(--text-min);
}

/* A pressed toggle (the replay speed buttons) takes the page's colour. */
.btn.is-active {
  --btn-c: var(--mode);
}

/* ------------------------------------------------------- inputs and fields */

.field {
  display: grid;
  gap: 0.28rem;
  color: var(--muted);
  font-size: var(--text-min);
  font-weight: 600;
}

.field > span,
.field > label {
  letter-spacing: 0.02em;
}

/* Browsers set form controls at 13.33 px unless told otherwise. */
input,
select,
textarea,
button {
  font-size: var(--text-min);
}

/* Inset glass: a dark well with a shadow along its top edge. */
.field input,
.field select,
.field textarea,
.input {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid rgba(0, 0, 0, 0.7);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.28));
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.55),
    0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 400;
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}

/* The open list draws on the select's background colour, not the gradient;
   without one it is white under the light text. */
.field select {
  background-color: var(--panel);
}

.field select option {
  background-color: var(--panel);
  color: var(--text);
}

.field textarea,
textarea.input {
  min-height: 5rem;
  resize: vertical;
  line-height: 1.45;
}

.field input::placeholder,
.field textarea::placeholder,
.input::placeholder {
  color: rgba(143, 144, 154, 0.7);
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.input:focus {
  outline: 0;
  border-color: var(--mode-line);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.55),
    0 0 0 3px var(--mode-faint);
}

.field input[type="checkbox"],
.field input[type="radio"] {
  width: auto;
  box-shadow: none;
  accent-color: var(--mode);
}

/* ---------------------------------------------------------- panels & cards */

/* A pane of smoked glass: a dark rim, a bright edge on the top face, a
   reflection over the upper part and a shadow that falls well below. The top
   border carries a trace of the page's colour. */
.panel,
.card {
  position: relative;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-top-color: var(--mode-line);
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.045) 0%,
      rgba(255, 255, 255, 0.015) 38%,
      rgba(255, 255, 255, 0) 38.5%),
    linear-gradient(180deg, #1d1e23 0%, #141518 100%);
  box-shadow: var(--shadow-panel);
}

.panel-title,
.card-title {
  margin: 0 0 0.6rem;
  color: var(--muted);
  font-size: var(--text-min);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* ------------------------------------------------------------------ tables */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-min);
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.48rem 0.6rem;
  border-bottom: 1px solid var(--grid);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: var(--text-min);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--mode) 6%, transparent);
}

.table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(11, 11, 13, 0.35);
}

/* ------------------------------------------------------------------- pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.16rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(143, 144, 154, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: var(--text-min);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.5;
  white-space: nowrap;
}

.pill-accent {
  border-color: var(--mode-line);
  background: var(--mode-faint);
  color: var(--accent);
}

.pill-ok {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(74, 222, 128, 0.12);
  color: #4ade80;
}

.pill-warn {
  border-color: rgba(245, 158, 11, 0.42);
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
}

.pill-danger {
  border-color: rgba(248, 113, 113, 0.42);
  background: rgba(248, 113, 113, 0.12);
  color: #f87171;
}

/* ------------------------------------------------------------------ modals */

/* The blur only runs while a modal is up, when no game is moving. */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 4, 6, 0.72);
  backdrop-filter: blur(7px);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(30rem, 100%);
  padding: 1.4rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top: 2px solid var(--mode);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.06) 0%,
      rgba(255, 255, 255, 0.02) 30%,
      rgba(255, 255, 255, 0) 30.5%),
    radial-gradient(80% 50% at 50% 0%, var(--mode-faint), transparent 70%),
    linear-gradient(180deg, #1c1d22, #101114);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 40px 90px -20px rgba(0, 0, 0, 0.9),
    0 30px 60px -30px var(--mode-glow);
  animation: modal-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}

.modal-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1rem;
}

@keyframes modal-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------------ motion */

/* Pages cross-fade into each other on navigation; the top bar stays put. */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.22s;
}

/* Content rises into place on load: --rise-i staggers siblings. */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.rise {
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
  animation-delay: calc(var(--rise-i, 0) * 70ms);
}

@media (prefers-reduced-motion: reduce) {
  .rise,
  .modal-card {
    animation: none;
  }

  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }

  .btn,
  .btn:hover {
    transition: none;
    transform: none;
  }
}

/* --------------------------------------------------------------- utilities */

.hidden {
  display: none !important;
}

/* A name with its own capitals (PvCPU) inside an all-caps label. */
.keep-case {
  text-transform: none !important;
}

/* Print: keep the dark UI legible on paper by flipping to ink-on-white. */
@media print {
  :root {
    color-scheme: light;
    --bg: #fff;
    --panel: #fff;
    --text: #151515;
    --muted: #545454;
    --accent: #0969a8;
    --line: rgba(21, 21, 21, 0.22);
    --grid: rgba(21, 21, 21, 0.1);
  }

  body {
    background: #fff;
  }

  body::before {
    display: none;
  }

  .panel,
  .card,
  .table,
  .modal-card {
    box-shadow: none;
    background: #fff;
  }

  a {
    color: inherit;
    text-decoration: underline;
  }
}
