/*
 * Chouquette — "café table" theme.
 * Wooden table, felt-lined dice tray, paper score sheet and notebook,
 * printed-card buttons and rubber-stamp announcements.
 * Every texture is an inline SVG noise filter, so there are no image assets.
 */

:root {
  --accent: #1f6f62;

  --wood: #4a2c1a;
  --wood-dark: #2a1910;
  --wood-light: #6b4329;
  --felt: #1e5a40;
  --felt-dark: #123826;
  --paper: #f4ecd8;
  --paper-2: #ebe0c6;
  --paper-line: #d8c9a6;
  --margin-red: #d9897c;
  --ink: #2b2118;
  --ink-soft: #6b5a46;
  --ink-faint: #9a876c;
  --cream: #f6eedb;
  --cream-soft: #cfc3a7;
  --lacquer: #a8322a;
  --lacquer-dark: #6e1d17;
  --brass: #c9a24a;
  --brass-dark: #8f6d22;
  --red: #b3261e;
  --green: #2e7d4f;
  --highlight: rgba(255, 214, 64, .55);

  --font: 'Fraunces', Georgia, 'Times New Roman', serif;
  --hand: 'Caveat', 'Bradley Hand', 'Segoe Print', cursive;

  --tex-wood: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='560' height='560'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.005 0.12' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.07 0 0 0 0 0.035 0 0 0 0 0.015 0 0 0 1.25 -0.4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tex-felt: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.32 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tex-paper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.25 0 0 0 0 0.1 0 0 0 0.14 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  color: var(--cream);
  font: 15px/1.45 var(--font);
  font-optical-sizing: auto;
  background-color: var(--wood);
  background-image:
    radial-gradient(120% 90% at 50% 30%, rgba(255, 190, 120, .10), transparent 60%),
    radial-gradient(140% 120% at 50% 50%, transparent 55%, rgba(0, 0, 0, .55)),
    var(--tex-wood),
    linear-gradient(180deg, var(--wood-light), var(--wood) 40%, var(--wood-dark));
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--ink-soft); }

/* Paper surfaces (score sheet, notebook, cards, modal) */
.paper {
  color: var(--ink);
  background-color: var(--paper);
  background-image: var(--tex-paper), linear-gradient(180deg, #f8f1df, var(--paper) 60%, var(--paper-2));
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .5) inset, 0 2px 3px rgba(0, 0, 0, .25), 0 14px 30px -8px rgba(0, 0, 0, .55);
}

/* ---------- Buttons: printed card stock ---------- */

.btn {
  --oc: var(--accent);
  position: relative;
  border: 1px solid rgba(43, 33, 24, .35);
  background: var(--paper) var(--tex-paper);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 6px 14px -4px rgba(0, 0, 0, .4);
  transition: transform .12s ease, box-shadow .12s ease, opacity .2s, filter .2s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 5px 0 rgba(0, 0, 0, .35), 0 10px 18px -4px rgba(0, 0, 0, .45); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .3); }
.btn:disabled { opacity: .5; filter: grayscale(.6); cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .type-toggle:focus-visible, .step:focus-visible { outline: 3px solid var(--brass); outline-offset: 3px; }

.btn.primary {
  background: linear-gradient(180deg, #bf3d33, var(--lacquer) 55%, #922a23);
  border-color: var(--lacquer-dark);
  color: #fbefd9;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
  box-shadow: 0 3px 0 var(--lacquer-dark), 0 6px 14px -4px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 5px 0 var(--lacquer-dark), 0 10px 18px -4px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .25); }
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--lacquer-dark), inset 0 1px 0 rgba(255, 255, 255, .2); }
.btn.danger { background: var(--lacquer); color: #fbefd9; border-color: var(--lacquer-dark); box-shadow: 0 3px 0 var(--lacquer-dark); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; border-style: dashed; }
.btn.ghost:hover:not(:disabled) { background: rgba(43, 33, 24, .05); box-shadow: none; }
.btn.link { background: none; border: none; box-shadow: none; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; font-style: italic; }
.btn.link:hover { color: var(--ink); transform: none; box-shadow: none; }
.btn.big { padding: 13px 26px; font-size: 18px; }
.btn.wide { width: 100%; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid rgba(43, 33, 24, .4);
  background: var(--paper) var(--tex-paper);
  color: var(--ink);
  cursor: pointer; font-weight: 700; display: grid; place-items: center;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .4), 0 4px 10px rgba(0, 0, 0, .3);
  transition: transform .12s;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn:active { transform: translateY(1px); }

/* ---------- Screens ---------- */

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; animation: screenIn .45s ease-out; }
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Setup: the rule-book cover ---------- */

