:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1b2a3a;
  --muted: #6b7a8c;
  --line: #e4ded1;
  --accent: #0f5132;
  --accent-soft: #e3f0e8;
  --ok: #1a7f4b;
  --ok-soft: #e6f4ec;
  --warn: #b3541e;
  --warn-soft: #fdf0e6;
  --tile-w: clamp(30px, 8.4vw, 46px);
  --radius: 16px;
  --shadow: 0 1px 2px rgba(27, 42, 58, .06), 0 8px 24px rgba(27, 42, 58, .07);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --card: #1b2129;
    --ink: #e8edf3;
    --muted: #94a3b4;
    --line: #2c343e;
    --accent: #4ec38a;
    --accent-soft: #1d2b25;
    --ok: #4ec38a;
    --ok-soft: #17291f;
    --warn: #e8a06a;
    --warn-soft: #2a2018;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Class-level display rules outrank the UA rule for [hidden], so restate it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 650; }

/* --- Top bar ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--accent);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .topbar { background: #0d1f17; color: var(--ink); }
}

.brand { font-weight: 650; letter-spacing: .01em; }

.tally { display: flex; gap: 6px; }

.tally-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.tally-item.ok { color: #9ce8bd; }
.tally-item.bad { color: #f3c1a3; }

/* --- Layout ------------------------------------------------------------- */

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 12px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 14px;
}

.card-title { font-size: 16px; margin-bottom: 12px; }

.mini-title {
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 16px 0 6px;
}

.hand-head h1 { font-size: 19px; }

