/* Card Game Companion — design system.
   Tokens first; every page and tool uses only these. Light = card-table cream, dark = night felt. */
:root {
  --bg: #f7f3ea;
  --surface: #ffffff;
  --surface-2: #efe9dc;
  --ink: #1d1b16;
  --ink-2: #57524a;
  --line: #ddd5c4;
  --felt: #1f5c45;
  --felt-2: #2c7a5c;
  --felt-ink: #f4f1e8;
  --accent: #b5452b;
  --accent-ink: #ffffff;
  --red-suit: #c0392b;
  --black-suit: #1d1b16;
  --good: #2f7d4f;
  --warn: #a86a00;
  --focus: #2f6fdb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101814; --surface: #17221c; --surface-2: #1e2c25; --ink: #eef0ea; --ink-2: #a9b3ab;
    --line: #2b3b33; --felt: #1b4d3a; --felt-2: #24694f; --accent: #e0705a; --red-suit: #ff7a6b;
    --black-suit: #eef0ea; --good: #5cc28a; --warn: #e3a53a; --focus: #7aa7ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101814; --surface: #17221c; --surface-2: #1e2c25; --ink: #eef0ea; --ink-2: #a9b3ab;
  --line: #2b3b33; --felt: #1b4d3a; --felt-2: #24694f; --accent: #e0705a; --red-suit: #ff7a6b;
  --black-suit: #eef0ea; --good: #5cc28a; --warn: #e3a53a; --focus: #7aa7ff;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); }
img, svg { max-width: 100%; }
a { color: var(--felt-2); text-underline-offset: 2px; }
:root[data-theme="dark"] a, :root:not([data-theme="light"]) a { color: inherit; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.8rem); margin: 0 0 .4em; }
h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); margin: 1.8em 0 .5em; }
h3 { font-size: 1.15rem; margin: 1.4em 0 .4em; }
p, ul, ol { margin: 0 0 1em; }
small, .muted { color: var(--ink-2); }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 740px; }

/* header / nav */
.site-head { background: var(--felt); color: var(--felt-ink); }
.site-head .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { color: var(--felt-ink); text-decoration: none; font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.brand:hover { color: #fff; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.nav a { color: var(--felt-ink); text-decoration: none; padding: 6px 10px; border-radius: 999px; font-size: .95rem; }
.nav a:hover, .nav a[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; }

.crumbs { font-size: .9rem; color: var(--ink-2); margin: 18px 0 6px; }
.crumbs a { color: var(--ink-2); }
main { padding-bottom: 48px; }
.lede { font-size: 1.15rem; color: var(--ink-2); max-width: 62ch; }

/* cards / panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.tile { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s; }
.tile:hover { transform: translateY(-2px); border-color: var(--felt-2); color: inherit; }
.tile h3 { margin: 0 0 .3em; }
.tile p { margin: 0; color: var(--ink-2); font-size: .95rem; }
.tag { display: inline-block; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--felt-2); font-weight: 600; }

/* buttons & inputs */
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--radius-sm); padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn:hover { border-color: var(--felt-2); }
.btn-primary { background: var(--felt); border-color: var(--felt); color: var(--felt-ink); }
.btn-primary:hover { background: var(--felt-2); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 36px; padding: 5px 10px; font-size: .9rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
label { font-weight: 600; font-size: .95rem; }
input[type=text], input[type=number], select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; min-height: 44px; width: 100%; }
input[type=number] { max-width: 8em; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin: 0 0 12px; }
legend { font-weight: 700; padding: 0 6px; }

/* playing cards (rendered by core/cards.js) */
.cards { display: flex; gap: 8px; flex-wrap: wrap; }
.pcard { width: 64px; height: 90px; border-radius: 7px; background: #fff; border: 1px solid #cfc7b5; box-shadow: 0 1px 2px rgba(0,0,0,.12); position: relative; display: inline-flex; flex-direction: column; justify-content: space-between; padding: 5px 6px; font-weight: 700; line-height: 1; user-select: none; color: #1d1b16; }
.pcard.red { color: #c0392b; }
.pcard .c-rank { font-size: 1.15rem; }
.pcard .c-suit { font-size: 1.6rem; align-self: center; margin-bottom: 14px; }
.pcard .c-rank-b { font-size: 1.15rem; align-self: flex-end; transform: rotate(180deg); }
.pcard.sm { width: 44px; height: 62px; padding: 3px 4px; }
.pcard.sm .c-rank, .pcard.sm .c-rank-b { font-size: .9rem; }
.pcard.sm .c-suit { font-size: 1.1rem; margin-bottom: 6px; }
.pcard.hl { outline: 3px solid var(--accent); outline-offset: 1px; }
.pcard.empty { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, transparent 6px, transparent 12px); border-style: dashed; color: var(--ink-2); align-items: center; justify-content: center; font-size: .8rem; font-weight: 600; }
button.pcard { cursor: pointer; font: inherit; font-weight: 700; }
button.pcard[aria-pressed="true"] { outline: 3px solid var(--felt-2); outline-offset: 1px; transform: translateY(-4px); }

/* card picker */
.picker { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 4px; }
.picker button { min-height: 40px; padding: 0; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); font: inherit; font-weight: 700; cursor: pointer; color: var(--black-suit); }
.picker button.red { color: var(--red-suit); }
.picker button[aria-pressed="true"] { background: var(--felt); color: var(--felt-ink); border-color: var(--felt); }
.picker button:disabled { opacity: .3; cursor: not-allowed; }
@media (max-width: 560px) { .picker { grid-template-columns: repeat(7, minmax(0, 1fr)); } }

/* score tables */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 800; border-top: 2px solid var(--ink); }
.table-wrap { overflow-x: auto; }

