/* Flipmeister — one stylesheet, no framework.
   Mobile portrait first; wider screens get a second column where it helps. */

/* ------------------------------------------------------------ tokens --- */
/* Dark is the native look and lives on :root. The light values are defined
   once as --l-* and mapped over the active tokens in two places: when the
   system asks for light and nothing overrides it, and when the user picks
   light outright. Picking dark needs no block, because the media rule skips
   [data-theme="dark"]. */
:root {
  color-scheme: dark;

  --bg:        #0d0a14;
  /* Softer glows: the old ones washed the corners light enough to eat the
     contrast of every small label sitting over them. */
  --glow-1:    #1e1739;
  --glow-2:    #2b1030;
  --surface:   #1a1530;
  --surface-2: #241d40;
  --surface-3: #2e2652;
  --line:      rgba(255, 255, 255, 0.10);
  --line-soft: rgba(255, 255, 255, 0.055);
  --wash:      rgba(255, 255, 255, 0.03);
  --wash-2:    rgba(255, 255, 255, 0.07);

  --text:  #f4f1ff;
  --soft:  #d9d3f0;
  --muted: #b4abd4;
  --faint: #948ab8;

  --primary:   #e11d48;
  --primary-2: #c94a12;
  --gold:      #ffc531;
  --gold-ink:  #ffc531;
  --green:     #2fd07a;
  --danger:    #ff4757;
  --violet:      #a06bff;
  --violet-fill: #6d3ad4;
  --neg-ink:   #ff8098;
  --err-ink:   #ffa8b1;
  --warn-ink:  #ffdf9e;

  /* Ring and tick on a selected card: white reads against a dark page. */
  --ring:      #ffffff;
  --ring-ink:  #15111f;

  --shadow:      0 10px 30px rgba(0, 0, 0, 0.45);
  --card-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  --card-lift:   0 6px 14px rgba(0, 0, 0, 0.5);

  /* ---- the light palette, defined once, applied below ---- */
  --l-bg:        #f4f1fa;
  --l-glow-1:    #ece5ff;
  --l-glow-2:    #ffeaf1;
  --l-surface:   #ffffff;
  --l-surface-2: #f4f0fa;
  --l-surface-3: #e6e0f2;
  --l-line:      rgba(28, 16, 56, 0.14);
  --l-line-soft: rgba(28, 16, 56, 0.08);
  --l-wash:      rgba(28, 16, 56, 0.035);
  --l-wash-2:    rgba(28, 16, 56, 0.08);

  --l-text:  #1b1430;
  --l-soft:  #382e54;
  --l-muted: #4f4670;
  --l-faint: #665d85;

  --l-primary:   #d4153f;
  --l-primary-2: #bf440f;
  --l-gold:      #ffc531;
  --l-gold-ink:  #845400;
  --l-green:     #0f7a42;
  --l-danger:    #cf2318;
  --l-violet:      #5f32c9;
  --l-violet-fill: #5f32c9;
  --l-neg-ink:   #99003f;
  --l-err-ink:   #a81e14;
  --l-warn-ink:  #6d4300;

  --l-ring:     #191130;
  --l-ring-ink: #ffffff;

  --l-shadow:      0 10px 28px rgba(40, 22, 80, 0.16);
  /* Cards keep the printed colours, so on a pale page they lean on a shadow
     and a hairline rim to separate from the background. */
  --l-card-shadow: 0 2px 6px rgba(30, 16, 62, 0.28), 0 0 0 1px rgba(30, 16, 62, 0.14);
  --l-card-lift:   0 8px 18px rgba(30, 16, 62, 0.34);

  --r-sm: 10px;
  --r:    16px;
  --r-lg: 22px;

  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --font: ui-rounded, "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system,
          Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: var(--l-bg); --glow-1: var(--l-glow-1); --glow-2: var(--l-glow-2);
    --surface: var(--l-surface); --surface-2: var(--l-surface-2); --surface-3: var(--l-surface-3);
    --line: var(--l-line); --line-soft: var(--l-line-soft);
    --wash: var(--l-wash); --wash-2: var(--l-wash-2);
    --text: var(--l-text); --soft: var(--l-soft); --muted: var(--l-muted); --faint: var(--l-faint);
    --primary: var(--l-primary); --primary-2: var(--l-primary-2);
    --gold: var(--l-gold); --gold-ink: var(--l-gold-ink);
    --green: var(--l-green); --danger: var(--l-danger);
    --violet: var(--l-violet); --violet-fill: var(--l-violet-fill);
    --neg-ink: var(--l-neg-ink); --err-ink: var(--l-err-ink); --warn-ink: var(--l-warn-ink);
    --ring: var(--l-ring); --ring-ink: var(--l-ring-ink);
    --shadow: var(--l-shadow); --card-shadow: var(--l-card-shadow); --card-lift: var(--l-card-lift);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: var(--l-bg); --glow-1: var(--l-glow-1); --glow-2: var(--l-glow-2);
  --surface: var(--l-surface); --surface-2: var(--l-surface-2); --surface-3: var(--l-surface-3);
  --line: var(--l-line); --line-soft: var(--l-line-soft);
  --wash: var(--l-wash); --wash-2: var(--l-wash-2);
  --text: var(--l-text); --soft: var(--l-soft); --muted: var(--l-muted); --faint: var(--l-faint);
  --primary: var(--l-primary); --primary-2: var(--l-primary-2);
  --gold: var(--l-gold); --gold-ink: var(--l-gold-ink);
  --green: var(--l-green); --danger: var(--l-danger);
  --violet: var(--l-violet); --violet-fill: var(--l-violet-fill);
  --neg-ink: var(--l-neg-ink); --err-ink: var(--l-err-ink); --warn-ink: var(--l-warn-ink);
  --ring: var(--l-ring); --ring-ink: var(--l-ring-ink);
  --shadow: var(--l-shadow); --card-shadow: var(--l-card-shadow); --card-lift: var(--l-card-lift);
}