#setup.active { display: grid; place-items: center; padding: 32px 16px; }
.setup-card {
  position: relative;
  width: min(520px, 100%);
  padding: 30px 32px 22px;
  display: flex; flex-direction: column; gap: 14px;
  transform: rotate(-.4deg);
}
.setup-card::before, .setup-card::after { content: ''; position: absolute; pointer-events: none; border-radius: 3px; }
.setup-card::before { inset: 10px; border: 2px solid rgba(43, 33, 24, .7); }
.setup-card::after { inset: 15px; border: 1px solid rgba(43, 33, 24, .45); }
.setup-card > * { position: relative; z-index: 1; }

.logo { text-align: center; }
.logo-dice { height: 120px; margin: -6px -10px -4px; }
.logo-dice canvas { display: block; width: 100%; height: 100%; }
.kicker { margin: 0; font-size: 12px; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-soft); }
.logo h1 {
  margin: 2px 0 4px;
  font: italic 800 clamp(46px, 10vw, 66px)/1 var(--font);
  font-variation-settings: 'SOFT' 100, 'WONK' 1;
  color: var(--lacquer);
  letter-spacing: -.5px;
  text-shadow: 2px 2px 0 rgba(43, 33, 24, .14);
}
.tagline { margin: 0 auto; max-width: 34ch; font-style: italic; color: var(--ink-soft); }

.setup-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 8px; border-bottom: 2px solid var(--ink); padding-bottom: 4px; }
.setup-head h2 { margin: 0; font: 700 15px var(--font); letter-spacing: .14em; text-transform: uppercase; }
.count-pill { font-family: var(--hand); font-size: 22px; font-weight: 700; color: var(--ink-soft); }

.player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.prow {
  display: flex; align-items: center; gap: 10px; padding: 6px 2px;
  border-bottom: 1px solid var(--paper-line);
  animation: rowIn .3s ease-out both;
}
@keyframes rowIn { from { opacity: 0; transform: translateX(-8px); } }
.prow .dot { flex: none; }
.prow input {
  flex: 1; min-width: 0; background: transparent; border: none; color: var(--ink);
  font: 700 25px/1.1 var(--hand); padding: 2px 4px; border-radius: 4px;
}
.prow input:focus { outline: none; background: var(--highlight); }
.type-toggle {
  flex: none; border: 1.5px solid currentColor; background: transparent; border-radius: 4px;
  padding: 2px 8px; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-soft); cursor: pointer; transform: rotate(-2deg);
}
.type-toggle.bot { color: #6a4598; }
.rm { flex: none; width: 30px; height: 30px; border: none; background: none; color: var(--ink-faint); border-radius: 50%; cursor: pointer; font-size: 15px; }
.rm:hover:not(:disabled) { color: var(--red); background: rgba(179, 38, 30, .08); }
.rm:disabled { opacity: .3; cursor: default; }

.setup-actions { display: flex; gap: 10px; margin-top: 4px; }
.setup-actions .btn { flex: 1; }
#start-btn { margin-top: 6px; }

/* Player token: a little game chip */
.dot, .avatar, .dist-avatar {
  display: grid; place-items: center; border-radius: 50%;
  background: var(--pc);
  color: #fff8ea;
  font: 700 15px var(--font);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
  box-shadow: inset 0 0 0 3px var(--pc), inset 0 0 0 5px rgba(255, 248, 234, .75), 0 2px 0 rgba(0, 0, 0, .35), 0 3px 6px rgba(0, 0, 0, .25);
}
.dot { width: 36px; height: 36px; }

/* ---------- Game layout ---------- */

#game.active { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 20px 10px;
}
.brand {
  font: italic 800 26px var(--font);
  font-variation-settings: 'SOFT' 100, 'WONK' 1;
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .45);
}
.top-actions { display: flex; gap: 10px; }

.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 290px;
  gap: 20px;
  padding: 0 20px calc(18px + env(safe-area-inset-bottom, 0px));
}

/* ---------- Score sheet ---------- */

