/* Layout: notebook graph-paper page; board left, game ledger right, stacks on phones. Single deliberate look (paper), both host themes. */
:root {
  --paper: #fbfaf4;
  --paper-2: #f1efe6;
  --ink: #23262d;
  --muted: #6a6f7a;
  --rule: #3d63d1;
  --grid: #a7adb6;
  --land: #c6c6c2;
  --land-dim: #e3e2dc;
  --edge: #d8d5ca;
  --p1: #d1443b; --p2: #2c6bd4; --p3: #239150; --p4: #8a46cc;
  --btn-hover: #3a3f49;
  --warn-bg: #fde7d9; --warn-edge: #f0b896;
  --hover-fill: rgba(61,99,209,.12);
  --tile: #ebe8dc;
  --crater: #8a8780; --crater-pit: #5f5c56;
  /* ---- UI style settings: change these (or override them in a theme block) ----
     Fonts: display = title and result heading; body = everything else; mono = scores, codes.
     Fonts load from Google Fonts in index.html; any installed font name works too. */
  --font-display: "Bagel Fat One", "Arial Black", Impact, sans-serif;
  --font-body: "Chivo", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Chivo Mono", ui-monospace, Menlo, Consolas, monospace;
  --font-size: 14px;            /* base text size */
  /* Lines and borders */
  --line-style: solid;          /* solid, dashed, dotted, double... for every box border */
  --border-thin: 1px;           /* board frame, chips, inventory tiles */
  --border: 1.5px;              /* buttons, inputs, cards, panels */
  --border-thick: 2px;          /* turn bar, result card */
  --rule-width: 2px;            /* line under the title */
  --log-bar: 3px;               /* bar beside each log line */
  /* Corners */
  --radius-sm: 4px;             /* board frame, item tiles */
  --radius: 6px;                /* buttons, inputs */
  --radius-md: 8px;             /* cards, panels, turn bar */
  --radius-lg: 12px;            /* result card */
  --radius-pill: 999px;         /* chips, Tuesday badge */
  /* Shadows */
  --shadow-card: 3px 3px 0;             /* current player's card: offset only, colored with that player's color */
  --shadow-pop: 6px 6px 0 var(--ink);    /* result card */
  color-scheme: light;
}
/* Dark mode: night-desk graph paper */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --paper: #17191e; --paper-2: #22252c; --ink: #e8e6dd; --muted: #9aa0ab;
  --rule: #7b9bf0; --grid: #3b4049; --land: #555a64; --land-dim: #2a2d34; --edge: #343841;
  --p1: #ff6b5e; --p2: #6aa5ff; --p3: #4fd17f; --p4: #c08bff;
  --btn-hover: #cfccc2; --warn-bg: #4a2a1c; --warn-edge: #8a4b2c; --hover-fill: rgba(123,155,240,.18); --tile: #cfccc1; --crater: #2b2c31; --crater-pit: #111215;
  color-scheme: dark;
} }
:root[data-theme="dark"] {
  --paper: #17191e; --paper-2: #22252c; --ink: #e8e6dd; --muted: #9aa0ab;
  --rule: #7b9bf0; --grid: #3b4049; --land: #555a64; --land-dim: #2a2d34; --edge: #343841;
  --p1: #ff6b5e; --p2: #6aa5ff; --p3: #4fd17f; --p4: #c08bff;
  --btn-hover: #cfccc2; --warn-bg: #4a2a1c; --warn-edge: #8a4b2c; --hover-fill: rgba(123,155,240,.18); --tile: #cfccc1; --crater: #2b2c31; --crater-pit: #111215;
  color-scheme: dark;
}
/* NES (8-bit): dark theme redone with the NES palette, a pixel font, white dialog boxes
   with square corners, and hard shadows. The board and icons switch to pixel art (see THEMES in main.js). */
