/*
 * Liar's Dice: "Altiplano" theme.
 * A high-plains night: indigo woven cloth, clay cups with painted bands,
 * bone dice, and stripes of madder, saffron, turquoise and cochineal from
 * a carrying cloth. Saffron marks counting dice and the next move,
 * cochineal marks wilds, madder marks a call or a loss, turquoise is you.
 */

@font-face {
  font-family: 'Dela Gothic One';
  src: url('fonts/dela-gothic-one-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('fonts/bricolage-grotesque-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('fonts/bricolage-grotesque-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #121433;
  --bg-2: #191c48;
  --panel: #171a45;
  --cloth: #252a6e;
  --cloth-2: #2e3482;
  --cloth-dk: #1a1e56;
  --line: rgba(246, 239, 225, 0.14);
  --line-2: rgba(246, 239, 225, 0.26);
  --text: #f6efe1;
  --muted: #b9b7da;
  --dim: #8a88b4;
  --bone: #f5ecd9;
  --bone-sh: #d9c8a7;
  --pip: #1c1e48;
  --madder: #dc4530;
  --madder-dk: #a8301f;
  --saffron: #f4b740;
  --saffron-dk: #c98a17;
  --cochineal: #e24a86;
  --turq: #38c1ad;
  --clay: #c4683f;
  --clay-dk: #8b3f22;
  --ink: #15163a;
  --display: 'Dela Gothic One', 'Arial Black', system-ui, sans-serif;
  --text-font: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
  --ease-pop: cubic-bezier(0.2, 0.9, 0.25, 1.25);
  --ease: cubic-bezier(0.25, 0.8, 0.25, 1);
  --aguayo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='14'%3E%3Crect width='24' height='14' fill='%23dc4530'/%3E%3Crect y='3' width='24' height='8' fill='%231c1e48'/%3E%3Cpath d='M0 10.5 6 3.5l6 7 6-7 6 7' fill='none' stroke='%23f4b740' stroke-width='2'/%3E%3Ccircle cx='6' cy='9' r='1.3' fill='%23e24a86'/%3E%3Ccircle cx='18' cy='9' r='1.3' fill='%23e24a86'/%3E%3Crect width='24' height='1.4' fill='%2338c1ad'/%3E%3Crect y='12.6' width='24' height='1.4' fill='%2338c1ad'/%3E%3C/svg%3E");
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --ds: 25px;
  --cupw: 62px;
  --my-ds: 52px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 520px at 50% -10%, rgba(92, 104, 210, 0.35), transparent 70%),
    radial-gradient(800px 600px at 110% 110%, rgba(226, 74, 134, 0.12), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--text-font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--grain);
  opacity: 0.07;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 100;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 3px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Shell */

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.brand { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.wordmark {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1;
}
.wordmark b, .setup-title b { color: var(--saffron); font-weight: 400; }
.tick {
  display: inline-block;
  width: 0.26em;
  height: 0.26em;
  margin: 0 0.04em 0 0.06em;
  background: var(--cochineal);
  border-radius: 0.06em;
  transform: translateY(-0.52em) rotate(45deg);
}
.meta { margin: 0; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.meta b { color: var(--text); font-weight: 700; }
.tools { display: flex; gap: 6px; flex: none; }
.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 1.5px solid var(--line-2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 14px;
  font-weight: 700;
}
.tool:hover { background: rgba(255, 255, 255, 0.08); }
.tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.room {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
}
.table-wrap {
  display: flex;
  min-height: 0;
  padding: 6px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
}

/* ------------------------------------------------------------------ */
/* The cloth */

.table {
  position: relative;
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  padding: 34px clamp(12px, 3vw, 36px) 30px;
  border-radius: 30px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.028) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.09) 0 1px, transparent 1px 4px),
    radial-gradient(ellipse at 50% 45%, var(--cloth-2), var(--cloth) 55%, var(--cloth-dk));
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.25),
    inset 0 0 80px rgba(8, 9, 30, 0.6),
    0 30px 60px -30px rgba(0, 0, 0, 0.8);
}
.table::before, .table::after {
  content: '';
  position: absolute;
  left: 22px;
  right: 22px;
  height: 14px;
  background: var(--aguayo) repeat-x;
  border-radius: 3px;
  opacity: 0.92;
  pointer-events: none;
}
.table::before { top: 10px; }
.table::after { bottom: 10px; transform: scaleY(-1); }

/* ------------------------------------------------------------------ */
/* Dice */

