/* Shared styles for the landing page and every game page. */

/* ---- fonts ------------------------------------------------------------ */
/* Inter (SIL OFL, see fonts/LICENSE.txt), subset by
   .tools/scripts/subset_inter.py: weights 100-900 on one variable axis. */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/InterVariable.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/InterVariable-Italic.woff2") format("woff2");
}

/* ---- tokens ----------------------------------------------------------- */
/* Themes: dark by default, light when the system asks for it. The Theme
   setting overrides either by setting data-theme on <html> (theme.js). The
   light palette is listed twice, once per way of choosing it. */

:root {
  color-scheme: dark;
  --bg: #14161a;
  --bg-glow: #20242b;
  --panel: #1d2026;
  --panel-2: #23272f;
  --panel-hover: #2c313b;
  --seg-on: #3a404c;          /* the pressed segment of a segmented control */
  --text: #e8e6e0;
  --text-dim: #9aa0ab;
  --line: #343943;
  --line-strong: #4a505c;
  --accent: #ffd54f;
  --accent-ink: #14161a;      /* text on an accent fill */
  --accent-soft: rgba(255, 213, 79, 0.2);
  --stone-edge: rgba(255, 255, 255, 0.18);
  --board-filter: brightness(0.9);   /* tones down bright boards on dark pages */

  /* Radii: panels, controls and inset boxes, small tags. */
  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 4px;
  /* Spacing scale. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --gutter: clamp(8px, 2.2vw, 16px);
  --gap: clamp(10px, 2vh, 16px);
  --pad-top: max(clamp(12px, 2.5vw, 24px), env(safe-area-inset-top));
  --pad-bottom: clamp(16px, 4vw, 40px);
  --pad-left: max(var(--gutter), env(safe-area-inset-left));
  --pad-right: max(var(--gutter), env(safe-area-inset-right));
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f1ea;
    --bg-glow: #fbf9f4;
    --panel: #fffdf8;
    --panel-2: #f5f1e8;
    --panel-hover: #ebe5d7;
    --seg-on: #ffffff;
    --text: #222222;
    --text-dim: #6b665c;
    --line: #d8d2c4;
    --line-strong: #bfb6a2;
    --accent: #9a6200;
    --accent-ink: #ffffff;
    --accent-soft: rgba(154, 98, 0, 0.14);
    --stone-edge: rgba(0, 0, 0, 0.3);
    --board-filter: none;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f1ea;
  --bg-glow: #fbf9f4;
  --panel: #fffdf8;
  --panel-2: #f5f1e8;
  --panel-hover: #ebe5d7;
  --seg-on: #ffffff;
  --text: #222222;
  --text-dim: #6b665c;
  --line: #d8d2c4;
  --line-strong: #bfb6a2;
  --accent: #9a6200;
  --accent-ink: #ffffff;
  --accent-soft: rgba(154, 98, 0, 0.14);
  --stone-edge: rgba(0, 0, 0, 0.3);
  --board-filter: none;
}

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

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg-glow) 0%, var(--bg) 60%);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100svh;
  padding: var(--pad-top) var(--pad-right) var(--pad-bottom) var(--pad-left);
  -webkit-font-smoothing: antialiased;
  /* Fractional glyph positions. Without this, Chromium and Firefox on Linux
     snap each letter to a whole pixel, and Inter's even spacing turns
     uneven at text sizes (in "empty", e-m opens up and m-p closes). */
  text-rendering: geometricPrecision;
}

a { color: var(--accent); }

/* One focus ring for everything keyboard-reachable. */
:where(a, button, select, summary, input, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Section and card headings: the only small caps text. */
.eyebrow, .section > summary h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ---- buttons and form controls -------------------------------------- */

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--panel-hover); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:hover { background: var(--panel-2); }
select.btn { padding: 6px 10px; }

/* The move itself (Pass, Swap, Promote): filled with the accent. */
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent); filter: brightness(1.08); }

