/* paisho.org — design system, "Night Garden".
   Calm and flat, after Lichess: one quiet page colour, raised panels that differ from it by
   lightness alone (no borders, glows or gradients), small radii, light-weight numerals. Jade is
   the one action colour (buttons, links, focus, live dots); gold is for the brand and rank
   highlights only. Garden red/white belong to the board and tiles only — never to UI chrome.
   Dark by default, a light theme follows the system setting or the menu's manual toggle
   (`<html data-theme="dark|light">`). */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(../fonts/inter-latin-ext-wght-normal.woff2) format("woff2-variations"), url(../fonts/inter-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(../fonts/inter-latin-wght-normal.woff2) format("woff2-variations"), url(../fonts/inter-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #16191d;
  --surface: #20242a;
  --surface-2: #2a2f36;
  --surface-hover: #2f353d;
  --text: #e3e1dc;
  --muted: #959ba3;
  --accent: #3fbf8f;
  --accent-ink: #062016;
  --gold: #e3b04b;
  --danger: #d0615b;
  --garden-red: #b8453c;
  --garden-white: #efe9dc;

  /* the page: flat, with only a faint lift under the top bar */
  --glow: linear-gradient(180deg, #1b1f24 0, transparent 220px);

  --radius: 6px;
  --radius-lg: 8px;
  --gap: 12px;
  --tap: 44px;

  --hairline: rgba(255, 255, 255, 0.07);
  /* a panel sits on the page by a soft drop shadow, as Lichess's boxes do — never a border */
  --shadow-box: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
  --shadow-lift: 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-sheet: 0 -12px 32px rgba(0, 0, 0, 0.4);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-title: 1.75rem;
  --fs-body: 1rem;
  --fs-label: 0.8125rem;
}

/* The light theme, written twice: once for the system setting, once for the menu's toggle. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #edebe6;
    --surface: #ffffff;
    --surface-2: #f2f0eb;
    --surface-hover: #e9e6df;
    --text: #1d1f22;
    --muted: #5f6670;
    --accent: #1d855f;
    --accent-ink: #ffffff;
    --gold: #956610;
    --danger: #a93832;
    --glow: linear-gradient(180deg, #f5f3ef 0, transparent 220px);
    --hairline: rgba(0, 0, 0, 0.08);
    --shadow-box: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.05);
    --shadow-lift: 0 10px 24px rgba(0, 0, 0, 0.12);
    --shadow-sheet: 0 -12px 28px rgba(0, 0, 0, 0.16);
  }
}

:root[data-theme="light"] {
  --bg: #edebe6;
  --surface: #ffffff;
  --surface-2: #f2f0eb;
  --surface-hover: #e9e6df;
  --text: #1d1f22;
  --muted: #5f6670;
  --accent: #1d855f;
  --accent-ink: #ffffff;
  --gold: #956610;
  --danger: #a93832;
  --glow: linear-gradient(180deg, #f5f3ef 0, transparent 220px);
  --hairline: rgba(0, 0, 0, 0.08);
  --shadow-box: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.05);
  --shadow-lift: 0 10px 24px rgba(0, 0, 0, 0.12);
  --shadow-sheet: 0 -12px 28px rgba(0, 0, 0, 0.16);
}

* { box-sizing: border-box; }

/* `hidden` always hides. Without this, any class that sets `display` (.btn, .chip, .tag, ...)
   outranks the browser's own [hidden] rule, and a script's `el.hidden = true` does nothing: the
   tutorial's Next button and the signed-in player's guest-name chip both stayed on screen. */
[hidden] { display: none !important; }

/* No rubber-band bounce on a page that has nothing to scroll: Chrome and Brave on Windows (and
   macOS) bounce the page under a touchpad otherwise. Mouse and touchpad devices only, so phones
   keep pull-to-refresh (the game page turns that off for itself). */
@media (hover: hover) and (pointer: fine) {
  html { overscroll-behavior-y: none; }
}

body {
  background: var(--glow) no-repeat, var(--bg);
  color: var(--text);
  margin: 0;
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
body.page--game { background: var(--bg); }     /* the game page stays calm: no glow behind the board */

a { color: inherit; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 4px; }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

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

.num { font-variant-numeric: tabular-nums; }

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

/* ---------------------------------------------------------------- top bar
   Brand, the main nav (wide windows), the live stat pill (≥1100px), then the account slot,
   nickname chip and menu. One row, 56px, every item centred on the same line. */

/* The announcement bar above the top bar (maintenance, a coming restart). Hidden unless there is one. */
.announce {
  padding: 6px 16px;
  background: var(--gold);
  color: #16191d;
  font-size: var(--fs-label);
  font-weight: 600;
  text-align: center;
}
.announce[hidden] { display: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--gap);
  height: 56px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.2px;
}
.topbar__name b { color: var(--muted); font-weight: 400; }

.topbar__logo {
  width: 28px;
  height: 28px;
  display: block;
}

.topbar__grow { flex: 1 1 auto; min-width: 0; }

.topbar__stat {
  display: none;
  align-items: center;
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.topbar__stat b { color: var(--text); font-weight: 600; }
.live-pulse {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
@media (prefers-reduced-motion: no-preference) {
  .live-pulse { animation: live-pulse 2s ease-in-out infinite; }
}
@keyframes live-pulse { 50% { opacity: 0.35; } }
@media (min-width: 1100px) {
  .topbar__stat:not([hidden]) { display: inline-flex; }
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.topbar__right [data-account-slot]:empty { display: none; }
/* Sign in is a jade word, not a second filled button beside the nickname (Lichess's SIGN IN). */
.topbar .topbar__signin { min-height: 36px; padding: 0 12px; font-size: 14px; font-weight: 600; background: transparent; color: var(--accent); }
@media (hover: hover) and (pointer: fine) {
  .topbar .topbar__signin:hover { background: var(--surface-2); filter: none; }
}
/* The nickname / username in the bar is plain text that turns into a button under the pointer. */
.topbar__right .chip { min-height: 36px; background: transparent; color: var(--text); font-size: 14px; font-weight: 500; }
@media (hover: hover) and (pointer: fine) {
  .topbar__right .chip:hover { background: var(--surface-2); }
}

/* ------------------------------------------------------------------- chip */

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-label);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
@media (hover: hover) and (pointer: fine) {
  .chip:hover { color: var(--text); background: var(--surface-hover); }
}

.chip--level {
  padding: 0;
  width: var(--tap);
  font-size: 1rem;
}

.chip.is-selected {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface-2));
}

/* ----------------------------------------------------------------- button */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s ease, filter 0.15s ease, background-color 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--surface-hover); }
  .btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }


.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

/* A big action (the home page's Play a friend / Play MushiBot / Pass and play): a raised panel
   button with an icon on the left, as Lichess's "Create a game" column. */
.btn-big {
  justify-content: flex-start;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
  background: var(--surface);
  box-shadow: var(--shadow-box);
  font-weight: 500;
  font-size: 1rem;
}
.btn-big__icon {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (hover: hover) and (pointer: fine) {
  .btn-big:hover { background: var(--surface-hover); }
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn-quiet {
  background: transparent;
  color: var(--muted);
}
@media (hover: hover) and (pointer: fine) {
  .btn-quiet:hover { background: var(--surface-2); filter: none; color: var(--text); }
}

/* ------------------------------------------------------------------- card
   The one surface for content: a flat raised panel (no border), a quiet sentence-case heading
   with an optional jade link on the right. */
.card {
  background: var(--surface);
  box-shadow: var(--shadow-box);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
}
.card__title {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
  font-weight: 500;
  color: var(--text);
}
.card__link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
  .card__link:hover { text-decoration: underline; }
}

.tag[hidden] { display: none; }
.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--gold) 15%, transparent);
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.3px;
  vertical-align: middle;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 96px;
  margin: 0;
  padding: 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}
.empty p { margin: 0; }
.empty a:not(.btn) { color: var(--accent); text-decoration: none; font-weight: 600; }