/* -------------------------------------------------------------- reset --- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1000px 620px at 50% -12%, var(--glow-1) 0%, transparent 62%),
    radial-gradient(760px 520px at 100% 104%, var(--glow-2) 0%, transparent 60%);
  background-attachment: fixed;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

.app { max-width: 780px; margin: 0 auto; padding-bottom: calc(24px + var(--safe-b)); }
.screen { display: flex; flex-direction: column; gap: 22px; padding-bottom: 12px; }
/* Flex items default to min-width:auto, which lets a wide table push the whole
   page sideways instead of scrolling inside its own box. */
.screen > * { min-width: 0; }
.pad { padding-inline: var(--pad); }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
/* Edge fades on horizontal scrollers, switched on by fadeScroller() only when
   there is actually more content that way. */
.fade-end {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent);
}
.fade-start {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 34px), transparent);
  mask-image: linear-gradient(to left, #000 calc(100% - 34px), transparent);
}
.fade-start.fade-end {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 34px, #000 calc(100% - 34px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 34px, #000 calc(100% - 34px), transparent);
}

.center { text-align: center; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 10px; padding-inline: var(--pad); }

.hint { color: var(--muted); font-size: 0.86rem; padding-inline: var(--pad); }
.hint.center { text-align: center; }
.hint.version { font-family: ui-monospace, Consolas, monospace; font-size: 0.72rem; color: var(--faint); }

.section { display: flex; flex-direction: column; gap: 12px; }
.section-title {
  font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--faint); padding-inline: var(--pad);
}
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-inline: var(--pad);
}
.section-head .section-title { padding-inline: 0; }