/* Segmented control: every choice in view, the chosen one pressed. */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.seg {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  padding: 5px 10px;
  border: 0;
  border-radius: calc(var(--radius-md) - 3px);
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg:hover:not(:disabled) { color: var(--text); background: var(--panel-hover); }
.seg[aria-pressed="true"] {
  background: var(--seg-on);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), inset 0 0 0 1px var(--line-strong);
}
.seg:disabled { opacity: 0.35; cursor: default; }
.seg:focus-visible { outline-offset: 0; }

/* ---- game page layout ------------------------------------------------ */
/* One column (narrow screens): head, board, then the gutter's cards, with
   the gutter's children flowing straight into the page. Two columns (see
   WIDE_QUERY in shell.js): the board on the left, a sticky gutter on the
   right that scrolls on its own. */

body.game {
  --gutter-w: clamp(260px, 30vw, 360px);
  --card-gap: var(--space-3);
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--card-gap);
  max-width: 720px;
  margin-inline: auto;
}
.board-col { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.gutter { display: contents; }
.page-head { order: -1; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
}

.page-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: 0 2px;
}
.page-head .back {
  font-size: 14px;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
}
.page-head .back:hover { color: var(--text); }
.page-head .title {
  margin: 0 0 0 auto;
  font-size: clamp(17px, 4.5vw, 24px);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-transform: uppercase;
}
.page-head .blurb { display: none; }

@media (orientation: landscape) and (min-width: 560px), (min-width: 1000px) {
  .page {
    display: grid;
    grid-template-columns: auto var(--gutter-w);
    justify-content: center;
    align-items: start;
    column-gap: var(--gap);
    max-width: none;
  }
  .gutter {
    display: flex;
    flex-direction: column;
    gap: var(--card-gap);
    position: sticky;
    top: var(--pad-top);
    max-height: calc(100vh - var(--pad-top) - var(--pad-bottom));
    max-height: calc(100dvh - var(--pad-top) - var(--pad-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px;            /* room for focus rings at the scroll edge */
    margin: -2px;
  }
  .page-head { flex-direction: column; align-items: flex-start; gap: var(--space-1); }
  .page-head .title { margin: 0; }
  .page-head .blurb { display: block; margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }
  .rules-blurb { display: none; }
}

/* Landscape phones are height-starved: trim the padding and the blurb
   (it is repeated at the top of Rules). */
@media (orientation: landscape) and (max-height: 500px) {
  body.game { --pad-top: 6px; --pad-bottom: 6px; --card-gap: var(--space-2); }
  .board-wrap { --wrap-pad: 6px; }
  .page-head { flex-direction: row; align-items: baseline; gap: var(--space-3); }
  .page-head .blurb { display: none; }
  .rules-blurb { display: block; }
}

/* The board: on a panel when it fills a rectangle, straight on the page
   otherwise (shell.js sets .frameless). */
.board-wrap {
  --wrap-pad: var(--space-3);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--wrap-pad);
  width: var(--board-w, min(100%, 720px));
  max-width: 100%;
}
.board-wrap.frameless {
  --wrap-pad: var(--space-1);
  background: none;
  border-color: transparent;
}
@media (max-width: 480px) {
  .board-wrap { --wrap-pad: var(--space-2); }
  .board-wrap.frameless { --wrap-pad: 2px; }
}
/* A Lichess-style chessboard (see render.js) stands flush, edge to edge
   with any hand panels above and below it. */
.board-wrap.frameless.lichess { --wrap-pad: 0px; }
svg.board { width: 100%; height: auto; display: block; }

/* Hands (pieces held to drop) above and below the board, as Lichess shows
   Crazyhouse pockets: one slot per piece a cell wide (shell.js sets
   --hand-cell), greyed out when none is held, with a count badge. */
.hand {
  display: flex;
  justify-content: center;
  width: var(--board-w, min(100%, 720px));
  max-width: 100%;
  padding: 3px var(--space-3);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.hand[hidden] { display: none; }
.hand-slot {
  position: relative;
  width: var(--hand-cell, 48px);
  height: var(--hand-cell, 48px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  font: inherit;
}
.hand-slot img { display: block; width: 100%; height: 100%; pointer-events: none; }
.hand-slot.empty img { opacity: 0.18; filter: grayscale(1); }
.hand-slot.droppable { cursor: pointer; }
.hand-slot.droppable:hover { background: var(--line); }
.hand-slot.selected { background: rgba(255, 213, 79, 0.25); box-shadow: inset 0 0 0 2px #ffd54f; }
.hand-slot:disabled { cursor: default; }
.hand-count {
  position: absolute;
  right: 0;
  bottom: 0;
  min-width: 1.4em;
  padding: 0 0.3em;
  border-radius: 4px;
  background: #d85000;
  color: #fff;
  font-size: max(11px, calc(var(--hand-cell, 48px) * 0.26));
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}
svg.board, .game-card svg { filter: var(--board-filter); }

.cell { cursor: pointer; transition: filter 0.12s ease; }
.cell:hover { filter: brightness(1.15); }
.board.locked .cell { cursor: default; }
.board.locked .cell:hover { filter: none; }

/* ---- turn card -------------------------------------------------------- */

.turn-card { display: flex; flex-direction: column; gap: var(--space-3); }

.players { display: flex; flex-direction: column; gap: 2px; margin: 0 calc(-1 * var(--space-2)); }
/* Both players at full strength; the one to move gets a tinted row with
   an accent bar. */
.player-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: var(--space-1) var(--space-2);
  border-left: 3px solid transparent;
  border-radius: var(--radius-md);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.player-row.active { background: var(--panel-2); border-left-color: var(--accent); }
.player-name { font-size: 15px; font-weight: 500; }
.player-row.active .player-name { font-weight: 700; }
.player-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 5px;
}
.player-score { margin-left: auto; display: flex; align-items: baseline; gap: var(--space-2); }
.score-main { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-sub { font-size: 12px; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

.turn-stone {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--stone-edge);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.35);
  flex: none;
}
.player-row.active .turn-stone {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), inset 0 -2px 3px rgba(0, 0, 0, 0.4);
}

/* AI "thinking" indicator: an ellipsis on the active player's row. */
.thinking { display: inline-flex; align-items: center; gap: 3px; }
.thinking span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text);
  opacity: 0.6;
  animation: think 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes think { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 0.9; } }