/* the hamburger menu trigger: its own shape, not a text button */
.menu-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  .menu-btn:hover { background: var(--surface-2); }
}
.menu-btn span {
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}

/* ------------------------------------------------------------------- tile */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--gap);
}

.tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-height: 110px;
  width: 100%;
  margin: 0;
  padding: 18px;
  border-radius: var(--radius);
  border: 0;
  background: var(--surface);
  box-shadow: var(--shadow-box);
  color: inherit;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .tile:hover { background: var(--surface-hover); }
}

.tile h3 {
  font-size: 1.1rem;
  font-weight: 650;
}

.tile--primary {
  position: relative;
  overflow: hidden;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* A very subtle garden-colour motif — a thin red/white sliver along the top
   edge of the primary tile. The only place garden colour touches the home
   page's chrome; everywhere else on this page stays jade + neutral. */
.tile--primary::after {
  content: '';
  position: absolute;
  top: 0;
  right: 18px;
  width: 56px;
  height: 4px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(to right, var(--garden-red) 50%, var(--garden-white) 50%);
  opacity: 0.75;
  pointer-events: none;
}

.tile-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
}

.tile-icon--pair {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 36px;
}
.tile-icon--pair img {
  position: absolute;
  top: 3px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  box-shadow: 0 0 0 2px var(--surface);
}
.tile-icon--pair img:first-child { left: 0; z-index: 1; }
.tile-icon--pair img:last-child { left: 16px; }

.tile-text {
  flex: 1 1 auto;
  min-width: 0;
}

.tile-sub { margin: 2px 0 0; }

/* ------------------------------------------------------------------ strip */

.strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
}

.strip__name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.strip__turn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.strip.is-turn .strip__turn-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Who a seat is: an account links to its profile, a guest is only typed text (italic, tagged),
   a bot is tagged. A guest called "MushiBot" must not look official. */
.strip__guest { font-style: italic; color: var(--muted); }
.strip__user { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
.strip__tag {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  color: var(--muted);
}

/* Clocks: display only (the server decides). Tabular figures so the digits don't jitter. */
.strip__clock {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 1.125rem;
  padding: 2px 10px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
}

.strip__clock.clock--running { color: var(--accent-ink); background: var(--accent); }

.strip__clock.clock--warn { color: color-mix(in srgb, var(--danger) 55%, var(--text)); }

.strip__clock.clock--low {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
}

.time-control { margin: 0 0 var(--gap); }

.time-control__label { display: block; font-size: var(--fs-label); margin-bottom: 4px; }

.time-control__note { margin: 6px 0 0; font-size: var(--fs-label); }

/* ------------------------------------------------------------------- menu */

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-list a, .menu-list button {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

/* `display: flex` above would otherwise outrank the UA `[hidden]` rule (Admin, Lab, sign in/out). */
.menu-list a[hidden], .menu-list button[hidden] { display: none; }

@media (hover: hover) and (pointer: fine) {
  .menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }
}

.menu-sep { height: 1px; background: var(--hairline); margin: 8px 4px; }

/* ------------------------------------------------------------------ sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-radius: 10px 10px 0 0;
  box-shadow: var(--shadow-sheet);
  transform: translateY(100%);
  transition: transform 0.22s ease;
}

.sheet-backdrop.is-open .sheet { transform: translateY(0); }

@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet {
    width: 440px;
    max-height: 85vh;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lift);
    transform: translateY(12px) scale(0.98);
  }
  .sheet-backdrop.is-open .sheet { transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .tile, .btn, .sheet, .sheet-backdrop { transition: none; }
}

/* ------------------------------------------------------------------ board */
/* Board-only colours: the two players' piece/harmony colour, distinct from
   --accent (which means "your turn" / primary action) and from the garden
   red/white that belong to the board's own diamond and gates. */
:root {
  --pb-p1: #5a9ad9;
  --pb-p2: #d9735a;
  --pb-tile-size: 52px;
  --last-move: #e3b93c;     /* the newest move's points, as Lichess's yellow squares */
}

.pb-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* Lichess-style two-column layout once there's room: the board stays the
   large, central element and both hands move into a side panel to its
   right (opponent's hand on top, yours on the bottom) instead of stacking
   above/below the board and eating into its own size budget. */
@media (min-width: 900px) {
  .pb-root {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    grid-template-areas: "board handtop" "board handbottom";
    align-items: start;
    gap: 16px;
  }
  .pb-wrap { grid-area: board; }
  .pb-hand[data-slot="top"] { grid-area: handtop; }
  .pb-hand[data-slot="bottom"] { grid-area: handbottom; }
}

.pb-hand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 720px;
}

.pb-hand-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

/* flex-basis + shrink (not a fixed width, and no flex-wrap) rather than a
   flat width: a narrower container - the Lab-card-padded tutorial board, or
   the ~240px desktop hand panel - shrinks all 6 tiles in the row together
   down to min-width, instead of wrapping one lone tile onto its own line. */
.pb-tile {
  position: relative;
  flex: 0 1 var(--pb-tile-size);
  min-width: 34px;
  aspect-ratio: 1 / 1;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
@media (hover: hover) and (pointer: fine) {
  .pb-tile:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.3);
  }
}
.pb-tile:active:not(:disabled) { transform: translateY(0); }
.pb-tile:disabled { opacity: 0.35; cursor: not-allowed; }
.pb-tile--empty { opacity: 0.3; }
.pb-tile--selected {
  box-shadow: 0 0 0 2px var(--accent), 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent);
}
/* The harmony/clash indicator: while a basic flower is selected (in a hand
   or on the board), its two Circle-of-Harmony neighbours get a solid green
   ring and its opposite (clashing) flower a dashed red ring - the same
   colour language the Learn page's own circle legend already uses for
   harmony vs. clash. Shown on both players' hands and on board tiles
   regardless of owner, since harmony/clash is about flower identity, not
   who played it. */
.pb-tile--harmony-hint, .pb-piece--harmony-hint {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pb-tile--clash-hint, .pb-piece--clash-hint {
  outline: 2px dashed var(--danger);
  outline-offset: 2px;
}
.pb-tile__img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; pointer-events: none; }
.pb-tile__count {
  position: absolute;
  bottom: -4px;
  right: -4px;
  min-width: 16px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  pointer-events: none;
}

