:root {
  --navy: #0F1B2D;
  --teal: #12C8BE;
  --teal-dark: #0B7A75;
  --teal-soft: #DDF6F4;
  --bg: #F3F5F8;
  --card: #FFFFFF;
  --line: #DCE2EA;
  --line-soft: #EEF1F5;
  --muted: #4A5568;
  --bad: #B4380A;
  --display: 'Archivo Black', 'Arial Black', sans-serif;
  --body: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--navy); font-family: var(--body); font-size: 16px; font-weight: 500; line-height: 1.4; }
h1, h2, p { margin: 0; }
a { color: var(--teal-dark); font-weight: 700; }
a:hover { color: var(--navy); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--muted); font-weight: 600; }
.small { font-size: 13px; }
.teal { color: var(--teal); }

/* ---------- header ---------- */
.topbar { height: 60px; background: var(--navy); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; }
.wordmark { font-family: var(--display); font-size: 22px; letter-spacing: -0.5px; color: #fff; text-decoration: none; }
.wordmark:hover { color: #fff; }
.badge { font-size: 13px; font-weight: 700; color: var(--navy); background: var(--teal); border-radius: 6px; padding: 4px 8px; }

/* ---------- layout ---------- */
.page { max-width: 520px; margin: 0 auto; padding: 18px 16px 32px; display: flex; flex-direction: column; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.h1 { font-family: var(--display); font-size: 28px; letter-spacing: -0.5px; line-height: 1.1; }
.sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.hint { color: var(--muted); font-size: 14px; }
.fine { color: var(--muted); font-size: 13px; text-align: center; }
.hero { padding: 28px 0 8px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.hero h1 { font-family: var(--display); font-size: 36px; line-height: 1.05; letter-spacing: -1px; }
.hero p { font-size: 18px; color: var(--muted); }
.steps { margin: 0; padding: 0 0 0 22px; display: flex; flex-direction: column; gap: 10px; }
.hostlink { text-align: center; padding-bottom: 28px; margin: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px; border: 0; border-radius: 12px; font-family: var(--body); font-size: 16px; font-weight: 700; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--teal); color: var(--navy); font-family: var(--display); font-weight: 400; }
.btn.primary:hover { color: var(--navy); filter: brightness(0.95); }
.btn.primary:disabled { background: #C9D2DE; color: var(--muted); cursor: default; filter: none; }
.btn.big { min-height: 56px; font-size: 18px; width: 100%; }
.btn.ghost { background: #fff; color: var(--navy); border: 2px solid var(--navy); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn.teal { background: var(--teal); color: var(--navy); }
.btn.link { background: none; color: var(--teal-dark); min-height: 44px; padding: 0 4px; }
.iconbtn { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 8px; }
.iconbtn:hover { background: var(--line-soft); color: var(--bad); }
:focus-visible { outline: 3px solid var(--teal-dark); outline-offset: 2px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > label, .field > legend { font-size: 14px; font-weight: 700; padding: 0; margin-bottom: 0; }
fieldset.field > legend { margin-bottom: 6px; }
input[type=text], input[type=email], input[type=number], input[type=search] {
  height: 50px; width: 100%; border: 1px solid #C9D2DE; border-radius: 10px; background: #fff; padding: 0 14px;
  font-family: var(--body); font-size: 17px; font-weight: 600; color: var(--navy);
}
input::placeholder { color: #8C9BB0; font-weight: 500; }
.money, .pct { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--muted); }
.pct input { width: 76px; text-align: right; height: 44px; }
.pairrow { display: flex; gap: 10px; }
.pairrow .field { flex: 1; }
.pairrow .field.narrow { flex: 0 0 96px; }
.quad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.quad input { padding: 0 8px; text-align: center; }

.segment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: #E3E8EF; border-radius: 10px; padding: 4px; }
.segment label { position: relative; }
.segment input, .chips input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segment span { display: flex; align-items: center; justify-content: center; height: 44px; border-radius: 8px; font-weight: 600; }
.segment input:checked + span { background: var(--navy); color: #fff; font-weight: 700; }
.segment input:focus-visible + span, .chips input:focus-visible + span { outline: 3px solid var(--teal-dark); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; }
.chips span { display: flex; align-items: center; height: 44px; padding: 0 14px; border: 2px solid #C9D2DE; border-radius: 22px; background: #fff; font-size: 15px; font-weight: 600; }
.chips input:checked + span { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 700; }

.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; flex: 0 0 52px; border-radius: 16px; background: #B7C2D0; position: relative; margin: 0; cursor: pointer; transition: background 0.15s; }
.switch::after { content: ''; position: absolute; left: 3px; top: 3px; width: 26px; height: 26px; border-radius: 13px; background: #fff; transition: transform 0.15s; }
.switch:checked { background: var(--teal-dark); }
.switch:checked::after { transform: translateX(20px); }

.gamelist { max-height: 300px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; }
.dayhead { font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); padding: 10px 14px 4px; background: var(--bg); }
.gamerow { display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 4px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.gamerow input { width: 20px; height: 20px; margin: 0; accent-color: var(--teal-dark); flex: 0 0 auto; }
.gamerow .teams { flex: 1; font-weight: 600; }
.gamerow .when { font-size: 14px; color: var(--muted); }
.gamerow:has(input:checked) { background: var(--teal-soft); }
.gamerow:has(input:checked) .teams { font-weight: 700; }
.gamerow.other { background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; }
.gamerow.other:has(input:checked) { background: var(--teal-soft); }
#manualteams { margin-top: 8px; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.card.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.card.dark p { color: #C9D3E0; font-size: 15px; }
.card.dark a { color: var(--teal); }
.card.dark h2 { font-family: var(--display); font-size: 20px; font-weight: 400; }
.card.dark .btn { align-self: flex-start; }
.card.win { background: var(--teal); border-color: var(--teal); }
.card h2 { font-size: 16px; font-weight: 700; }
.eyebrow, .card.dark h2.eyebrow { font-family: var(--body); font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.card.dark .eyebrow { color: var(--teal); }
.bigname { font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.1; }
.cardhead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.cardhead.plain { padding: 0; border: 0; align-items: center; }
.cardhead span { font-size: 13px; color: var(--muted); text-align: right; }
.empty { padding: 16px 14px; color: var(--muted); }
.note { background: #E7EEF6; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.alert { background: #FDECE4; border: 1px solid #F2B79F; color: #7A2606; border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.alert.soft { background: #E7EEF6; border-color: #C9D2DE; color: var(--navy); }
.rows { padding: 2px 14px; gap: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.row label { display: flex; flex-direction: column; cursor: pointer; }
.row label span { font-size: 14px; color: var(--muted); }
.copyrow { display: flex; gap: 8px; align-items: center; }
.copyrow input { height: 40px; font-size: 14px; background: #1C2A40; border-color: #34465F; color: #fff; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stats.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats > div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; }
.stats span { font-size: 13px; font-weight: 600; color: var(--muted); }
.stats strong { font-size: 20px; }
.stats strong.smalltext { font-size: 16px; line-height: 1.55; }
.good { color: var(--teal-dark); }
.bad { color: var(--bad); }

/* ---------- players ---------- */
.player { display: flex; align-items: center; gap: 8px; min-height: 54px; padding: 4px 6px 4px 14px; border-bottom: 1px solid var(--line-soft); }
.pill { min-width: 78px; height: 36px; border-radius: 18px; font-family: var(--body); font-size: 14px; font-weight: 700; cursor: pointer; }
.pill.paid { border: 0; background: var(--teal-soft); color: var(--teal-dark); }
.pill.unpaid { border: 2px solid var(--bad); background: #fff; color: var(--bad); }
.adder { padding: 4px 14px 14px; }
.adder summary, #scores summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--teal-dark); font-weight: 700; }
#scores summary { color: var(--navy); }
#scores details { display: flex; flex-direction: column; gap: 10px; }
#scores details > * + * { margin-top: 10px; }
.scoretable { width: 100%; border-collapse: collapse; }
.scoretable th { text-align: left; font-size: 14px; font-weight: 700; padding: 4px 6px 4px 0; }
.scoretable thead th { color: var(--muted); font-size: 13px; }
.scoretable td { padding: 4px 0 4px 8px; width: 30%; }
.scoretable input { height: 44px; padding: 0 8px; text-align: center; }

/* ---------- board ---------- */
.boardwrap { display: flex; flex-direction: column; gap: 4px; }
.boardrow { display: flex; gap: 4px; }
.axis { font-size: 12px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); text-align: center; }
.axis.top { padding-left: 20px; }
.axis.side { width: 16px; flex: 0 0 16px; display: flex; align-items: center; justify-content: center; }
.axis.side span { transform: rotate(-90deg); white-space: nowrap; }
.board { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 2px; }
.board.withnums { grid-template-columns: 20px repeat(10, minmax(0, 1fr)); }
.board form { display: contents; }
.num { display: flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 13px; min-height: 20px; }
.cell { aspect-ratio: 1; min-width: 0; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 4px; padding: 0; margin: 0;
  font-family: var(--body); font-size: 9.5px; font-weight: 600; line-height: 1; letter-spacing: -0.2px; overflow: hidden; white-space: nowrap; color: var(--muted); }
button.cell { cursor: pointer; }
.cell.open { background: #fff; border: 1.5px dashed #B7C2D0; }
.cell.taken { background: #E3E8EF; }
.cell.sel { background: #fff; border: 2.5px solid var(--teal-dark); color: var(--teal-dark); font-size: 16px; font-weight: 700; }
.cell.mine, .cell.hl { background: var(--teal); color: var(--navy); font-weight: 700; }
.cell.won { box-shadow: inset 0 0 0 2px var(--teal-dark); }
.cell.now { background: var(--navy); color: #fff; font-weight: 700; box-shadow: none; }
.cell.now.hl { box-shadow: inset 0 0 0 3px var(--teal); }
.cell.open.now { border: 0; }

.spots { display: flex; flex-direction: column; gap: 6px; }
.spot { display: flex; align-items: center; gap: 12px; min-height: 50px; width: 100%; padding: 0 10px; border-radius: 10px; background: #fff; border: 1px solid var(--line);
  font-family: var(--body); font-size: 16px; font-weight: 600; color: var(--navy); text-align: left; }
button.spot { cursor: pointer; }
.spot .digit { width: 34px; height: 34px; flex: 0 0 34px; border: 2px solid var(--navy); border-radius: 7px; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 18px; }
.spot .tag { font-size: 13px; font-weight: 700; color: var(--teal-dark); }
.spot.open { border-style: dashed; border-color: #B7C2D0; color: var(--muted); }
.spot.sel { border: 2px solid var(--teal-dark); }
.spot.mine, .spot.hl { background: var(--teal-soft); border-color: var(--teal-dark); }
.spot.won .tag { background: var(--teal-soft); border-radius: 6px; padding: 4px 8px; }
.spot.now { background: var(--navy); border-color: var(--navy); color: #fff; }
.spot.now .digit { background: var(--teal); border-color: var(--teal); color: var(--navy); }
.spot.now .tag { color: var(--teal); background: none; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.k { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.k.mine { background: var(--teal); }
.k.taken { background: #E3E8EF; }
.k.open { border: 1.5px dashed #B7C2D0; }
.k.now { background: var(--navy); }
.k.won { box-shadow: inset 0 0 0 2px var(--teal-dark); background: #E3E8EF; }

.pairs { display: flex; flex-wrap: wrap; gap: 6px; }
.pair { background: var(--bg); border-radius: 8px; padding: 5px 9px; font-size: 14px; font-weight: 600; }
.pair.hot { background: var(--teal-soft); }
.pair b { color: var(--teal-dark); font-weight: 700; }

/* ---------- scores and payouts ---------- */
.scorebar { background: var(--navy); color: #fff; border-radius: 12px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.scorebar .side { display: flex; flex-direction: column; }
.scorebar .side.right { text-align: right; }
.scorebar .side span { font-size: 14px; font-weight: 600; color: #C9D3E0; }
.scorebar .side strong { font-family: var(--display); font-weight: 400; font-size: 40px; line-height: 1.05; }
.scorebar .mid { font-size: 13px; font-weight: 700; letter-spacing: 1px; color: var(--teal); text-align: center; }
.payrow { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 14px; border-bottom: 1px solid var(--line-soft); }
.payrow:last-child { border-bottom: 0; }
.payrow .when { width: 44px; font-weight: 700; }
.payrow .score { width: 52px; color: var(--muted); }
.payrow .amt { font-weight: 700; color: var(--teal-dark); }
.payrow .muted { font-size: 14px; }
.total { display: flex; justify-content: space-between; min-height: 30px; align-items: center; font-weight: 600; }
.total strong { font-weight: 700; }

.bar { position: sticky; bottom: 0; margin: 0 -16px -32px; background: #fff; border-top: 1px solid var(--line); padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px; }
.bar .grow { display: flex; flex-direction: column; }
.bar span { font-size: 14px; color: var(--muted); }

/* ---------- TV mode ---------- */
.tvbody { background: #0B1422; }
.tv { min-height: 100vh; padding: 3vh 3vw; display: flex; gap: 3vw; align-items: flex-start; color: #fff; }
.tvboard { flex: 0 0 auto; width: min(58vw, 90vh); }
.tvpanel { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2vh; }
.tvhead { display: flex; align-items: baseline; justify-content: space-between; gap: 2vw; flex-wrap: wrap; }
.tvhead .wordmark { font-size: clamp(20px, 2.4vw, 40px); }
.tvpool { font-size: clamp(14px, 1.5vw, 24px); font-weight: 600; color: #C9D3E0; }
.tvcard { background: #16233A; border-radius: 14px; padding: 1.8vh 1.6vw; }
.tvcard.win { background: var(--teal); color: #0B1422; }
.tv .eyebrow { font-size: clamp(12px, 1.2vw, 18px); letter-spacing: 2px; color: var(--teal); }
.tvcard.win .eyebrow { color: #0B1422; }
.tvscore { display: flex; align-items: center; justify-content: space-between; margin-top: 0.6vh; }
.tvscore span { display: block; font-size: clamp(14px, 1.5vw, 24px); font-weight: 600; color: #C9D3E0; }
.tvscore strong { font-family: var(--display); font-weight: 400; font-size: clamp(40px, 5.4vw, 96px); line-height: 1; }
.tvscore .right { text-align: right; }
.tvscore .dash { font-size: 3vw; color: #5E6E86; }
.tvname { font-family: var(--display); font-size: clamp(28px, 3.6vw, 64px); line-height: 1.1; }
.tvjoin { font-family: var(--display); font-size: clamp(18px, 2vw, 34px); line-height: 1.2; word-break: break-all; }
.tvsmall { font-size: clamp(14px, 1.4vw, 22px); font-weight: 600; }
.tvrow { display: flex; justify-content: space-between; align-items: center; gap: 1vw; font-size: clamp(15px, 1.6vw, 26px); font-weight: 600; padding: 0.4vh 0; }
.tvrow strong { color: var(--teal); font-weight: 700; }
.tvbig { font-family: var(--display); font-weight: 400; font-size: clamp(28px, 3vw, 54px); }
.tv .axis { color: #C9D3E0; font-size: clamp(12px, 1.2vw, 20px); letter-spacing: 3px; }
.tv .axis.top { padding-left: calc(2.4vw + 26px); }
.tv .axis.side { width: 2vw; flex-basis: 2vw; }
.tv .board { gap: 0.35vw; }
.tv .board.withnums { grid-template-columns: 2.4vw repeat(10, minmax(0, 1fr)); }
.tv .num { color: #fff; font-size: clamp(14px, 1.7vw, 30px); min-height: 2.4vw; }
.tv .cell { font-size: clamp(9px, 1vw, 18px); border-radius: 6px; }
.tv .cell.taken { background: #16233A; color: #A9B6C8; }
.tv .cell.open { background: transparent; border: 1px dashed #2A3B55; }
.tv .cell.won { background: #13314A; color: #fff; box-shadow: inset 0 0 0 2px var(--teal); }
.tv .cell.now { background: var(--teal); color: #0B1422; font-weight: 700; box-shadow: 0 0 0 3px #fff; border: 0; }
.tv .spots { gap: 1vh; }
.tv .spot { background: #16233A; border-color: #16233A; color: #fff; min-height: 7.6vh; font-size: clamp(16px, 2vw, 34px); padding: 0 1.2vw; gap: 1.4vw; }
.tv .spot.open { background: transparent; border: 1px dashed #2A3B55; color: #8C9BB0; }
.tv .spot .digit { width: 5.6vh; height: 5.6vh; flex-basis: 5.6vh; border-color: #fff; font-size: clamp(16px, 2.2vw, 36px); }
.tv .spot.won { box-shadow: inset 0 0 0 2px var(--teal); }
.tv .spot.now { background: var(--teal); border-color: var(--teal); color: #0B1422; }
.tv .spot.now .digit { background: #0B1422; border-color: #0B1422; color: var(--teal); }
.tv .spot .tag { font-size: clamp(11px, 1.1vw, 18px); color: #0B1422; }

@media (max-width: 760px) {
  .tv { flex-direction: column; }
  .tvboard { width: 100%; }
  .tvpanel { width: 100%; }
}
