/* Board-games — design tokens & primitives
 * ---------------------------------------------------------------------------
 * The "renovation" system: a cool parchment + deep-emerald/ink, Material-3-
 * flavoured maison. Flat & squared (hairline-bordered surfaces, minimal shadow;
 * a big soft shadow only on the hero/board). Display = Libre Caslon Text,
 * body/UI = Inter, Korean = Noto Serif/Sans KR. See DESIGN.md.
 *
 * UI tokens adapt to light/dark. The game-state palette (--c0..--c3,
 * --board-navy, stones, …) is FIXED across themes — it encodes state, not
 * style, and mirrors each engine's COLORS.
 *
 * Re-skinning the whole site = editing the token VALUES below (+ shared
 * components for structure); zero edits inside any game's app.css.
 */

:root {
  /* Grounds & ink — parchment grounds, emerald-ink headings.
   * Default (no data-theme) tracks the light palette; the light/dark blocks
   * below own the real values, so a theme flip is one attribute. */
  --bg: #fdf9f2;
  --panel: #f7f3ec;
  --panel-2: #f1ede6;
  --panel-3: #ebe8e1;
  --well: #ffffff;
  --ink: #1c1c18;
  --ink-strong: #001610;    /* emerald-ink — headings, primary fills */
  --muted: #5e5e5b;
  --line: rgba(0,22,16,.10);
  --line-2: #c1c8c4;        /* stronger hairline — inputs, ghost buttons */
  --accent: #46645b;        /* emerald — eyebrows, focus, small marks */
  --accent-deep: #0d2c24;
  --accent-soft: rgba(70,100,91,.12);
  --live: #047857;          /* "live / active" green dot & pulse */
  --btn-bg: #001610;        /* primary button fill */
  --btn-fg: #ffffff;

  /* Game colors — fixed heritage jewel tones; identical to engine COLORS */
  --c0: #a8423a; /* madder red    */
  --c1: #2f5f77; /* petrol blue   */
  --c2: #cf9f4c; /* ochre amber   */
  --c3: #4f7a54; /* viridian      */

  /* ---- Shape: squared editorial surfaces. One scale the whole site draws
   * from — re-skinning "rounder / flatter" = edit these. This maison is flat:
   * ~2px on surfaces, 0 on buttons, a full pill only where a pill is meant. */
  --radius-xs: 2px;
  --radius-sm: 2px;
  --radius-md: 2px;
  --radius-lg: 2px;
  --radius-xl: 2px;
  --radius-2xl: 2px;
  --radius-pill: 9999px;
  --radius: 2px;            /* legacy default (Mosaic card / sheet) */
  --radius-tile: 0px;       /* mosaic tiles have hard edges */

  /* Named surface radii — components consume these, not raw px, so a theme
   * can restyle every card/button/modal at once. */
  --radius-card: 2px;
  --radius-btn: 0px;
  --radius-input: 2px;
  --radius-modal: 2px;
  --radius-chip: 2px;

  /* ---- Space: a step scale for structural padding/gaps ---------------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 10px;
  --space-4: 12px;
  --space-5: 14px;
  --space-6: 16px;
  --space-7: 18px;
  --space-8: 22px;

  /* Flat by default; a real float only on the hero/board. */
  --shadow: 0 1px 2px rgba(0,22,16,.04);
  --shadow-float: 0 26px 60px -24px rgba(0,22,16,.5);
  --shadow-lg: var(--shadow-float);

  /* ---- Type: label / eyebrow sizing (shared by every game's eyebrows) - */
  --fs-eyebrow: .72rem;
  --tracking-eyebrow: .18em;

  --font-serif: 'Libre Caslon Text', 'Hahmlet', 'Noto Serif KR', Georgia, 'Times New Roman', ui-serif, serif;
  --font-sans: 'Inter', 'Noto Sans KR', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* ======================================================================
   * Game-state palette — FIXED across light/dark (encodes state, not style)
   * ----------------------------------------------------------------------
   * These live only in :root (never overridden in the light/dark blocks) so
   * a piece color means the same thing in every theme. A future maison that
   * WANTS to re-skin the boards can override them in its theme block; by
   * default they hold today's hand-picked values. Keep in sync with each
   * engine's COLORS. */
  --scrim: rgba(20,17,12,.5);   /* modal/overlay backdrop — a warm dim, both themes */
  --turn: #ff3b3b;              /* active-turn cue — thin red (Mosaic / Running Mate) */
  --turn-bright: #ff5a5a;       /* the brighter half of the neon-pulse */
  --ink-on-accent: #26221c;     /* dark text on a brass fill — stays dark in both themes */

  --board-navy: #22364c;        /* Three-Story board disc (framed art) */
  --mesh: rgba(255,255,255,.22);      /* board lattice lines */
  --mesh-soft: rgba(255,255,255,.06); /* board hover wash */
  --mesh-strong: rgba(255,255,255,.34);/* board centre dots */
  --under: rgba(0,0,0,.32);           /* buried-stack shadow */
  --gold: #c9a24b;              /* Three-Story ring / hints */
  --gold-bright: #e7c56a;       /* selected stone / pending ring */
  --stone-dark: #1c1a17;        /* dark stone */
  --stone-light: #f4ece0;       /* light stone */
}