.players {
  align-self: start;
  max-height: 100%;
  overflow-y: auto;
  padding: 12px 0 14px;
  transform: rotate(-.6deg);
  background-image:
    linear-gradient(90deg, transparent 46px, var(--margin-red) 46px, var(--margin-red) 47.5px, transparent 47.5px),
    var(--tex-paper),
    linear-gradient(180deg, #f8f1df, var(--paper) 60%, var(--paper-2));
}
.sheet-head {
  margin: 0 14px 6px 58px;
  font: 700 12px var(--font); letter-spacing: .18em; text-transform: uppercase; color: var(--ink-soft);
  border-bottom: 2px solid var(--ink); padding-bottom: 4px;
}

.pcard {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 9px 14px 9px 8px;
  border-bottom: 1px solid var(--paper-line);
  transition: background .3s;
}
.pcard .avatar { width: 32px; height: 32px; font-size: 14px; flex: none; }
.pinfo { flex: 1; min-width: 0; padding-left: 8px; }
.pname { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 16px; color: var(--ink); }
.pname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; transition: background-size .5s ease; background: linear-gradient(transparent 52%, var(--highlight) 52%, var(--highlight) 92%, transparent 92%) no-repeat 0 0 / 0% 100%; }
.pcard.active .pname span { background-size: 100% 100%; }
.pcard.active { background: linear-gradient(90deg, rgba(255, 214, 64, .16), transparent 70%); }

.bot-tag {
  font-style: normal; font-size: 9px; font-weight: 800; letter-spacing: .1em; padding: 0 4px; border-radius: 3px;
  border: 1.5px solid #6a4598; color: #6a4598; transform: rotate(-4deg); line-height: 1.5;
}
.pbar { height: 5px; margin-top: 5px; border-radius: 3px; background: rgba(43, 33, 24, .08); overflow: hidden; }
.pbar i {
  display: block; height: 100%;
  background: repeating-linear-gradient(-45deg, var(--pc) 0 2px, transparent 2px 4px);
  opacity: .85;
  transition: width .7s ease;
}
.ppts { font: 700 34px/1 var(--hand); min-width: 40px; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }

