
/* Layout: one narrow column like a score pad on the table; game grid on home, sticky scoreboard while playing */
:root {
  --bg: #EEF1ED;
  --surface: #FFFFFF;
  --sunk: #E3E8E3;
  --ink: #17231E;
  --muted: #5B6862;
  --line: #CFD7D1;
  --red: #B3261E;
  --red-soft: #F6E1DF;
  --felt: #1E5A44;
  --felt-soft: #DCEBE3;
  --warn: #8A5A00;
  --display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1613; --surface: #17211C; --sunk: #1F2B25; --ink: #E8EEEA; --muted: #97A49D;
    --line: #2C3A33; --red: #F0766B; --red-soft: #3A2220; --felt: #6CC7A0; --felt-soft: #1B3329; --warn: #E9B44C;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1613; --surface: #17211C; --sunk: #1F2B25; --ink: #E8EEEA; --muted: #97A49D;
  --line: #2C3A33; --red: #F0766B; --red-soft: #3A2220; --felt: #6CC7A0; --felt-soft: #1B3329; --warn: #E9B44C;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.5; }
#app {
  max-width: 760px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 64px;
  display: flex; flex-direction: column; gap: 20px;
}
h1, h2, h3 { font-family: var(--display); font-stretch: 75%; line-height: 1.05; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(2.2rem, 7vw, 3.2rem); font-weight: 850; letter-spacing: -0.01em; }
h2 { font-size: 1.6rem; font-weight: 800; }
h3 { font-size: 1.2rem; font-weight: 750; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--felt); outline-offset: 2px; }
.num, .tab { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.label { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 10px 18px; font-weight: 650; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.red { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; padding-inline: 10px; }
.btn.ghost:hover { background: var(--sunk); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

/* Home */
.masthead { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; }
.masthead .suits { font-family: var(--display); font-weight: 800; letter-spacing: 0.3em; color: var(--red); font-size: 0.9rem; }
.resume { background: var(--felt); color: #fff; border-radius: var(--r); padding: 16px 18px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
:root[data-theme="dark"] .resume { color: #0F1613; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .resume { color: #0F1613; } }
.resume .btn { background: transparent; color: inherit; border-color: currentColor; }
.search { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 12px 14px; min-height: 48px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 14px; font-size: 0.9rem; font-weight: 600; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.game { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.game .meta { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.game p { color: var(--muted); font-size: 0.92rem; flex: 1; }
.game .row .btn { flex: 1; padding-inline: 10px; }
.kind { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--red); }
.history { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.history div { display: flex; gap: 12px; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; flex-wrap: wrap; }

/* Shared panels */
.topbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar h2 { flex: 1; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: 0.94rem; }
.inp { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 10px 12px; min-height: 44px; width: 100%; }
.toggle { display: flex; gap: 10px; align-items: center; font-weight: 600; font-size: 0.94rem; min-height: 44px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--felt); }
.players { display: flex; flex-direction: column; gap: 8px; }
.player-row { display: flex; gap: 8px; align-items: center; }
.player-row .seat { width: 28px; text-align: center; font-family: var(--display); font-weight: 800; color: var(--muted); }
.saved .chip { font-weight: 500; }
.note { background: var(--sunk); border-radius: 8px; padding: 10px 12px; font-size: 0.9rem; }
.error { color: var(--red); font-weight: 600; font-size: 0.92rem; }

/* Rules */
.rules { display: flex; flex-direction: column; gap: 14px; max-width: 65ch; }
.rules h3 { margin-top: 6px; }
.rules ul, .rules ol { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; }
.rules table { border-collapse: collapse; width: 100%; font-size: 0.94rem; }
.rules td { border-bottom: 1px solid var(--line); padding: 6px 4px; }
.rules td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Play */
.board { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); padding-block: 8px; margin-block: -8px; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.sides { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.side.lead { border-color: var(--felt); box-shadow: inset 0 0 0 1px var(--felt); }
.side.turn { background: var(--felt-soft); }
.side .name { font-weight: 650; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .sub { font-size: 0.76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .total { font-family: var(--display); font-stretch: 70%; font-weight: 850; font-size: 2.3rem; line-height: 1; font-variant-numeric: tabular-nums; }
.side .badge { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em; color: var(--felt); text-transform: uppercase; }
.side .badge.red { color: var(--red); }
.status { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); }

.egrid { display: flex; flex-direction: column; gap: 8px; }
.erow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; align-items: center; }
.erow .ename { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.erow .ctrls { display: flex; gap: 6px; align-items: center; }
.erow input[type=number] { width: 92px; text-align: right; font-family: var(--display); font-weight: 750; font-size: 1.25rem; font-stretch: 80%; }
.erow select { width: auto; }
.team-block { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.team-block:last-child { border-bottom: 0; padding-bottom: 0; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
table.score { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.score th, table.score td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.score th:first-child, table.score td:first-child { text-align: left; color: var(--muted); width: 1%; }
table.score thead th { font-size: 0.8rem; font-weight: 700; color: var(--muted); max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
table.score td .d { font-weight: 650; }
table.score td .n { display: block; font-size: 0.72rem; color: var(--red); font-weight: 600; }
table.score tfoot td { font-family: var(--display); font-stretch: 75%; font-weight: 850; font-size: 1.2rem; border-bottom: 0; color: var(--ink); }
table.score tbody tr:last-child td { border-bottom: 2px solid var(--ink); }
.neg { color: var(--red); }

.winner { background: var(--ink); color: var(--bg); border-radius: var(--r); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.winner h2 { font-size: 2.2rem; }
.winner .btn { background: transparent; color: inherit; border-color: currentColor; }
.winner ol { margin: 0; padding-left: 1.3em; }

/* Farkle */
.turn-total { font-family: var(--display); font-stretch: 70%; font-weight: 900; font-size: 3.4rem; line-height: 1; font-variant-numeric: tabular-nums; }
.dice-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-width: 380px; }
.die { aspect-ratio: 1; max-width: 100%; border-radius: 10px; border: 1.5px solid var(--ink); background: var(--surface); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 14%; gap: 4%; }
.die i { border-radius: 50%; }
.die i.p { background: var(--ink); }
.die.one i.p, .die.five i.p { background: var(--red); }
button.die { padding: 14%; }
.tray { display: flex; gap: 6px; flex-wrap: wrap; min-height: 46px; align-items: center; }
.tray .die { width: 42px; }
.log { display: flex; gap: 6px; flex-wrap: wrap; }
.log span { display: inline-flex; align-items: center; background: var(--sunk); border-radius: 999px; padding: 2px 10px; font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* Golf card counter */
.golf-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; max-width: 300px; }
.golf-grid select { text-align: center; padding: 8px 4px; }
.golf-help { grid-column: 1 / -1; }

@media (prefers-reduced-motion: no-preference) {
  .side .total { transition: color .2s; }
}
@media (max-width: 420px) {
  .side .total { font-size: 1.9rem; }
  .erow input[type=number] { width: 80px; }
}

/* ---- Site chrome ---- */
.site-head, .site-foot, main.wrap {
  max-width: 760px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.site-head { display: flex; align-items: center; gap: 12px; padding-block: 14px; border-bottom: 1px solid var(--line); }
.brand { font-family: var(--display); font-stretch: 75%; font-weight: 850; font-size: 1.45rem; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand b { color: var(--red); font-weight: 850; }
.site-head nav { margin-left: auto; display: flex; gap: 4px; }
.site-head nav a { color: var(--ink); text-decoration: none; font-weight: 600; padding: 8px 12px; border-radius: 999px; }
.site-head nav a:hover { background: var(--sunk); }
main.wrap { display: flex; flex-direction: column; gap: 20px; padding-block: 20px 48px; }
#app { max-width: none; margin: 0; padding: 0; }
.site-foot { border-top: 1px solid var(--line); padding-block: 20px 40px; display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.88rem; color: var(--muted); }
.site-foot a { color: var(--muted); }
a { color: var(--felt); }
.game { text-decoration: none; color: inherit; }
a.game:hover { border-color: var(--muted); }
.game .go { font-weight: 700; color: var(--felt); font-size: 0.92rem; }
.page-intro { display: flex; flex-direction: column; gap: 8px; }
.page-intro p { color: var(--muted); max-width: 60ch; }
section.rules-section { border-top: 1px solid var(--line); padding-top: 24px; display: flex; flex-direction: column; gap: 14px; }
.legal { max-width: 65ch; display: flex; flex-direction: column; gap: 12px; }
.legal h2 { margin-top: 10px; font-size: 1.3rem; }
.more-games { display: flex; flex-wrap: wrap; gap: 8px; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
a.btn { text-decoration: none; color: inherit; }
img { max-width: 100%; }
a.chip { text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; }
.crib-count { display: flex; flex-direction: column; gap: 8px; }
.crib-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.crib-card { display: flex; flex-direction: column; gap: 4px; background: var(--sunk); border-radius: 8px; padding: 8px; }
.crib-card select { padding: 6px 8px; min-height: 38px; }
.erow .ctrls .btn.small { padding-inline: 8px; min-height: 36px; font-size: 0.84rem; }
@media (max-width: 420px) { .erow .ctrls { justify-content: flex-end; flex-wrap: wrap; } }
.tiles { display: flex; flex-wrap: wrap; gap: 6px; }
.tile { width: 40px; height: 44px; border-radius: 6px; border: 1.5px solid var(--line); background: var(--surface); font-family: var(--display); font-weight: 800; font-size: 1.1rem; }
.tile[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.target-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.target-grid .btn { padding-inline: 8px; }
.cricket-board td.mark { font-family: var(--display); font-weight: 850; font-size: 1.2rem; text-align: center; color: var(--felt); }
.cricket-board th.cur { color: var(--ink); }
.cricket-board td:first-child { font-weight: 700; color: var(--ink); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.btn.cat { justify-content: space-between; border-radius: 10px; }
.btn.cat strong { font-family: var(--display); font-size: 1.15rem; }
table.five-card tr.sub td { color: var(--muted); font-size: 0.86rem; background: var(--sunk); }
.cricket-board th { text-align: center !important; } .cricket-board th:first-child { text-align: left !important; }
