/* Yahtzee — felt table, ivory dice, a wooden tray. Theme colours arrive as
   custom properties from themes.js; the defaults below are "Casino felt". */

:root {
  --felt: #1f6a40;
  --felt-deep: #134a2b;
  --felt-light: #2f8653;
  --wood: #6e4327;
  --wood-light: #a06a3e;
  --wood-rim: #3f2415;
  --bg-a: #ece4d4;
  --bg-b: #cbd4c7;
  --paper: #f8f4ec;
  --paper-2: #eee7da;
  --ink: #2a2420;
  --ink-soft: #6c6157;
  --line: rgba(50, 38, 25, 0.12);
  --accent: #8a5a34;
  --accent-ink: #fff8ee;
  --glow: #f3d98b;
  --ivory: #fffdf5;
  --ivory-2: #ece2c8;
  --pip: #23232a;
  --radius: 18px;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --settle: cubic-bezier(0.22, 1, 0.36, 1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --die: 54px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  transition: background 0.8s, color 0.4s;
}

/* ---------------------------------------------------------- background */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg .blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.5; will-change: transform; }
.bg .b1 { width: 60vmax; height: 60vmax; left: -22vmax; top: -26vmax; background: color-mix(in oklab, var(--paper) 80%, white); animation: drift 50s ease-in-out infinite alternate; }
.bg .b2 { width: 52vmax; height: 52vmax; right: -22vmax; bottom: -22vmax; background: color-mix(in oklab, var(--felt-light) 30%, transparent); animation: drift 64s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 32vw; bottom: -26vmax; background: color-mix(in oklab, var(--wood-light) 28%, transparent); animation: drift 76s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.12); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 2px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 40px; height: 40px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: 0.02em; }
.brand small { font-size: 11.5px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }
.menu { display: flex; gap: 4px; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: color-mix(in oklab, var(--ink) 8%, transparent); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 4px 16px 6px; }
.stat {
  background: color-mix(in oklab, var(--paper) 50%, transparent);
  border: 1px solid color-mix(in oklab, var(--paper) 70%, transparent);
  box-shadow: 0 1px 2px rgba(40, 30, 20, 0.06);
  border-radius: 12px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.stat span { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
.stat b { font-family: var(--serif); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- table */
.table {
  container-type: inline-size;
  padding: 2px 16px 0;
  flex: 0 0 auto;
}
.felt {
  --die: clamp(40px, calc((100cqw - 28px - 4 * 12px) / 5), 64px);
  --gap: 12px;
  position: relative;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--felt-img) center / 300px 300px, var(--felt);
  box-shadow:
    0 0 0 6px var(--wood),
    0 0 0 7px var(--wood-rim),
    inset 0 2px 10px rgba(0, 0, 0, 0.35),
    inset 0 -1px 0 rgba(255, 255, 255, 0.12),
    0 18px 34px -16px rgba(30, 20, 10, 0.55),
    0 4px 10px -4px rgba(30, 20, 10, 0.35);
  margin: 7px 7px 9px;
  transition: background 0.6s;
  overflow: hidden;
}
.felt::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.12), transparent 60%);
  pointer-events: none;
}
.tray {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--die) + 22px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 30%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.05) 0 2px, rgba(0, 0, 0, 0) 2px 9px),
    linear-gradient(180deg, var(--wood-light), var(--wood) 55%, color-mix(in oklab, var(--wood) 80%, black));
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  border-top: 1px solid var(--wood-rim);
}
.tray::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px; top: 9px;
  height: calc(100% - 16px);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.45), inset 0 -1px 0 rgba(255, 255, 255, 0.12);
}

