/* Cribbage Square — styles. Light/dark via tokens. No external assets. */
:root {
  --bg: #edf0eb;
  --surface: #fbfcfa;
  --surface-2: #e1e7df;
  --text: #1d2420;
  --text-muted: #556058;
  --border: #cdd5ca;
  --felt: #1e5a3e;
  --felt-2: #174a32;
  --felt-line: rgba(255, 255, 255, 0.14);
  --felt-text: #eaf3ec;
  --felt-muted: #b9d2c2;
  --accent: #ad2a30;
  --accent-text: #ffffff;
  --gold: #e3b341;
  --card: #fffdf8;
  --card-border: #cfc8b8;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, .18), 0 3px 8px rgba(0, 0, 0, .14);
  --red: #c0262d;
  --black: #1a1a1a;
  --blue: #1f5fbf;
  --green: #17803d;
  --back-1: #8c2a22;
  --back-2: #a83a2f;
  --good: #1d7a45;
  --hl: #f4c430;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101512; --surface: #18201b; --surface-2: #222b25; --text: #e6ebe7; --text-muted: #a3aea6;
    --border: #2f3a33; --felt: #173f2c; --felt-2: #123423; --felt-text: #e3eee6; --felt-muted: #9fbfaa;
    --accent: #d9583f; --card: #f1ede3; --card-border: #b9b2a2; --back-1: #6f211b; --back-2: #87302a;
    --good: #43b06f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101512; --surface: #18201b; --surface-2: #222b25; --text: #e6ebe7; --text-muted: #a3aea6;
  --border: #2f3a33; --felt: #173f2c; --felt-2: #123423; --felt-text: #e3eee6; --felt-muted: #9fbfaa;
  --accent: #d9583f; --card: #f1ede3; --card-border: #b9b2a2; --back-1: #6f211b; --back-2: #87302a;
  --good: #43b06f; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 17px; line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--hl); outline-offset: 2px; }

/* ---------- Header ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .inner { max-width: 1040px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); margin-right: auto; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; color: var(--text-muted); padding: 6px 10px; border-radius: 8px; font-size: .95rem; white-space: nowrap; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }
.header-actions { display: flex; gap: 6px; }
.site-header .btn { white-space: nowrap; padding: 8px 14px; min-height: 40px; }
@media (max-width: 760px) { .nav { display: none; } .brand-name { font-size: 1.15rem; } }

/* ---------- Layout ---------- */
main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 16px; }
.game-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; justify-items: center; }

.mode-tabs { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; }
.mode-tabs button { border: 0; background: transparent; padding: 8px 18px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--text-muted); }
.mode-tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.puzzle-meta { color: var(--text-muted); font-size: .95rem; text-align: center; min-height: 1.5em; }

/* ---------- Table (felt) ---------- */
.table {
  --cell: min(19vw, clamp(56px, calc((100vh - 350px) / 5.6), 92px));
  display: grid; justify-content: center;
  width: 100%; max-width: 640px; border-radius: 18px; padding: 18px 16px 20px;
  background: radial-gradient(120% 90% at 50% 0%, var(--felt) 0%, var(--felt-2) 100%);
  color: var(--felt-text); box-shadow: inset 0 0 0 1px var(--felt-line), 0 6px 20px rgba(0,0,0,.18);
}
.board { display: grid; grid-template-columns: repeat(4, var(--cell)) auto; grid-template-rows: repeat(4, calc(var(--cell) * 1.4)) auto; gap: 8px; justify-content: center; }
.cell {
  width: var(--cell); height: calc(var(--cell) * 1.4); border-radius: 10px; padding: 0; position: relative;
  border: 2px dashed var(--felt-line); background: rgba(0,0,0,.12); cursor: pointer; transition: background .15s, border-color .15s, transform .1s;
}
.cell:not(.filled):hover, .cell:not(.filled):focus-visible { background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.45); }
.cell:not(.filled):active { transform: scale(.97); }
.cell.filled { border: 0; background: transparent; cursor: default; }
.board.locked .cell { cursor: default; }
.cell.hl .card { box-shadow: 0 0 0 3px var(--hl), var(--card-shadow); }
.cell.dim .card { opacity: .45; }

