@font-face {
  font-family: "Bowlby One";
  src: url("fonts/bowlby-one-latin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Nunito Sans";
  src: url("fonts/nunito-sans-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #EBEFF6; --surface: #FFFFFF; --surface-2: #E2E8F2; --ink: #131A2C; --muted: #586379; --line: #D0D8E5;
  --accent: #2443CF; --accent-ink: #FFFFFF; --accent-soft: #DCE3FF;
  --bust: #C52F3B; --bust-soft: #FBE0E3;
  --gold: #9A6500; --gold-fill: #E8A512; --gold-ink: #241800; --gold-soft: #FFF1CC;
  --chip-l: 40%; --chip-s: 72%; --chip-fill-l: 44%;
  --shadow: 0 1px 0 rgba(19,26,44,.05), 0 10px 28px -16px rgba(19,26,44,.35);
  --display: "Bowlby One", "Arial Black", Impact, sans-serif;
  --body: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* With a Vengeance: the table turns red. */
:root[data-edition="vengeance"] {
  --accent: #B3202E; --accent-soft: #F9DCDF;
  --gold: #6E3FA3; --gold-fill: #7B47B5; --gold-ink: #FFFFFF; --gold-soft: #EEE3FA;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0D1220; --surface: #161E30; --surface-2: #1F2940; --ink: #EDF0F8; --muted: #98A2B8; --line: #2B3751;
    --accent: #8AA2FF; --accent-ink: #0D1220; --accent-soft: #232F55;
    --bust: #FF6D77; --bust-soft: #3A1C24;
    --gold: #F4BE45; --gold-fill: #F4BE45; --gold-ink: #1E1500; --gold-soft: #342A12;
    --chip-l: 68%; --chip-s: 80%; --chip-fill-l: 46%;
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 12px 30px -18px rgba(0,0,0,.8);
  }
  :root[data-edition="vengeance"] {
    --bg: #150D12; --surface: #21151C; --surface-2: #2E1D27; --line: #45293A;
    --accent: #FF7A85; --accent-ink: #1A0B10; --accent-soft: #4A1F2A;
    --gold: #C9A2F2; --gold-fill: #B98AEE; --gold-ink: #1A0B24; --gold-soft: #33203F;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--body); font-size: 15px; line-height: 1.45;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { max-width: 760px; margin: 0 auto; padding-inline: max(16px, env(safe-area-inset-left, 0px)); padding-block: 18px 56px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.app > *, .pk > * { min-width: 0; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 30px; letter-spacing: .01em; line-height: 1; }
.brand h1 span { display: inline-block; background: var(--accent); color: var(--accent-ink); padding: 2px 9px 0; border-radius: 7px; transform: rotate(-6deg); margin-left: 4px; }
.brand small { color: var(--muted); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 11px; }
.top-actions { display: flex; gap: 8px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; font-weight: 700; display: inline-flex; align-items: center; gap: 7px; min-height: 42px; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); border-color: transparent; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: transparent; }
.btn-warn { background: var(--bust-soft); color: var(--bust); border-color: transparent; }
.btn svg { width: 18px; height: 18px; flex: none; }

.panel { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; }
.panel h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 20px; letter-spacing: .01em; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }

.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.banner.win { background: var(--gold-soft); }
.banner.win strong { font-family: var(--display); font-weight: 400; font-size: 18px; }

/* standings */
.st-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.st-list { display: grid; gap: 14px; }
.st-row { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 5px; align-items: end; }
.st-name { font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.pill { font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; background: var(--gold-soft); color: var(--gold); }
.st-total { font-family: var(--display); font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; text-align: right; }
.st-total.neg { color: var(--bust); }
.st-bar { grid-column: 1 / -1; position: relative; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.st-bar .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 99px; }
.st-bar .live { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(-45deg, var(--accent) 0 3px, transparent 3px 6px); opacity: .55; }
.st-row.lead .st-bar .fill { background: var(--gold-fill); }
.st-row.lead .st-bar .live { background: repeating-linear-gradient(-45deg, var(--gold-fill) 0 3px, transparent 3px 6px); }
.st-meta { grid-column: 1 / -1; font-size: 13px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.st-meta b { color: var(--ink); font-variant-numeric: tabular-nums; }
.st-meta .bust { color: var(--bust); font-weight: 800; }

/* round */
.round-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; margin-bottom: 12px; scrollbar-width: thin; }
.tab { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 8px 6px 14px; display: flex; align-items: center; gap: 8px; font-weight: 700; }
.tab .ts { min-width: 34px; text-align: center; border-radius: 99px; background: var(--surface-2); padding: 2px 8px; font-variant-numeric: tabular-nums; font-size: 13px; }
.tab .ts.b { background: var(--bust-soft); color: var(--bust); }
.tab[aria-selected="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tab[aria-selected="true"] .ts { background: var(--accent); color: var(--accent-ink); }

.pk { border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; gap: 14px; }
.pk.is-bust { border-color: var(--bust); background: linear-gradient(var(--bust-soft), transparent 120px); }
.pk-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.pk-name { font-weight: 800; font-size: 18px; overflow-wrap: anywhere; }
.pk-break { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.pk-score { font-family: var(--display); font-size: 40px; line-height: .9; font-variant-numeric: tabular-nums; text-align: right; }
.pk-score.b { color: var(--bust); font-size: 28px; }
.pk-score.neg { color: var(--bust); }
.pk-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.btn[aria-pressed="true"].bust-t { background: var(--bust); color: #fff; border-color: transparent; }

.lbl { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.lbl .note { font-size: 12px; }
.dots { display: flex; gap: 4px; align-items: center; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.dots i.on { background: var(--accent); box-shadow: none; }
.dots.full i.on { background: var(--gold-fill); }
.f7 { font-family: var(--display); font-size: 12px; letter-spacing: .04em; color: var(--gold-ink); background: var(--gold-fill); padding: 2px 8px 1px; border-radius: 6px; margin-right: 4px; }

.nums { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.num { position: relative; aspect-ratio: 5 / 7; max-width: 100%; border-radius: 8px; border: 2px solid hsl(var(--h) var(--chip-s) var(--chip-l) / .38); background: var(--surface); color: hsl(var(--h) var(--chip-s) var(--chip-l)); font-family: var(--display); font-size: clamp(17px, 4.6vw, 26px); display: grid; place-items: center; padding: 0; transition: transform .12s ease, box-shadow .12s ease; }
.num::before, .num::after { content: attr(data-n); position: absolute; font-size: 8px; line-height: 1; opacity: .75; }
.num::before { top: 4px; left: 5px; }
.num::after { bottom: 4px; right: 5px; transform: rotate(180deg); }
.num:hover:not(:disabled) { border-color: hsl(var(--h) var(--chip-s) var(--chip-l)); }
.num[aria-pressed="true"] { background: hsl(var(--h) 68% var(--chip-fill-l)); border-color: transparent; color: #fff; transform: translateY(-3px); box-shadow: 0 6px 14px -8px hsl(var(--h) 70% 30%); }
.num:disabled { opacity: .3; cursor: not-allowed; }
.is-bust .num[aria-pressed="true"] { filter: grayscale(.7); opacity: .7; }

.extras { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-weight: 700; font-size: 13px; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--gold-fill); color: var(--gold-ink); border-color: transparent; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.hint strong { color: var(--ink); }

.mods { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.mod { border-radius: 8px; border: 2px dashed color-mix(in srgb, var(--gold) 45%, transparent); background: var(--surface); color: var(--gold); font-family: var(--display); font-size: clamp(14px, 3.8vw, 19px); min-height: 46px; padding: 0; }
.mod[aria-pressed="true"] { background: var(--gold-fill); color: var(--gold-ink); border-style: solid; border-color: transparent; }

.f7pick { display: grid; gap: 8px; background: var(--gold-soft); border-radius: 12px; padding: 12px; }
.f7pick .row { display: flex; gap: 8px; flex-wrap: wrap; }

.scan { display: flex; gap: 12px; align-items: flex-start; background: var(--surface-2); border-radius: 12px; padding: 10px; }
.scan img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; }
.scan p { margin: 0; font-size: 14px; }
.scan .x { margin-left: auto; flex: none; }
.scan.err { background: var(--bust-soft); }
.spin { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); border-right-color: transparent; animation: sp .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } .num { transition: none; } }

.round-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* history */
.hist-wrap { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; color: var(--muted); }
thead th { font-size: 12px; font-weight: 800; letter-spacing: .04em; }
td.b, td.neg { color: var(--bust); font-weight: 700; }
td.f { color: var(--gold); font-weight: 800; }
tfoot td { font-weight: 800; border-bottom: 0; font-size: 15px; color: var(--ink); }
.hist-foot { display: flex; justify-content: flex-end; margin-top: 10px; }

/* setup */
.setup { display: grid; gap: 14px; }
.setup h3 { margin: 4px 0 0; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.pl-row { display: flex; gap: 8px; }
.pl-row input, .field input, .key-row input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 12px; }
.field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.field input { flex: none; width: 96px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 10px 8px; font-weight: 800; line-height: 1.2; }
.seg button small { display: block; font-weight: 600; font-size: 12px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.key-row { display: flex; gap: 8px; flex-wrap: wrap; }
.setup-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.rules { font-size: 13px; color: var(--muted); max-width: 65ch; margin: 0; }
.ok { color: #1d7a4b; font-weight: 700; }
@media (prefers-color-scheme: dark) { .ok { color: #6fd3a0; } }

/* live card scanner */
body.scanning { overflow: hidden; }
.scanner {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 16px) max(16px, env(safe-area-inset-left, 0px));
}
.sc-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 17px; }
.sc-view { position: relative; min-height: 0; border-radius: 16px; overflow: hidden; background: #05070d; display: grid; place-items: center; }
.sc-view video { width: 100%; height: 100%; object-fit: cover; }
.sc-view.off video { display: none; }
/* the square matches the centre crop the model looks at */
.sc-frame { position: absolute; width: min(78%, 78vh); aspect-ratio: 1; max-width: 100%; border: 3px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(5,7,13,.35); pointer-events: none; }
.sc-view.off .sc-frame { display: none; }
.sc-guess { position: absolute; left: 12px; right: 12px; bottom: 12px; text-align: center; background: rgba(5,7,13,.72); color: #fff; font-weight: 800; border-radius: 12px; padding: 10px 12px; }
.sc-view.off .sc-guess { position: static; background: transparent; max-width: 36ch; }
.scanner.flash .sc-frame { animation: scflash .45s ease-out; }
@keyframes scflash { 0% { border-color: var(--gold-fill); transform: scale(1.04); } 100% { border-color: rgba(255,255,255,.9); transform: scale(1); } }
.sc-list { display: flex; flex-wrap: wrap; gap: 8px; min-height: 44px; align-content: flex-start; max-height: 30vh; overflow-y: auto; }
.sc-empty { margin: 0; color: var(--muted); font-size: 14px; }
.sc-chip { border: 0; min-width: 44px; min-height: 44px; padding: 0 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-family: var(--display); font-size: 20px; }
.sc-chip.mod { background: var(--gold-fill); color: var(--gold-ink); }
.sc-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.sc-foot .btn-primary { flex: 1 1 180px; justify-content: center; }
@media (prefers-reduced-motion: reduce) { .scanner.flash .sc-frame { animation: none; } }

/* manual score entry */
.pk-tools .scan-group { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.typed { display: grid; gap: 8px; }
.typed-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.typed-row input { width: 7ch; min-width: 0; border: 2px solid var(--accent); background: var(--bg); border-radius: 12px; padding: 8px 12px; font-family: var(--display); font-size: 32px; text-align: center; font-variant-numeric: tabular-nums; }