.dice {
  position: relative;
  height: calc(var(--die) * 2 + 20px);
  touch-action: none;
  z-index: 1;
}
.die {
  position: absolute;
  top: 0;
  left: calc(var(--slot) * (var(--die) + (100% - 5 * var(--die)) / 4));
  width: var(--die);
  height: var(--die);
  cursor: pointer;
  transition: top 0.45s var(--ease), opacity 0.3s, filter 0.3s;
  transform: rotate(var(--tilt, 0deg));
  transform-origin: center;
  will-change: top;
}
.die.held { top: calc(var(--die) + 20px); }
.die.ghost { opacity: 0.58; filter: saturate(0.85); cursor: default; }
.die.dragging { transition: none; z-index: 5; }
.die::after {
  content: "";
  position: absolute;
  left: 8%; right: 8%; bottom: -8%;
  height: 20%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.42);
  filter: blur(4px);
  z-index: -1;
  transition: transform 0.3s, opacity 0.3s;
}
.die.held::after { background: rgba(0, 0, 0, 0.55); }
.die.rolling { animation: toss 1s var(--settle); }
.die.rolling::after { animation: toss-shadow 1s var(--settle); }
@keyframes toss {
  0% { transform: translateY(0) rotate(var(--tilt, 0deg)) scale(1); }
  30% { transform: translateY(-38%) rotate(calc(var(--tilt, 0deg) + 40deg)) scale(1.1); }
  62% { transform: translateY(0) rotate(var(--tilt, 0deg)) scale(1); }
  76% { transform: translateY(-9%) rotate(var(--tilt, 0deg)) scale(1.03); }
  88% { transform: translateY(0) rotate(var(--tilt, 0deg)) scale(0.98, 1.02); }
  100% { transform: translateY(0) rotate(var(--tilt, 0deg)) scale(1); }
}
@keyframes toss-shadow {
  30% { transform: scale(0.7); opacity: 0.4; }
  62% { transform: scale(1); opacity: 1; }
  76% { transform: scale(0.92); opacity: 0.8; }
}
.die.wobble .cube { animation: wobble 0.35s var(--ease); }
@keyframes wobble { 30% { transform: var(--rot) rotate(-6deg); } 70% { transform: var(--rot) rotate(5deg); } }

.cube {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: var(--rot, rotateX(0deg) rotateY(0deg));
  transition: transform 1.05s var(--settle);
}
.dice.instant .cube, .dice.instant .die { transition: none; }
.face {
  position: absolute;
  inset: 0;
  border-radius: 16%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 55%),
    linear-gradient(150deg, var(--ivory), var(--ivory-2));
  box-shadow:
    inset 0 0 0 1px rgba(90, 70, 40, 0.12),
    inset 2px 2px 3px rgba(255, 255, 255, 0.85),
    inset -3px -4px 6px rgba(120, 95, 55, 0.28);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 15%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.f1 { transform: rotateY(0deg) translateZ(calc(var(--die) / 2)); }
.face.f2 { transform: rotateY(90deg) translateZ(calc(var(--die) / 2)); }
.face.f3 { transform: rotateX(90deg) translateZ(calc(var(--die) / 2)); }
.face.f4 { transform: rotateX(-90deg) translateZ(calc(var(--die) / 2)); }
.face.f5 { transform: rotateY(-90deg) translateZ(calc(var(--die) / 2)); }
.face.f6 { transform: rotateY(180deg) translateZ(calc(var(--die) / 2)); }
.face i {
  display: block;
  width: 76%;
  height: 76%;
  margin: auto;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, color-mix(in oklab, var(--pip) 60%, #9a9aa6), var(--pip) 66%);
  box-shadow: inset 0 1px 1.5px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.6);
}
.face i.p1 { grid-area: 1 / 1; } .face i.p2 { grid-area: 1 / 2; } .face i.p3 { grid-area: 1 / 3; }
.face i.p4 { grid-area: 2 / 1; } .face i.p5 { grid-area: 2 / 2; } .face i.p6 { grid-area: 2 / 3; }
.face i.p7 { grid-area: 3 / 1; } .face i.p8 { grid-area: 3 / 2; } .face i.p9 { grid-area: 3 / 3; }

.hint {
  margin: 0;
  padding: 0 4px 4px;
  min-height: 20px;
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-soft);
  transition: opacity 0.3s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------ scorecard */
.ptabs { display: flex; gap: 8px; padding: 0 16px 6px; }
.ptab {
  appearance: none;
  flex: 1;
  border: 1.5px solid var(--line);
  background: color-mix(in oklab, var(--paper) 50%, transparent);
  color: var(--ink-soft);
  font: 500 13px var(--sans);
  padding: 6px 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.ptab b { font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.ptab[aria-selected="true"] { background: var(--paper); color: var(--ink); border-color: color-mix(in oklab, var(--accent) 60%, transparent); }
.ptab .dot { width: 8px; height: 8px; border-radius: 50%; background: transparent; transition: background 0.3s; }
.ptab.turn .dot { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent); }

.cards {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 0 16px 6px;
}
.card {
  flex: 0 1 350px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(40, 30, 20, 0.08), 0 8px 24px -14px rgba(40, 30, 20, 0.4);
  border: 1px solid color-mix(in oklab, var(--line) 60%, transparent);
  overflow: hidden;
  transition: opacity 0.3s, box-shadow 0.3s;
}
.cards.duo .card:not(.active) { display: none; }
.cards.duo .card.turn { box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 45%, transparent), 0 8px 24px -14px rgba(40, 30, 20, 0.4); }
.card > header { display: none; align-items: center; justify-content: space-between; padding: 7px 12px 2px; font-size: 12.5px; color: var(--ink-soft); letter-spacing: 0.06em; text-transform: uppercase; }
.card > header b { font-family: var(--serif); font-size: 16px; color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 600; }
.cards.duo .card > header { display: flex; }
.cols { flex: 1 1 auto; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: minmax(0, 1fr); gap: 0 8px; padding: 4px 8px 2px; min-height: 0; }
.card > header, .card-total { flex: 0 0 auto; }
.col { display: grid; grid-template-rows: repeat(7, minmax(0, 1fr)); min-height: 0; }