/* ------------------------------------------------------------- topbar --- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 8px) 12px 10px;
  background: linear-gradient(to bottom, var(--bg) 62%, transparent);
  backdrop-filter: blur(10px);
}
.topbar-title { min-width: 0; text-align: center; }
.topbar-title h1 {
  font-size: 1.02rem; font-weight: 800; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-title p { font-size: 0.74rem; color: var(--muted); }
.topbar-actions { display: flex; gap: 4px; justify-content: flex-end; min-width: 44px; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.25rem; line-height: 1; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.sm { width: 36px; height: 36px; font-size: 1rem; }
.icon-btn.spacer { background: none; border: 0; pointer-events: none; }

/* ------------------------------------------------------------ buttons --- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 12px 20px;
  border-radius: var(--r); border: 1px solid transparent;
  font-weight: 800; font-size: 1rem; letter-spacing: 0.01em;
  transition: transform 0.1s, filter 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn.big { min-height: 58px; font-size: 1.06rem; }

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 8px 22px rgba(255, 46, 85, 0.3);
}
.btn.secondary { background: var(--surface-2); border-color: var(--line); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.danger { color: #fff; background: var(--danger); }
.danger-text { color: var(--danger); }

.sticky-foot {
  position: sticky; bottom: 0; z-index: 25;
  display: grid; gap: 10px;
  padding: 12px var(--pad) calc(12px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 58%, transparent);
}
.sticky-foot.two { grid-template-columns: 1fr 1.6fr; }
.sticky-foot.three { grid-template-columns: 48px minmax(0, 1fr) minmax(0, 1.5fr); }
.btn.back { min-height: 50px; padding: 0; font-size: 1.4rem; line-height: 1; }

/* --------------------------------------------------------------- home --- */
.brand { text-align: center; padding: 26px var(--pad) 2px; }
.brand-cards { display: flex; justify-content: center; gap: -8px; margin-bottom: 14px; height: 74px; }
.brand-card {
  width: 54px; height: 74px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 1.7rem; font-weight: 900; color: #fff;
  box-shadow: var(--shadow);
}
/* Each takes the ink its own colour can carry, the same way the cards do. */
.brand-card.bc0 { background: linear-gradient(160deg, #e0275a, #b01243); color: #fff; transform: rotate(-13deg) translateX(14px); }
.brand-card.bc1 { background: linear-gradient(160deg, #ffc531, #f59a0c); color: #3a2600; transform: translateY(-8px); z-index: 2; }
.brand-card.bc2 { background: linear-gradient(160deg, #47d9ff, #23a8e8); color: #04263a; transform: rotate(13deg) translateX(-14px); }
.brand-title { font-size: 2.1rem; font-weight: 900; letter-spacing: -0.02em; }
/* One word, two colours — no gap between the halves. */
.brand-title span { color: var(--primary); }
.brand-sub { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

.home-actions { display: flex; flex-direction: column; gap: 12px; padding-inline: var(--pad); }
.tile-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 14px 8px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); text-align: center;
}
.tile:active { transform: scale(0.97); }
.tile-icon { font-size: 1.35rem; }
.tile-label { font-weight: 700; font-size: 0.88rem; }
.tile-hint { font-size: 0.7rem; color: var(--faint); }

.resume {
  display: block; width: calc(100% - var(--pad) * 2); margin-inline: var(--pad);
  padding: 16px; border-radius: var(--r-lg); text-align: left;
  background: linear-gradient(150deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.resume:active { transform: scale(0.99); }
.resume-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.resume-round { margin-left: auto; font-size: 0.8rem; color: var(--muted); font-weight: 700; }
.resume-players { display: flex; flex-wrap: wrap; gap: 12px; }
.resume-player { display: flex; align-items: center; gap: 6px; }
.resume-score { font-weight: 900; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.resume-cta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft);
  color: var(--muted); font-size: 0.84rem;
}
.resume-arrow { font-size: 1.3rem; color: var(--text); }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--surface-3); color: var(--muted);
}
.badge.brutal { background: rgba(255, 46, 85, 0.16); color: var(--neg-ink); }
.badge.done { background: rgba(47, 208, 122, 0.14); color: var(--green); text-transform: none; letter-spacing: 0; }

/* --------------------------------------------------------------- list --- */
.list { display: flex; flex-direction: column; gap: 8px; padding-inline: var(--pad); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); text-align: left;
}
.row:active { transform: scale(0.99); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.row-avatars { display: flex; }
.row-avatars .avatar { margin-right: -10px; border: 2px solid var(--surface); }

.pickable .row.is-on { border-color: var(--primary); background: rgba(255, 46, 85, 0.09); }
.check {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--line); font-size: 0.8rem; font-weight: 900;
}
.check.is-on { background: var(--primary); border-color: var(--primary); color: #fff; }

.avatar {
  width: 38px; height: 38px; flex: 0 0 auto; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 900; color: var(--avatar-ink, #fff);
  background: linear-gradient(150deg, hsl(var(--hue) 68% 46%), hsl(calc(var(--hue) + 28) 66% 36%));
}
.avatar-sm { width: 28px; height: 28px; font-size: 0.66rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.05rem; }

.empty { text-align: center; padding: 40px var(--pad); color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.empty-icon { font-size: 2.4rem; }
.empty h3 { color: var(--text); font-size: 1.05rem; }
.empty p { font-size: 0.88rem; max-width: 30ch; }

/* ------------------------------------------------------------- inputs --- */
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-inline: var(--pad); }
.field-label { font-size: 0.84rem; color: var(--muted); font-weight: 600; }
.input {
  width: 100%; padding: 13px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
}
.input.num { width: 110px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }
.code-input {
  font-family: ui-monospace, Consolas, monospace; font-size: 0.72rem; line-height: 1.4;
  resize: vertical; word-break: break-all;
}
.select {
  padding: 9px 12px; border-radius: 999px; font-size: 0.84rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--line);
}

.segmented {
  display: flex; gap: 4px; padding: 4px; margin-inline: var(--pad);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.seg {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 9px 6px; border-radius: 12px; color: var(--muted); font-weight: 700; font-size: 0.86rem;
}
.seg.is-on { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg-hint { font-size: 0.64rem; color: var(--muted); font-weight: 600; }

.toggle {
  display: flex; align-items: center; gap: 12px; margin-inline: var(--pad);
  padding: 13px 14px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
}
.toggle.is-on { border-color: var(--primary); background: rgba(255, 46, 85, 0.07); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-text { flex: 1; display: flex; flex-direction: column; }
.toggle-label { font-weight: 700; }
.toggle-hint { font-size: 0.74rem; color: var(--muted); }
.toggle-track {
  width: 48px; height: 28px; flex: 0 0 auto; border-radius: 999px;
  background: var(--surface-3); transition: background 0.18s; position: relative;
}
.toggle.is-on .toggle-track { background: var(--primary); }
.toggle-knob {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.18s;
}
.toggle.is-on .toggle-knob { transform: translateX(20px); }

/* --------------------------------------------------------------- cards -- */
.card {
  --c: #6c6392;
  --ink: #fff;
  position: relative; display: grid; place-items: center;
  border-radius: 10px; font-weight: 900;
  color: var(--ink);
  background: var(--c);
  background-image: linear-gradient(158deg, var(--c), color-mix(in srgb, var(--c) 74%, #000));
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.2), var(--card-shadow);
  transition: transform 0.12s, box-shadow 0.15s, opacity 0.15s;
  user-select: none;
}
/* Slightly squatter than a real card, so four picker rows fit a phone. The
   numeral is sized against the card rather than the viewport, so "−10" fits
   whatever font the device happens to use. */
.card-pick {
  aspect-ratio: 5 / 6; width: 100%; min-width: 0;
  container-type: inline-size;
}
/* On the child, not the card: a container query length resolves against the
   nearest ancestor container, so cqw written on the container itself would
   measure the thing above it and behave like vw. */
.card-pick > .card-value { font-size: min(1.5rem, 46cqw); }
.card-chip { width: 42px; height: 50px; flex: 0 0 auto; font-size: 1.1rem; }
.card-value { line-height: 1; }

.card-tag {
  position: absolute; bottom: 4px; left: 0; right: 0;
  font-size: 0.5rem; font-weight: 900; letter-spacing: 0.02em; text-align: center;
  text-shadow: none; opacity: 0.94;
}
.card-chip .card-tag { font-size: 0.45rem; bottom: 3px; }

.card-check {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.68rem;
  background: var(--ring); color: var(--ring-ink); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.card.is-selected { transform: translateY(-3px); box-shadow: inset 0 0 0 2px var(--ring), var(--card-lift); }
.card.is-disabled { opacity: 0.26; filter: saturate(0.4); }
button.card:active:not(.is-disabled) { transform: scale(0.94); }

.tone-zero    { --c: #2f2a45; --ink: #fff; box-shadow: inset 0 0 0 1.5px #ff2e55, var(--card-shadow); }
.tone-unlucky { --c: #8e1026; --ink: #fff; box-shadow: inset 0 0 0 1.5px #ff6b7f, var(--card-shadow); }
.tone-lucky   { --c: #ffd34d; --ink: #3a2600; }
.tone-div     { --c: #8452f0; --ink: #fff; }
.tone-mul     { --c: #ffc531; --ink: #3a2600; }
.tone-plus    { --c: #2fd07a; --ink: #05301a; }
.tone-minus   { --c: #de2e45; --ink: #fff; }

/* Seven to a row everywhere, so a modifier is exactly as big as a number.
   minmax(0, 1fr) rather than 1fr: a plain 1fr will not shrink below the
   widest label, so on a system with wider fonts the row pushes the page
   sideways instead of the cards getting smaller. */
.card-grid {
  display: grid; gap: 6px; padding-inline: var(--pad);
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
@media (max-width: 351px) { .card-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

/* -------------------------------------------------------------- board --- */
.board-screen { gap: 14px; }
.score-cta { display: grid; gap: 8px; padding-inline: var(--pad); }
.score-cta-row { display: grid; grid-template-columns: minmax(0, 1fr) 58px; gap: 10px; }
.btn.square { min-height: 58px; padding: 0; font-size: 1.5rem; font-weight: 900; }

.banner {
  display: flex; align-items: center; gap: 10px; margin-inline: var(--pad);
  padding: 12px 14px; border-radius: var(--r); font-size: 0.88rem;
  background: rgba(255, 197, 49, 0.12); border: 1px solid rgba(255, 197, 49, 0.35);
}
.banner.done { background: rgba(47, 208, 122, 0.12); border-color: rgba(47, 208, 122, 0.35); }
.banner-icon { font-size: 1.3rem; }

/* The gutter lives on the wrapper so the fade sits at the table edge, not
   34px inside it. */
.board-wrap { padding-inline: var(--pad); }
.board-wrap .hint { padding-inline: 0; }
.board { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.score-table {
  /* Fixed layout keeps every player the same width; --cols sets the point at
     which the table gives up and scrolls sideways instead of squeezing. */
  table-layout: fixed; width: 100%;
  min-width: calc(46px + var(--cols, 4) * 58px);
  border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums;
}
.score-table th, .score-table td { padding: 8px 4px; text-align: center; }

/* The corner column stays put while a wide table scrolls sideways. Vertical
   stickiness is pointless here: .board is its own scroll container. */
.score-table thead th { background: var(--bg); }
.corner {
  position: sticky; left: 0; z-index: 2; background: var(--bg);
  width: 46px; min-width: 46px; text-align: left !important;
}
.row-label { font-size: 0.7rem; font-weight: 800; color: var(--faint); letter-spacing: 0.06em; }

.player-head { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.player-name {
  font-size: clamp(0.62rem, 2.6vw, 0.74rem); font-weight: 700; color: var(--muted);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.player-col.is-leader .player-name { color: var(--gold-ink); }

.totals td { padding-bottom: 12px; }
.total-value { display: block; font-size: clamp(1.05rem, 5vw, 1.65rem); font-weight: 900; letter-spacing: -0.03em; }
.total-cell.is-leader .total-value { color: var(--gold-ink); }
.total-bar { display: block; height: 3px; margin-top: 5px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.total-bar i { display: block; height: 100%; background: var(--primary); }
.total-cell.is-leader .total-bar i { background: var(--gold); }

.round-row { cursor: pointer; }
.round-row:nth-child(odd) td, .round-row:nth-child(odd) .corner { background: var(--wash); }
.round-row:active td { background: var(--wash-2); }
.cell { font-weight: 700; font-size: clamp(0.78rem, 3.4vw, 1rem); color: var(--muted); border-top: 1px solid var(--line-soft); }
.cell.is-pos { color: var(--text); }
.cell.is-neg { color: var(--neg-ink); }
.cell.is-bust { color: var(--faint); font-style: italic; }
.cell-value { display: block; }
.cell-marks { display: flex; gap: 3px; justify-content: center; margin-top: 2px; }
.mark {
  font-size: 0.56rem; font-weight: 900; padding: 1px 4px; border-radius: 4px;
  background: var(--surface-3); color: var(--muted);
}
.mark.flip7 { background: var(--gold); color: #2a1c00; }
.mark.zero { background: var(--surface-3); color: var(--neg-ink); }
.mark.hit { background: rgba(255, 46, 85, 0.2); color: var(--neg-ink); }

/* --------------------------------------------------------------- entry -- */
.score-screen { gap: 0; }
.entry { display: flex; flex-direction: column; gap: 10px; }
.entry-top {
  position: sticky; top: 0; z-index: 30;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: calc(var(--safe-t) + 8px) 12px 8px;
  background: linear-gradient(to bottom, var(--bg) 66%, transparent);
  backdrop-filter: blur(10px);
}
.entry-title { text-align: center; }
.entry-round { display: block; font-weight: 800; font-size: 0.95rem; }
.entry-step { display: block; font-size: 0.72rem; color: var(--muted); }

.pips { display: flex; gap: 6px; justify-content: center; padding-inline: var(--pad); }
.pip {
  /* 4px of paint, 20px of thumb: background-clip keeps the padding invisible. */
  width: 100%; max-width: 44px; height: 20px; padding-block: 8px;
  border-radius: 2px; background-clip: content-box;
  background-color: var(--surface-3); transition: background-color 0.2s;
}
.pip.is-done { background-color: var(--violet); }
.pip.is-on { background-color: var(--primary); }

.whose {
  display: flex; align-items: center; gap: 10px; margin-inline: var(--pad);
  padding: 8px 12px; border-radius: var(--r);
  background: linear-gradient(150deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
}
.whose-text { flex: 1; min-width: 0; }
.whose-text h2 { font-size: 1.05rem; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Fixed line box: the Flip 7 badge swaps in without nudging the picker. */
.whose-text p {
  display: flex; align-items: center; gap: 6px; height: 20px;
  font-size: 0.72rem; color: var(--muted);
}
.whose-text p.is-flip7 { color: var(--gold-ink); font-weight: 800; }
.whose-text .flip7-badge { font-size: 0.6rem; padding: 2px 7px; line-height: 1.2; }
.whose-score { text-align: right; line-height: 1; }
.whose-value { font-size: 1.85rem; font-weight: 900; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.whose-unit { display: block; font-size: 0.64rem; color: var(--faint); letter-spacing: 0.1em; text-transform: uppercase; }
.whose-score.is-pos .whose-value { color: var(--green); }
.whose-score.is-neg .whose-value { color: var(--neg-ink); }
.whose-score.is-bust .whose-value { color: var(--faint); }

/* Two rows, reserved whether or not they are filled: the picker must not
   shift downwards the moment a seventh card lands in the hand. */
.hand {
  --chip-h: 50px;
  --hand-pad: 8px;
  --hand-gap: 6px;
  display: flex; flex-direction: column; gap: var(--hand-gap);
  margin-inline: var(--pad); padding: var(--hand-pad);
  /* Two chip rows, the gap, the padding, and the 1px border on each side —
     box-sizing means min-height has to cover the border too. */
  min-height: calc(var(--chip-h) * 2 + var(--hand-gap) + var(--hand-pad) * 2 + 2px);
  border-radius: var(--r); background: var(--wash);
  border: 1px dashed var(--line);
}
.hand-row { display: flex; flex-wrap: wrap; gap: var(--hand-gap); min-width: 0; min-height: var(--chip-h); }
/* Numbers fill the top row from the left, modifiers sit bottom right. */
.hand-mods { justify-content: flex-end; align-items: flex-end; margin-top: auto; }
.hand.is-empty {
  justify-content: center; align-items: center; text-align: center;
  color: var(--faint); font-size: 0.84rem;
}

.bust-toggle {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 12px 10px;
  border-radius: var(--r);
  background: rgba(255, 71, 87, 0.12); border: 2px solid rgba(255, 71, 87, 0.5);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.bust-toggle:active { transform: scale(0.98); }
.bust-toggle.is-on { background: var(--danger); border-color: var(--danger); }
.bust-mark {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 900; font-size: 0.95rem;
  background: #fff; color: var(--danger);
}
.bust-mark:empty { display: none; }
.bust-label { font-weight: 900; letter-spacing: 0.08em; color: var(--neg-ink); }
.bust-toggle.is-on .bust-label { color: #fff; letter-spacing: 0.04em; }

.flip7-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  margin-inline: var(--pad); padding: 10px 14px; border-radius: var(--r);
  background: linear-gradient(140deg, rgba(255, 197, 49, 0.18), rgba(255, 138, 31, 0.08));
  border: 1px solid rgba(255, 197, 49, 0.42);
}

.flip7-badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--gold); color: #2a1c00; font-weight: 900; font-size: 0.7rem; letter-spacing: 0.1em;
}
.flip7-choice {
  display: flex; flex-wrap: nowrap; gap: 6px; flex-basis: 100%;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; padding-bottom: 2px;
}
.flip7-choice::-webkit-scrollbar { display: none; }
.chip-btn { white-space: nowrap; flex: 0 0 auto; }
.chip-btn {
  padding: 8px 13px; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.chip-btn.is-on { background: var(--gold); border-color: var(--gold); color: #2a1c00; }

.issues { display: grid; gap: 6px; padding-inline: var(--pad); }
.issue {
  padding: 9px 12px; border-radius: var(--r-sm); font-size: 0.8rem;
  background: rgba(255, 197, 49, 0.1); border: 1px solid rgba(255, 197, 49, 0.3); color: var(--warn-ink);
}
.issue.error { background: rgba(255, 71, 87, 0.12); border-color: rgba(255, 71, 87, 0.35); color: var(--err-ink); }
.issue.warn { margin-inline: var(--pad); }

.entry-cols { display: flex; flex-direction: column; gap: 10px; }
.entry-side, .entry-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.picker { display: flex; flex-direction: column; gap: 12px; }
.picker-row { display: flex; flex-direction: column; gap: 6px; }
.picker-label {
  display: flex; align-items: center; gap: 8px; padding-inline: var(--pad);
  font-size: 0.7rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; color: var(--faint);
}
.picker-locked { font-size: 0.6rem; color: var(--danger); letter-spacing: 0.06em; }

.breakdown {
  margin-inline: var(--pad); padding: 0 14px 4px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.breakdown:not([open]) { border-color: var(--line-soft); background: transparent; }
.breakdown > summary {
  list-style: none; cursor: pointer; padding: 10px 0;
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint);
}
.breakdown > summary::-webkit-details-marker { display: none; }
.bd-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 0.86rem; border-top: 1px solid var(--line-soft); }
.bd-label { color: var(--muted); }
.bd-value { font-weight: 800; }
.bd-row.flip7 .bd-value { color: var(--gold-ink); }
.bd-row.bust .bd-value, .bd-row.zero .bd-value { color: var(--neg-ink); }
.bd-row.minus .bd-value { color: var(--neg-ink); }
.bd-row.plus .bd-value { color: var(--green); }

/* ------------------------------------------------------------ summary --- */
.summary-list { display: flex; flex-direction: column; gap: 8px; padding-inline: var(--pad); }
.summary-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); text-align: left;
}
.summary-main { flex: 1; min-width: 0; }
.summary-name { display: block; font-weight: 700; }
.summary-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tag {
  font-size: 0.62rem; font-weight: 800; padding: 2px 6px; border-radius: 5px;
  background: var(--surface-3); color: var(--muted); letter-spacing: 0.04em;
}
.tag.bust { background: rgba(255, 71, 87, 0.18); color: var(--neg-ink); }
.tag.flip7 { background: var(--gold); color: #2a1c00; }
.tag.zero { background: var(--surface-3); color: var(--muted); }
.tag.hit { background: rgba(255, 46, 85, 0.2); color: var(--neg-ink); }
.summary-delta { font-weight: 900; font-size: 1.1rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.summary-delta.is-pos { color: var(--green); }
.summary-delta.is-neg { color: var(--neg-ink); }
.summary-total {
  min-width: 52px; text-align: right; font-weight: 900; font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------- rules --- */
.basics { margin-inline: var(--pad); }
.basics > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); font-weight: 800; font-size: 0.9rem;
}
.basics > summary::-webkit-details-marker { display: none; }
.basics > summary::after { content: " +"; color: var(--violet); }
.basics[open] > summary { border-radius: var(--r) var(--r) 0 0; }
.basics[open] > summary::after { content: " −"; }
.basics .core { padding-inline: 0; padding-top: 10px; }
.core { display: grid; gap: 10px; padding-inline: var(--pad); }
.core-block { padding: 13px 15px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.core-block h3 { font-size: 0.88rem; font-weight: 800; margin-bottom: 6px; }
.core-block li { font-size: 0.83rem; color: var(--muted); padding-left: 14px; position: relative; margin-top: 4px; }
.core-block li::before { content: "·"; position: absolute; left: 3px; color: var(--violet); font-weight: 900; }

.ref-list { display: flex; flex-direction: column; gap: 8px; padding-inline: var(--pad); }
.ref { border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.ref.is-open { border-color: var(--violet); }
.ref-head { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; }
.ref-glyph {
  width: 42px; height: 56px; flex: 0 0 auto; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface-3); font-weight: 900; font-size: 1.2rem; color: var(--muted);
}
.ref-main { flex: 1; min-width: 0; }
.ref-name { display: block; font-weight: 800; }
.ref-sub { display: block; font-size: 0.79rem; color: var(--muted); }
.ref-caret { font-size: 1.3rem; color: var(--faint); }
.ref-body { padding: 0 14px 14px; display: grid; gap: 12px; }
.ref-copies { font-size: 0.7rem; color: var(--faint); letter-spacing: 0.08em; text-transform: uppercase; font-weight: 800; }
.ref-steps { counter-reset: s; display: grid; gap: 7px; }
.ref-steps li {
  counter-increment: s; position: relative; padding-left: 28px; font-size: 0.85rem; color: var(--soft);
}
.ref-steps li::before {
  content: counter(s); position: absolute; left: 0; top: 1px;
  width: 19px; height: 19px; border-radius: 50%; display: grid; place-items: center;
  background: var(--violet-fill); color: #fff; font-size: 0.64rem; font-weight: 900;
}
.ref-notes li { font-size: 0.8rem; color: var(--muted); padding-left: 16px; position: relative; margin-top: 5px; }
.ref-notes li::before { content: "!"; position: absolute; left: 2px; color: var(--gold-ink); font-weight: 900; }

.targeting { padding: 11px 13px; border-radius: var(--r-sm); background: var(--wash); }
.targeting h4 { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); margin-bottom: 8px; }
.target-grid { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; align-items: center; }
.target-grid dt { font-size: 0.83rem; color: var(--muted); }
.target-grid dd { font-size: 0.74rem; font-weight: 900; }
.yes { color: var(--green); }
.no { color: var(--danger); }
.na { color: var(--faint); }
.target-note { font-size: 0.78rem; color: var(--muted); margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line-soft); }

.notes { display: grid; gap: 7px; padding-inline: var(--pad); }
.notes li { font-size: 0.83rem; color: var(--muted); padding-left: 16px; position: relative; }
.notes li::before { content: "→"; position: absolute; left: 0; color: var(--violet); }

/* ------------------------------------------------------------ overlays -- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(6, 4, 12, 0.66); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity 0.18s;
}
.overlay.show { opacity: 1; }
.sheet {
  width: min(460px, 100%);
  display: grid; gap: 12px;
  padding: 22px var(--pad) calc(22px + var(--safe-b));
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  transform: translateY(14px); transition: transform 0.2s;
}
.overlay.show .sheet { transform: none; }
.sheet h2 { font-size: 1.1rem; font-weight: 900; }
.sheet p { font-size: 0.86rem; color: var(--muted); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.menu-sheet { gap: 6px; }
.menu-item {
  padding: 14px; border-radius: var(--r-sm); text-align: left; font-weight: 700;
  background: var(--surface-2);
}
.menu-item:disabled { opacity: 0.35; pointer-events: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); z-index: 200;
  transform: translate(-50%, 18px);
  padding: 12px 20px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 0.88rem; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: #6b1226; border-color: #a6203c; }
.toast.win { background: #7a5a00; border-color: var(--gold); }

/* --------------------------------------------------------- wide screens - */
@media (min-width: 720px) {
  :root { --pad: 24px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
  .brand { padding-top: 40px; }
  .brand-title { font-size: 2.6rem; }
  .player-name { font-size: 0.8rem; }
  .total-value { font-size: 1.9rem; }
}

/* Tablet in landscape: score panel down the left, card grid takes the room.
   display:contents flattens the two phone columns so the breakdown can sit
   with the score panel instead of trailing the grid. */
@media (min-width: 860px) and (orientation: landscape) {
  .app { max-width: 1040px; }
  .entry-cols {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    column-gap: 22px; row-gap: 10px;
    align-items: start;
    padding-inline: var(--pad);
  }
  .entry-side, .entry-main { display: contents; }

  /* Drop the page gutter only; these boxes keep their own inner padding. */
  .entry-cols > * > .whose,
  .entry-cols > * > .hand,
  .entry-cols > * > .flip7-box,
  .entry-cols > * > .issues,
  .entry-cols > * > .breakdown { grid-column: 1; margin-inline: 0; }
  .entry-cols > * > .issues { padding-inline: 0; }

  /* Span every implicit row so the grid stays pinned to the top right. */
  .entry-cols > * > .picker { grid-column: 2; grid-row: 1 / span 30; align-self: start; }
  .entry-cols .card-grid {
    grid-template-columns: repeat(7, minmax(0, 84px));
    justify-content: start; padding-inline: 0;
  }
  .entry-cols .picker-label { padding-inline: 0; }

  .sticky-foot.two { grid-template-columns: 200px minmax(0, 1fr); }
  .sticky-foot.three { grid-template-columns: 70px 200px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
