/* ============================================================
   Tumblin' Dice — a bright, chunky, toy-shop score keeper.
   Glossy primary-colour dice, fat rounded cards, satisfying
   press-down buttons. Built to feel like a Fisher-Price toy.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --cream:     #fdf6e3;
  --cream-2:   #f6e9c4;
  --paper:     #ffffff;
  --ink:       #41342a;
  --ink-2:     #766654;
  --ink-3:     #857761;

  --red:       #ef4d44;
  --red-d:     #cd362e;
  --blue:      #2f93d8;
  --blue-d:    #2278b6;
  --green:     #54bb46;
  --green-d:   #429a37;
  --yellow:    #ffc62e;
  --yellow-d:  #e7a514;
  --plum:      #8a6cf0;

  --card-edge: #ead9ad;
  --soft:      rgba(108,82,38,0.26);

  --ease:      cubic-bezier(.32,.72,0,1);
  --spring:    cubic-bezier(.34,1.46,.5,1);
}

html, body { height: 100%; }

body {
  color: var(--ink);
  font-family: 'Fredoka', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  background-color: var(--cream);
  background-image:
    radial-gradient(ellipse 120% 60% at 50% -8%, #fffaee, transparent 66%),
    radial-gradient(circle at 50% 110%, #fbeecb, transparent 60%),
    radial-gradient(var(--cream-2) 2.1px, transparent 2.6px);
  background-size: auto, auto, 40px 40px;
  background-position: 0 0, 0 0, 0 0;
  background-attachment: fixed;
}

::selection { background: var(--yellow); color: var(--ink); }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 10px; }

.num { font-variant-numeric: tabular-nums; }

/* ============ SHELL ============ */
.app {
  max-width: 560px; margin: 0 auto;
  padding: max(30px, calc(env(safe-area-inset-top, 0px) + 10px)) 16px
    calc(26px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
}

/* Capacitor's iPhone WKWebView reports a zero top safe-area inset here. */
.native-ios-phone .app { padding-top: 72px; }

/* ============ TOPBAR ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 11px; }
/* the brand mark — the app's 3D-die icon; tumbles when tapped */
.brand-logo {
  width: 42px; height: 40px;
  flex-shrink: 0;
  border: none; background: none; padding: 0;
  cursor: pointer;
  display: grid; place-items: center;
  perspective: 460px;
}
.brand-logo img {
  width: 40px; height: 40px;
  display: block;
  filter: drop-shadow(0 3px 4px rgba(70,52,20,0.26));
  -webkit-user-select: none; user-select: none;
}
.brand-logo.roll img { animation: brandRoll .8s var(--spring); }
@keyframes brandRoll {
  0%   { transform: rotateY(0) scale(1); }
  48%  { transform: rotateY(180deg) scale(1.13); }
  100% { transform: rotateY(360deg) scale(1); }
}
.brand-name {
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.iconbtn {
  width: 46px; height: 46px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 15px;
  border: none;
  color: var(--ink-2);
  cursor: pointer;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--card-edge), 0 7px 12px -4px var(--soft);
  transition: transform .1s var(--ease), box-shadow .1s var(--ease);
}
.iconbtn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--card-edge), 0 3px 6px -3px var(--soft);
}
.iconbtn svg { width: 21px; height: 21px; }
.demobtn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 46px; padding: 0 15px;
  border: none; border-radius: 15px;
  color: var(--ink-2); cursor: pointer;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--card-edge), 0 7px 12px -4px var(--soft);
  transition: transform .1s var(--ease), box-shadow .1s var(--ease);
  font-family: inherit; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.demobtn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--card-edge), 0 3px 6px -3px var(--soft);
}
.demobtn svg { width: 18px; height: 18px; }
@media (max-width: 560px) {
  .demobtn { width: 46px; padding: 0; justify-content: center; }
  .demobtn-label { display: none; }
}