@media (prefers-reduced-motion: reduce) { .thinking span { animation: none; } }

.status {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-dim);
}
.status:empty { display: none; }
.status b { color: var(--text); font-weight: 600; }
.status .verdict { font-size: 18px; color: var(--text); }
.status .scoreline { font-size: 13px; margin-top: var(--space-1); }

.move-actions, .turn-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.move-actions:empty { display: none; }

/* While reviewing an earlier position: a neutral strip with an accent bar. */
.review {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin: 0 calc(-1 * var(--space-2));
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  font-size: 13px;
  color: var(--text-dim);
}
.review[hidden] { display: none; }
.review b { color: var(--text); font-weight: 600; }
.review-text { flex: 1 1 180px; }
.review .btn { padding: 5px 12px; }

/* ---- log -------------------------------------------------------------- */

.log-scroll {
  position: relative;
  max-height: min(240px, 30vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  padding: var(--space-1) 0;
}
.log-list { list-style: none; margin: 0; padding: 0; font-size: 13px; line-height: 1.4; }
.log-list li { display: flex; align-items: baseline; gap: 6px; padding: 1px var(--space-2); }
.log-list .turn-no {
  min-width: 2.2em;
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex: none;
}
.log-list .turn-stone { width: 10px; height: 10px; border-width: 1px; align-self: center; }
.log-list .plies { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-1); }
.log-list .sep { color: var(--text-dim); }
.log-list .ply {
  font: inherit;
  color: var(--text);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 var(--space-1);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.log-list .ply:hover { background: var(--panel-hover); }
.log-list .ply:focus-visible { outline-offset: -1px; }
.log-list .ply.current { border-color: var(--accent); background: var(--accent-soft); }
.log-list .ply.future { color: var(--text-dim); opacity: 0.6; }
.log-start .ply { color: var(--text-dim); }
.log-result { font-weight: 600; padding-left: calc(2.2em + 14px) !important; }

.log-nav { display: flex; gap: 6px; margin-top: var(--space-2); }
.log-nav .btn.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  min-width: 36px;
}
.log-nav svg.icon { width: 14px; height: 14px; fill: currentColor; }
.log-nav .copy-link { margin-left: auto; padding: 5px 12px; }