.line-score {
  display: grid; place-items: center; min-width: 44px; height: 100%; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--felt-muted); font-size: 1.05rem; border-radius: 8px; border: 0; background: transparent; padding: 0 4px; cursor: default;
}
.line-score.col { height: auto; min-height: 34px; width: var(--cell); }
.line-score.has { color: var(--felt-text); }
.line-score.final { cursor: pointer; background: rgba(0,0,0,.18); }
.line-score.final:hover, .line-score.final.active { background: rgba(255,255,255,.16); color: #fff; }
.line-score .lbl { display: block; font-size: .62rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; opacity: .7; line-height: 1; }
.corner-total { display: grid; place-items: center; min-height: 34px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

/* ---------- Deal area ---------- */
.deal { display: flex; justify-content: center; align-items: flex-end; gap: 22px; margin-top: 18px; flex-wrap: wrap; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.slot-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--felt-muted); font-weight: 600; }
.slot .holder { width: var(--cell); height: calc(var(--cell) * 1.4); border-radius: 10px; border: 2px dashed var(--felt-line); position: relative; perspective: 800px; }
.score-box { text-align: center; min-width: 120px; }
.score-box .big { font-size: 2.3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-box .sub { font-size: .85rem; color: var(--felt-muted); }
.score-box .win { color: var(--gold); }
.controls { display: flex; justify-content: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  position: absolute; inset: 0; border-radius: 10px; background: var(--card); border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow); color: var(--black); user-select: none; overflow: hidden;
}
.card.red { color: var(--red); }
.four-color .card.s-D { color: var(--blue); }
.four-color .card.s-C { color: var(--green); }
.card .corner { position: absolute; display: flex; flex-direction: column; align-items: center; line-height: .95; font-weight: 700; font-size: calc(var(--cell) * .2); }
.card .corner .s { font-size: .85em; }
.card .tl { top: 5%; left: 7%; }
.card .br { bottom: 5%; right: 7%; transform: rotate(180deg); }
.card .pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--cell) * .5); }
.card .face { position: absolute; inset: 22% 18%; border: 1.5px solid currentColor; border-radius: 6px; display: grid; place-items: center; font-family: var(--serif); font-weight: 700; font-size: calc(var(--cell) * .42); opacity: .92; }
.card .face small { position: absolute; bottom: 4%; font-size: .38em; }
.card.back {
  background: repeating-linear-gradient(45deg, var(--back-1) 0 6px, var(--back-2) 6px 12px);
  border: 4px solid var(--card);
}
.card.anim-in { animation: dealIn .22s ease-out; }
@keyframes dealIn { from { transform: translateY(-10px) scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
.flip { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .6s ease; }
.flip.flipped { transform: rotateY(180deg); }
.flip .card { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip .card.front { transform: rotateY(180deg); }
@media (prefers-reduced-motion: reduce) { .flip { transition: none; } .card.anim-in { animation: none; } }

@media (min-width: 860px) {
  .table { max-width: 860px; grid-template-columns: auto 220px; column-gap: 32px; align-items: center; padding: 22px 28px; }
  .deal { flex-direction: column; align-items: center; margin-top: 0; gap: 18px; }
  .controls { grid-column: 1 / -1; }
}

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost-felt { background: rgba(0,0,0,.2); border-color: var(--felt-line); color: var(--felt-text); }
.btn.ghost-felt:hover { background: rgba(255,255,255,.12); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- Breakdown ---------- */
.breakdown { width: 100%; max-width: 640px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.breakdown h2 { margin: 0 0 8px; font-size: 1.05rem; }
.breakdown ul { list-style: none; margin: 0; padding: 0; }
.breakdown li { display: grid; grid-template-columns: 92px 1fr auto; gap: 10px; align-items: baseline; padding: 7px 6px; border-top: 1px solid var(--border); cursor: pointer; border-radius: 6px; }
.breakdown li:first-child { border-top: 0; }
.breakdown li:hover, .breakdown li.active { background: var(--surface-2); }
.breakdown .hn { font-weight: 600; white-space: nowrap; }
.breakdown .hd { color: var(--text-muted); font-size: .92rem; }
.breakdown .hp { font-weight: 800; font-variant-numeric: tabular-nums; }
.breakdown .tot { display: flex; justify-content: space-between; padding: 10px 6px 0; border-top: 2px solid var(--border); margin-top: 4px; font-weight: 800; }

/* ---------- Modals ---------- */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 15, 12, .55); }
.modal { padding: 22px 22px 20px; position: relative; }
.modal h2 { margin: 0 0 12px; font-family: var(--serif); font-size: 1.5rem; }
.modal h3 { margin: 18px 0 8px; font-size: 1rem; }
.modal p, .modal li { color: var(--text); }
.modal ul { padding-left: 20px; margin: 6px 0; }
.modal .close { position: absolute; top: 12px; right: 12px; }
.modal .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.result-score { text-align: center; margin: 4px 0 6px; }
.result-score .n { font-size: 3.6rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.result-score .v { font-weight: 700; margin-top: 6px; }
.result-score .v.win { color: var(--good); }
.share-preview { white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; font-size: .95rem; overflow-x: auto; }
.countdown { text-align: center; color: var(--text-muted); margin-top: 12px; font-size: .95rem; }
.countdown b { color: var(--text); font-variant-numeric: tabular-nums; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats-grid .st { background: var(--surface-2); border-radius: 10px; padding: 10px 4px; }
.stats-grid .st b { display: block; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats-grid .st span { font-size: .78rem; color: var(--text-muted); }
.dist { display: grid; gap: 6px; margin-top: 4px; }
.dist .row { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; font-size: .88rem; }
.dist .bar { background: var(--felt); color: #fff; border-radius: 5px; padding: 2px 8px; text-align: right; min-width: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dist .bar.me { background: var(--accent); }

.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.setting:first-of-type { border-top: 0; }
.setting small { display: block; color: var(--text-muted); }
.switch { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); position: relative; cursor: pointer; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-muted); transition: transform .15s; }
.switch:checked { background: var(--felt); border-color: var(--felt); }
.switch:checked::after { transform: translateX(20px); background: #fff; }
select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Content pages ---------- */
.prose { max-width: 760px; margin: 0 auto; }
.prose h1 { font-family: var(--serif); font-size: 2.1rem; line-height: 1.2; margin: 8px 0 12px; }
.prose h2 { font-family: var(--serif); font-size: 1.45rem; margin: 30px 0 10px; }
.prose h3 { font-size: 1.1rem; margin: 22px 0 6px; }
.prose p, .prose li { color: var(--text); }
.prose .lede { font-size: 1.12rem; color: var(--text-muted); }
.prose table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: .97rem; }
.prose th, .prose td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.prose th { background: var(--surface-2); }
.callout { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--felt); border-radius: 10px; padding: 12px 16px; margin: 16px 0; }
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin: 20px 0; }

/* Calculator */
.calc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.calc-slots { --cell: min(14.5vw, 82px); display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.calc-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.calc-slot button.holder { width: var(--cell); height: calc(var(--cell) * 1.4); border-radius: 10px; border: 2px dashed var(--border); background: var(--surface-2); position: relative; cursor: pointer; padding: 0; }
.calc-slot button.holder.sel { border-color: var(--accent); border-style: solid; }
.calc-slot .lab { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.calc-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }
.picker { margin-top: 14px; display: grid; gap: 8px; }
.picker .ranks, .picker .suits { display: flex; flex-wrap: wrap; gap: 6px; }
.picker button { min-width: 42px; min-height: 42px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 700; }
.picker button:hover { background: var(--surface-2); }
.picker button.on { background: var(--felt); color: #fff; border-color: var(--felt); }
.picker .suits button { font-size: 1.3rem; min-width: 52px; }
.picker .suits .red { color: var(--red); }
.picker .suits button.on { color: #fff; }
.calc-result { margin-top: 14px; }
.calc-result .n { font-size: 2.4rem; font-weight: 800; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 28px; }
.site-footer .inner { max-width: 1040px; margin: 0 auto; padding: 18px 16px; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between; color: var(--text-muted); font-size: .92rem; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.site-footer a { color: var(--text-muted); }
.donate { display: none; }
.donate.on { display: inline-flex; }

/* Ad slot placeholder (hidden until you enable ads) */
.ad-slot { width: 100%; max-width: 728px; min-height: 90px; margin: 8px auto; display: none; }
.ad-slot.on { display: block; }

@media (max-width: 420px) {
  main { padding: 12px; }
  .table { padding: 12px 8px 14px; border-radius: 14px; }
  .table { --cell: min(18.5vw, 92px); }
  .board { gap: 5px; }
  .line-score { min-width: 34px; font-size: .95rem; }
  .deal { gap: 14px; }
  .breakdown li { grid-template-columns: 76px 1fr auto; }
}