.pb-wrap {
  position: relative;
  width: 100%;
  max-width: 820px;
  min-width: 320px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.pb-visuals {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 50%;
  /* Wood, the same two stops as miniboard.js's wood board, so the board in a game, a puzzle and
     every thumbnail is one object. A dark rim and a soft drop shadow set it on the table. */
  background: radial-gradient(circle at 50% 45%, #f1d9a6 0%, #cfa462 78%);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.3),
    0 2px 6px rgba(0, 0, 0, 0.2),
    inset 0 0 0 3px #4a2f18,
    inset 0 0 22px rgba(74, 47, 24, 0.35);
}

/* Board lines (drawn by board.js as an SVG in point coordinates): Pai Sho
   is played on the INTERSECTIONS, so every line passes through the centre of
   a cell — never along cell edges. Weighted enough to read as etched into
   the board, not a faint CSS overlay. */
.pb-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.pb-lines line {
  stroke: rgba(74, 47, 24, 0.38);
  stroke-width: 0.05;
  vector-effect: none;
}
.pb-lines .pb-line--axis { stroke: rgba(74, 47, 24, 0.55); stroke-width: 0.075; }

.pb-diamond {
  position: absolute;
  left: calc(100% * 2.5 / 19);
  top: calc(100% * 2.5 / 19);
  width: calc(100% * 14 / 19);
  height: calc(100% * 14 / 19);
  /* The vignette (transparent centre, darkened rim) is blended `multiply`
     over the flat red/white quadrants - it reads as a lit surface with real
     depth without touching the quadrants' own hue, and without the glossy
     skeuomorphic highlight a lighten-blend would give. */
  background:
    radial-gradient(circle at 50% 50%, transparent 55%, rgba(74, 47, 24, 0.22) 100%),
    conic-gradient(
      var(--garden-red) 0deg 90deg,
      var(--garden-white) 90deg 180deg,
      var(--garden-red) 180deg 270deg,
      var(--garden-white) 270deg 360deg
    );
  background-blend-mode: multiply, normal;
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.pb-gate { position: absolute; background: var(--garden-red); opacity: 0.85; }
.pb-gate--n { top: 0; left: calc(100% * 7 / 19); width: calc(100% * 5 / 19); height: calc(100% * 2.5 / 19); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.pb-gate--s { bottom: 0; left: calc(100% * 7 / 19); width: calc(100% * 5 / 19); height: calc(100% * 2.5 / 19); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.pb-gate--w { left: 0; top: calc(100% * 7 / 19); width: calc(100% * 2.5 / 19); height: calc(100% * 5 / 19); clip-path: polygon(0 0, 100% 50%, 0 100%); }
.pb-gate--e { right: 0; top: calc(100% * 7 / 19); width: calc(100% * 2.5 / 19); height: calc(100% * 5 / 19); clip-path: polygon(100% 0, 100% 100%, 0 50%); }

.pb-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(19, 1fr);
  grid-template-rows: repeat(19, 1fr);
}

/* The role="row" wrappers the grid needs for ARIA: they generate no box, so each cell is still a
   grid item of .pb-grid and keeps its inline grid-row / grid-column. */
.pb-row {
  display: contents;
}

.pb-cell {
  position: relative;
  cursor: pointer;
}

/* The intersection marker: present on every one of the 249 valid spaces
   regardless of whether a tile occupies it (a tile's .pb-piece-slot renders
   on top of it). Subtle on purpose — it's a point on the board, not a UI
   affordance competing with hint dots or tiles. */
.pb-point {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16%;
  height: 16%;
  min-width: 3px;
  min-height: 3px;
  margin: -8% 0 0 -8%;
  border-radius: 50%;
  background: transparent;   /* intersections are marked by the crossing lines, as on a real board */
  pointer-events: none;
}

.pb-piece-slot {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pb-cell--hint::after {
  content: '';
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  border: 2px solid var(--accent);
  pointer-events: none;
  transition: background 0.12s ease, transform 0.12s ease;
  animation: pb-hint-enter 0.15s ease-out;
}
/* A legal-move dot grows slightly under the pointer - the one place on the
   board (besides a piece itself) that responds to hover, since every one of
   the 249 points is clickable but only hinted ones are a legal move right
   now. */
@media (hover: hover) and (pointer: fine) {
  .pb-cell--hint:hover::after {
    background: color-mix(in srgb, var(--accent) 42%, transparent);
    transform: scale(1.15);
  }
}

.pb-piece {
  width: 94%;
  height: 94%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, filter 0.12s ease;
}
@media (hover: hover) and (pointer: fine) {
  .pb-piece:hover { transform: scale(1.06); filter: brightness(1.15); }
}
.pb-piece--p1 { border: 2px solid var(--pb-p1); background: color-mix(in srgb, var(--pb-p1) 30%, var(--surface)); }
.pb-piece--p2 { border: 2px solid var(--pb-p2); background: color-mix(in srgb, var(--pb-p2) 30%, var(--surface)); }
.pb-piece--growing { opacity: 0.7; border-style: dashed; }
.pb-piece--selected { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.pb-piece__img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; pointer-events: none; }

/* A tile fades and scales up into place the moment it's actually new (see
   board.js's prevTileKeys) - redraws of a tile already there (a selection
   change, a poll tick) never replay this, so the board doesn't flicker. */
.pb-piece--enter { animation: pb-piece-enter 0.22s ease-out; }
@keyframes pb-piece-enter {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
/* The newest move: both of its points are tinted (a plant has only the landing point), under the
   piece. The piece itself slides in from where it came from (board.js sets --dx/--dy in cells),
   and a captured piece fades out beneath it. */
.pb-cell--last-from::before, .pb-cell--last-to::before {
  content: '';
  position: absolute;
  inset: 2%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--last-move) 32%, transparent);
  pointer-events: none;
}
.pb-cell--last-to::before { background: color-mix(in srgb, var(--last-move) 52%, transparent); }
.pb-piece--slide { position: relative; z-index: 6; animation: pb-piece-slide 0.18s ease-out; }
@keyframes pb-piece-slide {
  from { transform: translate(calc(var(--dx) * 106.4%), calc(var(--dy) * 106.4%)); }
  to { transform: none; }
}
.pb-piece--ghost { position: absolute; z-index: 1; pointer-events: none; animation: pb-piece-capture 0.2s ease-out forwards; }
@keyframes pb-piece-capture {
  from { opacity: 0.9; transform: scale(1); }
  to { opacity: 0; transform: scale(0.5); }
}
@keyframes pb-hint-enter {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .pb-piece--enter, .pb-piece--slide, .pb-cell--hint::after { animation: none; }
  .pb-piece--ghost { display: none; }
  .pb-piece, .pb-tile, .pb-cell--hint::after { transition: none; }
}

.pb-harmony { position: absolute; inset: 0; pointer-events: none; }
.pb-harmony-line--p1, .pb-harmony-line--p2 {
  stroke-width: 0.12;
  stroke-dasharray: 0.3 0.22;
  stroke-linecap: round;
  opacity: 0.8;
}
.pb-harmony-line--p1 { stroke: var(--pb-p1); }
.pb-harmony-line--p2 { stroke: var(--pb-p2); }
.pb-harmony-line--win { stroke-dasharray: none; stroke-width: 0.16; opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  .pb-harmony-line--p1, .pb-harmony-line--p2 { animation: pb-flow 4s linear infinite; }
  @keyframes pb-flow { to { stroke-dashoffset: -1; } }
}

/* -------------------------------------------------------------- game page */

/* ------------------------------------------------------------- game page
   One grid. The board is the page: its cell is a size container, so the board is the largest
   square that fits (100cqmin) with no JavaScript measuring. Phones stack bars around it and
   never scroll; wide screens (and landscape phones) put everything else in a right-hand panel.
   Hands are filled by board.js into #game-hand-top / #game-hand-bottom. */

body.page--game { --topbar-h: 48px; overscroll-behavior: none; }
body.page--game .page { max-width: none; padding: 0; }
body.page--game .topbar {
  position: static;
  height: var(--topbar-h);
  padding: 0 12px;
}
@media (max-width: 1099px) {
  body.page--game .topbar__nav, body.page--game .topbar__stat { display: none; }
}

.game {
  --gutter: 12px;
  display: grid;
  /* Pinned to the edges of the visible window (not 100vh/100dvh, which some mobile browsers get
     wrong while their toolbar is showing): the action bar can never be pushed below the fold. */
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto auto auto auto;
  grid-template-areas: "meta" "moves" "topstrip" "tophand" "board" "botstrip" "bothand" "hint" "actions";
  gap: 4px;
  padding: 0 0 max(6px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.game__meta { grid-area: meta; display: flex; gap: 8px; justify-content: center; align-items: center; margin: 0 var(--gutter); }
.game__meta:empty, .game__meta:not(:has(:not([hidden]))) { display: none; }
#game-top-strip { grid-area: topstrip; }
#game-hand-top { grid-area: tophand; }
.game__board { grid-area: board; container-type: size; min-height: 0; display: grid; place-items: center; }
#game-bottom-strip { grid-area: botstrip; }
#game-hand-bottom { grid-area: bothand; }
.game__hint { grid-area: hint; }
.game__actions { grid-area: actions; }
.game__moves { grid-area: moves; display: flex; align-items: center; gap: 6px; min-width: 0; margin-inline: var(--gutter); }
.game__moves:has(#game-move-list:empty) { display: none; }
.game > .strip, .game__hand, .game__hint, .game__actions { margin-inline: var(--gutter); }

.game__board .pb-root {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: none;
  place-items: center;
  width: 100%;
  height: 100%;
  gap: 0;
}
.game__board .pb-wrap {
  grid-area: auto;
  width: calc(100cqmin * var(--board-fit, 1));
  height: calc(100cqmin * var(--board-fit, 1));
  min-width: 0;
  max-width: none;
  margin: 0;
  aspect-ratio: auto;
}
#board-resize { display: none; }

.game__badge {
  padding: 2px 10px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-label);
  font-weight: 600;
}

/* Hands, compact (phones): yours is one row of six 44px+ tiles (accents and specials appear only
   on a bonus turn, when they can be played); the opponent's is a thin row of counts. */
.game__hand { display: flex; flex-direction: column; gap: 4px; width: auto; max-width: none; }
.game__hand .pb-hand-row { gap: 6px; justify-content: space-between; }
.game__hand .pb-tile { flex: 1 1 0; min-width: 44px; max-width: 56px; }
/* The accent/special row is always laid out (dimmed and disabled until a bonus turn), so earning a
   harmony never changes the height of the page: the board stays exactly where it was. */
.game__hand .pb-hand-row--other .pb-tile { max-width: 44px; }
#game-hand-bottom:not([data-bonus]) .pb-hand-row--other .pb-tile { opacity: 0.3; }
#game-hand-top .pb-hand-row { justify-content: center; }
#game-hand-top .pb-tile { flex: 0 0 28px; min-width: 0; max-width: none; pointer-events: none; }
#game-hand-top .pb-hand-row--other { display: none; }
#game-hand-top .pb-tile__count { bottom: -3px; right: -3px; min-width: 14px; font-size: 0.6rem; line-height: 14px; }
.game--watching #game-hand-bottom .pb-tile { flex: 0 0 28px; min-width: 0; max-width: none; pointer-events: none; }
.game--watching #game-hand-bottom .pb-hand-row { justify-content: center; }
.game--watching #game-hand-bottom .pb-hand-row--other { display: none; }

.game__hint {
  text-align: center;
  min-height: 22px;
  margin-block: 0;
  font-size: var(--fs-label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game__actions { display: flex; flex-wrap: nowrap; gap: 8px; justify-content: center; position: relative; }
.say-pop {
  position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  padding: 8px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-box);
}
.say-pop .chip { min-height: 36px; }
.chip--quiet { color: var(--muted); background: transparent; }
.game__said { list-style: none; margin: 0; padding: 0; font-size: var(--fs-label); color: var(--muted); text-align: center; }
.game__said[hidden] { display: none; }
.game__actions .btn {
  flex: 1 1 0;
  min-width: 0;
  max-width: 200px;
  padding: 0 8px;
  font-size: 0.85rem;
  white-space: nowrap;      /* one line: a wrapped label would take board height */
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 430px) { .game__actions .btn { font-size: 0.8rem; padding: 0 4px; } }

/* Strips are bars: name on the left, a big clock on the right. */
.game > .strip { padding: 2px 12px; min-height: 44px; }
.game > .strip .strip__clock { font-size: 1.5rem; padding: 2px 12px; }

@media (max-width: 899px) and (orientation: portrait) {
  /* The slim game header: the global top bar keeps only the logo and the menu. */
  body.page--game .topbar__name,
  body.page--game .topbar [data-nickname-chip],
  body.page--game .topbar [data-account-slot] { display: none; }
}

/* Roomy hands once there is a side panel and the window is tall enough for them. */
@media (min-width: 900px) and (min-height: 600px) {
  .game__hand .pb-tile { flex: 0 1 var(--pb-tile-size); min-width: 40px; max-width: none; }
  .game__hand .pb-hand-row { justify-content: center; }
  #game-hand-bottom:not([data-bonus]) .pb-hand-row--other { display: flex; }
  #game-hand-top .pb-tile { flex: 0 1 var(--pb-tile-size); pointer-events: none; opacity: 0.8; }
  #game-hand-top .pb-hand-row--other { display: flex; }
  #game-hand-top .pb-tile:disabled { opacity: 0.55; }
  .game--watching #game-hand-bottom .pb-tile { flex: 0 1 var(--pb-tile-size); }
  .game--watching #game-hand-bottom .pb-hand-row--other { display: flex; }
}

/* Wide window (or a landscape phone): board on the left at full height, everything else in a
   right-hand panel. */
@media (min-width: 900px), (orientation: landscape) and (max-height: 500px) {
  .game {
    --panel-w: 320px;
    --col-gap: 24px;
    --avail-h: calc(100dvh - var(--topbar-h) - 24px);
    position: static;
    inset: auto;
    height: var(--avail-h);
    margin: 12px auto;
    padding: 0;
    overflow: visible;
    justify-content: center;
    column-gap: var(--col-gap);
    grid-template-columns: min(var(--avail-h), calc(100vw - var(--panel-w) - 3 * var(--col-gap))) var(--panel-w);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto auto auto;
    grid-template-areas:
      "board meta" "board tophand" "board topstrip" "board moves"
      "board botstrip" "board bothand" "board hint" "board actions";
  }
  .game > .strip, .game__hand, .game__hint, .game__actions, .game__meta { margin-inline: 0; }
  /* The opponent's bar, the move list and your bar are one panel: no gaps, square inner corners. */
  .game { row-gap: 0; }
  .game__meta:not(:empty) { margin-bottom: 10px; }
  #game-hand-top { margin-bottom: 10px; }
  #game-hand-bottom { margin-top: 10px; }
  .game__hint { margin-top: 10px; }
  .game__actions { margin-top: 6px; }
  .game > #game-top-strip { border-radius: var(--radius) var(--radius) 0 0; }
  .game > #game-bottom-strip { border-radius: 0 0 var(--radius) var(--radius); }
  .game__moves { background: var(--surface); border-block: 1px solid var(--hairline); }
  #board-resize {
    display: block;
    position: absolute;
    right: 0;
    bottom: 0;
    width: 22px;
    height: 22px;
    cursor: nwse-resize;
    touch-action: none;
    background: linear-gradient(135deg, transparent 0 55%, var(--muted) 55% 62%, transparent 62% 72%, var(--muted) 72% 79%, transparent 79%);
    opacity: 0.6;
  }
  #board-resize:hover { opacity: 1; }
  .game__moves { display: flex; flex-direction: column; align-items: stretch; gap: 0; min-height: 0; width: auto; max-width: none; margin: 0; }
  .game__moves:has(#game-move-list:empty) { display: flex; }
  .game .mv-nav { display: flex; align-items: stretch; border-bottom: 1px solid var(--hairline); }
  .game .mv-nav button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 36px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
  }
  .game .mv-nav button:not(:disabled):hover { background: var(--surface-hover); color: var(--text); }
  .game .mv-nav button:disabled { opacity: 0.35; cursor: default; }
  .game .mv-nav .mv-download { align-self: center; }
  .game #game-move-list { flex: 1 1 auto; min-height: 0; flex-direction: column; align-items: stretch; gap: 0; overflow-x: hidden; overflow-y: auto; white-space: normal; padding: 0; }
  .game #game-move-list:empty::before { content: "No moves yet"; padding: 14px; color: var(--muted); font-size: var(--fs-label); text-align: center; }
  .game .mv-row { display: grid; grid-template-columns: 2.6em minmax(0, 1fr) minmax(0, 1fr); align-items: stretch; }
  .game .mv-no { align-self: stretch; padding: 6px 0 0; text-align: center; background: var(--surface-2); }
  .game .mv-turn { flex-direction: column; align-items: stretch; gap: 0; }
  .game .mv-cell { text-align: left; }
  .game .mv-bonus { padding-left: 16px; font-size: 0.75rem; }
  .game .mv-live { align-self: flex-start; }
  .game__hint { white-space: normal; text-align: left; min-height: 20px; }
  .game__actions { flex-wrap: wrap; justify-content: flex-start; gap: 6px; }
  .game__actions .btn { flex: 1 1 auto; max-width: none; min-height: 38px; padding: 0 12px; }
  .game__meta { justify-content: flex-start; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .game__moves, .game__moves:has(#game-move-list:empty) { display: none; }   /* no room: the panel is only strips, hand and actions */
}
@media (min-width: 900px) and (min-height: 600px) {
  .game > .strip { min-height: 52px; }
  .game > .strip .strip__clock { font-size: 2rem; }
}

/* The move list. Phone: one horizontal strip of PSN tokens above the opponent's bar, newest at the
   right; wide: a table of turns (Guest | Host) filling the side panel. */
.mv-nav { display: none; }
.mv-live {
  flex: none;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 4px;
  border: 0;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font: inherit;
  font-size: var(--fs-label);
  font-weight: 700;
  cursor: pointer;
}
#game-move-list {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 2px 0;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}
#game-move-list::-webkit-scrollbar { display: none; }
.mv-row { display: contents; }
.mv-no { flex: none; color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; padding-left: 4px; }
.mv-turn { display: inline-flex; flex: none; align-items: center; gap: 2px; }
.mv-cell {
  min-height: 28px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: 0.8125rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  cursor: pointer;
}
.mv-turn.is-p1 .mv-cell { border-left-color: var(--pb-p1); }
.mv-turn.is-p2 .mv-cell { border-left-color: var(--pb-p2); }
.mv-bonus { color: var(--muted); }
.mv-cell[aria-current="true"] {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--text);
  font-weight: 600;
}
.mv-download { font-size: var(--fs-label); font-weight: 600; text-decoration: none; padding: 4px 8px; color: var(--accent); }
.shortcut-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  font: 0.8125rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
}
.pb-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 50%; }

.game__expired { max-width: 420px; margin: 40px auto; text-align: center; }

.game__sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }

.game__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
  font-size: var(--fs-label);
  color: var(--muted);
}
.game__field input {
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

/* -------------------------------------------------------------- home page */

.bot-level-line {
  margin: 8px 0 0;
  font-size: var(--fs-label);
}

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }

.qm-seeks {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.qm-seek-item {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 0 10px;
  border-radius: var(--radius);
  border: 0;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-label);
  text-align: left;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  .qm-seek-item:hover { background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); }
}


.qr-wrap { margin: 14px 0; display: flex; justify-content: center; }
.qr-wrap svg { width: 180px; height: 180px; background: #fff; border-radius: 8px; padding: 8px; }

.custom-accents {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 14px 0;
}

.custom-accent-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0;
  font-size: var(--fs-label);
  color: var(--muted);
}

.custom-accent-field input {
  width: 56px;
  min-height: var(--tap);
  padding: 0 8px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}


@media (max-width: 480px) {
  .custom-accents { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ learn */

.learn { padding: 16px 0 40px; display: flex; flex-direction: column; gap: 4px; }
.learn h1 { font-size: 2rem; font-weight: 300; letter-spacing: -0.01em; }
.learn > p.muted { margin: 0 0 20px; }

.learn-tutorial {
  background: var(--surface);
  box-shadow: var(--shadow-box);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 32px;
}
.learn-tutorial__head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); flex-wrap: wrap; }
.learn-tutorial__head h2 { font-size: 1.15rem; margin: 0; }

.learn-dots { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.learn-dots li {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
}
.learn-tutorial__head h2 { font-weight: 500; }
.learn-dots li.is-current { background: var(--accent); border-color: var(--accent); }
.learn-dots li.is-done { background: var(--accent); border-color: var(--accent); opacity: 0.55; }

#tutorial-intro { margin-top: 12px; }
#tutorial-intro p { margin: 0 0 12px; }

.learn-step { margin-top: 12px; }
.learn-step h3 { font-size: 1.05rem; }
#tutorial-step-text { margin: 4px 0 14px; }

/* .learn-step-brief (title+text) and .learn-step-outcome (feedback+actions)
   wrap the board's usual neighbours without moving them: `display: contents`
   makes each wrapper invisible to layout, so the step still reads title,
   text, board, feedback, actions top to bottom exactly as before. Only at
   the panel breakpoint below do they become real boxes, for the desktop
   side-by-side layout. */
.learn-step-brief, .learn-step-outcome { display: contents; }

/* PC: the words sit in a panel beside the board instead of above it, so
   reading the instructions, making the move, and seeing the feedback/Next
   button no longer requires scrolling the board in and out of view (the
   complaint this fixes). */
@media (min-width: 900px) {
  /* :not([hidden]) matters: an ID selector's `display: grid` would otherwise
     outrank the UA stylesheet's `[hidden] { display: none }` (author rules
     always beat UA ones), showing the step while tutorial.js has it hidden.
     The board mount and board.js's .pb-root are `display: contents`, so the board and the two
     hands are items of this grid: the board fills the left column, and the right-hand panel
     reads instructions, the opponent's hand, feedback, then your hand at the bottom, by your
     side of the board (as Lichess's puzzle panel). */
  #tutorial-step:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, min(760px, calc(100dvh - 190px))) 300px;
    grid-template-rows: auto auto 1fr auto;
    justify-content: center;
    column-gap: 32px;
    align-items: start;
  }
  #tutorial-board, #tutorial-board .pb-root { display: contents; }
  .learn-step-brief, .learn-step-outcome { display: block; }
  .learn-step-brief { grid-column: 2; grid-row: 1; }
  #tutorial-step .pb-wrap { grid-area: 1 / 1 / -1 / 2; width: 100%; max-width: none; }
  #tutorial-step .pb-hand[data-slot="top"] { grid-area: 2 / 2; margin-top: 16px; }
  .learn-step-outcome { grid-column: 2; grid-row: 3; }
  #tutorial-step .pb-hand[data-slot="bottom"] { grid-area: 4 / 2; align-self: end; }
  #tutorial-step .learn-feedback, #tutorial-step .learn-step-actions { text-align: left; justify-content: flex-start; }
}

.learn-feedback { min-height: 22px; margin: 10px 0 0; font-weight: 600; text-align: center; }
.learn-feedback.is-success { color: var(--accent); }
.learn-feedback.is-error { color: var(--danger); }

.learn-step-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }

.learn-rules { max-width: 760px; }
.learn-rules h2 {
  font-size: 1.3rem;
  font-weight: 500;
  margin-top: 32px;
  padding-top: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hairline);
  scroll-margin-top: 70px;
}
.learn-rules h2:first-child { margin-top: 0; }
.learn-rules h3 { font-size: 1rem; margin-top: 18px; scroll-margin-top: 70px; }
.learn-rules p, .learn-rules li { line-height: 1.6; }
.learn-rules ul, .learn-rules ol { padding-left: 22px; }