.pcard.target .ppts { color: var(--red); }
.pcard.target::after {
  content: ''; position: absolute; right: 4px; top: 50%; width: 58px; height: 44px; translate: 0 -50%;
  border: 2.5px solid var(--red); border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  transform: rotate(-6deg); animation: circleIn .35s ease-out;
}
@keyframes circleIn { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.pcard.zero .pname span, .pcard.zero .ppts { color: var(--ink-faint); }
.pcard.zero .avatar { filter: grayscale(.8) opacity(.7); }
.pcard.hurt { animation: hurt .7s ease-out; }
.pcard.heal { animation: heal .9s ease-out; }
@keyframes hurt { 0% { background: rgba(179, 38, 30, .22); } }
@keyframes heal { 0% { background: rgba(46, 125, 79, .22); } }

.pchip {
  position: absolute; right: 8px; top: -8px; padding: 0 7px; border-radius: 3px;
  font: 700 17px/1.3 var(--hand);
  background: var(--paper); color: var(--ink); border: 1px solid rgba(43, 33, 24, .35);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
  opacity: 0; transform: translateY(4px) rotate(3deg) scale(.8);
  transition: all .25s ease; pointer-events: none; z-index: 2;
}
.pchip.on { opacity: 1; transform: rotate(3deg); }
.pchip[style*="background"] { color: #fff8ea; border-color: transparent; }

.pshield {
  position: absolute; left: 60px; bottom: 4px;
  font: 700 10px var(--font); letter-spacing: .1em; text-transform: uppercase;
  color: var(--green); border: 1.5px solid var(--green); border-radius: 3px; padding: 1px 4px;
  opacity: 0; transform: rotate(-4deg) scale(1.8); line-height: 1.2;
  transition: all .35s cubic-bezier(.3, 1.4, .5, 1);
}
.pshield::before { content: 'Shrek'; }
.pcard.zero .pshield { opacity: .9; transform: rotate(-4deg); }
.pcard.zero .pbar { visibility: hidden; }

/* ---------- The dice tray: wood rim, felt lining ---------- */

.table-wrap { display: flex; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; }

.table {
  position: relative; flex: 1; min-height: 420px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 18px 20px 14px;
  border: 16px solid transparent;
  border-radius: 26px;
  overflow: hidden; isolation: isolate;
  background:
    radial-gradient(90% 75% at 50% 45%, rgba(255, 230, 170, .10), transparent 70%) padding-box,
    var(--tex-felt) padding-box,
    linear-gradient(var(--felt), var(--felt-dark)) padding-box,
    var(--tex-wood) border-box,
    linear-gradient(160deg, #7a4d2e, #4a2c1a 45%, #2e1b10) border-box;
  box-shadow:
    inset 0 10px 22px rgba(0, 0, 0, .55),
    inset 0 0 0 1px rgba(0, 0, 0, .4),
    0 2px 0 rgba(255, 220, 170, .12),
    0 22px 40px -12px rgba(0, 0, 0, .7);
}
/* Stitched seam around the felt */
.table::before {
  content: ''; position: absolute; inset: 8px; z-index: 0; pointer-events: none;
  border: 2px dashed rgba(246, 238, 219, .16); border-radius: 12px;
}

.status { text-align: center; max-width: 640px; }
.mode-badge {
  display: inline-block; padding: 3px 12px 2px; border-radius: 3px;
  font: 800 12px var(--font); letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent);
  background: var(--paper) var(--tex-paper);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .3), 0 4px 8px rgba(0, 0, 0, .25);
  transform: rotate(-1.5deg);
}
.mode-badge.pop { animation: tagIn .4s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes tagIn { from { transform: rotate(-12deg) scale(.6); opacity: 0; } }
.status h2 { margin: 12px 0 2px; font: 600 clamp(20px, 2.8vw, 27px)/1.2 var(--font); color: var(--cream); text-shadow: 0 2px 4px rgba(0, 0, 0, .45); }
.status h2 b { filter: brightness(1.45) saturate(.85); }
.status h2.pop { animation: titleIn .4s ease-out; }
.status p { margin: 0; color: var(--cream-soft); font-style: italic; min-height: 1.45em; }
@keyframes titleIn { from { transform: translateY(6px); opacity: 0; } }
.xval { display: inline-grid; place-items: center; min-width: 1.4em; padding: 0 .25em; border-radius: 4px; background: var(--paper); color: var(--red); font-style: normal; text-shadow: none; }

.meters { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 58px; margin-top: 10px; }
.rolls { display: flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 30px; background: rgba(0, 0, 0, .22); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .4); }
.rolls-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--cream-soft); margin-right: 4px; }
/* brass pegs in holes */
.rolls i { width: 11px; height: 11px; border-radius: 50%; background: rgba(0, 0, 0, .45); box-shadow: inset 0 2px 2px rgba(0, 0, 0, .6); transition: all .25s; }
.rolls i.on { background: radial-gradient(circle at 35% 30%, #f3d98f, var(--brass) 55%, var(--brass-dark)); box-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
.rolls i.cur { transform: scale(1.25); }

.meter {
  display: flex; align-items: baseline; gap: 10px; padding: 4px 14px 2px;
  color: var(--ink);
  background: var(--paper) var(--tex-paper);
  border-radius: 4px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .3), 0 5px 10px rgba(0, 0, 0, .3);
  transform: rotate(.8deg);
}
.meter-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-soft); }
.meter-val { font: 700 36px/1 var(--hand); font-variant-numeric: tabular-nums; display: inline-block; }
.meter-hint { font: 700 20px var(--hand); color: var(--ink-soft); }
.meter-hint.good { color: var(--green); }
.meter-hint.bad { color: var(--red); }

.hint { margin-top: auto; min-height: 20px; color: var(--cream-soft); font-size: 13px; }

/* three.js canvas fills the felt; the text floats above it */
.tray { position: absolute; inset: 0; z-index: 0; }
.tray canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.status, .meters, .hint { position: relative; z-index: 1; pointer-events: none; }

/* ---------- Mini printed dice (buttons, log) ---------- */

.pip { width: 100%; height: 100%; border-radius: 50%; place-self: center; background: #1d1813; }
.mini-die {
  display: inline-grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); width: 26px; height: 26px; padding: 4px; gap: 1px;
  border-radius: 6px; background: #fbf7ee; border: 1px solid rgba(43, 33, 24, .35);
  box-shadow: 0 1px 0 rgba(43, 33, 24, .3); vertical-align: middle;
}
.mini-die.v1 .pip { background: var(--lacquer); transform: scale(1.2); }
.mini-row { display: inline-flex; gap: 2px; vertical-align: middle; }
.mini-row .mini-die { width: 17px; height: 17px; padding: 2px; border-radius: 4px; gap: .5px; }