/* ---- sections --------------------------------------------------------- */

.section { padding: 0; }
.section > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  border-radius: var(--radius-lg);
  user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex: none;
}
.section[open] > summary::before { transform: rotate(45deg); }
.section > summary:hover h2 { color: var(--text); }
.section-body { padding: 0 var(--space-4) var(--space-3); }

/* Settings rows: sentence-case labels, the control on the right (wrapping
   under the label when the gutter is narrow). */
.option-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px var(--space-3);
  margin-bottom: 10px;
}
.option-row:last-child { margin-bottom: 0; }
.option-row .label { font-size: 14px; color: var(--text); }

.section-rules .section-body { font-size: 13px; line-height: 1.6; }
.section-rules p { margin: 0 0 10px; }
.section-rules p:last-child { margin-bottom: 0; }
.section-rules h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.rules-blurb { color: var(--text-dim); font-style: italic; }

/* ---- landing page ---------------------------------------------------- */

.landing {
  max-width: 960px;
  margin: 0 auto;
}
.landing header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
  margin: var(--space-3) 0 28px;
}
.landing h1 {
  margin: 0 0 6px;
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.landing header p { margin: 0; color: var(--text-dim); font-size: 15px; }
.landing .theme-row { display: flex; align-items: center; gap: var(--space-2); color: var(--text-dim); font-size: 13px; }
.game-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.game-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.game-card:hover { background: var(--panel-2); border-color: var(--line-strong); }
.game-card svg { width: 100%; aspect-ratio: 1; display: block; margin-bottom: var(--space-3); }
.game-card svg .cell { cursor: inherit; }
.game-card h2 { margin: 0 0 var(--space-1); font-size: 18px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.game-card .board-kind { font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.game-card p { margin: var(--space-2) 0 0; font-size: 14px; line-height: 1.5; color: var(--text-dim); }
.landing footer { margin-top: 32px; font-size: 13px; color: var(--text-dim); }
.game-card svg .cell:hover { filter: none; }

/* ---- chance devices (bags of marbles, dice) --------------------------- */

.chance {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.chance[hidden] { display: none; }
.bag {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px var(--space-3);
  max-width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 6px var(--space-3);
  font-size: 14px;
}
.bag.active { border-color: var(--accent); }
.bag-title { display: flex; align-items: center; gap: 6px; color: var(--text-dim); }
.bag-contents, .bag-drawn { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.bag-drawn { gap: 3px; padding-left: 10px; border-left: 1px solid var(--line); }
.bag-count { display: inline-flex; align-items: center; gap: var(--space-1); font-variant-numeric: tabular-nums; }
.bag-count.zero { opacity: 0.35; }
.bag-more { color: var(--text-dim); font-size: 12px; margin-right: 2px; }
.marble {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #0e0f13;
  box-shadow: inset -2px -3px 4px rgba(0, 0, 0, 0.25), inset 2px 2px 3px rgba(255, 255, 255, 0.35);
}
.marble.small { width: 11px; height: 11px; }
.marble.newest { width: 15px; height: 15px; outline: 2px solid var(--accent); outline-offset: 1px; }
.bag .turn-stone { width: 12px; height: 12px; }
.die {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #0e0f13;
  background: #f2f2f0;
  color: #0e0f13;
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.die.blank { color: #8a8d93; font-weight: 600; }
.dice-result { padding-left: 10px; border-left: 1px solid var(--line); font-variant-numeric: tabular-nums; }
