:root {
  color-scheme: light;
  --bg: #f3f2ee;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dcdad3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #14532d;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe2;
  --red-suit: #c62828;
  --series-1: #2a78d6;
  --neg: #e34948;
  --grid: #e6e4de;
  --danger: #b42318;
  --vul: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #383835;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #2f8f55;
    --accent-ink: #ffffff;
    --accent-soft: #1d3a27;
    --red-suit: #ff6b6b;
    --series-1: #3987e5;
    --neg: #e66767;
    --grid: #2c2c2a;
    --danger: #ff6b6b;
    --vul: #ff6b6b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --border: #383835;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #2f8f55;
  --accent-ink: #ffffff; --accent-soft: #1d3a27; --red-suit: #ff6b6b;
  --series-1: #3987e5; --neg: #e66767; --grid: #2c2c2a; --danger: #ff6b6b; --vul: #ff6b6b;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: #14532d; color: #fff;
}
.brand { font-weight: 700; text-decoration: none; white-space: nowrap; }
.topbar nav { display: flex; gap: 2px; flex: 1; justify-content: center; }
.topbar nav a {
  text-decoration: none; padding: 6px 10px; border-radius: 999px; font-size: 15px; opacity: .85;
}
.topbar nav a.active { background: rgba(255,255,255,.18); opacity: 1; font-weight: 600; }
.lock { background: none; border: 0; font-size: 20px; padding: 4px 6px; cursor: pointer; }

main { max-width: 680px; margin: 0 auto; padding: 12px 16px 48px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
}
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; color: var(--text-2); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grow { flex: 1; }

/* Position strip: day / set / game / hand */
.pos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.pos div { background: var(--surface-2); border-radius: 10px; padding: 6px 2px; }
.pos b { display: block; font-size: 20px; }
.pos span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pos .end { grid-column: span 2; background: var(--accent-soft); }
.pos .date b { font-size: 14px; padding: 4px 0 3px; }