.learn-hl { color: var(--accent); }
.learn-clash { color: var(--danger); }

.learn-circle {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 16px 0 24px;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-box);
  border-radius: var(--radius);
}
.learn-circle svg { max-width: 420px; width: 100%; height: auto; }

.learn-legend { display: flex; gap: 22px; margin-top: 10px; font-size: var(--fs-label); color: var(--muted); flex-wrap: wrap; justify-content: center; }
.learn-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.learn-legend__swatch { display: inline-block; width: 22px; height: 3px; border-radius: 2px; }
.learn-legend__swatch--harmony { background: var(--accent); }
.learn-legend__swatch--clash { background: transparent; border-top: 2px dashed var(--danger); height: 0; }

.learn-table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; font-size: 0.92rem; }
.learn-table th, .learn-table td { padding: 7px 10px; border-bottom: 1px solid var(--hairline); text-align: left; }
.learn-table th { background: var(--surface-2); font-weight: 600; }
.learn-table tr:last-child td { border-bottom: none; }

.learn-tip {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin: 20px 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.92rem;
}

.learn-credit { margin-top: 24px; }
.learn-credit a { text-decoration: underline; }

/* ---------------------------------------------------------------- bots page */

.bots { padding: 16px 0 40px; }
.bots h1 { font-size: 2rem; font-weight: 300; letter-spacing: -0.01em; }
.bots > p.muted { margin: 0 0 20px; max-width: 60ch; }