.die, .face-icon, .face-die, .plaque-die, .hb-die, .hero-die {
  display: inline-block;
  position: relative;
  flex: none;
}
.die { width: var(--ds); height: var(--ds); }
.die svg, .face-icon svg, .face-die svg, .plaque-die svg, .hb-die svg, .hero-die svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.die-body { fill: var(--bone); }
.die-edge { fill: none; stroke: rgba(80, 60, 30, 0.28); stroke-width: 1; }
.pip { fill: var(--pip); }
.d1 .pip { fill: var(--cochineal); }
.die svg, .plaque-die svg, .hero-die svg { filter: drop-shadow(0 2px 0 var(--bone-sh)) drop-shadow(0 4px 5px rgba(0, 0, 0, 0.35)); }

/* ------------------------------------------------------------------ */
/* Opponents */

.rivals {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(8px, 2.2vw, 30px);
}
.seat {
  position: relative;
  flex: 0 1 170px;
  min-width: 0;
  margin-top: calc((1 - var(--arc, 1)) * 44px);
}
.seat-vis {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.cup-wrap {
  position: relative;
  width: 100%;
  height: calc(var(--cupw) * 0.92);
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
.cup {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: var(--cupw);
  height: calc(var(--cupw) * 0.92);
  margin-left: calc(var(--cupw) / -2);
  transform-origin: 30% 100%;
  transition: transform 0.5s var(--ease-pop), opacity 0.5s var(--ease);
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.45));
  z-index: 2;
}
.cup svg, .me-cup svg, .hero-cup svg { width: 100%; height: 100%; display: block; overflow: visible; }
.cup-body { fill: var(--clay); }
.cup-band { fill: var(--clay-dk); }
.cup-zig { stroke: var(--saffron); stroke-width: 2.6; stroke-linejoin: round; }
.cup-lip { fill: #a24f2c; }
.cup-shine { fill: rgba(255, 230, 200, 0.22); }
.seat .cup-band { fill: color-mix(in srgb, var(--c) 45%, var(--clay-dk)); }

.seat .dice {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-end;
  gap: 3px;
  max-width: 100%;
  padding-bottom: 2px;
  z-index: 1;
}
.seat.lifted .cup {
  transform: translate(calc(var(--cupw) * -0.25), -64%) rotate(-24deg);
  opacity: 0.32;
}
.seat.lifted .die { animation: pop-in 0.42s var(--ease-pop) backwards; animation-delay: calc(var(--i) * 45ms); }

.seat-plate {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 10px 5px 5px;
  border-radius: 999px;
  background: rgba(10, 12, 40, 0.55);
  border: 1.5px solid var(--line);
  transition: border-color 0.3s, box-shadow 0.3s;
}
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c, var(--turq)) 22%, #0d0f33);
  border: 2px solid var(--c, var(--turq));
}
.avatar svg { width: 20px; height: 20px; fill: none; stroke: var(--c, var(--turq)); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.seat-id { display: flex; flex-direction: column; min-width: 0; line-height: 1.12; }
.seat-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; }
.seat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; margin: 0; }
.count { display: flex; gap: 3px; min-height: 8px; }
.count i {
  width: 8px; height: 8px; border-radius: 2px;
  background: var(--bone);
  box-shadow: 0 1px 0 var(--bone-sh);
}
.count i.gone { background: transparent; box-shadow: inset 0 0 0 1.5px rgba(245, 236, 217, 0.28); }

.seat.is-turn .seat-plate { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent), 0 0 24px color-mix(in srgb, var(--c) 40%, transparent); }
.seat.is-turn .cup { animation: bob 1.1s ease-in-out infinite; }
.seat.is-bidder .seat-plate { border-color: var(--saffron); }
.seat.is-out .seat-vis { opacity: 0.38; filter: grayscale(0.8); }
.seat.is-out .cup { transform: translateY(14%) rotate(-96deg); }

.thinking { display: inline-flex; align-items: baseline; gap: 2px; color: var(--text); }
.thinking i {
  width: 4px; height: 4px; border-radius: 50%; background: currentColor;
  animation: dot 1s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }

/* Speech bubbles */
.say {
  position: absolute;
  left: 50%;
  top: -14px;
  z-index: 5;
  margin: 0;
  padding: 6px 11px 7px;
  border-radius: 12px;
  background: var(--bone);
  color: var(--ink);
  font-family: var(--display);
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 6px) scale(0.85);
  transition: opacity 0.2s, transform 0.25s var(--ease-pop);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}