.badge {
  display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); vertical-align: middle; white-space: nowrap;
}
.badge.vul { background: var(--vul); color: #fff; }
.badge.me { background: var(--accent); color: var(--accent-ink); }
.red { color: var(--red-suit); }

/* Scoresheet */
.sheet { display: grid; grid-template-columns: 1fr 1fr; border: 2px solid var(--text); border-radius: 10px; overflow: hidden; }
.sheet > div { padding: 4px 10px; }
.sheet > .c2 { border-left: 2px solid var(--text); }
.sheet .head { text-align: center; padding: 8px 4px; background: var(--surface-2); font-weight: 600; }
.sheet .head .names { display: block; font-size: 12px; font-weight: 400; color: var(--text-2); }
.sheet .above { display: flex; flex-direction: column-reverse; justify-content: flex-start; min-height: 56px; padding-bottom: 6px; }
.sheet .game { border-top: 1px solid var(--text-2); min-height: 34px; }
.sheet .game.first { border-top: 3px solid var(--text); }
.sheet .entry { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; font-size: 15px; }
.sheet .entry .lbl { color: var(--muted); font-size: 12px; }
.sheet .sub { border-top: 2px solid var(--text); text-align: right; font-size: 12px; color: var(--muted); padding-top: 6px; }
.sheet .sum { text-align: right; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; padding-bottom: 8px; }
.sheet .gamelabel { font-size: 11px; color: var(--muted); }
.result-banner { text-align: center; font-weight: 700; padding: 10px; border-radius: 10px; background: var(--accent-soft); margin-top: 10px; }

/* Hand list */
.hands { list-style: none; padding: 0; margin: 0; }
.hands li { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.hands li:first-child { border-top: 0; }
.hands li.clickable { cursor: pointer; }
.hands .no { font-weight: 700; text-align: center; font-size: 18px; line-height: 1; }
.hands .no small { display: block; font-size: 10px; font-weight: 400; color: var(--muted); }
.hands .main { font-size: 15px; }
.hands .meta { font-size: 12px; color: var(--muted); }
.hands .pts { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.hands .pts small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.hands li.gamesplit { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding: 12px 0 2px; border-top: 0; }

/* Form controls */
label.f { display: block; font-size: 13px; color: var(--text-2); margin: 12px 0 6px; font-weight: 600; }
.seg { display: grid; gap: 6px; grid-template-columns: repeat(var(--n, 4), 1fr); }
.seg button, .btn {
  min-height: 46px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  font-size: 17px; cursor: pointer; padding: 6px 4px; touch-action: manipulation;
}
.seg button small { display: block; font-size: 11px; color: var(--muted); line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg button.on small { color: var(--accent-ink); opacity: .85; }
.seg button:disabled { opacity: .35; }
.seg.results { grid-template-columns: repeat(7, 1fr); }
.seg.results button { min-height: 42px; font-size: 15px; }
.btn { padding: 10px 16px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 6px; }
.stepper input { text-align: center; font-size: 22px; font-weight: 700; }
input.t, select.t {
  width: 100%; min-height: 46px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); padding: 8px 12px; font-size: 17px;
}
.preview { margin-top: 14px; padding: 10px; border-radius: 10px; background: var(--surface-2); text-align: center; font-size: 15px; }
.preview b { font-size: 18px; }
.err { color: var(--danger); font-size: 14px; margin-top: 8px; }
.names-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.names-grid label { font-size: 12px; color: var(--muted); }

/* Days */
.daylist { list-style: none; margin: 0; padding: 0; }
.daylist li { border-top: 1px solid var(--border); }
.daylist li:first-child { border-top: 0; }
.daylist a { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 10px 0; text-decoration: none; }
.daylist .r { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Stats */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--text-2); stroke-width: 1; }
.chart .ref { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .sep { stroke: var(--border); stroke-width: 1; }
.chart .ln { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln2 { fill: none; stroke: var(--muted); stroke-width: 2; stroke-dasharray: 2 4; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .pos { fill: var(--series-1); }
.chart .neg { fill: var(--neg); }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .hl { fill: var(--surface); stroke: var(--series-1); stroke-width: 2.5; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin: 4px 0 2px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
.legend i.s1 { background: var(--series-1); }
.legend i.s2 { background: var(--muted); height: 2px; }
.legend i.box { width: 10px; height: 10px; }
.legend i.pos { background: var(--series-1); }
.legend i.neg { background: var(--neg); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.tbl th, table.tbl td { padding: 6px 4px; border-top: 1px solid var(--border); text-align: right; }
table.tbl th:first-child, table.tbl td:first-child { text-align: left; }
table.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; border-top: 0; }
details summary { cursor: pointer; color: var(--text-2); font-size: 14px; margin-top: 8px; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 6px 9px; border-radius: 8px; font-size: 13px; line-height: 1.35; max-width: 220px;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60;
}
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; padding: 16px; width: 100%; max-width: 360px; }

@media (max-width: 380px) {
  .topbar nav a { padding: 6px 7px; font-size: 14px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

.seat { font-size: 11px; color: var(--muted); font-weight: 400; border: 1px solid var(--border); border-radius: 4px; padding: 0 3px; vertical-align: 1px; }
.seg button .nm { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .head { font-size: 15px; }

.standings { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.st-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: 4px; }
.st-title .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.st-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; border-radius: 8px; font-size: 16px; }
.st-row b { font-size: 20px; font-variant-numeric: tabular-nums; }
.st-row.lead { background: var(--accent-soft); font-weight: 600; }
.setpts { display: inline-block; margin-top: 4px; font-size: 18px; }

/* Table / seats laid out like the real table */
.compass { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-areas: ". n ." "w m e" ". s ."; gap: 8px; align-items: center; margin-top: 8px; }
.c-n { grid-area: n; } .c-s { grid-area: s; } .c-e { grid-area: e; } .c-w { grid-area: w; }
.c-mid { grid-area: m; text-align: center; font-size: 34px; color: var(--accent); }
.seatbtn { width: 100%; min-height: 64px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; padding: 6px 4px; }
.seatbtn b { display: block; font-size: 18px; }
.seatbtn small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seatbtn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seatbtn.on small { color: var(--accent-ink); }
.seatbtn:disabled { opacity: .45; cursor: not-allowed; }
.seatcell { min-height: 64px; border-radius: 12px; border: 1px dashed var(--border); padding: 6px; text-align: center; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.seatcell.taken { border-style: solid; background: var(--surface-2); }
.seatcell.mine { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.seatcell b { font-size: 13px; color: var(--muted); }
.seatcell span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seatcell small { font-size: 11px; color: var(--muted); }
.small-input { min-height: 38px !important; font-size: 15px !important; padding: 4px 6px !important; text-align: center; }
.waiting p { margin: 12px 0; }
.spinner { width: 34px; height: 34px; margin: 4px auto 0; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.warn { color: var(--danger); }
@media (max-width: 420px) { .brand { display: none; } .topbar nav { justify-content: flex-start; } }

/* Presence */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.on { background: #22a35a; box-shadow: 0 0 0 2px rgba(34,163,90,.25); }
.dot.off { background: var(--muted); }
.seatcell.away { border-color: var(--danger); border-style: dashed; }
.seatcell.away span { color: var(--muted); }
.presence { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font-size: 13px; align-items: center; }
.presence .away { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--danger); }