.bots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--gap);
}

.bot-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-box);
}

.bot-card__head { display: flex; align-items: center; gap: 12px; }

.bot-card__level {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}

.bot-card__head h3 { font-size: 1.05rem; }

.bot-card__personality { margin: 0; line-height: 1.5; min-height: 2.6em; }

/* A six-segment meter, filled to the level's rung — a legitimate sequence
   device since the levels really are an ascending ladder (see RATINGS in
   bots.js), not decoration bolted onto arbitrary content. */
.bot-meter { display: flex; gap: 4px; }
.bot-meter__seg {
  flex: 1 1 0;
  height: 4px;
  border-radius: 2px;
  background: var(--hairline);
}
.bot-meter__seg.is-filled { background: var(--accent); }

.bot-card__foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.bot-card__rating { font-size: var(--fs-label); }

/* ----------------------------------------------------------- developers page */

.dev { padding: 16px 0 40px; max-width: 640px; }
.dev h1 { font-size: 2rem; font-weight: 300; letter-spacing: -0.01em; margin-bottom: 14px; }
.dev p { line-height: 1.6; }
.dev p a { text-decoration: underline; }

.dev-code {
  margin: 18px 0;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  overflow-x: auto;
  font: 0.85rem/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

/* -------------------------------------------------------------------- lab gate */

.lab-gate {
  max-width: 420px;
  margin: 40px auto;
  text-align: center;
}
.lab-gate h2 { font-size: 1.15rem; }
.lab-gate .game__field { text-align: left; margin: 16px 0 10px; }
.lab-gate .btn { width: 100%; }

/* ------------------------------------------------------------------ ratings */

.rated-toggle { margin-top: 6px; }

.rated-tag, .rated-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
}