/* first-visit nudge bubble that points at the "See demo" button */
.demo-nudge {
  position: fixed; z-index: 60;
  border: none; cursor: pointer;
  background: var(--yellow); color: var(--ink);
  font-family: inherit; font-weight: 600; font-size: 13.5px;
  padding: 10px 14px; border-radius: 13px;
  box-shadow: 0 3px 0 var(--yellow-d), 0 11px 22px -7px var(--soft);
  transform-origin: 82% -10px;
  animation: demo-nudge-pop .42s cubic-bezier(.34,1.56,.64,1) both,
             demo-nudge-bob 2.8s ease-in-out .6s infinite;
}
.demo-nudge.leaving { animation: demo-nudge-out .2s ease forwards; }
.demo-nudge-txt { position: relative; }
.demo-nudge-tail {
  position: absolute; top: -5px; left: var(--tail-x, 80%);
  width: 12px; height: 12px; margin-left: -6px;
  background: var(--yellow); border-radius: 3px 0 0 0;
  transform: rotate(45deg);
}
@keyframes demo-nudge-pop {
  from { opacity: 0; transform: scale(.55) translateY(-12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes demo-nudge-out {
  to { opacity: 0; transform: scale(.85) translateY(-6px); }
}
@keyframes demo-nudge-bob {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 3px; }
}
.demobtn.nudging { animation: demo-btn-pulse 1.5s var(--ease) infinite; }
@keyframes demo-btn-pulse {
  0%, 100% { box-shadow: 0 4px 0 var(--card-edge), 0 7px 12px -4px var(--soft), 0 0 0 0 rgba(255,198,46,.6); }
  55%      { box-shadow: 0 4px 0 var(--card-edge), 0 7px 12px -4px var(--soft), 0 0 0 9px rgba(255,198,46,0); }
}
@media (prefers-reduced-motion: reduce) {
  .demo-nudge { animation: demo-nudge-fade .25s ease both; }
  .demobtn.nudging { animation: none; }
}
@keyframes demo-nudge-fade { from { opacity: 0; } to { opacity: 1; } }

/* ============ HERO ============ */
.hero { margin-bottom: 20px; padding: 0 4px; }
.hero-eyebrow {
  display: inline-flex; align-items: center;
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink);
  background: var(--yellow);
  padding: 5px 12px 4px;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--yellow-d);
  margin-bottom: 13px;
}
.hero-title {
  font-weight: 600;
  font-size: clamp(26px, 7vw, 34px);
  line-height: 1.14;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.hero-title .soft { color: var(--ink-3); }
/* the first-visit instruction line — smaller so the hero stays three lines */
.hero-title .hero-sub { font-size: 0.72em; }
.hero-title .pop  { color: var(--red); }
/* the leader sentence — sized down so it sits on a single line on a phone */
.hero-title .hero-lead { font-size: 0.72em; }
.hero-title.swap { animation: heroSwap .42s var(--spring); }
@keyframes heroSwap {
  0% { opacity: 0; transform: translateY(8px) scale(.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============ BOARD / TILES ============ */
.board { display: flex; flex-direction: column; gap: 13px; }

/* A team tile = a fat glossy card. */
.tile {
  --team: #ef4d44;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  padding: 13px 14px;
  border-radius: 24px;
  background: var(--paper);
  box-shadow:
    0 5px 0 color-mix(in srgb, var(--team) 76%, #000),
    0 14px 22px -10px var(--soft);
  animation: tileIn .52s var(--spring) both;
  animation-delay: calc(var(--i,0) * 60ms);
  transition: transform .14s var(--spring), box-shadow .14s var(--ease);
}
@keyframes tileIn {
  0% { opacity: 0; transform: translateY(20px) scale(.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.tile:active { transform: scale(0.985); }

/* leader — sunny ring, lifted, a gold star pinned to the corner */
.tile.leader {
  background: linear-gradient(180deg, #fff7d8 0%, var(--paper) 58%);
  box-shadow:
    0 0 0 3.5px var(--yellow),
    0 5px 0 var(--yellow-d),
    0 16px 26px -10px rgba(160,110,20,0.5);
}
/* rank medal — the competitive standing, pinned to each card */
.tile-rank {
  position: absolute; top: -10px; left: -10px; z-index: 5;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-weight: 700; font-size: 14.5px;
  font-variant-numeric: tabular-nums;
  background: var(--paper);
  color: var(--ink-2);
  box-shadow: 0 3px 0 var(--card-edge), 0 6px 9px -3px var(--soft);
  animation: rankPop .42s var(--spring) both;
}
@keyframes rankPop {
  0% { transform: scale(0) rotate(-30deg); }
  100% { transform: scale(1) rotate(0); }
}
.tile-rank.r1 {
  background: linear-gradient(180deg, #ffe07a, #f3b821);
  color: #6a4607;
  box-shadow: 0 3px 0 #cd8f10, 0 7px 11px -3px rgba(170,115,10,0.55);
  overflow: hidden;
}
.tile-rank.r1::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 38%, rgba(255,255,255,0.8) 50%, transparent 62%);
  transform: translateX(-130%);
  animation: medalShine 3.6s ease-in-out 1.2s infinite;
  pointer-events: none;
}
@keyframes medalShine {
  0%, 16% { transform: translateX(-130%); }
  34%, 100% { transform: translateX(130%); }
}
.tile-rank.r2 {
  background: linear-gradient(180deg, #eef1f4, #c2c9d1);
  color: #4c525b;
  box-shadow: 0 3px 0 #969da6, 0 7px 11px -3px rgba(90,95,105,0.45);
}
.tile-rank.r3 {
  background: linear-gradient(180deg, #f2ad7e, #d2814a);
  color: #fff;
  box-shadow: 0 3px 0 #a8632f, 0 7px 11px -3px rgba(150,85,40,0.45);
}

/* ----- the team die: a glossy 3D cube ----- */
.die3d {
  width: 66px; height: 66px;
  flex-shrink: 0;
  position: relative;
  border: none; background: none; padding: 0; margin: 0;
  cursor: pointer;
  display: grid; place-items: center;
  perspective: 360px;
}
.die3d::after {
  content: ''; position: absolute;
  left: 50%; bottom: 5px;
  width: 50px; height: 13px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(70,52,20,0.32), transparent 72%);
  filter: blur(2.5px);
  z-index: 0;
}
.die3d .cube {
  position: relative; z-index: 1;
  width: 44px; height: 44px;
  transform-style: preserve-3d;
  transform: rotateX(-23deg) rotateY(-33deg);
  transition: transform .6s var(--spring);
}
.die3d:active .cube { transform: rotateX(-23deg) rotateY(-393deg); }
.die3d .face {
  position: absolute; inset: 0;
  border-radius: 13px;
  /* a faint edge keeps light-coloured cubes from melting into the card */
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.11);
}
.die3d .top {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 7px;
  transform: rotateX(90deg) translateZ(22px);
  background:
    radial-gradient(circle at 30% 24%, rgba(255,255,255,0.92), rgba(255,255,255,0) 48%),
    linear-gradient(150deg, color-mix(in srgb, var(--team) 72%, #fff), var(--team));
}
.die3d .ft {
  transform: translateZ(22px);
  background: linear-gradient(165deg,
    color-mix(in srgb, var(--team) 92%, #fff) 0%,
    color-mix(in srgb, var(--team) 84%, #000) 100%);
}
.die3d .rt {
  transform: rotateY(90deg) translateZ(22px);
  background: linear-gradient(165deg,
    color-mix(in srgb, var(--team) 76%, #000) 0%,
    color-mix(in srgb, var(--team) 62%, #000) 100%);
}
/* ----- logo-style team die — the score-table header tokens ----- */
/* a glossy rounded-square die matching the app icon, recoloured per team;
   it bobs and sways gently so the header feels alive */
.logo-die {
  width: 44px; height: 44px;
  flex-shrink: 0;
  background: none; padding: 0;
}
.logo-die .ld-face {
  position: absolute; inset: 0;
  border-radius: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 6px;
  background:
    radial-gradient(132% 120% at 30% 22%,
      color-mix(in srgb, var(--team) 30%, #fff) 0%,
      var(--team) 56%,
      color-mix(in srgb, var(--team) 66%, #000) 100%);
  box-shadow:
    inset 0 2px 1.5px rgba(255,255,255,0.62),
    inset 0 -4px 7px rgba(0,0,0,0.32),
    inset 0 0 0 1px rgba(0,0,0,0.07),
    0 4px 8px -2px rgba(70,52,20,0.5);
  animation: logoDieFloat 4.6s ease-in-out infinite;
}
/* the sheen — a soft white ellipse upper-left, like the icon's gloss */
.logo-die .ld-face::before {
  content: ''; position: absolute;
  left: 13%; top: 9%; width: 54%; height: 38%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 42% 40%,
    rgba(255,255,255,0.82), rgba(255,255,255,0) 72%);
  pointer-events: none; z-index: 2;
}
.logo-die .pip { position: relative; z-index: 1; }
.logo-die:hover { transform: translateY(-3px) scale(1.05); }
@keyframes logoDieFloat {
  0%, 100% { transform: translateY(1.5px) rotate(-3.6deg); }
  50%      { transform: translateY(-2.5px) rotate(3.6deg); }
}
@media (prefers-reduced-motion: reduce) {
  .logo-die .ld-face { animation: none; transform: rotate(-2.5deg); }
}

/* calibration badge — a team whose dice photo is saved */
.cal-badge {
  position: absolute; z-index: 3;
  top: 1px; right: 1px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: linear-gradient(180deg, #69c95c, var(--green) 65%);
  box-shadow: 0 2px 0 var(--green-d), 0 0 0 2.5px var(--paper);
}
.cal-badge::after {
  content: ''; position: absolute;
  left: 5px; top: 6px;
  width: 7px; height: 3.5px;
  border-left: 2.2px solid #fff; border-bottom: 2.2px solid #fff;
  transform: rotate(-45deg);
}

/* tap cue — signals the team die is tappable (recolour + dice scanner) */
.die-edit-cue {
  position: absolute; z-index: 3;
  bottom: -3px; right: -3px;
  width: 21px; height: 21px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-3);
  box-shadow: 0 2px 0 var(--card-edge), 0 0 0 2.5px var(--paper), 0 4px 7px -3px var(--soft);
}
.die-edit-cue svg { width: 11px; height: 11px; }
.die3d:active .die-edit-cue { transform: translateY(1px); }

/* ----- flat dice (mini roll + review) ----- */
.die {
  flex-shrink: 0;
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  background:
    radial-gradient(circle at 32% 26%, rgba(255,255,255,0.85), rgba(255,255,255,0) 52%),
    linear-gradient(150deg, color-mix(in srgb, var(--team) 74%, #fff), var(--team));
  box-shadow: 0 2px 4px -1px rgba(70,52,20,0.4), inset 0 0 0 1px rgba(0,0,0,0.06);
}
.die.sm { width: 34px; height: 34px; border-radius: 10px; padding: 6px; cursor: default; }
.die.xs { width: 21px; height: 21px; border-radius: 7px; padding: 4px; cursor: default; }
.pip {
  align-self: center; justify-self: center;
  width: 74%; aspect-ratio: 1;
  border-radius: 50%;
  background: var(--pip, #fff);
  box-shadow: 0 1.5px 2px rgba(0,0,0,0.28), inset 0 -1px 1px rgba(0,0,0,0.12);
}
.die.xs .pip { box-shadow: 0 1px 1px rgba(0,0,0,0.3); }

/* identity */
.tile-id { min-width: 0; }
.tile-name {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px dashed transparent;
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.012em;
  padding: 2px 0 3px;
  transition: border-color .18s var(--ease);
}
.tile-name:focus { border-bottom-color: var(--ink-3); }
.tile-name::placeholder { color: var(--ink-3); }
.tile-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 5px;
  font-size: 12px; font-weight: 500;
  color: var(--ink-2);
}
.tile-meta > span { color: var(--ink-3); }
.tile-mini-dice { display: flex; gap: 4px; }
.tile-x {
  margin-left: auto;
  background: none; border: none;
  color: var(--ink-3);
  font-size: 19px; line-height: 1;
  cursor: pointer; padding: 3px 6px;
  opacity: 0;
  transition: opacity .18s var(--ease), color .15s var(--ease);
}
.tile:hover .tile-x { opacity: 1; }
.tile-x:hover { color: var(--red); }
@media (hover: none) { .tile-x { opacity: 0.55; } }

/* score chip */
.tile-score {
  flex-shrink: 0;
  min-width: 76px;
  padding: 8px 13px 9px;
  border-radius: 17px;
  text-align: center;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.09), inset 0 -3px 0 rgba(120,90,30,0.07);
}
.tile-total {
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  display: block;
}
.tile.leader .tile-score {
  background: var(--yellow);
  box-shadow: inset 0 -3px 0 var(--yellow-d);
}
.tile.leader .tile-total { font-size: 34px; color: #5a3d0c; }
.tile.zero .tile-total { color: var(--ink-3); }
.tile-total.bump { animation: bump .6s var(--spring); }
@keyframes bump {
  0% { transform: scale(1); } 36% { transform: scale(1.22); } 100% { transform: scale(1); }
}
.tile-delta {
  display: block;
  font-weight: 600;
  font-size: 11.5px;
  margin-top: 2px;
}
.tile-delta.up   { color: var(--green-d); }
.tile-delta.down { color: var(--red); }

/* ============ BOARD FOOT ============ */
.board-foot { margin-top: 16px; display: flex; flex-direction: column; gap: 11px; align-items: flex-start; }
.addteam {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--paper);
  border: none;
  color: var(--ink-2);
  font-family: inherit;
  font-weight: 600; font-size: 14.5px;
  padding: 11px 18px;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--card-edge), 0 8px 13px -5px var(--soft);
  transition: transform .1s var(--ease), box-shadow .1s var(--ease);
}
.addteam:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--card-edge), 0 4px 7px -4px var(--soft);
}
.addteam svg { width: 15px; height: 15px; color: var(--green); }
.board-foot-hint {
  font-size: 12px; color: var(--ink-3);
  padding-left: 4px;
}

/* ============ HISTORY ============ */
.history { margin-top: 6px; }
.history-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 11px;
  padding: 0 4px;
}
.history-head h2 {
  font-weight: 600; font-size: 17px;
  color: var(--ink);
}
.history-head button {
  background: none; border: none;
  color: var(--ink-3); font-size: 13px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.history-head button:hover { color: var(--red); }
/* the score table — every round tracked, totals across the bottom */
.stable-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--card-edge), 0 12px 22px -10px var(--soft);
}
.stable {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}
.stable th, .stable td {
  padding: 10px 11px;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
/* header — one column per team */
.stable thead th {
  font-weight: 600; font-size: 12.5px;
  color: var(--ink-2);
  padding-top: 13px; padding-bottom: 11px;
  border-bottom: 2px solid var(--cream-2);
}
.stable-corner {
  position: sticky; left: 0; z-index: 3;
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  background: var(--paper);
}
.stable-team { min-width: 78px; }
/* <=4 teams: a fixed layout fits every column on screen, no sideways scroll */
.stable.fit { table-layout: fixed; }
.stable.fit .stable-corner { width: 52px; }
.stable.fit .stable-team { min-width: 0; }
/* 5+ teams: shrink everything so the columns fit phone width without scroll */
.stable.compact { font-size: 12px; }
.stable.compact th, .stable.compact td { padding: 7px 4px; }
.stable.compact .stable-corner { width: 36px; font-size: 9px; padding-left: 6px; }
.stable.compact thead th { font-size: 11px; padding-top: 9px; padding-bottom: 8px; }
.stable.compact .stable-die { transform: scale(0.78); }
.stable.compact .stable-tn-input { font-size: 10.5px; padding: 2px 1px; }
.stable.compact .die-cam { width: 14px; height: 14px; top: -2px; right: -2px; }
.stable.compact .die-cam svg { width: 8.5px; height: 8.5px; }
/* team identity carried in the score-table header */
.stable-id {
  display: flex; flex-direction: column;
  align-items: center; gap: 5px;
}
.stable-die {
  position: relative;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s var(--ease);
}
.stable-die:active { transform: scale(0.9); }
/* mini camera badge — signals you can re-photograph a team's dice */
.die-cam {
  position: absolute;
  top: -4px; right: -4px;
  width: 17px; height: 17px;
  display: grid; place-items: center;
  background: var(--ink);
  color: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--paper), 0 1.5px 4px rgba(0,0,0,0.32);
  z-index: 3;
  pointer-events: none;
}
.die-cam svg { width: 10.5px; height: 10.5px; }
.stable-tn-input {
  width: 100%; max-width: 90px;
  border: 0;
  border-bottom: 1.5px dashed var(--ink-3);   /* signals it is editable */
  background: transparent;
  font: 600 12.5px/1.25 Fredoka, sans-serif;
  color: var(--ink-2);
  text-align: center;
  padding: 3px 2px 2px;
  border-radius: 5px 5px 0 0;
}
.stable-tn-input::placeholder { color: var(--ink-3); }
.stable-tn-input:focus {
  outline: 0;
  background: var(--cream-2);
  color: var(--ink);
}
/* sticky round-label column */
.stable .rlabel {
  position: sticky; left: 0; z-index: 2;
  text-align: left;
  font-weight: 700; font-size: 13px;
  color: var(--ink-2);
  background: var(--paper);
}
/* body — one row per round, tap to review */
.stable tbody tr { cursor: pointer; }
.stable tbody tr:nth-child(even) td,
.stable tbody tr:nth-child(even) .rlabel { background: #fffdf5; }
.stable tbody tr:active td,
.stable tbody tr:active .rlabel { background: var(--cream-2); }
.stable .scell { font-weight: 600; font-size: 15px; color: var(--ink); }
.stable .scell.z { color: var(--ink-3); font-weight: 400; font-size: 13px; }
.stable .scell.neg { color: var(--red); }
.stable .scell.best { color: var(--green-d); font-weight: 700; }
/* the leader's column reads as one tinted band */
.stable .col-lead { background: #fcecb6 !important; }
/* totals row */
.stable tfoot td {
  border-top: 2.5px solid var(--cream-2);
  font-weight: 700; font-size: 17px;
  color: var(--ink);
  padding-top: 12px; padding-bottom: 13px;
}
.stable tfoot .rlabel {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-2);
}
.stable tfoot .tcell.lead { color: #5a3d0c; background: var(--yellow); }
.stable-hint {
  font-size: 12px; color: var(--ink-3);
  margin-top: 9px; padding-left: 4px;
}
/* the round plan — ghost rows for rounds still to come */
.stable tbody.plan tr { cursor: default; }
.stable tbody.plan tr td,
.stable tbody.plan tr .rlabel,
.stable tbody.plan tr:active td,
.stable tbody.plan tr:active .rlabel { background: var(--paper); }
.stable .ghost .rlabel { color: var(--ink-3); font-weight: 600; }
.stable .ghost .scell { color: #cbb78f; }
/* the game-start demo round — it breathes so it clearly invites a tap */
.stable .demo-row { cursor: pointer; }
.stable .demo-row td,
.stable .demo-row .rlabel {
  background: #fff4d2;
  animation: demoBreathe 2.8s var(--ease) infinite;
}
@keyframes demoBreathe {
  0%, 100% { background-color: #fff4d2; }
  50%      { background-color: #ffe6a6; }
}
.stable .demo-row:active td,
.stable .demo-row:active .rlabel { background: #ffdf94; animation: none; }
.stable .demo-row .rlabel {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  color: var(--ink);
}
.demo-tag {
  font-size: 8px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: #fff; background: var(--yellow-d);
  padding: 2px 5px; border-radius: 5px;
  animation: demoTagPulse 2.8s var(--ease) infinite;
}
@keyframes demoTagPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231,165,20,0.5); }
  50%      { transform: scale(1.12); box-shadow: 0 0 0 5px rgba(231,165,20,0); }
}
@media (prefers-reduced-motion: reduce) {
  .stable .demo-row td, .stable .demo-row .rlabel, .demo-tag { animation: none; }
}
/* first-visit nudge — a bubble that points down at the R1 demo row */
#history-list { position: relative; }
.demo-cue {
  position: absolute; z-index: 5;
  pointer-events: none;
  transform: translate(0, -100%) translateY(-7px);
  animation: demoCueIn .3s var(--spring) both, demoCueBob 1.8s var(--ease) .3s infinite;
}
.demo-cue-txt {
  display: block;
  background: var(--ink); color: #fff;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.01em;
  padding: 7px 11px;
  border-radius: 11px;
  white-space: nowrap;
  box-shadow: 0 8px 16px -5px rgba(40,30,15,0.55);
}
.demo-cue-tail {
  position: absolute; left: 18px; top: 100%;
  width: 0; height: 0;
  border: 7px solid transparent; border-bottom: 0;
  border-top-color: var(--ink);
}
@keyframes demoCueIn {
  from { opacity: 0; transform: translate(0, -100%) translateY(3px); }
}
@keyframes demoCueBob {
  0%, 100% { transform: translate(0, -100%) translateY(-7px); }
  50%      { transform: translate(0, -100%) translateY(-13px); }
}
@media (prefers-reduced-motion: reduce) {
  .demo-cue { animation: demoCueIn .3s var(--spring) both; }
}
/* below the score table: team stepper + finish-mode stepper, side by side */
.score-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 10px;
  margin-top: 13px;
}
.roundpill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 5px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--card-edge), 0 8px 13px -5px var(--soft);
}
.roundpill-label {
  font-weight: 600; font-size: 13.5px; color: var(--ink-2);
  padding: 0 7px; min-width: 82px; text-align: center;
}
.rstep {
  width: 32px; height: 32px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
  cursor: pointer;
  transition: transform .1s var(--ease), background .12s var(--ease);
}
.rstep svg { width: 16px; height: 16px; }
.rstep:active { transform: scale(0.9); }
.rstep:disabled { opacity: 0.34; pointer-events: none; }
/* finish the game on demand */
.finish-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%;
  margin-top: 11px;
  padding: 14px 20px;
  border: none; border-radius: 17px;
  background: linear-gradient(180deg, #ffd75e, var(--yellow) 64%);
  color: #5a3d0c;
  font-family: inherit; font-weight: 700; font-size: 15.5px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--yellow-d), inset 0 2px 0 rgba(255,255,255,0.45);
  transition: transform .1s var(--ease), box-shadow .1s var(--ease);
}
.finish-btn:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--yellow-d), inset 0 2px 0 rgba(255,255,255,0.45);
}
.finish-btn svg { width: 18px; height: 18px; }
/* review sheet — demo placeholder shown in place of a photo */
.review-demopad {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 7px;
  min-height: 240px;
  padding: 28px 24px;
  text-align: center;
  background:
    radial-gradient(ellipse 80% 60% at 50% 38%, #fffaf0, transparent 70%),
    var(--cream);
}
.review-demopad svg { width: 76px; height: 76px; margin-bottom: 4px; }
.review-demopad-title { font-weight: 700; font-size: 18px; color: var(--ink); }
.review-demopad-sub {
  font-size: 13.5px; color: var(--ink-2); max-width: 30ch; line-height: 1.4;
}
.review-demo-note { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
/* retake the photo / re-run the read from the review sheet */
/* Action chips above the scanned photo — Retake, Rescan, Full screen.
   Stays OUT of the photo so a dice marker is never hidden behind a button. */
.review-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 0 0 10px;
}
.review-act {
  flex: 1 1 0; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 12px;
  border: 1px solid rgba(120,90,30,0.18);
  border-radius: 13px;
  background: var(--cream-2);
  color: var(--ink);
  font-family: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer;
  transition: transform .1s var(--ease), background .15s;
}
.review-act:active { transform: scale(0.96); }
.review-act:hover { background: rgba(241,233,213,0.85); }
.review-act svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ============ DOCK ============ */
/* the snap button sits in the space below the score table */
.shoot-dock {
  flex: 1 1 auto;
  min-height: 76px;
  margin-top: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
}
/* secondary "import a photo" action — quiet next to the big red Snap button,
   but a reliable getUserMedia-free import path (critical on iOS PWAs). */
.shoot-alt {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; background: none; cursor: pointer;
  padding: 6px 12px; border-radius: 12px;
  color: var(--ink-2, #766654);
  font-family: inherit; font-weight: 600; font-size: 14.5px;
  letter-spacing: -0.005em;
  -webkit-tap-highlight-color: transparent;
  transition: color .12s var(--ease), transform .1s var(--ease);
}
.shoot-alt:active { transform: scale(0.96); color: var(--red); }
.shoot-alt-ico { display: inline-flex; }
.shoot-alt-ico svg { width: 17px; height: 17px; }
/* the score button — a candy-red, press-down toy button */
.shoot {
  position: relative; overflow: hidden;
  width: 100%; max-width: 340px;
  display: flex; align-items: center; justify-content: center; gap: 11px;
  border: none;
  border-radius: 22px;
  padding: 18px 24px;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  font-weight: 600; font-size: 18px;
  letter-spacing: -0.005em;
  background: linear-gradient(180deg, #ff6258, var(--red) 62%);
  box-shadow:
    0 8px 0 var(--red-d),
    0 16px 22px -8px rgba(170,50,40,0.55),
    inset 0 2px 0 rgba(255,255,255,0.4);
  transition: transform .1s var(--ease), box-shadow .1s var(--ease);
}
.shoot:active {
  transform: translateY(6px);
  box-shadow:
    0 2px 0 var(--red-d),
    0 6px 11px -6px rgba(170,50,40,0.55),
    inset 0 2px 0 rgba(255,255,255,0.4);
}
.shoot[disabled] { opacity: 0.7; }
.shoot::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 38%;
  background: linear-gradient(108deg, transparent, rgba(255,255,255,0.34), transparent);
  transform: translateX(-240%);
  animation: shootShine 4.4s ease-in-out 1.6s infinite;
  pointer-events: none;
}
@keyframes shootShine {
  0%, 72% { transform: translateX(-240%); }
  90%, 100% { transform: translateX(360%); }
}
.shoot-ico { display: inline-flex; }
.shoot-ico svg { width: 23px; height: 23px; }
.shoot-loading { display: none; align-items: center; gap: 11px; }
.shoot.loading .shoot-ico, .shoot.loading .shoot-label { display: none; }
.shoot.loading .shoot-loading { display: inline-flex; }

.spinner {
  width: 17px; height: 17px;
  border: 2.5px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner.big { width: 30px; height: 30px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ CAMERA ============ */
.camera {
  position: fixed; inset: 0; background: #1c1814; z-index: 90;
  display: flex; flex-direction: column;
  animation: fade .25s var(--ease);
}
.camera-video, .camera-frozen {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.camera-guide {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: calc(70px + env(safe-area-inset-top, 0px));
  pointer-events: none;
}
/* the framing guide is the whole viewport rectangle, not a centred square */
.camera-frame {
  position: absolute; inset: 15px;
  border-radius: 22px;
  outline: 3px solid rgba(255,255,255,0.82);
  outline-offset: -3px;
}
.camera-frame::before, .camera-frame::after {
  content: ''; position: absolute;
  width: 40px; height: 40px;
  border: 5px solid var(--yellow);
}
.camera-frame::before {
  top: -3px; left: -3px;
  border-right: none; border-bottom: none;
  border-radius: 22px 0 0 0;
}
.camera-frame::after {
  bottom: -3px; right: -3px;
  border-left: none; border-top: none;
  border-radius: 0 0 22px 0;
}
.camera-hint {
  color: #fff;
  font-weight: 500;
  font-size: 14px;
  text-align: center; max-width: 290px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(28,24,20,0.7);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.camera-controls {
  margin-top: auto; position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 30px calc(38px + env(safe-area-inset-bottom, 0px));
}
.camera-cancel {
  background: none; border: none;
  color: #fff; font-size: 15px; font-weight: 600;
  font-family: inherit;
  cursor: pointer; width: 76px; text-align: left;
}
.camera-shutter {
  width: 82px; height: 82px; border-radius: 50%;
  background: transparent; border: 5px solid #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.camera-shutter span {
  width: 62px; height: 62px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
  transition: transform .12s var(--spring);
}
.camera-shutter:active span { transform: scale(0.82); }
.camera-spacer {
  width: 76px; height: 48px;
  display: flex; align-items: center; justify-content: flex-end;
  background: none; border: none; color: #fff; cursor: pointer;
}
.camera-spacer svg { width: 26px; height: 26px; }
.camera-confirm {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; gap: 12px;
  padding: 20px 22px calc(30px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, transparent, rgba(28,24,20,0.94));
}
.camera-confirm .btn-soft, .camera-confirm .btn-solid { flex: 1; }
/* "use a photo you already have" — opens the OS library picker */
.camera-library {
  position: absolute; z-index: 2;
  top: calc(18px + env(safe-area-inset-top, 0px));
  right: 16px;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 13px 8px 11px;
  border: none; border-radius: 999px;
  background: rgba(28,24,20,0.72);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  color: #fff; font-family: inherit;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: transform .12s var(--spring);
}
.camera-library svg { width: 18px; height: 18px; }
.camera-library:active { transform: scale(0.94); }

/* ============ SHEETS ============ */
.sheet-scrim {
  position: fixed; inset: 0;
  background: rgba(58,44,30,0.42);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .22s var(--ease);
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  width: 100%; max-width: 560px;
  background: var(--paper);
  border-radius: 30px 30px 0 0;
  box-shadow: 0 -12px 40px -10px rgba(58,44,30,0.4);
  /* Use dvh so the sheet honours the SMALLER, post-URL-bar viewport on iOS
     Safari + Android Chrome. With plain vh the footer kept landing below
     the visible area whenever the address bar was showing. */
  max-height: 92vh;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: sheetUp .46s var(--spring);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip {
  width: 46px; height: 5px; border-radius: 99px;
  background: var(--cream-2);
  margin: 12px auto 4px;
}
.sheet-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 12px 22px 14px;
}
.sheet-eyebrow {
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink);
  background: var(--yellow);
  display: inline-block;
  padding: 4px 11px 3px;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--yellow-d);
  margin-bottom: 7px;
}
.sheet-title {
  font-weight: 600; font-size: 24px;
  letter-spacing: -0.018em;
  color: var(--ink);
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 22px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--cream-2) transparent;
}
.sheet-body::-webkit-scrollbar { width: 9px; }
.sheet-body::-webkit-scrollbar-track { background: transparent; }
.sheet-body::-webkit-scrollbar-thumb {
  background: var(--cream-2);
  border-radius: 99px;
  border: 2px solid var(--paper);
}
.sheet-body::-webkit-scrollbar-thumb:active { background: var(--yellow-d); }
.sheet-foot {
  display: flex; gap: 11px;
  padding: 14px 22px calc(20px + env(safe-area-inset-bottom, 0px));
  /* Belt-and-suspenders: even if the sheet-body content overflows the sheet
     for some reason, the action buttons stay visible at the bottom. */
  position: sticky;
  bottom: 0;
  background: var(--paper);
  z-index: 2;
  box-shadow: 0 -8px 16px -10px rgba(58,44,30,0.25);
}
.sheet-foot .btn-soft, .sheet-foot .btn-solid { flex: 1; }

.btn-soft, .btn-solid {
  border: none; border-radius: 17px;
  padding: 15px 20px;
  font-family: inherit;
  font-weight: 600; font-size: 15.5px;
  cursor: pointer;
  transition: transform .1s var(--ease), box-shadow .1s var(--ease);
}
.btn-soft {
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--card-edge);
}
.btn-soft:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--card-edge);
}
.btn-soft.danger { color: var(--red); }
.btn-solid {
  background: linear-gradient(180deg, #69c95c, var(--green) 62%);
  color: #fff;
  box-shadow: 0 5px 0 var(--green-d), inset 0 2px 0 rgba(255,255,255,0.35);
}
.btn-solid:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--green-d), inset 0 2px 0 rgba(255,255,255,0.35);
}
.btn-solid[disabled] {
  opacity: 0.55;
  transform: none;
  box-shadow: 0 5px 0 var(--green-d), inset 0 2px 0 rgba(255,255,255,0.35);
}
.btn-solid.danger {
  background: linear-gradient(180deg, #f5675f, var(--red) 62%);
  box-shadow: 0 5px 0 var(--red-d), inset 0 2px 0 rgba(255,255,255,0.32);
}
.btn-solid.danger:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--red-d), inset 0 2px 0 rgba(255,255,255,0.32);
}
.btn-solid.btn-yellow {
  background: linear-gradient(180deg, #ffd566, var(--yellow) 64%);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--yellow-d), inset 0 2px 0 rgba(255,255,255,0.5);
}
.btn-solid.btn-yellow:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--yellow-d), inset 0 2px 0 rgba(255,255,255,0.5);
}

/* ============ REVIEW ============ */
.review-photo-wrap {
  position: relative;
  aspect-ratio: 4 / 5;
  max-height: 56vh;
  border-radius: 18px;
  overflow: hidden;
  background: var(--cream-2);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.12);
  /* a touch must only ever land on a dice marker — never select the photo,
     never select a marker, never raise the iOS image callout */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* the board photo is a pure backdrop — fully inert to touch */
.review-photo {
  width: 100%; height: 100%;
  object-fit: contain; display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
.review-analyzing {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 13px;
  background: rgba(24,20,16,0.52);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
}
.review-analyzing::after {
  content: '';
  position: absolute; left: 0; right: 0;
  height: 40%;
  background: linear-gradient(180deg, transparent, rgba(255,232,140,0.5), transparent);
  animation: scanBeam 1.55s var(--ease) infinite;
}
@keyframes scanBeam {
  0%   { top: -40%; }
  100% { top: 100%; }
}
/* step-by-step scan progress — a checklist that ticks forward, never loops */
.scan-steps {
  display: flex; flex-direction: column; gap: 11px;
  padding: 17px 20px;
  border-radius: 16px;
  background: rgba(20,16,12,0.62);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.scan-step {
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 600;
  color: rgba(255,255,255,0.4);
  transition: color .3s var(--ease);
}
.scan-mark {
  flex: none; position: relative;
  width: 19px; height: 19px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.28);
  box-sizing: border-box;
  transition: border-color .3s var(--ease), background .3s var(--ease);
}
.scan-step.active { color: #fff; }
.scan-step.active .scan-mark {
  border-color: var(--yellow);
  border-top-color: transparent;
  animation: spin .7s linear infinite;
}
.scan-step.done { color: rgba(255,255,255,0.9); }
.scan-step.done .scan-mark {
  border-color: var(--green); background: var(--green);
  animation: scan-pop .3s var(--ease) both;
}
.scan-step.done .scan-mark::after {
  content: '';
  position: absolute; left: 4.5px; top: 1.5px;
  width: 5px; height: 9px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
@keyframes scan-pop {
  from { transform: scale(.4); }
  to   { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .scan-step.active .scan-mark,
  .scan-step.done .scan-mark { animation: none; }
}
.review-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 13px 0 4px;
  font-size: 12px; color: var(--ink-2);
}
.conf-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  font-weight: 600; font-size: 11.5px;
  background: var(--cream);
  box-shadow: inset 0 0 0 1.5px rgba(120,90,30,0.12);
}
.conf-chip.hi  { color: var(--green-d); }
.conf-chip.mid { color: var(--yellow-d); }
.conf-chip.lo  { color: var(--red); }
.conf-chip i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.review-tip {
  font-size: 13.5px;
  color: var(--ink-2);
  margin: 15px 0 10px;
}
/* review body — one block per team, every die editable */
.review-rows { display: flex; flex-direction: column; gap: 13px; }
.rteam {
  border-radius: 18px;
  background: var(--cream);
  padding: 10px 11px 11px;
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.08);
}
.rteam-head {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 9px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.rteam-caret {
  flex: none; width: 17px; height: 17px;
  color: var(--ink-3);
  transition: transform .18s var(--ease);
}
.rteam.collapsed .rteam-caret { transform: rotate(-90deg); }
.rteam.collapsed .rteam-head { margin-bottom: 0; }
.rteam.collapsed .rteam-empty,
.rteam.collapsed .rteam-secs { display: none; }
.rteam-dot {
  width: 24px; height: 24px; flex: none;
  border-radius: 8px; background: var(--team);
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.45), inset 0 -3px 5px rgba(0,0,0,0.22);
}
.rteam-name {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: 15.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rteam-total {
  flex: none;
  font-weight: 700; font-size: 18px; color: var(--ink);
  font-variant-numeric: tabular-nums;
  background: var(--yellow);
  padding: 3px 14px 2px;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--yellow-d);
}
.rteam-empty {
  font-size: 12.5px; font-weight: 500; color: var(--ink-3);
  padding: 0 2px 9px;
}
/* zones laid out as 5 columns side by side, like the board's tiers */
.rteam-secs {
  display: flex; flex-direction: row;
  align-items: flex-start;
  gap: 6px;
}
.rsec {
  flex: 1 1 0; min-width: 0;
  background: var(--paper);
  border-radius: 12px;
}
.rsec.neg { background: #fbe9e7; }
.rsec-row {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 5px;
  padding: 7px 5px 8px;
}
.rsec-mult {
  order: 0;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: var(--ink);
  font-variant-numeric: tabular-nums;
  background: var(--cream-2);
  border-radius: 8px; padding: 6px 0;
  box-shadow: inset 0 0 0 1.5px rgba(120,90,30,0.10);
}
.rsec.neg .rsec-mult {
  color: #fff; background: var(--red);
  box-shadow: 0 2px 0 rgba(0,0,0,0.16);
}
.rsec-sub {
  order: 1;
  text-align: center;
  font-weight: 800; font-size: 15px; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.rsec-sub.zero { color: var(--ink-3); font-weight: 700; }
.rsec.neg .rsec-sub { color: var(--red); }
.rsec-dice {
  order: 2;
  display: flex; flex-direction: column; align-items: center;
  gap: 5px;
}
.rchip {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: none; border-radius: 9px;
  background: var(--team); color: #fff;
  font-family: inherit; font-weight: 800; font-size: 17px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.42),
              inset 0 -3px 5px rgba(0,0,0,0.26);
  text-shadow: 0 1px 2px rgba(0,0,0,0.32);
  transition: transform .1s var(--ease);
  touch-action: none;                       /* so a drag never scrolls the sheet */
}
.rchip:active { transform: scale(0.9); }
.rchip.editing { outline: 3px solid var(--ink); outline-offset: 2px; }
.rchip.pop { animation: chipPop .22s var(--ease); }
/* a chip lifted out to drag into another zone */
.rchip.dragging {
  position: fixed;
  z-index: 250;
  transform: scale(1.18);
  box-shadow: 0 12px 24px -6px rgba(40,30,15,0.6),
              inset 0 2px 3px rgba(255,255,255,0.42);
}
/* the zone column a dragged chip would drop into */
.rsec.drop-target {
  background: var(--cream-2);
  outline: 2.5px dashed var(--green);
  outline-offset: -2px;
}
@keyframes chipPop {
  0%   { transform: scale(0.2); opacity: 0; }
  70%  { transform: scale(1.14); }
  100% { transform: scale(1); opacity: 1; }
}
.rsec-add {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 2px dashed var(--card-edge); border-radius: 9px;
  background: none; color: var(--ink-3);
  font-family: inherit; font-weight: 700; font-size: 20px; line-height: 1;
  cursor: pointer;
  transition: background .12s var(--ease), color .12s var(--ease), border-color .12s var(--ease);
}
.rsec-add:hover { background: var(--cream-2); color: var(--ink); }
.rsec-add.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.rpad {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
  padding: 9px;
  border-radius: 12px;
  background: var(--cream-2);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.08);
}
.rpad-zone {
  flex: 1 1 100%;
  font-weight: 700; font-size: 12.5px; color: var(--ink-2);
  padding: 0 2px 2px;
}
.rpad-key {
  flex: 1 1 0; min-width: 38px; height: 46px;
  border: none; border-radius: 11px;
  background: var(--paper); color: var(--ink);
  font-family: inherit; font-weight: 800; font-size: 19px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(120,90,30,0.18);
  transition: transform .08s var(--ease), box-shadow .08s var(--ease);
}
.rpad-key:active { transform: translateY(3px); box-shadow: 0 0 0 rgba(120,90,30,0); }
.rpad-act {
  flex: 1 1 100%; height: 40px;
  border: none; border-radius: 11px;
  background: var(--ink); color: #fff;
  font-family: inherit; font-weight: 700; font-size: 14px;
  cursor: pointer; margin-top: 1px;
}
.rpad-act.danger { background: var(--red); }

/* scan detection overlay — markers lock onto the dice the AI found */
.review-detect {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 18px;
}
/* zone editor owns the photo — detected-dice markers go inert */
.review-detect.zone-lock .det-marker { pointer-events: none; }
.review-detect.zone-lock .det-add { pointer-events: none; opacity: 0; }
/* "+ Add a dice" — one tap drops a die, no mode to enter */
.det-add {
  position: absolute; left: 9px; bottom: 10px; z-index: 6;
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 12px 7px 9px;
  font: 600 12px/1 Fredoka, sans-serif;
  color: #fff;
  background: rgba(24,20,16,0.78);
  border: 0; border-radius: 999px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  transition: transform .1s var(--ease), opacity .15s var(--ease);
}
.det-add span { font-size: 15px; font-weight: 700; }
.det-add:active { transform: scale(0.94); }
/* a detected die — live by default: drag to move it, tap to open its editor */
.det-marker {
  position: absolute;
  box-sizing: border-box;            /* visual rectangle == the detected box (no 4px border bleed right+down) */
  border: 2px solid var(--team);
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.5),
              0 1px 5px rgba(0,0,0,0.3);
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  animation: detLock .42s var(--ease) both;
}
.det-marker.dragging {
  cursor: grabbing;
  z-index: 8;
  animation: none;
  border-width: 3px;
  box-shadow: 0 0 0 2px #fff, 0 5px 15px rgba(0,0,0,0.45);
}
/* the marker whose editor menu is currently open */
.det-marker.sel {
  z-index: 7;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--team),
              0 2px 9px rgba(0,0,0,0.4);
}
/* a precise re-scan is in flight — pulse the box in the team colour */
.det-marker.det-scanning { animation: detScan 1s ease-in-out infinite; }
@keyframes detScan {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255,255,255,0.5), 0 0 0 0 var(--team); }
  50%      { box-shadow: 0 0 0 1px rgba(255,255,255,0.5), 0 0 10px 3px var(--team); }
}
/* a quick flash when a tap or re-scan changes the die */
.det-marker.det-bumped { animation: detBump .32s var(--ease); }
@keyframes detBump {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.22); }
  100% { transform: scale(1); }
}
/* detected pip count — die-coloured, light, clear above the box */
.det-num {
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  font: 600 12.5px/1 Fredoka, sans-serif;
  font-variant-numeric: tabular-nums;
  color: var(--team);
  text-shadow: 0 0 2px #fff, 0 0 3px #fff, 0 0 3px #fff, 0 1px 1px #fff;
  pointer-events: none;
  white-space: nowrap;
}
/* tap-a-die editor — the little menu: number keys, team dots, actions */
.det-pop {
  position: absolute;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px;
  border-radius: 13px;
  background: var(--paper);
  box-shadow: 0 8px 24px rgba(24,20,16,0.34);
  pointer-events: auto;
  animation: detPopIn .15s var(--ease) both;
}
@keyframes detPopIn {
  from { opacity: 0; transform: scale(0.86); }
  to   { opacity: 1; transform: scale(1); }
}
/* close X — straddles the menu's top-right corner */
.det-pop-x {
  position: absolute;
  top: -9px; right: -9px;
  width: 22px; height: 22px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font: 700 14px/1 Fredoka, sans-serif;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
}
.det-pop-x:active { transform: scale(0.88); }
.det-pop-nums { display: flex; gap: 4px; }
.det-pop-num {
  width: 29px; height: 33px;
  border: none; border-radius: 8px;
  background: var(--cream-2); color: var(--ink);
  font: 800 16px/1 Fredoka, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.det-pop-num.on { background: var(--team); color: #fff; }
.det-pop-teams {
  display: flex; gap: 9px; justify-content: center;
  padding-top: 7px;
  border-top: 1px solid rgba(120,90,30,0.14);
}
.det-pop-team {
  width: 17px; height: 17px; padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(120,90,30,0.3);
}
.det-pop-team.on { box-shadow: 0 0 0 2px var(--ink); }
.det-pop-acts {
  display: flex; gap: 6px;
  padding-top: 7px;
  border-top: 1px solid rgba(120,90,30,0.14);
}
.det-pop-act {
  flex: 1;
  padding: 8px;
  border: none; border-radius: 8px;
  background: var(--cream-2); color: var(--ink);
  font: 700 12px/1 Fredoka, sans-serif;
  cursor: pointer;
  transition: transform .1s var(--ease);
}
.det-pop-act.danger { color: var(--red); }
.det-pop-act:active { transform: scale(0.94); }
.det-pop-act:disabled { opacity: 0.6; cursor: default; }
@keyframes detLock {
  0%   { opacity: 0; transform: scale(1.7); }
  60%  { opacity: 1; }
  80%  { transform: scale(0.94); }
  100% { opacity: 1; transform: scale(1); }
}
.det-count {
  position: absolute; left: 9px; top: 9px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(24,20,16,0.82);
  color: #fff;
  font-weight: 700; font-size: 11.5px;
  animation: detCountIn .3s var(--ease) both;
}
@keyframes detCountIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .det-marker, .det-count { animation-duration: .01ms; }
}

/* ============ ZONE EDITOR ============ */
.review-zones {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 18px;
}
.rz-label {
  position: absolute; left: 8px;
  transform: translateY(-50%);
  font: 700 12px/1 Fredoka, sans-serif;
  color: #fff;
  background: rgba(24,20,16,0.62);
  padding: 4px 8px; border-radius: 7px;
  pointer-events: none;
}
.rz-svg {
  position: absolute;
  overflow: visible;
  pointer-events: none;
}
.rz-path {
  fill: none;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-dasharray: 8 6;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.75));
}
.rz-grip {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: ns-resize;
  touch-action: none;
  background: #ef4d44;
  box-shadow: 0 2px 7px rgba(0,0,0,0.45), inset 0 0 0 2px rgba(255,255,255,0.65);
  transition: transform .1s var(--ease);
}
.rz-move {
  width: 46px; height: 23px;
  border-radius: 999px;
}
.rz-move::before, .rz-move::after {
  content: ''; position: absolute; left: 14px; right: 14px; height: 2px;
  background: rgba(255,255,255,0.92); border-radius: 2px;
}
.rz-move::before { top: 7px; }
.rz-move::after  { bottom: 7px; }
.rz-curve {
  width: 27px; height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(0,0,0,0.45), inset 0 0 0 3.5px #ef4d44;
}
.rz-grip:active { transform: translate(-50%, -50%) scale(1.16); }
.rz-movetoggle {
  position: absolute; left: 10px; bottom: 10px;
  padding: 8px 13px;
  font: 600 12.5px/1 Fredoka, sans-serif;
  color: #fff;
  background: rgba(24,20,16,0.72);
  border: 0; border-radius: 999px;
  box-shadow: 0 2px 9px rgba(0,0,0,0.34);
  cursor: pointer;
  pointer-events: auto;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.rz-movetoggle.on {
  background: #ef4d44;
  box-shadow: 0 2px 9px rgba(0,0,0,0.34), 0 0 0 2px rgba(255,255,255,0.3) inset;
}

/* "?" help button on the review photo + auto-popping tip bubble */
.helpbtn {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 17px/1 Fredoka, sans-serif;
  color: #fff;
  background: rgba(24,20,16,0.72);
  border: 0; border-radius: 50%;
  cursor: pointer;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  box-shadow: 0 2px 9px rgba(0,0,0,0.34);
  transition: transform .1s var(--ease);
}
.helpbtn:active { transform: scale(0.92); }
.helpbtn.on { background: var(--ink); }
.helptip {
  position: absolute; top: 50px; right: 10px; z-index: 6;
  max-width: 230px;
  padding: 12px 14px 10px;
  background: var(--paper);
  border: 1px solid rgba(120,90,30,0.18);
  border-radius: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22);
  color: var(--ink);
  font-size: 12.5px; line-height: 1.4;
  animation: helptipIn .25s var(--ease);
}
.helptip[hidden] { display: none; }
.helptip strong { display: block; font-size: 13.5px; margin: 0 0 6px; }
.helptip p { margin: 5px 0; font-size: 12px; color: var(--ink-2); }
.helptip-x {
  position: absolute; top: 3px; right: 4px;
  width: 22px; height: 22px;
  font: 700 17px/1 Fredoka, sans-serif;
  background: transparent; border: 0; color: var(--ink-3);
  cursor: pointer;
}
@keyframes helptipIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* long-press ripple — fades in over 500ms to show the press is in flight */
/* "Hold a spot to add a dice" overlay -- only mounted when the scan crashed
   or came back with zero dice. Pointer-events:none so the user can long-press
   THROUGH it to drop a die wherever they tap. */
.det-empty-hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 5;
  background: rgba(24,20,16,0.78);
  color: #fff;
  padding: 14px 22px;
  border-radius: 18px;
  text-align: center;
  font-family: Fredoka, sans-serif;
  box-shadow: 0 8px 28px -10px rgba(0,0,0,0.5);
  animation: emptyHintIn .35s var(--ease);
  max-width: 78%;
}
.det-empty-hint-title { display: block; font-weight: 600; font-size: 14px; letter-spacing: 0.01em; }
.det-empty-hint-sub   { display: block; font-weight: 400; font-size: 12px; opacity: 0.78; margin-top: 4px; }
@keyframes emptyHintIn {
  from { transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1);    opacity: 1; }
}