.say::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px; height: 12px;
  margin-left: -6px;
  background: inherit;
  transform: rotate(45deg);
  border-radius: 2px;
  z-index: -1;
}
.say.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.say.tone-liar { background: var(--madder); color: #fff; font-size: 17px; }
.say.tone-win { background: var(--saffron); }

.seat-stamp {
  position: absolute;
  left: 78%;
  top: -6px;
  z-index: 6;
  padding: 3px 8px;
  border: 3px solid currentColor;
  border-radius: 6px;
  font-family: var(--display);
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(16, 18, 52, 0.82);
  opacity: 0;
  transform: translate(-50%, -50%) rotate(12deg) scale(1.6);
  pointer-events: none;
}
.seat-stamp.show { animation: seat-stamp-in 0.38s var(--ease-pop) forwards; }
.seat-stamp.tone-lose { color: var(--madder); }
.seat-stamp.tone-win { color: var(--turq); }

/* ------------------------------------------------------------------ */
/* Plaque */

.plaque {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 0;
  gap: 2px;
}
.plaque-kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--saffron);
}
.plaque-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: clamp(52px, 9vw, 92px);
}
.plaque-main .q {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(48px, 8vw, 88px);
  line-height: 1;
  color: var(--bone);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
}
.plaque-main .x { font-family: var(--display); font-size: clamp(22px, 3vw, 34px); color: var(--muted); }
.plaque-main .vs {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 2.4em;
  padding: 4px 8px 6px;
  margin-left: 6px;
  border: 2px solid var(--line-2);
  border-radius: 12px;
  font-family: var(--display);
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1;
  color: var(--bone);
}
.plaque-main .vs small { font-family: var(--text-font); font-weight: 700; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.plaque-die { width: clamp(44px, 6.4vw, 68px); height: clamp(44px, 6.4vw, 68px); transform: rotate(-6deg); }
.plaque-main .open { font-family: var(--display); font-size: clamp(22px, 3.4vw, 34px); color: var(--bone); }
.plaque-main.slam { animation: slam 0.42s var(--ease-pop); }
.plaque-words { margin: 2px 0 0; font-size: 17px; font-weight: 700; color: var(--text); }
.of-total { font-weight: 400; color: var(--muted); }
.plaque[data-tone="lie"] .plaque-kicker, .plaque[data-tone="lie"] .plaque-words { color: #ff8c78; }
.plaque[data-tone="true"] .plaque-kicker, .plaque[data-tone="true"] .plaque-words { color: var(--turq); }
.plaque[data-tone="count"] .q { color: var(--saffron); }
.plaque[data-tone="lie"] .q { color: #ff8c78; }
.plaque[data-tone="true"] .q { color: var(--turq); }

.stamp {
  position: absolute;
  left: 64%;
  top: 22%;
  margin: 0;
  padding: 6px 22px 10px;
  border: 6px solid var(--madder);
  border-radius: 14px;
  color: var(--madder);
  background: rgba(18, 20, 51, 0.85);
  font-family: var(--display);
  font-size: clamp(36px, 5.4vw, 60px);
  line-height: 1;
  letter-spacing: 0.02em;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-10deg) scale(2.2);
  z-index: 8;
}
.stamp.show { animation: stamp-in 0.4s var(--ease-pop) forwards; }

/* ------------------------------------------------------------------ */
/* Your seat */

.me {
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(12px, 3vw, 32px);
}
.me-plate {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 6px;
}
.avatar-me {
  width: 44px; height: 44px;
  font-family: var(--display);
  font-size: 12px;
  color: var(--turq);
  border-color: var(--turq);
}
.me-text { display: flex; flex-direction: column; line-height: 1.15; }
.me-text .seat-name { font-size: 17px; }
.me .seat-sub { font-size: 13px; }
.turn-flag { color: var(--saffron) !important; font-weight: 700; }
.say-me { top: auto; bottom: calc(100% + 4px); left: 22px; transform: translate(-30%, 6px) scale(0.85); }
.say-me.show { transform: translate(-30%, 0) scale(1); }

.tray-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 14px 12px;
  border-radius: 20px;
  background: rgba(8, 10, 36, 0.45);
  border: 1.5px solid var(--line);
  transition: border-color 0.3s, box-shadow 0.3s;
}
.me.is-turn .tray-wrap { border-color: var(--turq); box-shadow: 0 0 0 3px rgba(56, 193, 173, 0.18), 0 0 30px rgba(56, 193, 173, 0.25); }
.me.is-out .tray-wrap { opacity: 0.45; }
.me-cup {
  width: 46px;
  height: 42px;
  transform: rotate(-18deg) translateY(-6px);
  transform-origin: 50% 100%;
  filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.4));
}
.me-cup .cup-band { fill: #1f6f66; }
.tray { display: flex; gap: 8px; min-width: 0; min-height: var(--my-ds); align-items: flex-end; --ds: var(--my-ds); }
.tray .die { flex: 0 1 var(--ds); min-width: 0; height: auto; aspect-ratio: 1; }
.tray-wrap { min-width: 0; }
.tray .die { transition: transform 0.25s var(--ease-pop); }
.tray .die::after, .seat .die::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 28%;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.tray .die.match { transform: translateY(-7px); }
.tray .die.match::after { opacity: 1; box-shadow: 0 0 0 3px var(--saffron), 0 0 16px rgba(244, 183, 64, 0.6); }
.tray .die.match-wild { transform: translateY(-7px); }
.tray .die.match-wild::after { opacity: 1; box-shadow: 0 0 0 3px var(--cochineal), 0 0 16px rgba(226, 74, 134, 0.6); }

/* Reveal: count the dice */
.die.dim { opacity: 0.3; filter: saturate(0.4); transition: opacity 0.3s; }
.die.hit { animation: hit 0.32s var(--ease-pop); }
.die.hit::after { opacity: 1 !important; box-shadow: 0 0 0 3px var(--saffron), 0 0 18px rgba(244, 183, 64, 0.75) !important; }
.die.hit.wild::after { box-shadow: 0 0 0 3px var(--cochineal), 0 0 18px rgba(226, 74, 134, 0.75) !important; }
.die.lost { animation: lose 0.7s var(--ease) 0.15s forwards; }

/* New round: cups shake, your dice tumble in */
.table.rolling .seat:not(.is-out) .cup, .table.rolling .me-cup { animation: shake 0.55s ease-in-out; }
.table.rolling .tray .die { animation: tumble 0.6s var(--ease-pop) backwards; animation-delay: calc(var(--i) * 55ms + 0.25s); }

/* ------------------------------------------------------------------ */
/* History */

.history {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(12, 14, 42, 0.97);
  border-top: 1.5px solid var(--line);
}
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}
.history-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 18px; }
.history-head h2:focus { outline: none; }
.history-head h2:focus-visible { outline: 3px solid var(--saffron); outline-offset: 4px; }
.history-list { list-style: none; margin: 0; padding: 0 16px 16px; overflow: auto; flex: 1; }
.history-empty { margin: 0; padding: 0 16px 16px; color: var(--muted); font-size: 14px; }
.rd { padding: 10px 0 12px; border-top: 1px solid var(--line); }
.rd:first-child { border-top: 0; }
.rd:not(.current) { opacity: 0.66; }
.rd-title { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 6px; font-size: 13px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--saffron); }
.rd-title span { color: var(--dim); font-size: 12px; letter-spacing: 0; text-transform: none; font-weight: 400; }
.rd ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 14px; }
.rd li { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.rd li.meta { color: var(--dim); }
.rd li.call { color: #ff8c78; font-weight: 700; }
.rd li.outcome { display: block; padding: 6px 9px; border-radius: 10px; background: rgba(56, 193, 173, 0.1); border-left: 3px solid var(--turq); }
.rd li.outcome.bad { background: rgba(220, 69, 48, 0.12); border-left-color: var(--madder); }
.who { font-weight: 700; color: var(--c, var(--text)); }
.hb { display: inline-flex; align-items: center; gap: 3px; font-family: var(--display); font-size: 15px; }
.hb-die { width: 17px; height: 17px; }

/* ------------------------------------------------------------------ */
/* Bottom bar */

.bar {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 18px max(14px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: #0d0f2e;
  z-index: 10;
}
.bar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 9px;
  background: var(--aguayo) repeat-x;
  background-size: 16px 9px;
}
.status { margin: 0; min-height: 2.6em; font-size: 15px; line-height: 1.3; max-width: 980px; justify-self: center; width: 100%; text-align: center; }
.status b { color: var(--saffron); }
.actions { width: 100%; max-width: 980px; justify-self: center; }
.actions[data-kind="single"] { display: flex; justify-content: center; }
.actions[data-kind="single"] .act { width: min(100%, 460px); }

.act {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 54px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.1;
  transition: transform 0.12s, filter 0.15s, box-shadow 0.15s;
}
.act:not(:disabled):hover { filter: brightness(1.08); }
.act:not(:disabled):active { transform: translateY(2px); }
.act:disabled { cursor: not-allowed; opacity: 0.4; }
.act b { font-family: var(--display); font-weight: 400; font-size: 19px; white-space: nowrap; }
.act-k { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }
.key {
  position: absolute;
  top: 5px; right: 6px;
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  background: rgba(0, 0, 0, 0.18);
  opacity: 0.75;
}
@media (hover: none) { .key { display: none; } }
.act-wait { background: transparent; border: 2px dashed var(--line-2); color: var(--muted); opacity: 1 !important; cursor: default !important; }
.act-next { background: var(--saffron); color: var(--ink); box-shadow: 0 4px 0 var(--saffron-dk); }
.act-bid { background: var(--turq); color: var(--ink); box-shadow: 0 4px 0 #23877a; }
.act-liar { background: var(--madder); color: #fff; box-shadow: 0 4px 0 var(--madder-dk); }
.act-liar .key { background: rgba(255, 255, 255, 0.2); }
.act-ghost { background: transparent; color: var(--text); border: 2px solid var(--line-2); }

.picker {
  display: grid;
  grid-template-columns: auto auto minmax(150px, 1fr) minmax(130px, auto);
  grid-template-areas: "hint hint hint hint" "faces qty bid liar";
  gap: 8px 10px;
  align-items: stretch;
}
.picker.opening { grid-template-columns: auto auto minmax(150px, 1fr); grid-template-areas: "hint hint hint" "faces qty bid"; }
.pk-hint { grid-area: hint; margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
.pk-hint b { color: var(--saffron); }
.faces { grid-area: faces; display: flex; gap: 6px; }
.face {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 54px;
  min-height: 54px;
  padding: 4px 0 3px;
  border-radius: 13px;
  border: 2px solid var(--line-2);
  background: rgba(255, 255, 255, 0.04);
  transition: transform 0.15s var(--ease-pop), border-color 0.15s, background 0.15s;
}
.face-die { width: 28px; height: 28px; }
.face-n { font-size: 11px; font-weight: 700; color: var(--muted); line-height: 1; }
.face[aria-pressed="true"] { border-color: var(--saffron); background: rgba(244, 183, 64, 0.16); transform: translateY(-3px); box-shadow: 0 4px 0 var(--saffron-dk); }
.face[aria-pressed="true"] .face-n { color: var(--saffron); }
.face:disabled { opacity: 0.22; cursor: not-allowed; }
.qty {
  grid-area: qty;
  display: flex;
  align-items: stretch;
  border: 2px solid var(--line-2);
  border-radius: 14px;
  overflow: hidden;
}
.step { width: 44px; border: 0; background: rgba(255, 255, 255, 0.05); font-size: 24px; font-weight: 700; }
.step:not(:disabled):hover { background: rgba(255, 255, 255, 0.12); }
.step:disabled { opacity: 0.3; cursor: not-allowed; }
.step:focus-visible { outline-offset: -3px; }
.qty-n { display: grid; place-items: center; min-width: 48px; font-family: var(--display); font-size: 26px; color: var(--bone); font-variant-numeric: tabular-nums; }
.act-bid { grid-area: bid; }
.picker .act-liar { grid-area: liar; }

.confirm { display: grid; gap: 6px; text-align: center; }
.confirm-q { margin: 0; font-size: 18px; }
.confirm-q b { color: #ff8c78; }
.confirm-help { margin: 0; font-size: 13px; color: var(--muted); }
.confirm-row { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.confirm-row .act { flex: 1; max-width: 260px; }

/* ------------------------------------------------------------------ */
/* Dialogs */

.dialog {
  max-width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 22px;
  border: 1.5px solid var(--line-2);
  border-radius: 22px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  overflow: auto;
}
.dialog::backdrop { background: rgba(7, 8, 28, 0.72); backdrop-filter: blur(3px); }
.dialog[open] { animation: rise 0.32s var(--ease-pop); }
.dialog-small { width: 440px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 22px; }
.dialog-note { color: var(--muted); font-size: 14px; margin: 12px 0 0; }
.kicker { margin: 0 0 4px; font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--saffron); }
.lede { margin: 6px 0 14px; color: var(--muted); }

.dialog-setup { width: 900px; max-width: calc(100vw - 24px); padding: 0; }
.setup { display: grid; grid-template-columns: 300px 1fr; }
.setup-hero {
  position: relative;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 60%, rgba(244, 183, 64, 0.16), transparent 60%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 4px),
    var(--cloth);
  overflow: hidden;
}
.setup-hero::before, .setup-hero::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 14px;
  background: var(--aguayo) repeat-x;
}
.setup-hero::before { top: 14px; }
.setup-hero::after { bottom: 14px; transform: scaleY(-1); }
.hero-cup {
  position: absolute;
  left: 50%;
  top: 34%;
  width: 150px;
  height: 138px;
  margin-left: -60px;
  transform: rotate(-28deg);
  filter: drop-shadow(0 18px 18px rgba(0, 0, 0, 0.5));
  animation: hero-cup 1s var(--ease-pop) both;
}
.hero-dice { position: absolute; inset: 0; }
.hero-die { position: absolute; width: 50px; height: 50px; animation: hero-roll 0.9s var(--ease-pop) both; }
.hd0 { left: 18%; top: 66%; --r: -18deg; animation-delay: 0.2s; }
.hd1 { left: 42%; top: 72%; --r: 12deg; animation-delay: 0.28s; }
.hd2 { left: 64%; top: 64%; --r: 30deg; animation-delay: 0.36s; }
.hd3 { left: 30%; top: 82%; --r: 6deg; animation-delay: 0.44s; }
.hd4 { left: 58%; top: 84%; --r: -24deg; animation-delay: 0.52s; }
.hero-die svg { transform: rotate(var(--r)); }
.hd1 .die-body, .hd2 .die-body { fill: var(--bone); }
.setup-body { padding: 26px 28px 24px; }
.setup-title { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(36px, 6vw, 52px); line-height: 1; }
.field { border: 0; padding: 0; margin: 0 0 16px; }
.field legend { padding: 0; margin-bottom: 8px; font-weight: 700; font-size: 14px; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.pill span {
  display: grid;
  place-items: center;
  min-width: 48px;
  height: 46px;
  padding: 0 12px;
  border-radius: 12px;
  border: 2px solid var(--line-2);
  font-family: var(--display);
  font-size: 18px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.pill input:checked + span { background: var(--saffron); border-color: var(--saffron); color: var(--ink); }
.pill input:focus-visible + span { outline: 3px solid var(--saffron); outline-offset: 3px; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.rival-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rival {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "av text sel" "av blurb blurb";
  align-items: center;
  gap: 2px 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid var(--line);
}
.rival .avatar { grid-area: av; }
.rival-text { grid-area: text; display: flex; flex-direction: column; line-height: 1.2; }
.rival-text small { color: var(--muted); font-size: 13px; }
.rival-style { grid-area: sel; }
.rival-style select {
  min-height: 38px;
  padding: 0 28px 0 10px;
  border-radius: 10px;
  border: 1.5px solid var(--line-2);
  background: #0f1137 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23f4b740' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 10px center;
  appearance: none;
  font-weight: 700;
}
.rival-blurb { grid-area: blurb; font-size: 12px; color: var(--dim); }
.setup-error { margin: 0 0 10px; color: #ff8c78; font-weight: 700; }
.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.btn {
  min-height: 50px;
  padding: 0 22px;
  border-radius: 14px;
  border: 0;
  font-weight: 700;
  font-size: 16px;
}
.btn-primary { background: var(--saffron); color: var(--ink); box-shadow: 0 4px 0 var(--saffron-dk); }
.btn-primary:disabled { opacity: 0.6; }
.btn-ghost { background: transparent; border: 2px solid var(--line-2); }
.btn:active { transform: translateY(2px); }

.menu-body { display: grid; gap: 10px; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--saffron); }
.keys h3 { margin: 8px 0 6px; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--saffron); }
.keys dl { margin: 0; display: grid; gap: 4px; }
.keys dl div { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.keys dt { min-width: 92px; }
.keys dd { margin: 0; color: var(--muted); }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--line-2);
  border-bottom-width: 3px;
  font: 700 12px/18px var(--text-font);
  text-align: center;
}
.rules-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.rules-list b { color: var(--saffron); }

.dialog-over { width: 460px; text-align: left; }
.over-title { margin: 0; font-family: var(--display); font-weight: 400; font-size: 40px; line-height: 1.05; }
.over-title i { font-style: normal; color: var(--saffron); }
.standings { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 4px; }
.standings li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); }
.standings li:first-child { background: rgba(244, 183, 64, 0.14); }
.standings li.you { outline: 1.5px solid rgba(56, 193, 173, 0.6); }
.st-place { font-family: var(--display); width: 22px; color: var(--muted); }
.st-name { font-weight: 700; color: var(--c); flex: 1; }
.st-note { color: var(--muted); font-size: 14px; }
.over-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 14px; }
.over-stats div { padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); }
.over-stats dt { font-size: 12px; color: var(--muted); }
.over-stats dd { margin: 0; font-weight: 700; }

/* ------------------------------------------------------------------ */
/* Motion */

@keyframes pop-in { from { transform: translateY(8px) scale(0.4) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0); } 30% { transform: translateY(-3px) rotate(-3deg); } 60% { transform: translateY(0) rotate(2deg); } }
@keyframes dot { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-3px); opacity: 1; } }
@keyframes stamp-in { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-10deg) scale(2.2); } 70% { opacity: 1; transform: translate(-50%, -50%) rotate(-12deg) scale(0.94); } 100% { opacity: 1; transform: translate(-50%, -50%) rotate(-12deg) scale(1); } }
@keyframes seat-stamp-in { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(16deg) scale(1.8); } 70% { opacity: 1; transform: translate(-50%, -50%) rotate(12deg) scale(0.94); } 100% { opacity: 1; transform: translate(-50%, -50%) rotate(12deg) scale(1); } }
@keyframes slam { 0% { transform: scale(1.35) rotate(-3deg); opacity: 0; } 60% { transform: scale(0.96); opacity: 1; } 100% { transform: none; } }
@keyframes hit { 0% { transform: scale(1); } 45% { transform: scale(1.28) translateY(-4px); } 100% { transform: scale(1.08) translateY(-2px); } }
@keyframes lose { 0% { transform: none; opacity: 1; } 35% { transform: translateY(-8px) rotate(-10deg); } 100% { transform: translateY(26px) rotate(70deg) scale(0.7); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: none; } 15% { transform: translateX(-4px) rotate(-8deg); } 35% { transform: translateX(4px) rotate(7deg); } 55% { transform: translateX(-3px) rotate(-5deg); } 75% { transform: translateX(2px) rotate(3deg); } }
@keyframes tumble { from { transform: translate(-30px, -18px) rotate(-200deg) scale(0.5); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(18px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes hero-cup { from { transform: translateY(-40px) rotate(0deg); } to { transform: rotate(-28deg); } }
@keyframes hero-roll { from { transform: translate(-60px, -80px) rotate(-180deg) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* The tray shakes when your bid is the one that lost */
.me.lost-die .tray-wrap { border-color: var(--madder); box-shadow: 0 0 0 3px rgba(220, 69, 48, 0.25); }
.me.won-call .tray-wrap { border-color: var(--turq); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .stamp.show { opacity: 1; transform: translate(-50%, -50%) rotate(-12deg); }
  .seat-stamp.show { opacity: 1; transform: translate(-50%, -50%) rotate(12deg); }
  .die.lost { opacity: 0.2; }
  .seat.is-turn .cup { transform: none; }
}

/* ------------------------------------------------------------------ */
/* Layout: wide screens get the history as a sidebar */

@media (min-width: 1100px) {
  .room { grid-template-columns: minmax(0, 1fr) 300px; }
  .history { border-top: 0; border-left: 1.5px solid var(--line); background: rgba(12, 14, 42, 0.6); }
  .history-btn, .history-close { display: none; }
}
@media (max-width: 1099px) {
  .history {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    max-height: 70dvh;
    z-index: 50;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.6);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.3s var(--ease), visibility 0s 0.3s;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .history.open { transform: none; visibility: visible; transition: transform 0.3s var(--ease); }
}

/* ------------------------------------------------------------------ */
/* Phones */

@media (max-width: 719px) {
  :root { --ds: 15px; --cupw: 44px; --my-ds: 42px; }
  .topbar { padding-top: 8px; padding-bottom: 4px; }
  .wordmark { font-size: 18px; }
  .meta { font-size: 12px; }
  .brand { flex-direction: column; gap: 2px; align-items: flex-start; }
  .tool { min-height: 38px; padding: 0 10px; }
  .table-wrap { padding: 4px 8px 8px; }
  .table { padding: 24px 8px 20px; border-radius: 22px; gap: 4px; }
  .table::before, .table::after { left: 14px; right: 14px; height: 9px; background-size: 16px 9px; }
  .table::before { top: 7px; }
  .table::after { bottom: 7px; }
  .rivals { flex-wrap: wrap; gap: 6px 4px; }
  .seat { flex: none; width: calc((100% - 8px) / 3); margin-top: 0; }
  .rivals[data-count="1"] .seat { width: 50%; }
  .rivals[data-count="2"] .seat { width: calc((100% - 4px) / 2); }
  .seat-vis { gap: 3px; }
  .seat-plate { gap: 5px; padding: 3px 7px 3px 3px; }
  .avatar { width: 26px; height: 26px; }
  .avatar svg { width: 15px; height: 15px; }
  .seat-name { font-size: 13px; }
  .seat-sub { font-size: 11px; }
  .count i { width: 6px; height: 6px; }
  .count { gap: 2px; min-height: 6px; }
  .seat .dice { gap: 2px; }
  .seat.lifted .cup { transform: translateY(-40%) rotate(-10deg); opacity: 0; }
  .bar:has(.confirm) .status { display: none; }
  .plaque-main .vs { font-size: 22px; }
  .dialog-setup .setup-actions {
    position: sticky;
    bottom: 0;
    margin: 6px -16px -18px;
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--panel) 30%);
  }
  .say { font-size: 12px; padding: 5px 8px 6px; top: -10px; }
  .say.tone-liar { font-size: 14px; }
  .seat-stamp { font-size: 12px; border-width: 2px; }
  .plaque-kicker { font-size: 11px; }
  .plaque-words { font-size: 15px; }
  .plaque-main { min-height: 50px; gap: 8px; }
  .plaque-main .q { font-size: 46px; }
  .plaque-die { width: 40px; height: 40px; }
  .stamp { font-size: 32px; border-width: 4px; padding: 3px 12px 6px; left: 66%; top: 14%; }
  .me { gap: 10px; align-items: center; }
  .me-plate { flex-direction: column; gap: 2px; padding: 0; }
  .avatar-me { width: 36px; height: 36px; font-size: 10px; }
  .me-text { align-items: center; }
  .me-text .seat-name { display: none; }
  .me .seat-sub { font-size: 12px; text-align: center; }
  .say-me { left: 50%; bottom: calc(100% + 2px); transform: translate(-50%, 6px) scale(0.85); }
  .say-me.show { transform: translate(-50%, 0) scale(1); }
  .tray-wrap { padding: 8px 10px; gap: 6px; border-radius: 16px; }
  .me-cup { display: none; }
  .tray { gap: 5px; }

  .bar { padding-top: 14px; gap: 6px; }
  .bar::before { height: 7px; background-size: 12px 7px; }
  .status { font-size: 14px; min-height: 2.6em; }
  .picker, .picker.opening {
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 0.8fr);
    grid-template-areas: "hint hint hint" "faces faces faces" "qty bid liar";
    gap: 6px;
  }
  .picker.opening { grid-template-areas: "hint hint hint" "faces faces faces" "qty bid bid"; }
  .pk-hint { font-size: 12px; }
  .face { flex: 1; width: auto; min-height: 50px; }
  .act { min-height: 50px; padding: 0 10px; }
  .act b { font-size: 16px; }
  .act-k { font-size: 11px; }
  .picker .act { flex-direction: column; gap: 0; }
  .step { width: 40px; }
  .qty-n { min-width: 38px; font-size: 22px; }
  .confirm-q { font-size: 16px; }

  .setup { grid-template-columns: 1fr; }
  .setup-hero { min-height: 120px; }
  .hero-cup { width: 84px; height: 78px; top: 8px; margin-left: -110px; }
  .hero-die { width: 34px; height: 34px; }
  .hd0 { left: 46%; top: 22%; } .hd1 { left: 60%; top: 42%; } .hd2 { left: 74%; top: 18%; }
  .hd3 { left: 54%; top: 64%; } .hd4 { left: 82%; top: 58%; }
  .setup-body { padding: 18px 16px 18px; }
  .dialog { padding: 18px; }
  .dialog-setup { padding: 0; }
  .over-title { font-size: 32px; }
}

@media (max-width: 400px) {
  .tool svg { display: none; }
  .tool { padding: 0 9px; font-size: 13px; }
}
@media (max-width: 359px) {
  .wordmark { font-size: 15px; }
  .meta { font-size: 11px; }
  .tools { gap: 4px; }
  .tool { padding: 0 7px; font-size: 12px; }
  .face-n { display: none; }
  .step { width: 32px; }
  .qty-n { min-width: 30px; }
}

@media (max-width: 719px) and (max-height: 700px) {
  .pk-hint { display: none; }
  .plaque-main .q { font-size: 40px; }
  .plaque-main { min-height: 44px; }
}