.row {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 500 clamp(11px, 2.9cqw, 13.5px) var(--sans);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 0 6px 0 8px;
  min-height: 24px;
  border-radius: 9px;
  text-align: left;
  position: relative;
  transition: background 0.2s, opacity 0.3s, transform 0.15s;
  overflow: hidden;
  cursor: default;
}
.row + .row::before { content: ""; position: absolute; left: 8px; right: 6px; top: 0; border-top: 1px dashed var(--line); }
.row .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.row .val {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.18em;
  font-variant-numeric: tabular-nums;
  min-width: 2.2em;
  text-align: right;
  color: var(--ink-soft);
  opacity: 0.55;
  transition: color 0.25s, opacity 0.25s, transform 0.25s;
}
.row.ready { cursor: pointer; }
.row.ready .label { color: var(--ink); }
.row.ready .val { opacity: 0.85; color: var(--accent); font-style: italic; }
.row.ready .val.zero { opacity: 0.45; color: var(--ink-soft); }
.row.ready:hover { background: color-mix(in oklab, var(--accent) 10%, transparent); }
.row.ready:active { transform: scale(0.985); background: color-mix(in oklab, var(--accent) 18%, transparent); }
.row.blocked { opacity: 0.38; }
.row.filled .label { color: var(--ink-soft); }
.row.filled .val { opacity: 1; color: var(--ink); font-style: normal; }
.row.filled .val.zero { opacity: 0.45; }
.row.just { animation: scored 0.9s var(--ease); }
.row.just .val { animation: popval 0.6s var(--ease); }
@keyframes scored { 0% { background: color-mix(in oklab, var(--glow) 55%, transparent); } 100% { background: transparent; } }
@keyframes popval { 30% { transform: scale(1.35); } }
.row .pill {
  font: 600 10px var(--sans);
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  padding: 2px 6px;
  margin-left: 4px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.row.bonus .label { color: var(--ink-soft); }
.row.bonus .sub { font-size: 0.82em; opacity: 0.75; margin-left: 4px; font-variant-numeric: tabular-nums; }
.row.bonus.earned .val { opacity: 1; color: #2f7a4c; }
[data-dark="true"] .row.bonus.earned .val { color: #8fd3a5; }

.card-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 5px 16px 7px;
  border-top: 1px solid var(--line);
  background: color-mix(in oklab, var(--paper-2) 70%, transparent);
}
.card-total span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.card-total b { font-family: var(--serif); font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }

/* -------------------------------------------------------------- actions */
.actions { display: flex; gap: 10px; padding: 4px 16px 12px; }
.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--paper) 70%, transparent);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(40, 30, 20, 0.08);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s, filter 0.2s;
}
.btn svg { width: 19px; height: 19px; }
.btn:hover { background: var(--paper); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary {
  flex: 1.6;
  background: linear-gradient(180deg, color-mix(in oklab, var(--wood-light) 85%, white), var(--wood));
  color: var(--accent-ink);
  border-color: var(--wood-rim);
  box-shadow: 0 4px 12px -4px rgba(60, 35, 20, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary em { font-style: normal; font-family: var(--serif); font-size: 1.1em; opacity: 0.85; }
.btn.primary.attention { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { box-shadow: 0 4px 18px -2px color-mix(in oklab, var(--glow) 70%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.25); } }
.btn.subtle { flex: 0 0 auto; background: transparent; box-shadow: none; border: 0; color: var(--ink-soft); font-size: 13.5px; margin: 14px auto 0; display: flex; }
.btn.mode { flex-direction: column; gap: 8px; padding: 14px 10px; }
.dice-glyph { position: relative; width: 30px; height: 30px; }
.dice-glyph::before, .dice-glyph::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 7px;
  background: linear-gradient(150deg, var(--ivory), var(--ivory-2));
  box-shadow: inset 0 0 0 1px rgba(90, 70, 40, 0.15), 0 1px 2px rgba(0, 0, 0, 0.25);
  background-image: radial-gradient(circle, var(--pip) 0 3px, transparent 3.5px), linear-gradient(150deg, var(--ivory), var(--ivory-2));
  background-position: center, 0 0;
  background-size: 100% 100%, 100% 100%;
}
.dice-glyph.two::before { transform: translate(-8px, -3px) rotate(-10deg); }
.dice-glyph.two::after { transform: translate(8px, 4px) rotate(12deg); }
.dice-glyph.one::after { display: none; }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20, 16, 10, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(20, 16, 10, 0.3);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; flex: 0 0 auto; }
.sheet h2, .dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
}
.sheet-body h3 { font-family: var(--serif); font-weight: 600; font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 5px 0; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

@media (min-width: 700px) and (min-height: 560px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 24px; max-height: 80dvh; animation: pop 0.28s var(--ease); }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

.dialog {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  width: min(92vw, 400px);
  background: var(--paper);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(20, 16, 10, 0.4);
  text-align: center;
  animation: popc 0.3s var(--ease);
  overflow: hidden;
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); } }
.dialog p { margin: 8px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog .row { display: flex; gap: 10px; }
.dialog .row.modes { gap: 12px; }
.result .glow { position: absolute; inset: -40% -20% auto; height: 70%; background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--glow) 50%, transparent), transparent 65%); pointer-events: none; opacity: 0.8; }
.result h2 { position: relative; font-size: 30px; }
.result[data-best="true"] h2 { animation: shimmer 2.4s ease-in-out infinite; }
@keyframes shimmer { 50% { text-shadow: 0 0 18px color-mix(in oklab, var(--glow) 80%, white); } }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.result-stats div, .summary div { display: flex; flex-direction: column; align-items: center; background: var(--paper-2); border-radius: 12px; padding: 8px 4px; line-height: 1.2; }
.result-stats span, .summary span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.result-stats b, .summary b { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.score { display: flex; flex-direction: column; align-items: center; margin: 4px 0 18px; }
.score span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.score b { font-family: var(--serif); font-size: 46px; font-weight: 600; line-height: 1.05; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; vertical-align: bottom; font-weight: 500; color: var(--ink-soft); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.num, td.num { text-align: right; }
td.total { font-family: var(--serif); font-weight: 600; font-size: 15px; text-align: right; }
th.total { text-align: right; }
td.bonus.yes { color: #2f7a4c; font-weight: 600; }
[data-dark="true"] td.bonus.yes { color: #8fd3a5; }

/* ------------------------------------------------------------- settings */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.opts.lang .opt { padding-left: 14px; min-width: 96px; justify-content: center; }
.swatch { display: inline-block; width: 24px; height: 24px; border-radius: 7px; flex: 0 0 auto; background: var(--sw); box-shadow: inset 0 0 0 3px var(--sw2), inset 0 0 0 4px rgba(0, 0, 0, 0.2); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 22px; cursor: pointer; font-size: 15px; line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: color-mix(in oklab, var(--ink-soft) 40%, var(--paper-2)); position: relative; transition: background 0.25s; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  background: rgba(30, 24, 18, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: min(88vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------------ responsive */
@media (min-width: 700px) {
  .cards.duo { flex-direction: row; align-items: center; }
  .cards.duo .card { flex: 1 1 0; height: min(100%, 350px); }
  .cards.duo .card:not(.active) { display: grid; }
  .ptabs { display: none !important; }
  .row { font-size: 14px; min-height: 28px; }
}
@media (max-height: 700px) {
  .felt { --die: clamp(38px, calc((100cqw - 28px - 4 * 12px) / 5), 50px); }
}
@media (max-height: 640px) {
  .top { padding-top: 4px; }
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .brand img { width: 32px; height: 32px; }
  .icon-btn { width: 38px; height: 38px; }
  .stat b { font-size: 17px; }
  .stat { padding: 3px 6px; }
  .felt { --die: clamp(34px, calc((100cqw - 28px - 4 * 12px) / 5), 44px); padding: 9px 14px; }
  .dice { height: calc(var(--die) * 2 + 14px); }
  .die.held { top: calc(var(--die) + 14px); }
  .tray { height: calc(var(--die) + 16px); }
  .hint { min-height: 17px; font-size: 11.5px; padding-bottom: 2px; }
  .felt { margin: 7px 7px 7px; }
  .actions { padding: 2px 16px 8px; }
  .btn { padding: 8px 10px; }
  .card-total { padding: 3px 14px 5px; }
  .card-total b { font-size: 20px; }
  .row { min-height: 20px; }
}
@media (max-width: 520px) {
  .btn span { white-space: nowrap; }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .die, .cube, .sheet, .dialog, .backdrop, .row, .row .val { animation: none !important; transition-duration: 0.01s !important; }
  .btn.primary.attention { animation: none; }
}