:root[data-theme="nes"] {
  --paper: #000000; --paper-2: #1c1c1c; --ink: #fcfcfc; --muted: #bcbcbc;
  --rule: #f83800; --grid: #000000; --land: #7c7c7c; --land-dim: #3c3c3c; --edge: #fcfcfc;
  --p1: #f83800; --p2: #3cbcfc; --p3: #b8f818; --p4: #f878f8;
  --btn-hover: #f8b800; --warn-bg: #a81000; --warn-edge: #f83800; --hover-fill: rgba(252,252,252,.25);
  --tile: #fce0a8; --crater: #503000; --crater-pit: #000000;
  --font-display: "Press Start 2P", ui-monospace, monospace;
  --font-body: "Press Start 2P", ui-monospace, monospace;
  --font-mono: "Press Start 2P", ui-monospace, monospace;
  --font-size: 10px;
  --line-style: solid;
  --border-thin: 2px; --border: 3px; --border-thick: 4px; --rule-width: 4px; --log-bar: 4px;
  --radius-sm: 0; --radius: 0; --radius-md: 0; --radius-lg: 0; --radius-pill: 0;
  --shadow-card: 4px 4px 0; --shadow-pop: 6px 6px 0 #f83800;
  color-scheme: dark;
}
:root[data-theme="nes"] body { line-height: 1.9; }
:root[data-theme="nes"] h1 { font-size: clamp(20px, 4vw, 30px); letter-spacing: 0; }
:root[data-theme="nes"] img, :root[data-theme="nes"] #board { image-rendering: pixelated; }
:root[data-theme="nes"] .prompt { font-size: 11px; }
:root[data-theme="nes"] .result-title { font-size: 24px; line-height: 1.3; }
:root[data-theme="nes"] .player .score, :root[data-theme="nes"] .code { font-size: 16px; }
:root[data-theme="nes"] section h2, :root[data-theme="nes"] .result-kicker { font-size: 9px; color: var(--p3); }
:root[data-theme="nes"] .chip, :root[data-theme="nes"] .hint, :root[data-theme="nes"] .log, :root[data-theme="nes"] .legend, :root[data-theme="nes"] .chat-list { font-size: 9px; }
/* SNES (16-bit): blue-gradient menu windows with white rounded frames, a softer pixel font,
   lavender console buttons, and the four SNES controller button colors for the players. */