/* scoreboard */
.scoreboard { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.player { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.player.leader { border-color: var(--felt-2); box-shadow: 0 0 0 2px var(--felt-2) inset, var(--shadow); }
.player .pname { font-weight: 700; font-size: 1.05rem; width: 100%; border: none; background: transparent; padding: 0; min-height: 0; }
.player .pscore { font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.player .pnote { font-size: .85rem; color: var(--ink-2); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.bar > span { display: block; height: 100%; background: var(--felt-2); border-radius: 99px; transition: width .2s ease; }
.winner-banner { background: var(--felt); color: var(--felt-ink); border-radius: var(--radius); padding: 14px 18px; font-weight: 700; display: none; }
.winner-banner.show { display: block; }

/* callouts / steps / explainer */
.callout { border-left: 4px solid var(--felt-2); background: var(--surface-2); padding: 12px 16px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 0 0 1em; }
.callout.warn { border-color: var(--warn); }
.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li { counter-increment: step; position: relative; padding-left: 44px; margin-bottom: 14px; }
.steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--felt); color: var(--felt-ink); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.toc { font-size: .95rem; }
.toc ol { padding-left: 1.2em; }
details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 8px; }
summary { cursor: pointer; font-weight: 700; }
.result { font-family: var(--font-display); font-size: 2rem; font-weight: 700; }
.ok { color: var(--good); } .bad { color: var(--accent); }
.kbd { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* book promo */
.book-promo { display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: center; }
.book-promo img { border-radius: 4px; box-shadow: var(--shadow); }

/* footer */
.site-foot { border-top: 1px solid var(--line); padding: 28px 0 40px; color: var(--ink-2); font-size: .9rem; }
.site-foot a { color: var(--ink-2); }

/* print: score sheets and charts print clean */
@media print {
  .site-head, .site-foot, .noprint, .crumbs, nav { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .panel { box-shadow: none; border: none; padding: 0; }
  .sheet { page-break-inside: avoid; }
  .sheet table td { height: 26px; }
}
.sheet table { border: 2px solid var(--ink); }
.sheet th, .sheet td { border: 1px solid var(--ink-2); }
.sheet td { height: 30px; }