/* ---------- Actions ---------- */

.actions { min-height: 92px; display: flex; flex-direction: column; justify-content: center; }
.opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; animation: dealIn .35s ease-out; }
@keyframes dealIn { from { opacity: 0; transform: translateY(12px) rotate(1deg); } }

.opt { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 150px; }
.opt-label { font-weight: 700; font-size: 16px; }
.opt-sub { font-size: 12px; font-weight: 500; font-style: italic; color: var(--ink-soft); }
.btn.primary .opt-sub { color: #f2d9c4; }
.opt.chosen, .face-btn.chosen { opacity: 1 !important; filter: none !important; transform: translateY(-3px) rotate(-1deg); outline: 3px solid var(--brass); outline-offset: 3px; }

/* Strategy cards: coloured header stripe like a reference card */
.opt.mode-p25, .opt.mode-m10, .opt.mode-cq, .opt-group.mode-cqt { border-top: 6px solid var(--stripe); padding-top: 8px; }
.opt.mode-p25 { --stripe: #1f6f62; }
.opt.mode-m10 { --stripe: #2c5d8a; }
.opt.mode-cq { --stripe: #c4561d; }
.opt-group.mode-cqt { --stripe: #6a4598; }
.opt.target-btn { border-left: 6px solid var(--oc); }
.opt.target-btn .opt-label::before { content: '⚔ '; color: var(--red); }

.opt-group {
  display: flex; flex-direction: column; gap: 8px; padding: 8px 12px 10px; border-radius: 8px;
  color: var(--ink);
  background: var(--paper) var(--tex-paper);
  border: 1px solid rgba(43, 33, 24, .35);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 6px 14px -4px rgba(0, 0, 0, .4);
}
.opt-group-head { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.opt-group-row { display: flex; gap: 6px; }
.face-btn { position: relative; padding: 5px; border-radius: 6px; box-shadow: 0 2px 0 rgba(0, 0, 0, .25); background: #fffaf0; }
.face-count { position: absolute; right: -7px; top: -8px; font: 700 15px/1 var(--hand); padding: 1px 4px 0; border-radius: 3px; background: #6a4598; color: #fff8ea; }

.thinking { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 10px; color: var(--cream-soft); font: 700 20px var(--hand); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--cream-soft); animation: dot 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 50% { transform: translateY(-4px); } }

/* Distribution sheet */
.dist {
  max-width: 520px; width: 100%; margin: 0 auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
  color: var(--ink);
  background: var(--paper) var(--tex-paper);
  border-radius: 6px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, .25), 0 14px 30px -8px rgba(0, 0, 0, .55);
  animation: dealIn .35s ease-out;
}
.dist-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; padding-bottom: 6px; border-bottom: 2px solid var(--ink); text-transform: uppercase; letter-spacing: .1em; font-size: 13px; }
.dist-rem { font: 700 22px var(--hand); text-transform: none; letter-spacing: 0; color: var(--red); }
.dist-rem.done { color: var(--green); }
.dist-row { display: flex; align-items: center; gap: 10px; padding: 6px 2px; border-bottom: 1px solid var(--paper-line); }
.dist-avatar { flex: none; width: 30px; height: 30px; font-size: 13px; }
.dist-name { flex: 1; min-width: 0; font-weight: 600; display: flex; flex-direction: column; }
.dist-name small { font: 700 18px/1 var(--hand); color: var(--ink-soft); }
.stepper { display: flex; align-items: center; gap: 4px; }
.step {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(43, 33, 24, .4);
  background: #fffaf0; color: var(--ink); font-size: 18px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .3); transition: transform .1s;
}
.step:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.step:disabled { opacity: .3; cursor: default; }
.dist-val { min-width: 32px; text-align: center; font: 700 30px/1 var(--hand); }
.dist .btn.primary { margin-top: 10px; }

/* ---------- Notebook (log) ---------- */

.log-wrap {
  position: relative;
  padding: 26px 10px 8px 0;
  display: flex; flex-direction: column; min-height: 0;
  transform: rotate(.5deg);
  background-image:
    linear-gradient(90deg, transparent 34px, var(--margin-red) 34px, var(--margin-red) 35.5px, transparent 35.5px),
    var(--tex-paper),
    linear-gradient(180deg, #f8f1df, var(--paper) 60%, var(--paper-2));
}
/* spiral binding */
.log-wrap::before {
  content: ''; position: absolute; left: 14px; right: 14px; top: -9px; height: 22px;
  background:
    radial-gradient(circle at 50% 60%, #2a2622 0 4px, transparent 4.5px) 0 0 / 22px 22px repeat-x,
    radial-gradient(ellipse at 50% 30%, #b9b3a8 0 3px, #77716a 3.5px 4.5px, transparent 5px) 0 -6px / 22px 22px repeat-x;
}
.log-wrap h3 { margin: 0 0 6px 46px; font: 700 12px var(--font); letter-spacing: .18em; text-transform: uppercase; color: var(--ink-soft); }
.log {
  list-style: none; margin: 0; padding: 0 6px 0 46px; overflow-y: auto;
  display: flex; flex-direction: column;
  font: 600 19px/26px var(--hand); color: var(--ink);
  background: repeating-linear-gradient(transparent 0 25px, rgba(122, 160, 200, .35) 25px 26px);
  background-attachment: local;
}
.log li { --lc: var(--ink-soft); position: relative; animation: writeIn .5s ease-out; }
.log li::before { content: '•'; position: absolute; left: -14px; color: var(--lc); }
.log li b { font-weight: 700; }
@keyframes writeIn { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.players::-webkit-scrollbar, .log::-webkit-scrollbar { width: 6px; height: 6px; }
.players::-webkit-scrollbar-thumb, .log::-webkit-scrollbar-thumb { background: rgba(43, 33, 24, .2); border-radius: 6px; }

/* ---------- Rubber-stamp announcements ---------- */

.banner { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 50; opacity: 0; --bc: var(--lacquer); --dur: 1400ms; }
.banner::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, rgba(20, 12, 6, .3), rgba(20, 12, 6, .55)); }
.banner.show { animation: bannerFade var(--dur) ease forwards; }
.banner-inner {
  position: relative; text-align: center;
  padding: 16px 34px 14px;
  color: var(--bc);
  background: var(--paper) var(--tex-paper);
  border-radius: 4px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .25), 0 24px 50px -10px rgba(0, 0, 0, .7);
  max-width: calc(100vw - 40px);
}
.banner-inner::before { content: ''; position: absolute; inset: 7px; border: 3px solid var(--bc); border-radius: 3px; opacity: .9; }
.banner-title { font: 800 clamp(34px, 7vw, 72px)/1 var(--font); letter-spacing: .02em; text-transform: uppercase; }
.banner-sub { margin-top: 8px; font: 700 clamp(19px, 2.6vw, 26px)/1.1 var(--hand); color: var(--ink); }
.banner.show .banner-inner { animation: stamp var(--dur) cubic-bezier(.2, .9, .3, 1) forwards; }
@keyframes bannerFade { 0% { opacity: 0; } 6% { opacity: 1; } 84% { opacity: 1; } 100% { opacity: 0; } }
@keyframes stamp {
  0% { transform: scale(2.3) rotate(-14deg); opacity: 0; }
  12% { transform: scale(.94) rotate(-4deg); opacity: 1; }
  18% { transform: scale(1.02) rotate(-4deg); opacity: 1; }
  24%, 84% { transform: scale(1) rotate(-4deg); opacity: 1; }
  100% { transform: scale(1) rotate(-4deg) translateY(-14px); opacity: 0; }
}

/* ---------- Ink floaters & confetti ---------- */

.floaters { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.floater {
  position: absolute; translate: -50% -50%; font: 700 38px var(--hand);
  text-shadow: 0 0 6px rgba(244, 236, 216, .9), 0 0 2px rgba(244, 236, 216, 1);
  animation: floatUp 1.3s ease-out forwards;
}
.floater.big { font-size: 56px; }
@keyframes floatUp {
  0% { transform: translateY(8px) scale(.5) rotate(-8deg); opacity: 0; }
  15% { transform: translateY(-8px) scale(1.15) rotate(-4deg); opacity: 1; }
  30% { transform: translateY(-16px) scale(1) rotate(-4deg); }
  100% { transform: translateY(-70px) rotate(-4deg); opacity: 0; }
}
.fx-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 55; }

/* ---------- Modal sheet ---------- */

.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: rgba(20, 12, 6, .6); opacity: 0; transition: opacity .25s; }
.modal.open { opacity: 1; }
.modal-card { position: relative; width: min(640px, 100%); max-height: 88vh; overflow-y: auto; padding: 30px 32px; transform: translateY(18px) rotate(1deg); transition: transform .35s cubic-bezier(.2, .9, .3, 1.1); }
.modal.open .modal-card { transform: rotate(-.3deg); }
.modal-close { position: absolute; right: 16px; top: 16px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }

.rules h2 { margin: 0 40px 4px 0; font: italic 800 30px var(--font); color: var(--lacquer); }
.rules h3 { margin: 20px 0 4px; font: 700 13px var(--font); letter-spacing: .14em; text-transform: uppercase; border-bottom: 1px solid var(--ink); padding-bottom: 3px; }
.rules p { margin: 0; color: var(--ink); }
.rules .lead { color: var(--ink-soft); font-style: italic; }
.rules .small { margin-top: 16px; font-size: 13px; color: var(--ink-soft); font-style: italic; }
.rule-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 12px; }
.rule { padding: 10px 12px; border-radius: 4px; border: 1px solid rgba(43, 33, 24, .25); border-top: 5px solid var(--stripe); background: rgba(255, 252, 244, .6); }
.rule h4 { margin: 0 0 3px; font: 700 16px var(--font); color: var(--stripe); }
.rule p { font-size: 14px; }
.r-p25 { --stripe: #1f6f62; }
.r-m10 { --stripe: #2c5d8a; }
.r-cq { --stripe: #c4561d; }
.r-cqt { --stripe: #6a4598; }

.confirm, .gameover { text-align: center; }
.confirm h2 { margin: 0 0 6px; font: 700 24px var(--font); }
.gameover .trophy { font-size: 60px; line-height: 1; animation: trophy 1s cubic-bezier(.2, 1.4, .3, 1) both; }
@keyframes trophy { 0% { transform: scale(0) rotate(-30deg); } }
.gameover h2 { margin: 6px 0 0; font: italic 800 36px var(--font); }
.gameover h2 span { color: var(--pc); }
.standings { list-style: none; padding: 0; margin: 18px auto 0; max-width: 360px; display: flex; flex-direction: column; text-align: left; border-top: 2px solid var(--ink); }
.standings li { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--paper-line); animation: rowIn .35s both; }
.standings li:nth-child(1) .sname { background: linear-gradient(transparent 52%, var(--highlight) 52%, var(--highlight) 92%, transparent 92%); }
.standings li:nth-child(2) { animation-delay: .08s; } .standings li:nth-child(3) { animation-delay: .16s; } .standings li:nth-child(4) { animation-delay: .24s; }
.standings .rank { width: 18px; color: var(--ink-soft); font-weight: 700; }
.standings .sname { flex: 0 1 auto; margin-right: auto; font-weight: 600; }
.standings b { font: 700 28px/1 var(--hand); }

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr); }
  .log-wrap { display: none; }
}

@media (max-width: 820px) {
  #game.active { height: auto; min-height: 100dvh; }
  .topbar { padding-inline: 16px; }
  .layout { display: flex; flex-direction: column; gap: 14px; padding-inline: 16px; }
  .players {
    display: flex; flex-direction: row; overflow-x: auto; overflow-y: visible;
    padding: 8px 6px 8px 10px; transform: none; align-self: stretch;
    background-image: var(--tex-paper), linear-gradient(180deg, #f8f1df, var(--paper));
    scroll-snap-type: x proximity;
  }
  .sheet-head { display: none; }
  .pcard { flex: none; min-width: 168px; border-bottom: none; border-right: 1px solid var(--paper-line); padding: 6px 12px 6px 8px; scroll-snap-align: center; }
  .pcard:last-child { border-right: none; }
  .ppts { font-size: 30px; }
  .table { min-height: 460px; border-width: 12px; padding: 14px 12px 10px; }
  .log-wrap { display: flex; max-height: 280px; transform: none; margin-top: 10px; }
  .opt { min-width: 0; flex: 1 1 140px; }
}

@media (max-width: 420px) {
  .setup-card { padding: 26px 22px 18px; }
  .face-btn { padding: 4px; }
  .mini-die { width: 22px; height: 22px; padding: 3px; }
  .opt-group { width: 100%; }
  .opt-group-row { justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