/* Light + dark packs. Values live here (and in the data-theme blocks); a
 * localStorage['theme'] flip on <html data-theme> re-colors the whole site. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12140f; --panel: #1a1d15; --panel-2: #1f231a; --panel-3: #262b20; --well: #0e100b;
    --ink: #f4f0e9; --ink-strong: #eef3ec; --muted: #c8c6c2;
    --line: rgba(240,240,230,.12); --line-2: #3a3f38;
    --accent: #adcec1; --accent-deep: #c8eadd; --accent-soft: rgba(173,206,193,.14); --live: #6fd39f;
    --btn-bg: #adcec1; --btn-fg: #00201a;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    --shadow-float: 0 26px 60px -24px rgba(0,0,0,.6);
    --shadow-lg: var(--shadow-float);
  }
}
:root[data-theme="light"] {
  --bg: #fdf9f2; --panel: #f7f3ec; --panel-2: #f1ede6; --panel-3: #ebe8e1; --well: #ffffff;
  --ink: #1c1c18; --ink-strong: #001610; --muted: #5e5e5b;
  --line: rgba(0,22,16,.10); --line-2: #c1c8c4;
  --accent: #46645b; --accent-deep: #0d2c24; --accent-soft: rgba(70,100,91,.12); --live: #047857;
  --btn-bg: #001610; --btn-fg: #ffffff;
  --shadow: 0 1px 2px rgba(0,22,16,.04);
  --shadow-float: 0 26px 60px -24px rgba(0,22,16,.5);
  --shadow-lg: var(--shadow-float);
}
:root[data-theme="dark"] {
  --bg: #12140f; --panel: #1a1d15; --panel-2: #1f231a; --panel-3: #262b20; --well: #0e100b;
  --ink: #f4f0e9; --ink-strong: #eef3ec; --muted: #c8c6c2;
  --line: rgba(240,240,230,.12); --line-2: #3a3f38;
  --accent: #adcec1; --accent-deep: #c8eadd; --accent-soft: rgba(173,206,193,.14); --live: #6fd39f;
  --btn-bg: #adcec1; --btn-fg: #00201a;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  --shadow-float: 0 26px 60px -24px rgba(0,0,0,.6);
  --shadow-lg: var(--shadow-float);
}

/* ----- Base ----- */
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-sans); line-height: 1.5; -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ----- Type primitives ----- */
.serif { font-family: var(--font-serif); font-weight: 400; }
.eyebrow { font-family: var(--font-sans); font-size: var(--fs-eyebrow); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; }

/* ----- Surfaces — flat, hairline-bordered cards ----- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow); padding: 22px;
}

/* ----- Buttons — squared, editorial ----- */
.btn {
  font-family: var(--font-sans); font-size: .8rem; font-weight: 600; letter-spacing: .04em;
  border: 1px solid var(--line-2); background: transparent; color: var(--ink);
  border-radius: var(--radius-btn); padding: 11px 17px; min-height: 46px; cursor: pointer; white-space: nowrap;
  touch-action: manipulation; transition: transform .1s ease, border-color .2s ease, background .2s ease, color .2s ease;
}
.btn:hover { border-color: var(--accent); color: var(--ink-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--btn-bg); border-color: var(--btn-bg); color: var(--btn-fg); }
.btn.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: var(--btn-fg); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----- Lobby pre-game settings (shared across games) -----
 * The lobby doubles as the host-only settings screen: everyone watches the
 * same values; only the host gets the live <select>. */
.lobby-settings {
  display: flex; flex-direction: column; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--radius-card);
  background: var(--panel-2); padding: 12px 14px; margin: 4px 0;
}
.lobby-field {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.lobby-sel {
  font-family: var(--font-sans); font-size: .9rem; font-weight: 500; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius-input);
  padding: 9px 12px; min-height: 42px; min-width: 130px; cursor: pointer;
}
.lobby-sel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Back nav on a lobby/settings screen: quiet, aligned left, natural page nav. */
.backbtn {
  align-self: flex-start; font-family: var(--font-sans); font-size: .8rem; font-weight: 600;
  letter-spacing: .04em; color: var(--muted); background: transparent; border: 0;
  padding: 6px 4px; min-height: 40px; cursor: pointer;
}
.backbtn:hover { color: var(--accent); }
.backbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Tournament setup header on a mounted sub-game's lobby: names the game + its
 * place in the chain, in place of the casual room code. */
.kssetup { display: flex; flex-direction: column; gap: 4px; }
.kssetup-name { font-family: var(--font-serif); font-size: 1.5rem; line-height: 1.15; }

/* =========================================================================
 * Mosaic primitives
 * ========================================================================= */

.tile {
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 1px; background: var(--line); background: color-mix(in srgb, var(--line) 50%, transparent);
  width: var(--size, 76px); height: var(--size, 76px);
  border-radius: var(--radius-tile); overflow: hidden;
}
.tile > i { display: block; }

/* The board is framed like a piece of art: a matte mount, a hairline frame,
 * thin "grout" between tiles, and a soft cast shadow. */
.board {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  width: var(--board-size, min(430px, calc(100vw - 76px))); aspect-ratio: 1;
  background: var(--line); padding: 1px; border-radius: 2px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(0,0,0,.04);
}
.board-frame {
  display: inline-block; padding: 8px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 4px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.4);
}
/* Each cell is one 2×2 tile. A 1px gap (the cell's own ground shows through)
 * draws a hairline between the four quads, so the tile's 2×2 make-up reads
 * even when neighbouring quads share a colour. The quad hairline is a touch
 * fainter than the tile grout (the board's --line) so the tiles still read as
 * units, not one flat grid. Falls back to --line if color-mix is unsupported. */
.cell { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 1px; background: var(--line); background: color-mix(in srgb, var(--line) 50%, transparent); border-radius: 0; overflow: hidden; }
.cell.empty { background: rgba(120,110,90,.10); box-shadow: inset 0 1px 3px rgba(0,0,0,.08); }
.q { transition: opacity .28s ease, filter .28s ease; }

.board.highlighting .q { opacity: .13; filter: saturate(.4); }
.board.highlighting .q.hot { opacity: 1; filter: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.6); }
@media (prefers-color-scheme: dark) { .board.highlighting .q.hot { box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); } }

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