.press-ripple {
  position: absolute;
  width: 26px; height: 26px;
  margin-left: -13px; margin-top: -13px;
  border-radius: 50%;
  background: rgba(239,77,68,0.20);
  border: 2px solid rgba(239,77,68,0.85);
  pointer-events: none;
  z-index: 4;
  animation: pressGrow 500ms cubic-bezier(0.25, 1, 0.5, 1) both;
}
@keyframes pressGrow {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1.6); opacity: 1; }
}

.zonebtn {
  position: absolute; right: 10px; bottom: 10px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  font: 600 13px/1 Fredoka, sans-serif;
  color: #fff;
  background: rgba(24,20,16,0.72);
  border: 0; border-radius: 999px;
  box-shadow: 0 2px 9px rgba(0,0,0,0.34);
  cursor: pointer;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.zonebtn svg { width: 16px; height: 16px; }
.zonebtn.on { background: #ef4d44; }
.zonebtn.hinting { animation: zonebtn-pulse 1.5s ease-in-out infinite; }
@keyframes zonebtn-pulse {
  0%, 100% { box-shadow: 0 2px 9px rgba(0,0,0,0.34), 0 0 0 0 rgba(255,198,46,0); }
  55%      { box-shadow: 0 2px 9px rgba(0,0,0,0.34), 0 0 0 7px rgba(255,198,46,0.34); }
}

/* the scan's "not 100% sure" nudge toward the Adjust-zones button */
.zone-hint {
  position: absolute; right: 10px; bottom: 53px; z-index: 6;
  display: flex; align-items: flex-start; gap: 8px;
  width: min(234px, 72%);
  text-align: left;
  border: none; cursor: pointer;
  background: var(--yellow); color: var(--ink);
  font-family: inherit; font-weight: 600; font-size: 12.5px; line-height: 1.36;
  padding: 10px 12px; border-radius: 14px;
  box-shadow: 0 3px 0 var(--yellow-d), 0 14px 24px -9px var(--soft);
  transform-origin: 86% 132%;
  animation: zone-hint-pop .42s cubic-bezier(.34,1.56,.64,1) both,
             zone-hint-bob 2.7s ease-in-out .62s infinite;
}
.zone-hint.leaving { animation: zone-hint-out .22s ease forwards; }
.zone-hint-icon {
  flex: none; display: grid; place-items: center;
  width: 22px; height: 22px; margin-top: -1px;
  color: var(--yellow-d);
}
.zone-hint-icon svg { width: 20px; height: 20px; }
.zone-hint-txt b { font-weight: 700; }
.zone-hint-tail {
  position: absolute; right: 27px; bottom: -5px;
  width: 12px; height: 12px;
  background: var(--yellow); border-radius: 0 0 3px 0;
  transform: rotate(45deg);
}
@keyframes zone-hint-pop {
  from { opacity: 0; transform: scale(.5) translateY(14px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes zone-hint-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
@keyframes zone-hint-out {
  to { opacity: 0; transform: scale(.84) translateY(8px); }
}
@media (prefers-reduced-motion: reduce) {
  .rz-grip:active { transform: translate(-50%, -50%); }
  .zonebtn.hinting { animation: none; }
  .zone-hint { animation: zone-hint-fade .25s ease both; }
  .zone-hint.leaving { animation: zone-hint-fade .2s ease reverse forwards; }
}
@keyframes zone-hint-fade { from { opacity: 0; } to { opacity: 1; } }

/* ============ MENU ============ */
.menu-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 15px 0;
  border-bottom: 2px solid var(--cream-2);
}
.menu-row-title { font-weight: 600; font-size: 15.5px; display: block; color: var(--ink); }
.menu-row-sub { font-size: 12px; color: var(--ink-3); margin-top: 1px; display: block; }
.menu-row-link { color: var(--blue-d); font-weight: 600; text-underline-offset: 2px; }
.menu-input {
  width: 86px; height: 50px;
  border: none; border-radius: 14px;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.12);
  color: var(--ink);
  font-family: inherit;
  font-weight: 700; font-size: 20px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.menu-action {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 15px 0;
  background: none; border: none;
  border-bottom: 2px solid var(--cream-2);
  cursor: pointer;
  font-family: inherit;
}
.menu-action svg { width: 19px; height: 19px; color: var(--ink-3); }
.menu-action.danger .menu-row-title { color: var(--red); }
.menu-action.danger svg { color: var(--red); }
.menu-action:last-child { border-bottom: none; }
/* Model-card style description list used inside the Pattern Recognition
   API dialog. Two-column key/value grid that reads like a model factsheet.
   .vertical-map shares the same key/value chassis but uses status pills. */
.confirm-msg-tight { margin: 8px 0 12px; line-height: 1.45; }
/* "Teams from photo" sheet -- per-appearance editable rows
   (body swatch, pip swatch, name, merge-into picker, delete). */
.dt-intro { margin: 4px 0 14px; color: var(--ink-2); font-size: 13.5px; line-height: 1.45; }
.dt-row {
  display: grid;
  grid-template-columns: 44px auto 1fr auto;
  gap: 10px; align-items: center;
  padding: 10px 12px;
  background: var(--cream);
  border: 1px solid var(--cream-2);
  border-radius: 14px;
  margin-bottom: 10px;
}
.dt-row.dt-row-off { opacity: 0.48; }
.dt-swatch {
  position: relative;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--swatch, #888);
  cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.5), 0 1px 0 rgba(0,0,0,0.15);
}
.dt-swatch input[type="color"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; border: none; padding: 0;
}
.dt-pip {
  position: absolute; right: -4px; bottom: -4px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--pipcolor, #fff);
  box-shadow: 0 0 0 2px var(--paper), 0 1px 2px rgba(0,0,0,0.3);
  cursor: pointer;
  overflow: hidden;
}
.dt-pip input[type="color"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; border: none; padding: 0; width: 100%; height: 100%;
}
.dt-count {
  font: 600 13px/1 Fredoka, sans-serif;
  color: var(--ink-3);
  background: var(--paper);
  padding: 5px 9px; border-radius: 999px;
  white-space: nowrap;
}
.dt-name {
  width: 100%;
  padding: 8px 10px;
  font: 500 14px Fredoka, sans-serif;
  border: 1px solid var(--cream-2);
  background: var(--paper); color: var(--ink);
  border-radius: 8px;
}
.dt-name:focus { outline: none; border-color: var(--yellow); }
.dt-actions { display: flex; gap: 6px; align-items: center; }
.dt-merge {
  font: 500 12px Fredoka, sans-serif; color: var(--ink-2);
  padding: 6px 8px; border: 1px dashed var(--cream-2); background: var(--paper);
  border-radius: 6px; cursor: pointer;
}
.dt-merge:hover { border-color: var(--ink-3); color: var(--ink); }
.dt-del {
  background: none; border: none; padding: 6px; cursor: pointer;
  color: var(--ink-3);
}
.dt-del:hover { color: var(--red); }
.dt-add {
  display: block; width: 100%;
  padding: 11px; margin: 4px 0 8px;
  background: var(--paper); border: 1.5px dashed var(--cream-2);
  border-radius: 12px; color: var(--ink-2);
  font: 600 13.5px Fredoka, sans-serif;
  cursor: pointer;
}
.dt-add:hover { border-color: var(--ink-3); color: var(--ink); }
/* Pattern Recognition API dialog -- bigger card, sticky header + footer,
   scrollable middle so the model-card never crops the title or the form. */
.apiaccess-confirm { padding: 14px; align-items: stretch; }
.apiaccess-card {
  max-width: 460px !important;
  max-height: 92dvh;
  max-height: 92vh;
  margin: auto;
  padding: 0 !important;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.apiaccess-head {
  padding: 22px 22px 12px;
  text-align: center;
  border-bottom: 1px solid var(--cream-2);
  background: var(--paper);
  flex: 0 0 auto;
}
.apiaccess-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 22px 8px;
  -webkit-overflow-scrolling: touch;
}
.apiaccess-foot {
  flex: 0 0 auto;
  padding: 12px 22px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  border-top: 1px solid var(--cream-2);
  box-shadow: 0 -8px 12px -8px rgba(58,44,30,0.18);
}
.apiaccess-sub {
  margin: 4px 0 0;
  font: 600 10.5px/1 Fredoka, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: center;
}
.apiaccess-card .confirm-ico { margin: 0 auto 10px; }
#apiaccess-done {
  padding: 22px 22px calc(20px + env(safe-area-inset-bottom, 0px));
  text-align: center;
}
.vertical-map {
  display: block; width: 100%;
  margin: 8px 0 14px; padding: 12px 14px;
  background: var(--cream); border-radius: 12px;
  border: 1px solid var(--cream-2);
  font: 500 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--ink-2); text-align: left;
}
.vertical-map > div { display: grid; grid-template-columns: 130px 1fr; gap: 8px; padding: 4px 0; }
.vertical-map dt { color: var(--ink); font-weight: 600; }
.vertical-map dd { margin: 0; }
.vstatus {
  display: inline-block; margin-right: 6px;
  padding: 1px 7px; font: 700 9.5px/1.4 Fredoka, sans-serif;
  letter-spacing: 0.05em; text-transform: uppercase;
  border-radius: 999px; color: #fff; vertical-align: 1px;
}
.vstatus-live  { background: var(--green); }
.vstatus-pilot { background: var(--yellow-d, #d4a01a); color: #2a1f10; }
.vstatus-rnd   { background: var(--cream-2); color: var(--ink-3); }
.model-card {
  display: block;
  width: 100%;
  margin: 8px 0 14px;
  padding: 12px 14px;
  background: var(--cream);
  border-radius: 12px;
  font: 500 11.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--ink-2);
  text-align: left;
  border: 1px solid var(--cream-2);
}
.model-card > div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--cream-2);
}
.model-card > div:last-child { border-bottom: none; }
.model-card dt { color: var(--ink); font-weight: 600; letter-spacing: 0.01em; }
.model-card dd { margin: 0; color: var(--ink-2); }
/* finish-mode picker — Best of N vs Target N, mutually exclusive */
.menu-row-col { flex-direction: column; align-items: stretch; gap: 11px; }
.mode-toggle { display: flex; gap: 9px; }
.mode-pill {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; gap: 1px;
  padding: 4px;
  border-radius: 15px;
  border: 2px solid;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.mode-pill.is-on  { border-color: var(--green); background: rgba(84,187,70,0.13); }
.mode-pill.is-off { border-color: var(--red);   background: rgba(239,77,68,0.09); }
.mode-body {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 6px 2px;
  border: none; background: none;
  font-family: inherit; cursor: pointer;
  border-radius: 9px;
}
.mode-name {
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.045em;
}
.mode-num {
  font-size: 21px; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.mode-pill.is-on  .mode-name, .mode-pill.is-on  .mode-num,
.mode-pill.is-on  .mode-step { color: var(--green-d); }
.mode-pill.is-off .mode-name, .mode-pill.is-off .mode-num,
.mode-pill.is-off .mode-step { color: var(--red-d); }
.mode-step {
  width: 30px; height: 30px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 9px;
  background: var(--paper);
  cursor: pointer;
  transition: transform .1s var(--ease);
}
.mode-step svg { width: 15px; height: 15px; }
.mode-step:active { transform: scale(0.86); }
.mode-step:disabled { opacity: 0.4; pointer-events: none; }

/* ============ WIN ============ */
.win {
  position: fixed; inset: 0;
  background: rgba(58,44,30,0.6);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 95;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: fade .3s var(--ease);
}
.win-card {
  position: relative;
  width: 100%; max-width: 348px;
  text-align: center;
  padding: 36px 28px 26px;
  border-radius: 30px;
  background: var(--paper);
  box-shadow:
    0 0 0 4px var(--yellow),
    0 10px 0 var(--yellow-d),
    0 36px 60px -20px rgba(40,30,15,0.6);
  animation: winPop .56s var(--spring);
}
@keyframes winPop {
  0% { opacity: 0; transform: scale(.8) translateY(24px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.win-trophy {
  width: 86px; height: 86px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 26px;
  color: #fff;
  background: linear-gradient(180deg, #ffd75e, var(--yellow) 62%);
  box-shadow: 0 7px 0 var(--yellow-d), inset 0 2px 0 rgba(255,255,255,0.5);
  animation: trophyIn .62s .15s var(--spring) both;
}
@keyframes trophyIn {
  0% { transform: scale(0) rotate(-30deg); }
  100% { transform: scale(1) rotate(0); }
}
.win-trophy svg { width: 42px; height: 42px; color: #fff; }
/* a single shine sweeps across the trophy as it lands */
.win-trophy { position: relative; overflow: hidden; }
.win-trophy::after {
  content: '';
  position: absolute;
  top: -50%; left: -130%;
  width: 55%; height: 200%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,0.6), transparent);
  transform: rotate(16deg);
  animation: trophyGleam 1.15s 0.7s ease-in-out both;
}
@keyframes trophyGleam {
  0%, 8% { left: -130%; }
  100% { left: 170%; }
}
@media (prefers-reduced-motion: reduce) {
  .win-trophy::after { display: none; }
}
.win-eyebrow {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-2);
  margin-bottom: 5px;
}
.win-name {
  font-weight: 700; font-size: 34px;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 2px;
}
.win-score {
  font-weight: 500; font-size: 16px;
  color: var(--ink-2);
  margin-bottom: 22px;
}
.win-btn { width: 100%; }
.win-keep {
  display: block; width: 100%; margin-top: 12px;
  background: none; border: none;
  color: var(--ink-3); font-size: 14px; font-weight: 600;
  font-family: inherit;
  cursor: pointer; padding: 8px;
}
.win-keep:hover { color: var(--ink); }

/* confetti */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 96; overflow: hidden; }
.confetti-bit {
  position: absolute; width: 10px; height: 15px; border-radius: 3px;
  background: var(--c, #ef4d44);
  will-change: transform, opacity;
  animation: confetti 1.4s cubic-bezier(.2,.6,.35,1) forwards;
}
.confetti-bit.round { border-radius: 50%; }
.confetti-bit.die {
  background: radial-gradient(circle at 50% 50%, #fff 0 23%, transparent 25%), var(--c, #ef4d44);
}
@keyframes confetti {
  0% { transform: translate(0,-30px) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), 64vh) rotate(var(--dr)); opacity: 0; }
}

/* ============ SWATCH POPOVER ============ */
.swatchpop {
  position: absolute; z-index: 85;
  display: flex; flex-direction: column;
  overflow: hidden;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--card-edge), 0 22px 44px -14px rgba(40,30,15,0.5);
  animation: popIn .2s var(--spring);
  transform-origin: top left;
}
/* the scrolling part — everything but the pinned "Photograph our dice" footer */
.swatchpop-body {
  display: grid; grid-template-columns: repeat(5, 36px); gap: 9px;
  padding: 14px;
  min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.86) translateY(-6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.swatchpop-cell {
  width: 36px; height: 36px; border-radius: 11px; cursor: pointer; border: none;
  background:
    radial-gradient(circle at 32% 26%, rgba(255,255,255,0.8), transparent 54%),
    var(--c);
  box-shadow: 0 3px 0 rgba(0,0,0,0.16), inset 0 0 0 1px rgba(0,0,0,0.08);
  transition: transform .14s var(--spring); position: relative;
}
.swatchpop-cell:hover { transform: scale(1.16) translateY(-2px); }
.swatchpop-cell.cur::after {
  content: ''; position: absolute; inset: -5px;
  border: 3px solid var(--ink); border-radius: 15px;
}
/* "Custom colour" — a rainbow swatch wrapping a transparent colour input;
   tapping it opens the OS colour picker. Same shape as a normal swatch. */
.swatchpop-custom {
  position: relative; display: block;
  width: 36px; height: 36px; border-radius: 11px;
  cursor: pointer; overflow: hidden;
  background:
    radial-gradient(circle at 32% 26%, rgba(255,255,255,0.72), transparent 55%),
    conic-gradient(from 210deg, #ef4d44, #ffc62e, #54bb46, #2fb6c8, #2f93d8, #8b5cf6, #ec5fae, #ef4d44);
  box-shadow: 0 3px 0 rgba(0,0,0,0.16), inset 0 0 0 1px rgba(0,0,0,0.08);
  transition: transform .14s var(--spring);
}
.swatchpop-custom:hover { transform: scale(1.16) translateY(-2px); }
.swatchpop-custom-inp {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  margin: 0; padding: 0; border: none;
  opacity: 0; cursor: pointer; background: none;
}
/* "Photograph our dice" — pinned footer, always visible below the scroll */
.swatchpop-cal {
  flex: none;
  padding: 14px 12px;
  border: none; border-radius: 0;
  border-top: 2px solid var(--cream-2);
  background: linear-gradient(180deg, #69c95c, var(--green) 62%);
  color: #fff;
  font-family: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer; text-align: center;
  transition: filter .1s var(--ease);
}
.swatchpop-cal:active { filter: brightness(0.92); }
.swatchpop-del {
  grid-column: 1 / -1; margin-top: 2px;
  padding: 9px 12px;
  border: none; border-radius: 12px;
  background: none;
  color: var(--red);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-align: center;
}
.swatchpop-del:hover { background: color-mix(in srgb, var(--red) 12%, transparent); }
.swatchpop-pip {
  grid-column: 1 / -1; margin-top: 5px; padding-top: 11px;
  border-top: 2px solid var(--cream-2);
}
.swatchpop-piplabel {
  font-family: inherit; font-size: 12.5px; font-weight: 700;
  color: var(--ink-2); letter-spacing: .02em;
}
.swatchpop-piphint {
  font-size: 10.5px; font-weight: 500; color: var(--ink-3);
  margin-top: 2px; line-height: 1.35;
}
.swatchpop-piprow {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px;
  margin-top: 9px;
}
.swatchpop-pipcell {
  aspect-ratio: 1; border-radius: 9px; cursor: pointer; border: none;
  background:
    radial-gradient(circle at 32% 26%, rgba(255,255,255,0.8), transparent 54%),
    var(--c);
  box-shadow: 0 2px 0 rgba(0,0,0,0.16), inset 0 0 0 1px rgba(0,0,0,0.08);
  transition: transform .14s var(--spring); position: relative;
}
.swatchpop-pipcell:hover { transform: scale(1.16) translateY(-2px); }
.swatchpop-pipcell.cur::after {
  content: ''; position: absolute; inset: -4px;
  border: 2.5px solid var(--ink); border-radius: 12px;
}
.swatchpop-pipcell.none {
  background:
    repeating-linear-gradient(45deg, var(--cream-2) 0 4.5px, var(--paper) 4.5px 9px);
  box-shadow: inset 0 0 0 1.5px var(--ink-3);
}
/* swatch header — title + an explicit X, since the popup now stays open */
.swatchpop-head {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between;
  margin: -2px 0 3px;
}
.swatchpop-title {
  font-family: inherit; font-size: 12.5px; font-weight: 700;
  color: var(--ink-2); letter-spacing: .02em;
}
.swatchpop-x {
  flex: none;
  width: 27px; height: 27px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--cream-2); color: var(--ink-2);
  display: grid; place-items: center;
  transition: transform .1s var(--ease), background .12s var(--ease);
}
.swatchpop-x:hover { background: var(--cream); color: var(--ink); }
.swatchpop-x:active { transform: scale(0.9); }
.swatchpop-x svg { width: 14px; height: 14px; }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 112px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px; border-radius: 999px;
  font-family: inherit;
  font-size: 13.5px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--spring);
  z-index: 200;
  box-shadow: 0 12px 26px -10px rgba(40,30,15,0.6);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

/* ============ CONFIRM ============ */
.confirm {
  position: fixed; inset: 0;
  background: rgba(58,44,30,0.6);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 210;
  display: flex; align-items: center; justify-content: center;
  padding: 26px;
  animation: fade .2s var(--ease);
}
.confirm-card {
  width: 100%; max-width: 314px;
  text-align: center;
  padding: 28px 24px 22px;
  border-radius: 27px;
  background: var(--paper);
  box-shadow: 0 8px 0 var(--card-edge), 0 30px 52px -18px rgba(40,30,15,0.55);
  animation: confirmPop .42s var(--spring);
}
@keyframes confirmPop {
  0% { opacity: 0; transform: scale(.84) translateY(18px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.confirm-ico {
  width: 62px; height: 62px;
  margin: 0 auto 15px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffd75e, var(--yellow) 62%);
  box-shadow: 0 5px 0 var(--yellow-d), inset 0 2px 0 rgba(255,255,255,0.5);
  transition: background .18s var(--ease), box-shadow .18s var(--ease);
}
.confirm-ico svg { width: 31px; height: 31px; color: #fff; }
.confirm-card:has(#confirm-yes.danger) .confirm-ico {
  background: linear-gradient(180deg, #f5675f, var(--red) 62%);
  box-shadow: 0 5px 0 var(--red-d), inset 0 2px 0 rgba(255,255,255,0.5);
}
.confirm-msg {
  font-weight: 500; font-size: 16.5px; line-height: 1.42;
  color: var(--ink);
  margin-bottom: 20px;
  padding: 0 6px;
}
.soon-title {
  font-weight: 700; font-size: 21px;
  letter-spacing: -0.012em;
  color: var(--ink);
  margin-bottom: 6px;
}
#soon .confirm-msg { margin-bottom: 18px; }
.confirm-row { display: flex; gap: 10px; }
.confirm-row .btn-soft, .confirm-row .btn-solid { flex: 1; }
/* team picker — list of teams the user can pick to remove */
.team-picker-list {
  display: flex; flex-direction: column; gap: 8px;
  margin: 14px 0 18px;
  max-height: 50vh; overflow-y: auto;
}
.team-picker-row {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 12px 14px;
  border: none; border-radius: 13px;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.13);
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  text-align: left;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.team-picker-row:hover {
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.28);
}
.team-picker-row:active { transform: scale(0.98); }
.team-picker-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--c, #999);
  border: 2px solid rgba(0,0,0,0.12);
  flex-shrink: 0;
}
.team-picker-name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}
/* text / email inputs inside the waitlist + request-a-scorer dialogs */
.field-input {
  width: 100%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: none; border-radius: 13px;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.13);
  color: var(--ink);
  font-family: inherit; font-size: 15.5px; font-weight: 500;
  -webkit-appearance: none;
}
.field-input::placeholder { color: var(--ink-3); }
.field-input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--yellow-d); }

/* ============ RESPONSIVE ============ */
@media (max-width: 420px) {
  .app { padding: 20px 12px 22px; }
  .tile { padding: 12px; gap: 11px; }
  .die3d { width: 58px; height: 58px; }
  .tile-total { font-size: 28px; }
  .tile.leader .tile-total { font-size: 31px; }
  /* tighten the score table so 4 teams fit a phone with no scroll */
  .stable th, .stable td { padding: 9px 5px; }
  .stable thead th { padding-top: 11px; padding-bottom: 9px; }
  .stable.fit .stable-tn-input { font-size: 11px; max-width: none; }
  .stable-corner { font-size: 9px; letter-spacing: 0.02em; }
  .stable .scell { font-size: 14px; }
  .stable tfoot td { font-size: 15.5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============ TOPBAR ACTIONS ============ */
.topbar-actions { display: flex; align-items: center; gap: 9px; }

/* ============ SCORE-TABLE ACTIONS ============ */
.history-actions { display: flex; align-items: center; gap: 6px; }
.history-actions button {
  background: none; border: none;
  color: var(--ink-3); font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer;
  padding: 4px 6px; border-radius: 9px;
}
#btn-undo-history:hover { color: var(--blue-d); }
#btn-clear-history:hover { color: var(--red); }

/* ============ RULES SHEET ============ */
.rules-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 13px;
  counter-reset: rule;
  margin: 6px 0;
}
.rules-list li {
  position: relative;
  padding-left: 42px;
  font-size: 14.5px; line-height: 1.42;
  color: var(--ink-2);
}
.rules-list li b { color: var(--ink); font-weight: 600; }
.rules-list li::before {
  counter-increment: rule;
  content: counter(rule);
  position: absolute; left: 0; top: -2px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  color: #5a3d0c;
  font-weight: 700; font-size: 14px;
  box-shadow: 0 3px 0 var(--yellow-d);
}
.rules-foot {
  margin-top: 15px; padding: 12px 14px;
  border-radius: 15px;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.09);
  font-size: 13px; color: var(--ink-2); line-height: 1.4;
}
/* help dialog — segmented tabs (the game / using the app) */
.rules-tabs {
  display: flex; gap: 4px;
  margin: 2px 22px 9px;
  padding: 4px;
  background: var(--cream-2);
  border-radius: 14px;
}
.rules-tab {
  flex: 1;
  padding: 9px 8px;
  border: 0; border-radius: 10px;
  background: none;
  font-family: inherit;
  font-weight: 600; font-size: 13.5px;
  color: var(--ink-3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.rules-tab.is-active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 2px 6px -2px var(--soft);
}
.rules-intro {
  font-size: 14.5px; font-weight: 500;
  color: var(--ink-2); line-height: 1.45;
  margin-bottom: 13px; padding: 0 2px;
}
.rules-buy { width: 100%; margin-top: 18px; }
.rules-credit {
  margin-top: 16px;
  text-align: center;
  font-size: 12px; color: var(--ink-3);
}

/* ============ MENU TOGGLE SWITCH ============ */
.menu-switch {
  appearance: none; -webkit-appearance: none;
  flex-shrink: 0;
  width: 60px; height: 44px;
  border-radius: 999px;
  background: var(--cream-2);
  box-shadow: inset 0 2px 4px rgba(120,90,30,0.22);
  cursor: pointer; position: relative;
  transition: background .18s var(--ease);
}
.menu-switch::after {
  content: ''; position: absolute;
  top: 4px; left: 4px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 2px 4px rgba(70,52,20,0.35);
  transition: transform .2s var(--spring);
}
.menu-switch:checked { background: var(--green); }
.menu-switch:checked::after { transform: translateX(16px); }
.menu-switch:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

/* ============ WIN — FINAL STANDINGS ============ */
.win-standings {
  list-style: none;
  display: flex; flex-direction: column; gap: 6px;
  margin: 6px 0 20px;
  text-align: left;
}
.ws-row {
  display: grid;
  grid-template-columns: 20px 16px 1fr auto;
  align-items: center; gap: 9px;
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(120,90,30,0.08);
  animation: wsIn .42s var(--spring) both;
  animation-delay: calc(var(--ws,0) * 70ms + 260ms);
}
@keyframes wsIn {
  0%   { opacity: 0; transform: translateX(-14px); }
  100% { opacity: 1; transform: translateX(0); }
}
.ws-row.ws-win {
  background: linear-gradient(180deg, #ffe07a, var(--yellow) 66%);
  box-shadow: inset 0 -3px 0 var(--yellow-d);
}
.ws-rank {
  font-weight: 700; font-size: 13px;
  color: var(--ink-3); text-align: center;
  font-variant-numeric: tabular-nums;
}
.ws-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.85), transparent 56%),
    var(--d, #ccc);
  box-shadow: inset 0 -1.5px 2px rgba(0,0,0,0.25), 0 0 0 1.5px rgba(255,255,255,0.7);
}
.ws-name {
  font-weight: 600; font-size: 15px;
  color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ws-score {
  font-weight: 700; font-size: 19px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ws-win .ws-rank, .ws-win .ws-name, .ws-win .ws-score { color: #5a3d0c; }

/* ============ WIN — SECONDARY ROW ============ */
.win-row { display: flex; gap: 10px; margin-top: 11px; }
.win-2nd {
  flex: 1;
  background: none; border: none;
  color: var(--ink-3); font-size: 14px; font-weight: 600;
  font-family: inherit;
  cursor: pointer; padding: 9px;
  border-radius: 12px;
  transition: color .14s var(--ease), background .14s var(--ease);
}
.win-2nd:hover { color: var(--ink); background: var(--cream); }
.win-card { max-height: 90vh; overflow-y: auto; }

/* ============ CALIBRATION SHEET ============ */
/* compact sheets (menu, rules, calibration) open tall — not squished at the bottom */
.sheet-compact { min-height: 62vh; }
.sheet-compact .sheet-body { flex: 1 1 auto; }

.cal-photos {
  display: flex; flex-wrap: wrap; gap: 14px;
  padding: 6px 2px 4px;
}
.cal-photo-fig { position: relative; margin: 0; flex: 0 0 auto; }
.cal-photo {
  display: block;
  width: 116px; height: 116px;
  object-fit: cover;
  border-radius: 18px;
  border: 3px solid var(--paper);
  box-shadow: 0 4px 0 var(--cream-2), 0 7px 16px -7px rgba(58,44,30,0.45);
}
.cal-x {
  position: absolute; top: -9px; right: -9px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 3px solid var(--paper); border-radius: 50%;
  background: var(--red); color: #fff; cursor: pointer;
  box-shadow: 0 3px 0 var(--red-d);
  transition: transform .1s var(--ease), box-shadow .1s var(--ease);
}
.cal-x svg { width: 13px; height: 13px; }
.cal-x:active { transform: translateY(3px); box-shadow: 0 0 0 var(--red-d); }
.cal-empty {
  margin: 8px 2px; color: var(--ink-3);
  font-size: 14px; font-weight: 500;
}
.cal-colors-head {
  margin: 16px 0 10px;
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-2);
}
@keyframes calPop { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
.cal-dice { display: flex; flex-direction: column; gap: 10px; }
.cal-die {
  padding: 11px 13px;
  background: var(--cream);
  border-radius: 16px;
  animation: calPop .34s var(--spring) both;
}
.cal-die-label {
  display: block;
  margin-bottom: 7px;
  font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-3);
}
.cal-die-cols { display: flex; flex-wrap: wrap; gap: 8px; }
.cal-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 7px;
  background: var(--paper);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1.5px rgba(120,90,30,0.1);
}
.cal-chip-dot {
  width: 24px; height: 24px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--d);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.5), inset 0 -3px 5px rgba(0,0,0,0.22),
              0 0 0 2px var(--paper), 0 2px 5px -1px rgba(58,44,30,0.38);
}
.cal-chip-txt { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.cal-chip-txt b { font-weight: 700; color: var(--ink-3); margin-right: 4px; }
.cal-die-status { font-size: 14px; font-weight: 600; color: var(--ink-3); }
.cal-die-status.err { color: var(--red); }
.cal-tip {
  margin: 12px 2px 2px;
  font-size: 13px; font-weight: 500;
  color: var(--ink-3); line-height: 1.5;
}

/* ============ FULL-SCREEN PHOTO ============ */
.fsphoto {
  position: fixed; inset: 0; z-index: 6000;
  background: rgba(20,15,10,0.92);
  display: flex; flex-direction: column;
}
.fsphoto[hidden] { display: none; }
.fsphoto-stage {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  width: 100%;
  overflow: auto;
  display: flex; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 10px 10px;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  touch-action: pinch-zoom pan-x pan-y;
}
.fsphoto-img {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  display: block;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.fsphoto-detect {
  position: absolute;
  pointer-events: none;
  overflow: visible;
}
.fsphoto-marker {
  pointer-events: none;
  animation: none;
}
.fsphoto-results {
  flex: 0 0 auto;
  width: 100%;
  padding: 11px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  background: rgba(255,251,241,0.97);
  color: var(--ink);
  box-shadow: 0 -10px 30px rgba(0,0,0,0.28);
}
.fsphoto-results-head {
  max-width: 880px;
  margin: 0 auto 8px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.fsphoto-results-head strong { font-size: 14px; }
.fsphoto-results-head span { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.fsphoto-results-list {
  max-width: 880px;
  margin: 0 auto;
  display: flex; gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 3px;
  -webkit-overflow-scrolling: touch;
}
.fsphoto-result {
  flex: 1 0 142px;
  min-width: 142px;
  max-width: 210px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  box-sizing: border-box;
  border-radius: 13px;
  background: var(--cream);
  box-shadow: inset 0 0 0 1.5px rgba(120,90,30,0.1);
}
.fsphoto-result-dot {
  width: 22px; height: 22px; flex: none;
  border-radius: 7px;
  background: var(--team);
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.45), inset 0 -3px 5px rgba(0,0,0,0.22);
}
.fsphoto-result-label {
  min-width: 0; flex: 1;
  display: flex; flex-direction: column;
}
.fsphoto-result-label strong {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px;
}
.fsphoto-result-label small { color: var(--ink-3); font-size: 10.5px; }
.fsphoto-result-total {
  flex: none;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.fsphoto-close {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: 14px;
  z-index: 1;
  width: 42px; height: 42px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.fsphoto-close svg { width: 20px; height: 20px; }

@media (max-height: 560px) {
  .fsphoto-results { padding-top: 8px; }
  .fsphoto-results-head { margin-bottom: 5px; }
  .fsphoto-result { padding-block: 6px; }
}

/* ============ SAVED SETUPS ============ */
.setups-save-row {
  display: flex; gap: 8px; align-items: stretch;
  margin: 4px 0 10px;
}
.setups-save-row .field-input { flex: 1 1 auto; }
.setups-save-row .btn-solid { flex: 0 0 auto; padding: 10px 14px; font-size: 13px; }
.setups-tip {
  margin: 0 2px 10px;
  font-size: 12.5px; font-weight: 500;
  color: var(--ink-3); line-height: 1.45;
}
.setups-list {
  display: flex; flex-direction: column; gap: 8px;
}
.setups-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(120,90,30,0.18);
  border-radius: 13px;
  background: var(--cream-2);
}
.setups-row-main {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  text-align: left;
  border: 0; background: transparent;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.setups-row-name { font-size: 14.5px; font-weight: 700; }
.setups-row-sub  { font-size: 12px; font-weight: 500; color: var(--ink-3); }
.setups-row-x {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: rgba(120,90,30,0.10);
  color: var(--ink-3);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.setups-row-x:active { transform: scale(0.93); }
.setups-row-x svg { width: 16px; height: 16px; }
.setups-empty {
  text-align: center;
  padding: 20px 12px;
  font-size: 13px; font-weight: 500;
  color: var(--ink-3);
}

/* ============ EXPORT FALLBACK (copy text) ============ */
.exportfb-text {
  width: 100%;
  margin: 10px 0 4px;
  padding: 10px;
  font-family: 'SFMono-Regular', Menlo, monospace;
  font-size: 11.5px;
  color: var(--ink);
  background: var(--cream-2);
  border: 1px solid rgba(120,90,30,0.2);
  border-radius: 10px;
  resize: vertical;
  -webkit-user-select: text; user-select: text;
}