.game__rated { display: flex; align-items: center; gap: 8px; font-size: var(--fs-label); }

.rated-detail { font-variant-numeric: tabular-nums; font-weight: 600; }

.strip__rating { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }

.rated-toggle[hidden], .game__rated[hidden] { display: none; }

/* First-move countdown, and "opponent left" with the Claim victory button. */
.game__alert { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; font-size: var(--fs-label); font-variant-numeric: tabular-nums; }
.game__alert[hidden] { display: none; }
.game__alert .btn { padding: 4px 12px; }

/* ------------------------------------------------------------------ touch
   Hover effects are wrapped in (hover: hover) and (pointer: fine) above, so a tap never leaves a
   lifted or brightened piece behind. Buttons and the board take taps without the double-tap
   zoom delay; the game board and hands never start a scroll or a text/image selection, because
   a finger on a piece is a drag (board.js). */
html { -webkit-tap-highlight-color: transparent; }
.btn, .chip, .pb-tile, .pb-cell, .pb-piece { touch-action: manipulation; }
body.page--game .pb-wrap, body.page--game .pb-tile, body.page--game .pb-piece { touch-action: none; }
.pb-wrap, .pb-hand, .pb-tile, .pb-piece {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.pb-tile__img, .pb-piece__img { -webkit-user-drag: none; user-drag: none; }
.pb-tile:active:not(:disabled), .pb-piece:active { transform: scale(0.96); }

/* Drag and drop (board.js): a ghost follows the pointer, the real piece dims, the point under
   the pointer lights up when it is a legal target. */
.pb-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  border-radius: 50%;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
  opacity: 0.92;
}
.pb-ghost img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.pb-piece--dragging { opacity: 0.3; }
.pb-cell--drop::after { transform: scale(1.3); background: color-mix(in srgb, var(--accent) 50%, transparent); }

/* ------------------------------------------------------------------- home
   A three-column dashboard at ≥1200px (puzzle, players, learn | play, open games, live | TV,
   news), two columns at 900–1199px (the left column becomes a row of three under the play
   column), one column below 900px in a fixed card order. Every gutter is 18px; each card
   reserves its loaded height, so data arriving never moves the page. */

body.page--home .page { max-width: none; padding: 0; }

.home {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 16px;
}
.home__col { display: contents; }
.home-play { order: 1; min-width: 0; }
.home-card--seeks { order: 2; }
.home-card--live { order: 3; }
.home-card--tv { order: 4; }
.home-card--puzzle { order: 5; }
.home-card--players { order: 6; }
.home-card--learn { order: 7; }
.home-card--news { order: 8; }

@media (min-width: 900px) {
  .home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas: "center right" "left right";
    align-items: start;
    padding: 20px;
  }
  .home__col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
  .home__col--left { grid-area: left; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
  .home__col--center { grid-area: center; }
  .home__col--right { grid-area: right; }
}
@media (min-width: 1200px) {
  .home {
    grid-template-columns: 260px minmax(0, 1fr) 320px;
    grid-template-areas: "left center right";
  }
  .home__col--left { display: flex; align-items: stretch; }
}

.home-card { min-width: 0; }
.home-card__body { min-width: 0; }

/* quick pairing */
.home-play__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-height: var(--tap);
  margin-bottom: 10px;
}
.home-play__head .card__title { font-size: 15px; }
@media (hover: hover) and (pointer: fine) {
  .home-play__head .chip { min-height: 32px; }
}

.pairing-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .pairing-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.pair-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 92px;
  min-width: 0;
  padding: 8px;
  border-radius: var(--radius);
  border: 0;
  background: var(--surface);
  box-shadow: var(--shadow-box);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease, color 0.15s ease;
}
.pair-tile { position: relative; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.pair-tile__count { position: absolute; top: 6px; right: 8px; font-style: normal; font-size: 12px; color: var(--muted); }
.pair-tile--dim { opacity: 0.45; }
.pair-tile--seeking { box-shadow: var(--shadow-box), inset 0 -2px 0 var(--accent); }
.pair-tile--seeking span { visibility: hidden; position: relative; }
.pair-tile--seeking span::after {
  visibility: visible; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  content: 'Searching\2026  \2715'; white-space: nowrap; color: var(--accent);
}
.pair-tile--seeking b { animation: pair-pulse 1.4s ease-in-out infinite; }
@keyframes pair-pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .pair-tile--seeking b { animation: none; } }
.pair-fallback { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-box); }
.pair-fallback p { margin: 0 0 8px; }
.pair-fallback__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bot-split { display: flex; gap: 6px; min-width: 0; }
.bot-split #bot-open-btn { flex: 1 1 auto; min-width: 0; }
.bot-split__gear { flex: 0 0 auto; padding-inline: 12px; }
.pair-tile b { font-size: 34px; line-height: 1.15; font-weight: 300; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.pair-tile span { color: var(--muted); font-size: 17px; font-weight: 300; }
.pair-tile--custom b { font-size: 26px; }
/* the untimed tile: where most games start, marked by a jade underline, not a glow */
.pair-tile--hot { box-shadow: var(--shadow-box), inset 0 -2px 0 var(--accent); }
.pair-tile:active { transform: scale(0.97); }
@media (min-width: 900px) {
  .pair-tile { aspect-ratio: 1.45; min-height: 0; }
}
@media (max-width: 559px) {
  /* a phone: the grid and the first button share the first screen */
  .home { gap: 14px; padding-top: 12px; }
  .pair-tile { min-height: 76px; }
  .pair-tile b { font-size: 24px; }
  .pair-tile span { font-size: 13px; }
  .pair-tile--custom b { font-size: 20px; }
}
@media (hover: hover) and (pointer: fine) {
  .pair-tile:hover { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
  .pair-tile:hover b { color: var(--accent); }
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.home-actions .btn { min-width: 0; }
@media (max-width: 559px) {
  .home-actions { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .home-actions #pass-tile {
    justify-content: center;
    min-height: var(--tap);
    background: transparent;
    box-shadow: none;
    color: var(--muted);
  }
  .home-actions #pass-tile .btn-big__icon { display: none; }
}

/* open games */
.home .qm-seeks { margin: 0; }
.home .qm-seek-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  font-size: 0.9rem;
}
.qm-empty { margin: 0; font-size: 0.9rem; }
.qm-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.qm-tc { font-variant-numeric: tabular-nums; }
.rated-toggle .chip.is-blocked { opacity: 0.55; }

/* live now: a strip of mini boards on a phone (two to a screen, scrolling sideways), a row of
   three (900–1199px) or four (≥1200px) on wider windows */
.live-grid {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x proximity;
  min-height: 120px;
}
.live-grid > .live-card { flex: 0 0 calc(50% - 6px); max-width: 190px; scroll-snap-align: start; }
.live-grid > .empty { flex: 1 1 auto; grid-column: 1 / -1; }
@media (min-width: 900px) {
  .live-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; padding: 0; }
  .live-grid > .live-card { max-width: none; }
  .live-grid > .live-card:nth-child(n + 4) { display: none; }
}
@media (min-width: 1200px) {
  .live-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .live-grid > .live-card:nth-child(n + 4) { display: flex; }
}
.live-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: inherit;
  text-decoration: none;
  font-size: 12px;
  transition: background-color 0.15s ease;
}
.live-card__names { display: flex; flex-direction: column; gap: 2px; font-weight: 600; font-size: 0.8rem; min-width: 0; }
.live-card__who { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; }
.live-card__who > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; }
.live-dot--p1 { background: var(--pb-p1); }
.live-dot--p2 { background: var(--pb-p2); }
.live-card__moves { font-size: 0.75rem; font-variant-numeric: tabular-nums; }
@media (hover: hover) and (pointer: fine) {
  .live-card:hover { background: var(--surface-hover); }
}