.hand-index {
  display: block;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

/* --- Chips -------------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.chip.neutral { background: var(--line); color: var(--muted); }

/* --- Rack --------------------------------------------------------------- */

.rack {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px 10px;
  padding: 14px 10px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, #7c4d28 0%, #5d3719 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .2),
    inset 0 -10px 16px rgba(0, 0, 0, .35),
    0 6px 16px rgba(0, 0, 0, .2);
}

.set { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.set-tiles {
  display: flex;
  gap: 2px;
  padding-bottom: 5px;
  border-bottom: 5px solid rgba(0, 0, 0, .3);
  border-radius: 0 0 5px 5px;
}

.set-label {
  font-size: 10px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .78);
}

.tile {
  width: var(--tile-w);
  aspect-ratio: 40 / 54;
  padding: 1px;
  border-radius: 6px;
  border: 1px solid rgba(126, 104, 62, .22);
  background: linear-gradient(170deg, #fffef7 0%, #fdfaee 55%, #f0e7d1 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .95) inset,
    0 -3px 5px rgba(124, 102, 60, .16) inset,
    0 2px 3px rgba(0, 0, 0, .32);
}

.tile svg { display: block; width: 100%; height: 100%; }

/* --- Bonus tiles -------------------------------------------------------- */

.bonus-tiles { display: flex; flex-wrap: wrap; gap: 10px; }

.bonus-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.bonus-tag { font-size: 10px; color: var(--muted); letter-spacing: .04em; }

.bonus-tag.hit { color: var(--accent); font-weight: 650; }

/* --- Steppers ----------------------------------------------------------- */

.stepper { margin-bottom: 14px; }

.stepper label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.stepper-row { display: flex; align-items: stretch; gap: 8px; }

.step {
  flex: 0 0 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.step:active { background: var(--accent-soft); }

.stepper-row input {
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: 650 22px/1 inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.stepper-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.stepper-row input::-webkit-outer-spin-button,
.stepper-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.stepper-row input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* --- Live score --------------------------------------------------------- */

.live {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 2px 10px;
  padding: 12px 14px;
  margin: 4px 0 14px;
  border-radius: 12px;
  background: var(--accent-soft);
}

.live-label { font-size: 13px; color: var(--muted); }

.live-score {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.live-math { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Buttons ------------------------------------------------------------ */

.actions { display: flex; gap: 8px; }

.primary, .ghost {
  height: 50px;
  border-radius: 12px;
  font: 650 16px/1 inherit;
  cursor: pointer;
}

.primary {
  flex: 1 1 auto;
  border: 0;
  background: var(--accent);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .primary { color: #0d1f17; }
}

.primary:active { filter: brightness(.92); }

.ghost {
  flex: 0 0 auto;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.link-btn {
  display: block;
  margin: 10px auto 0;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 13px/1 inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* --- Name prompt --------------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.welcome {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 22, 18, .72);
  backdrop-filter: blur(3px);
}

.welcome-card {
  width: 100%;
  max-width: 340px;
  padding: 22px 18px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
}

.welcome-card h1 { font-size: 21px; margin-bottom: 6px; }

.welcome-card p { margin: 0 0 16px; font-size: 14px; color: var(--muted); }

.welcome-card input {
  width: 100%;
  height: 50px;
  margin-bottom: 10px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: 16px/1 inherit;
  text-align: center;
}

.welcome-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.welcome-card .primary { width: 100%; }

.welcome-note { margin: 12px 0 0 !important; font-size: 12px; }

/* --- Verdict ------------------------------------------------------------ */

.verdict {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border-left: 4px solid var(--ok);
  background: var(--ok-soft);
}

.verdict.off { border-left-color: var(--warn); background: var(--warn-soft); }

.verdict.info { border-left-color: var(--muted); background: var(--line); }

.verdict-title { font-size: 16px; font-weight: 650; color: var(--ok); }

.verdict.off .verdict-title { color: var(--warn); }

.verdict.info .verdict-title { color: var(--ink); }

.verdict ul { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }

.verdict li { margin-bottom: 3px; }

/* --- Breakdown ---------------------------------------------------------- */

.score-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.score-table td { padding: 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }

.score-table td.value {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  padding-left: 10px;
}

.score-table .note { display: block; font-size: 12px; color: var(--muted); }

.score-table tr.total td { border-bottom: 0; border-top: 2px solid var(--line); font-weight: 700; }

.score-table tr.empty td { color: var(--muted); border-bottom: 0; }

.final-math {
  margin: 18px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.fine-print { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* --- Session summary ---------------------------------------------------- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  border-radius: 12px;
  background: var(--accent-soft);
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1.1;
}

.stat-value.ok { color: var(--ok); }
.stat-value.bad { color: var(--warn); }

.stat-label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.summary-line { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Played-hands table -------------------------------------------------- */

.history-wrap {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}

.history { width: 100%; border-collapse: collapse; font-size: 14px; }

.history-row { cursor: pointer; }

.history-row td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }

.history-row:last-child td { border-bottom: 0; }

.history-row:hover td, .history-row:focus-visible td { background: var(--accent-soft); }

.history-row.current td { background: var(--accent-soft); }

.history-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.h-num {
  width: 2.5em;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--muted);
}

.h-title .note { display: block; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.h-mark { width: 1.6em; text-align: right; font-size: 16px; font-weight: 700; }
.h-mark.ok { color: var(--ok); }
.h-mark.bad { color: var(--warn); }

.scorecard {
  margin: 14px 0 0;
  padding: 14px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: var(--bg);
  font: 13px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.scorecard:active { border-style: solid; border-color: var(--accent); }

.scorecard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.copy-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

.share-status { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* --- Minimum-doubles rule ------------------------------------------------ */

.live-warning {
  margin: -8px 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  border-left: 4px solid var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
}

.zero-callout {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  border-left: 4px solid var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 14px;
}

.zero-note { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

/* --- Rules page ---------------------------------------------------------- */

.topbar-link { color: inherit; font-size: 14px; text-decoration: none; padding: 6px 4px; }

.doc-title { font-size: 19px; margin-bottom: 10px; }

.doc h2.doc-title { font-size: 17px; }

.doc p { margin: 0 0 10px; font-size: 15px; }

.doc p:last-child { margin-bottom: 0; }

.doc-list { margin: 0; padding-left: 20px; font-size: 15px; }

.doc-list li { margin-bottom: 8px; }

.doc .final-math { font-size: 16px; }

.table-wrap { overflow-x: auto; margin: 0 0 6px; -webkit-overflow-scrolling: touch; }

.rules-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.rules-table th {
  text-align: left;
  padding: 8px 0;
  border-bottom: 2px solid var(--line);
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}

.rules-table th + th, .rules-table td + td { text-align: right; padding-left: 12px; white-space: nowrap; }

.rules-table td {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.rules-table td + td { font-weight: 650; font-variant-numeric: tabular-nums; }

.rules-table tr:last-child td { border-bottom: 0; }

.rules-table .note { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

.doc details {
  border-bottom: 1px solid var(--line);
  padding: 4px 0;
}

.doc details:last-of-type { border-bottom: 0; }

.doc summary {
  padding: 10px 0;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  list-style-position: outside;
}

.doc summary::marker { color: var(--muted); }

.doc details p { margin: 0 0 12px; color: var(--muted); }

footer {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

footer a { color: inherit; }