:root[data-theme="snes"] {
  --paper: #0c1030; --paper-2: #1a2268; --ink: #f4f4ff; --muted: #aab2e8;
  --rule: #e84848; --grid: #141c48; --land: #5868a0; --land-dim: #222c5c; --edge: #e8e8f8;
  --p1: #f05050; --p2: #f8d040; --p3: #48d068; --p4: #60a0ff;
  --btn-hover: #ddd6f6; --warn-bg: #7a2038; --warn-edge: #f05050; --hover-fill: rgba(248,248,255,.22);
  --tile: #d6cff2; --crater: #3e2c1e; --crater-pit: #0e0806;
  --panel: linear-gradient(180deg, #3a5ad0 0%, #2638a0 45%, #141c68 100%);
  --btn: #bab2dc; --btn-ink: #2a1f5c; --btn-edge: #5a4aa8;
  --font-display: "Pixelify Sans", "VT323", ui-monospace, monospace;
  --font-body: "Pixelify Sans", "VT323", ui-monospace, monospace;
  --font-mono: "Pixelify Sans", "VT323", ui-monospace, monospace;
  --font-size: 15px;
  --line-style: solid;
  --border-thin: 2px; --border: 3px; --border-thick: 3px; --rule-width: 4px; --log-bar: 3px;
  --radius-sm: 4px; --radius: 999px; --radius-md: 8px; --radius-lg: 10px; --radius-pill: 999px;
  --shadow-card: 0 0 0 3px; --shadow-pop: 0 0 0 4px #141c68, 0 8px 0 4px #000;
  color-scheme: dark;
}
:root[data-theme="snes"] body { background: radial-gradient(ellipse at 50% -20%, #22307a 0%, #0c1030 60%) fixed; }
:root[data-theme="snes"] h1 { font-weight: 700; letter-spacing: 1px; text-shadow: 3px 3px 0 #000; }
:root[data-theme="snes"] h1 span { color: var(--p2); }
:root[data-theme="snes"] img, :root[data-theme="snes"] #board { image-rendering: pixelated; }
:root[data-theme="snes"] .player, :root[data-theme="snes"] .online, :root[data-theme="snes"] .chat,
:root[data-theme="snes"] details, :root[data-theme="snes"] .result-card {
  background: var(--panel); border-color: var(--edge); box-shadow: inset 0 0 0 2px #0c1030, 0 3px 0 #000; text-shadow: 2px 2px 0 #0a0e2a;
}
:root[data-theme="snes"] .player.current { box-shadow: inset 0 0 0 2px #0c1030, 0 0 0 3px var(--pc); }
:root[data-theme="snes"] button { background: var(--btn); color: var(--btn-ink); border-color: var(--btn-edge); text-shadow: none; padding: 5px 14px; }
:root[data-theme="snes"] button:hover { background: var(--btn-hover); }
:root[data-theme="snes"] button.primary { background: var(--btn-edge); color: #fff; border-color: #2a1f5c; }
:root[data-theme="snes"] button.primary:hover { background: #6e5ec0; }
:root[data-theme="snes"] #gunBtn { border-color: var(--p1); }
:root[data-theme="snes"] #surrenderBtn.confirm { background: var(--p1); color: #fff; border-color: #7a2038; }
:root[data-theme="snes"] .form input[type=number], :root[data-theme="snes"] .form input[type=text], :root[data-theme="snes"] .form select,
:root[data-theme="snes"] .chat input, :root[data-theme="snes"] .join input, :root[data-theme="snes"] .theme-pick select, :root[data-theme="snes"] .share-link {
  background: #0c1030; color: var(--ink); border-color: var(--edge); border-radius: var(--radius-sm);
}
:root[data-theme="snes"] .chip { background: #0c1030; border-color: var(--muted); }
:root[data-theme="snes"] .chip.out { background: var(--ink); color: #0c1030; border-color: var(--ink); text-shadow: none; }
:root[data-theme="snes"] .chip.warn { background: var(--warn-bg); border-color: var(--warn-edge); }
:root[data-theme="snes"] .prompt { text-shadow: 2px 2px 0 rgba(0,0,0,.6); }
:root[data-theme="snes"] .prompt:not(.mine) { background: var(--panel); border-color: var(--turn); }
:root[data-theme="snes"] .board-wrap { border: var(--border) solid var(--edge); border-radius: var(--radius-md); box-shadow: 0 3px 0 #000; }
:root[data-theme="snes"] section h2, :root[data-theme="snes"] .result-kicker { color: var(--p2); }
:root[data-theme="snes"] .result-scores li { background: rgba(12,16,48,.6); }
[hidden] { display: none !important; }
html, body { background: var(--paper); color: var(--ink); }
body {
  font-family: var(--font-body); font-size: var(--font-size); line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 14px 28px;
}
header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; border-bottom: var(--rule-width) var(--line-style) var(--rule); padding-bottom: 8px; margin-bottom: 14px; }
h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(30px, 6vw, 44px); line-height: 1; margin: 0; letter-spacing: .5px; }
h1 span { color: var(--rule); }
.tag { color: var(--muted); }
.head-right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.theme-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.theme-pick select { font: inherit; padding: 3px 6px; border: var(--border) var(--line-style) var(--ink); border-radius: var(--radius); background: var(--paper); color: var(--ink); }
.tuesday { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; background: var(--ink); color: var(--paper); padding: 4px 10px; border-radius: var(--radius-pill); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.board-col { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.toolbar { display: flex; flex-wrap: nowrap; gap: 8px; align-items: center; }
.toolbar button { flex: none; white-space: nowrap; }
/* The turn bar keeps one fixed height (room for two lines) so the board never shifts. */
.prompt { box-sizing: border-box; height: calc(2.6em + 12px + 2 * var(--border-thick)); line-height: 1.3; overflow: hidden; }
.prompt > span, .prompt > .over { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-width: 0; }
.prompt > img { flex: none; }
/* Buttons sit in one row that never wraps; on a phone it goes under the turn bar and scrolls sideways if needed. */
.tools { display: flex; gap: 8px; flex: none; flex-wrap: nowrap; align-items: center; }
@media (max-width: 860px) {
  .toolbar { flex-wrap: wrap; }
  .toolbar .prompt { flex-basis: 100%; }
  .tools { width: 100%; overflow-x: auto; justify-content: flex-start; }
}
.prompt { flex: 1 1 260px; min-width: 0; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-md); border: var(--border-thick) var(--line-style) var(--turn, var(--edge)); background: color-mix(in srgb, var(--turn, transparent) 16%, var(--paper)); }
.prompt.mine { background: var(--turn); color: #fff; border-color: var(--turn); }
.prompt.mine img { background: #fff; border-radius: 50%; padding: 2px; }
.prompt .over { background: none; color: inherit; padding: 0; }
#gunBtn { border-color: var(--p1); }
#surrenderBtn.confirm { background: var(--p1); border-color: var(--p1); color: #fff; }
.chip.out { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.player.out { opacity: .6; }
.prompt canvas { flex: none; }
.board-wrap { overflow: auto; max-height: 78vh; border: var(--border-thin) var(--line-style) var(--edge); background: var(--paper); border-radius: var(--radius-sm); }
#board { display: block; cursor: pointer; touch-action: manipulation; }
button, select, input { font: inherit; color: var(--ink); }
button { background: var(--paper); border: var(--border) var(--line-style) var(--ink); border-radius: var(--radius); padding: 5px 11px; font-weight: 600; cursor: pointer; }
button:hover { background: var(--paper-2); }
button.primary { background: var(--ink); color: var(--paper); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary:hover { background: var(--btn-hover); }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: var(--border-thick) var(--line-style) var(--rule); outline-offset: 2px; }
aside { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
section h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 6px; font-weight: 800; }
.players { display: flex; flex-direction: column; gap: 6px; }
.player { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 8px 10px; border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius-md); background: var(--paper); }
.player.current { border-color: var(--pc, var(--ink)); box-shadow: var(--shadow-card) var(--pc, var(--ink)); }
.player .name { font-weight: 800; }
.player .score { font-family: var(--font-mono); font-size: 22px; font-variant-numeric: tabular-nums; }
.chips { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 4px; }
.inv { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 3px; }
.inv img { width: 24px; height: 24px; padding: 2px; border-radius: var(--radius-sm); background: var(--tile); border: var(--border-thin) var(--line-style) var(--edge); }
.inv img.used { filter: grayscale(1); opacity: .35; }
.inv img.waiting { opacity: .7; border: var(--border) dashed var(--muted); background: transparent; }
.chip { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; padding: 1px 7px 1px 3px; border-radius: var(--radius-pill); background: var(--paper-2); border: var(--border-thin) var(--line-style) var(--edge); }
.chip img { width: 16px; height: 16px; }
.chip.warn { background: var(--warn-bg); border-color: var(--warn-edge); }
.log { max-height: 200px; overflow: auto; font-size: 12.5px; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.log li { border-left: var(--log-bar) var(--line-style) var(--edge); padding-left: 7px; }
.legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 10px; font-size: 12.5px; }
.legend div { display: flex; gap: 6px; align-items: center; min-width: 0; }
.legend img { width: 20px; height: 20px; flex: none; }
details { border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius-md); padding: 8px 10px; background: var(--paper); }
summary { cursor: pointer; font-weight: 800; }
.form { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 10px; align-items: center; margin-top: 10px; }
.form input[type=number], .form input[type=text], .form select { box-sizing: border-box; width: 100%; padding: 4px 6px; border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius); background: var(--paper); }
.form .full { grid-column: 1 / 3; }
.hint { font-size: 12px; color: var(--muted); }
.ai-opts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.ai-opts label { display: inline-flex; align-items: center; gap: 4px; }
.row { display: flex; gap: 6px; }
.row input { flex: 1; min-width: 0; }
.online { display: flex; flex-direction: column; gap: 8px; border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius-md); padding: 10px; background: var(--paper); }
.online .row { align-items: center; }
.code { font-family: var(--font-mono); font-size: 26px; letter-spacing: .18em; font-variant-numeric: tabular-nums; }
.share-link { box-sizing: border-box; font-family: var(--font-mono); font-size: 12px; width: 100%; padding: 4px 6px; border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius); background: var(--paper-2); }
.join input { text-transform: uppercase; font-family: var(--font-mono); letter-spacing: .12em; padding: 4px 6px; border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius); background: var(--paper); }
.seat { font-size: 12px; color: var(--muted); }
.seat.you { color: var(--ink); font-weight: 800; }
.status { font-size: 12.5px; }
.status.err { color: var(--p1); }
.chat { display: flex; flex-direction: column; gap: 8px; border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius-md); padding: 10px; background: var(--paper); }
.chat-list { list-style: none; margin: 0; padding: 0; max-height: 240px; min-height: 80px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.chat-list li { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 6px; align-items: start; }
.chat-list li img { width: 18px; height: 18px; margin-top: 1px; }
.chat-who { font-weight: 800; margin-right: 4px; }
.chat-text { overflow-wrap: anywhere; }
.chat-time { color: var(--muted); font-size: 11px; margin-left: 4px; font-variant-numeric: tabular-nums; }
.chat-list li.chat-empty { display: block; color: var(--muted); font-size: 12.5px; }
.chat form { display: flex; gap: 6px; }
.chat input { flex: 1; min-width: 0; padding: 5px 7px; border: var(--border) var(--line-style) var(--edge); border-radius: var(--radius); background: var(--paper); }
.board-stage { position: relative; }
.result { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: color-mix(in srgb, var(--paper) 55%, transparent); border-radius: var(--radius-sm); }
.result-card { width: min(360px, 100%); background: var(--paper); border: var(--border-thick) var(--line-style) var(--ink); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.result-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 800; }
.result-title { font-family: var(--font-display); font-weight: 400; font-size: 40px; line-height: 1; margin: 0; text-wrap: balance; }
.result-title.win { color: var(--p3); }
.result-title.lose { color: var(--p1); }
.result-scores { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.result-scores li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: var(--radius); background: var(--paper-2); }
.result-scores li.top { outline: var(--border-thick) var(--line-style) var(--ink); }
.result-scores img { width: 22px; height: 22px; }
.result-scores .pts { font-family: var(--font-mono); font-size: 20px; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (prefers-reduced-motion: no-preference) { .result-card { animation: pop .35s cubic-bezier(.2,1.4,.4,1); } @keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } } }
.over { background: var(--ink); color: var(--paper); padding: 10px 12px; border-radius: var(--radius-md); font-weight: 800; }
@media (prefers-reduced-motion: no-preference) { .player { transition: box-shadow .15s, border-color .15s; } }