/* mini boards (miniboard.js) */
.mini-board { width: 100%; aspect-ratio: 1; display: block; }
.mini-bg:not(.mini-bg--wood) { fill: var(--surface-2); stroke: var(--hairline); stroke-width: 0.2; }
.mini-bg--wood { stroke: #3b2513; stroke-width: 0.4; }
.mini-red { fill: var(--garden-red); opacity: 0.85; }
.mini-white { fill: var(--garden-white); }
.mini-board--tiles .mini-red { fill: #c0584a; opacity: 0.9; }
.mini-board--tiles .mini-white { fill: #f6efe0; opacity: 0.9; }
.mini-gate { fill: var(--garden-red); opacity: 0.85; }
.mini-grid { fill: none; stroke: rgba(59, 37, 19, 0.2); stroke-width: 0.04; }
.mini-p1, .mini-p2 { stroke: var(--surface); stroke-width: 0.18; }
.mini-p1 { fill: var(--pb-p1); }
.mini-p2 { fill: var(--pb-p2); }
.mini-growing { fill-opacity: 0.55; stroke: currentColor; stroke-width: 0.14; stroke-dasharray: 0.3 0.25; }
.mini-p1.mini-ring, .mini-p2.mini-ring { fill: rgba(0, 0, 0, 0.18); stroke-width: 0.12; }
.mini-p1.mini-ring { stroke: var(--pb-p1); }
.mini-p2.mini-ring { stroke: var(--pb-p2); }
.mini-tile--growing { opacity: 0.7; }

/* Paisho TV */
.home-tv { min-width: 0; }
.home-tv:empty::before { content: ""; display: block; aspect-ratio: 1; margin: 38px 0; }   /* the board's room */
.tv-game { display: flex; flex-direction: column; gap: 6px; color: inherit; text-decoration: none; }
.tv-board { display: block; width: 100%; aspect-ratio: 1; }
.tv-board .mini-board { width: 100%; height: 100%; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35)); }
.tv-player { display: flex; align-items: center; gap: 8px; min-height: 32px; min-width: 0; font-size: 13px; font-weight: 600; }
.tv-player__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-player__meta {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}
.tv-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.tv-empty .tv-board { opacity: 0.85; margin-top: 4px; }
.tv-empty p { margin: 0; }
.tag--live { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .tag--live { animation: live-pulse 2s ease-in-out infinite; }
}
@media (min-width: 560px) and (max-width: 899px) {
  .home-tv { max-width: 420px; margin: 0 auto; width: 100%; }
}

/* puzzle of the day */
.home-puzzle { min-height: 96px; }
.home-puzzle__link { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.home-puzzle__board { flex: 0 0 96px; width: 96px; height: 96px; }
.home-puzzle__text { display: flex; flex-direction: column; gap: 3px; min-width: 0; font-size: 13px; line-height: 1.4; color: var(--muted); }
.home-puzzle__text strong { color: var(--text); font-size: 15px; }

/* top players */
.home-tabs { gap: 4px; margin-bottom: 6px; }
.home-tabs { flex-wrap: nowrap; gap: 2px; }
.home-tabs .chip { min-height: 28px; min-width: 0; padding: 0 8px; font-size: 12px; background: transparent; }
.home-tabs .chip.is-selected { background: color-mix(in srgb, var(--accent) 16%, transparent); }
@media (pointer: coarse) { .home-tabs .chip { min-height: 36px; } }
.home-players { min-height: 180px; }
.home-players .empty { min-height: 180px; }
.lb-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb-table th {
  padding: 6px 0;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--hairline);
}
.lb-table td { padding: 7px 0; border-bottom: 1px solid var(--hairline); height: 36px; }
.lb-table tr:last-child td { border-bottom: 0; }
.lb-table .num, .lb-rating, .lb-games { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lb-games { padding-right: 16px !important; }
.lb-rating { color: var(--muted); }
.lb-rank { width: 28px; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-rank--top { color: var(--gold); }
.lb-name { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-name a { color: var(--text); text-decoration: none; }
@media (hover: hover) and (pointer: fine) {
  .lb-name a:hover { text-decoration: underline; }
}

/* learn and news */
.home-rows { list-style: none; margin: 0; padding: 0; }
.home-rows a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 6px 0;
  border-bottom: 1px solid var(--hairline);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.home-rows li:last-child a { border-bottom: 0; }
.home-rows img { flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%; }
.home-rows span { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.news-item { display: block; padding: 8px 0; border-bottom: 1px solid var(--hairline); color: inherit; text-decoration: none; }
.news-item:last-child { border-bottom: 0; padding-bottom: 0; }
.news-item b { font-size: 14px; }
.news-item p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
@media (hover: hover) and (pointer: fine) {
  .home-rows a:hover, .news-item:hover b { color: var(--accent); }
}

.home-footer {
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 16px 14px;
  text-align: center;
  font-size: var(--fs-label);
}
.home-footer p { margin: 0; }
.home-footer a { text-decoration: none; color: var(--muted); }
@media (hover: hover) and (pointer: fine) {
  .home-footer a:hover { color: var(--accent); }
}

/* the empty-board strip under an empty live list, and the puzzle trainer's counter */
.live-empty { min-height: 112px; }
.learn-dots--count li {
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: var(--fs-label);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.learn-tutorial__head h1 { margin: 0; font-size: 1.4rem; }

/* The puzzle trainer (/puzzles): a wider page, and on a wide window the board is as large as the
   window's height allows (capped at the board's own 820px), with the hands beside it as on /learn.
   The tracks are minmax(0, …), so a narrower window shrinks the board instead of overflowing. */
body.page--trainer .page { max-width: 1400px; }
.trainer { padding: 12px 0 16px; }
.trainer .learn-tutorial { margin-bottom: 0; }
@media (min-width: 900px) {
  .trainer #tutorial-step:not([hidden]) { grid-template-columns: minmax(0, min(820px, calc(100dvh - 180px))) 320px; }
  .trainer #tutorial-step-title { font-size: 1.35rem; font-weight: 500; }
  .trainer #tutorial-step-text { font-size: 1.05rem; }
}
.trainer .learn-tutorial__head h1 { font-size: 1.5rem; font-weight: 300; }

/* ------------------------------------------------------- watch, leaderboard
   A page is one raised panel (Lichess's "box"): a light-weight title with its controls on the
   same line, then the content. An empty page says so in the middle of a panel of real height. */

.page-box {
  margin: 20px 0 40px;
  padding: 24px 32px 32px;
  background: var(--surface);
  box-shadow: var(--shadow-box);
  border-radius: var(--radius);
}
.page-box__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 0 0 18px;
}
.page-box__head h1 { margin: 0; font-size: 2rem; font-weight: 300; letter-spacing: -0.01em; }
.page-box__head p { margin: 0; }
.page-box__lead { margin: -8px 0 16px; font-size: 0.9rem; }
.empty--page { min-height: 280px; font-size: 1rem; }
@media (max-width: 559px) {
  .page-box { margin: 0 -16px; padding: 16px; border-radius: 0; box-shadow: none; }
  .page-box__head h1 { font-size: 1.6rem; }
}

.narrow-page { max-width: 900px; margin-inline: auto; }
.lb-tabs .chip { min-height: 34px; }
.lb-body { min-height: 120px; }
.lb-body .empty { min-height: 240px; }
.lb-more { margin: 10px 0 0; }
.watch-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .watch-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 900px) { .watch-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .watch-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.watch-grid > .empty { grid-column: 1 / -1; }
.watch-grid .live-card { padding: 10px; font-size: 13px; }
.watch-grid > .empty { min-height: 280px; }
.watch-grid .live-card__names { font-size: 0.9rem; }

/* ----------------------------------------------------------- top-bar nav
   A real navigation bar on wide windows; the hamburger menu keeps the same links everywhere. */
.topbar__nav { display: none; align-items: center; gap: 2px; margin-left: 8px; }
.topbar__nav a {
  position: relative;
  padding: 8px 11px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.topbar__nav a[aria-current="page"] { color: var(--text); }
.topbar__nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 11px;
  right: 11px;
  bottom: -11px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
@media (hover: hover) and (pointer: fine) {
  .topbar__nav a:hover { color: var(--text); }
}
@media (min-width: 900px) {
  .topbar__nav { display: flex; }     /* the menu button stays: it holds the theme, sound and sign-out entries */
}
@media (min-width: 900px) and (max-width: 1023px) {
  .topbar__nav a { padding: 8px 8px; letter-spacing: 0.3px; }
}
body[data-chrome="lab"] .topbar__nav { display: none; }
@media (max-width: 559px) {
  .topbar__name { display: none; }
}
@media (max-width: 480px) {
  .topbar__right .chip { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  [data-account-slot] > button { display: none; }      /* "Sign in" moves into the menu */
}

/* ------------------------------------------------------- profile and account */

.profile, .account { max-width: 720px; margin: 0 auto; padding: 24px 0 32px; }
.profile h2 { font-size: 1.1rem; margin: 24px 0 10px; }
.profile__head { display: flex; align-items: center; gap: 16px; }
.profile__head h1 { margin: 0; font-size: 2rem; font-weight: 300; }
.profile__head p { margin: 2px 0 0; }
.profile__avatar {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 22%, var(--surface-2));
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 1.8rem;
  font-weight: 700;
}

/* One card per rating category, the number first. A trailing "?" marks a provisional rating. */
.profile-ratings {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 560px) { .profile-ratings { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.rating-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-box);
}
.rating-cat { color: var(--muted); font-size: var(--fs-label); text-transform: capitalize; }
.rating-num { font-size: 1.9rem; font-weight: 300; font-variant-numeric: tabular-nums; line-height: 1.1; }

.profile-games { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--hairline); }
.profile-games li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 8em;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--hairline);
}
.pg-opp { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.pg-mode { font-size: var(--fs-label); text-transform: capitalize; }
.pg-result { justify-self: end; white-space: nowrap; font-weight: 700; font-size: var(--fs-label); text-transform: uppercase; letter-spacing: 0.04em; }
.pg-result--win { color: var(--accent); }
.pg-result--loss { color: var(--danger); }
.pg-result--draw, .pg-result--in-progress { color: var(--muted); }
@media (hover: hover) and (pointer: fine) {
  .profile-games li:hover { background: var(--surface-2); }
}

.account h1 { font-size: 2rem; font-weight: 300; margin-bottom: 6px; }
.account .menu-list { max-width: 360px; margin-top: 14px; }
.account-error {
  padding: 10px 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}
.account-form { display: flex; gap: 8px; max-width: 420px; margin-top: 14px; }
.account-form input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;            /* iOS zooms into smaller inputs */
}
.account-form input:invalid:not(:placeholder-shown), .account-form input:user-invalid { border-color: var(--danger); }
.account-msg { min-height: 1.4em; margin-top: 8px; }

/* ------------------------------------------------ connection pill, in-app note */
.conn-pill {
  grid-area: board;
  align-self: start;
  justify-self: center;
  z-index: 20;
  margin-top: 6px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-label);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}
.conn-pill[hidden] { display: none; }
/* Three bars: how fast the server answers (research 026). Sits in the board's top-right corner. */
.signal { grid-area: board; align-self: start; justify-self: end; z-index: 15; margin: 6px 8px 0 0; display: inline-flex;
  align-items: flex-end; gap: 2px; height: 14px; }
.signal[hidden] { display: none; }
.signal i { display: block; width: 3px; background: var(--muted); opacity: 0.35; border-radius: 1px; }
.signal i:nth-child(1) { height: 5px; } .signal i:nth-child(2) { height: 9px; } .signal i:nth-child(3) { height: 13px; }
.signal[data-bars="1"] i:nth-child(-n+1), .signal[data-bars="2"] i:nth-child(-n+2), .signal[data-bars="3"] i { opacity: 1; background: var(--accent); }
.signal[data-bars="1"] i:nth-child(1) { background: var(--danger); }
.inapp-note {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-size: var(--fs-label);
}

/* The owner-only console (/admin): phone first, existing tokens only. */
.con { max-width: 720px; margin: 0 auto; padding: 16px 16px 40px; overflow-wrap: anywhere; }
.con h1 { font-size: var(--fs-title); margin-bottom: 6px; }
.con h2 { font-size: 1.1rem; margin: 24px 0 10px; }
.admin-sub { font-size: var(--fs-label); color: var(--muted); text-transform: uppercase; margin: 14px 0 6px; }
.admin-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.admin-card h3 { font-size: var(--fs-body); margin: 0 0 4px; }
.admin-line { margin: 2px 0; font-size: var(--fs-label); }
.admin-plain { color: var(--text); }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.admin-input { width: 100%; max-width: 20rem; min-height: 36px; padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--border, #8884); background: var(--surface); color: var(--text); font: inherit; }
.admin-token { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: var(--fs-label); }
.admin-grow { flex: 1; min-width: 0; }
.admin-danger { color: var(--danger); }
.admin-audit { padding: 6px 0; border-bottom: 1px solid var(--hairline); font-size: var(--fs-label); }

/* admin console: one live setting */
.admin-setting { padding: 6px 0; border-top: 1px solid var(--hairline); }
.admin-setting input[type=number] { width: 8em; margin-right: 8px; }
.admin-source { margin-left: 8px; font-size: var(--fs-label); color: var(--muted); }
.admin-source--db { color: var(--gold); }

/* legal pages */
.legal { max-width: 46rem; padding: 16px 0 40px; line-height: 1.6; }
.legal h1 { font-size: 2rem; font-weight: 300; letter-spacing: -0.01em; }
.legal h2 { font-size: 1.1rem; font-weight: 500; margin: 1.6em 0 0.4em; }
.legal ul { padding-left: 1.2em; }
.legal-nav { margin-top: 2em; }
.legal-todo { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; padding: 0 4px; border-radius: 3px; }

.pair-error { margin: 8px 0 0; font-size: 14px; color: var(--danger, #d9534f); }
.puzzle-recent { margin-top: 20px; }
.puzzle-recent h3 { font-size: 1rem; font-weight: 500; margin: 0 0 6px; }
.puzzle-recent ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }

/* SEO text for the /pai-sho landing page (handbook 47) */
.about-pai-sho { max-width: 760px; margin: 0 auto; padding: 16px 0 40px; line-height: 1.65; }
.about-pai-sho h1 { font-size: 2rem; font-weight: 300; letter-spacing: -0.01em; margin: 0 0 8px; }
.about-pai-sho h2 { font-size: 1.3rem; font-weight: 400; margin: 28px 0 8px; }
.about-pai-sho dt { font-weight: 600; margin-top: 14px; }
.about-pai-sho dd { margin: 4px 0 0; color: var(--muted); }
.about-pai-sho a { color: var(--accent); }
.about-pai-sho .about-cta { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.about-pai-sho .about-note { font-size: 0.85rem; color: var(--muted); margin-top: 28px; }
