/* Ahab and the Whale - the real UI.
   Palette from the sell sheet / four-winds-art skill. Look lives here; geometry that depends
   on the game (cell positions) is inline style from components.js. */

:root {
  /* palette */
  --sand: #edbe74;
  --cream: #f3e3c3;
  --paper: #fbf6ec;
  --choc: #5a2e1e;
  --terra: #b83a26;
  --rust: #d9622b;
  --teal: #3fb5c0;
  --deep: #1f6f78;
  --navy: #1f3a5a;
  --ink: #2a1f1a;
  --muted: #6f5a4d; /* 5.1:1 on the cream panels */
  --line: rgba(90, 46, 30, 0.3);
  /* wind suit colours (numbers on the cards) */
  --suit-n: #203a5a;
  --suit-e: #b84a14; /* the wind colours are a shade deeper than the card art so the corner numbers pass 4.5:1 */
  --suit-s: #2a6a99;
  --suit-w: #8f2b2b;
  /* type */
  --font-display: 'Alfa Slab One', Rockwell, 'Roboto Slab', Georgia, serif;
  --font-body: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-num: Georgia, 'Times New Roman', serif;
  /* space and shape */
  --gutter: 16px;
  --gap: 12px;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 2px 0 rgba(90, 46, 30, 0.25), 0 6px 14px rgba(60, 30, 10, 0.18);
  --ease: cubic-bezier(0.3, 0.7, 0.3, 1);
  --move-ms: 550ms;
  /* the highlight colour for playable cards and focus */
  --focus: #1f3a5a;
  --legal: #1f6f78;
  /* layout */
  --board-max: 640px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--sand);
  color: var(--ink);
  font: 400 17px/1.45 var(--font-body);
  overflow-x: hidden;
}
#app { min-height: 100vh; }
h1, h2, h3 { margin: 0; font-weight: 400; }
h2 { font-family: var(--font-display); color: var(--terra); font-size: 1.5rem; line-height: 1.15; }
h3 { font-weight: 800; color: var(--choc); }
p { margin: 0 0 0.6em; }
img { max-width: 100%; }
a { color: var(--deep); font-weight: 700; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- asset fallback chip ---------- */
.asset-chip {
  display: inline-grid;
  place-items: center;
  min-width: 2em;
  padding: 0.1em 0.5em;
  border: 2px dashed var(--line);
  border-radius: 6px;
  background: var(--cream);
  color: var(--choc);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

/* ---------- buttons, badges ---------- */
.btn {
  font: 800 1rem/1 var(--font-body);
  min-height: 44px;
  padding: 0 18px;
  border: 2px solid var(--choc);
  border-radius: var(--radius-s);
  background: var(--cream);
  color: var(--choc);
  cursor: pointer;
  box-shadow: 0 2px 0 var(--choc);
}
.btn:hover { background: var(--paper); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--choc); }
.btn--primary { background: var(--terra); border-color: var(--choc); color: #fff; }
.btn--primary:hover { background: #c9462f; }
.btn--big { min-height: 52px; font-size: 1.15rem; width: 100%; }
.btn--small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.linkbtn { font: 700 0.95rem var(--font-body); background: none; border: 0; padding: 8px 4px; color: var(--choc); text-decoration: underline; cursor: pointer; min-height: 44px; }
.linkbtn:hover { color: var(--terra); }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font: 800 0.7rem/1.5 var(--font-body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1.5px solid currentColor;
  vertical-align: 2px;
}
.badge--human { color: var(--navy); background: #dbe6f0; }
.badge--bot { color: var(--choc); background: #f0dcc0; }
.badge--medium { color: #7a4a0a; }
.badge--hard { color: #fff; background: var(--terra); border-color: var(--terra); }

/* ---------- landing ---------- */
.landing { max-width: 980px; margin: 0 auto; padding: 0 var(--gutter) 40px; }
.topnav { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.topnav__brand { font-family: var(--font-display); color: var(--choc); font-size: 1rem; }
.topnav__links { display: flex; gap: 8px; }

.hero__art img, .hero__art .asset-chip { display: block; width: 100%; height: auto; border-radius: var(--radius); border: 3px solid var(--choc); box-shadow: var(--shadow); background: var(--cream); }
.hero__art .asset-chip { min-height: 180px; font-size: 1.2rem; }
.hero__text { text-align: center; padding: 18px 0 6px; }
.hero__kicker { font: 800 0.8rem var(--font-body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--choc); opacity: 0.85; margin-bottom: 4px; }
.hero__title { font-family: var(--font-display); color: var(--choc); font-size: clamp(2.2rem, 9vw, 4rem); line-height: 1; }
.hero__title span { color: var(--terra); font-size: 0.55em; vertical-align: 0.15em; }
.hero__hook { font: 700 italic clamp(1.15rem, 4.2vw, 1.6rem)/1.25 var(--font-body); color: var(--terra); margin: 10px 0 6px; }
.hero__sub { max-width: 560px; margin: 0 auto 8px; color: var(--ink); }

.stats { list-style: none; margin: 12px 0 16px; padding: 10px var(--gutter); display: flex; background: var(--choc); border-radius: var(--radius-s); }
.stats li { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--cream); }
.stats li + li { border-left: 1px solid rgba(243, 227, 195, 0.3); }
.stats svg { width: 30px; height: 30px; flex: none; }
.stats b { display: block; font: 400 1.35rem/1 var(--font-display); color: var(--sand); }
.stats span { display: block; font: 800 0.65rem/1.2 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }

.panel { background: var(--cream); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px var(--gutter) 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel > h2 { margin-bottom: 12px; }

.setup__seats { display: grid; gap: 12px; grid-template-columns: 1fr; }
.seatform, .modeform { border: 2px solid var(--line); border-radius: var(--radius-s); padding: 8px 12px 12px; margin: 0 0 12px; min-width: 0; }
.seatform legend, .modeform legend { font: 800 0.85rem var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--choc); padding: 0 6px; }
.field { display: block; margin-top: 8px; }
.field > span { display: block; font-weight: 700; font-size: 0.9rem; color: var(--choc); }
.field small { font-weight: 400; color: var(--muted); }
.field select, .field input[type='text'] {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  font: 600 1rem var(--font-body);
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--choc);
  border-radius: var(--radius-s);
}
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.radio input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--terra); flex: none; }
.radio b { display: block; color: var(--choc); }
.hint { color: var(--deep); font-weight: 700; font-size: 0.95rem; }
.form-msg { color: var(--terra); font-weight: 800; min-height: 1.45em; }

.how__lead { font-weight: 700; color: var(--choc); font-size: 1.1rem; }
.how__steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 12px; }
.how__steps > li { counter-increment: step; position: relative; padding: 10px 12px 6px 52px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-s); }
.how__steps > li::before {
  content: counter(step);
  position: absolute; left: 12px; top: 10px;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--terra); color: #fff; font: 400 1rem var(--font-display);
}
.how__steps h3 { font-size: 1.05rem; margin-bottom: 2px; }
.how__winds { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 8px; padding: 0; }
.how__winds li { display: flex; align-items: center; gap: 6px; font-size: 0.95rem; }
.how__glyph { width: 22px; height: 22px; object-fit: contain; }
.how__arrow { width: 16px; height: 16px; object-fit: contain; }
.how__table { width: 100%; border-collapse: collapse; margin: 6px 0 8px; font-size: 0.95rem; }
.how__table th, .how__table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.how__table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--terra); }
.how__note { font-size: 0.92rem; color: var(--choc); }
.how__tournament { margin-top: 12px; }

.footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; padding: 14px var(--gutter); background: var(--choc); color: var(--cream); border-radius: var(--radius-s); font-size: 0.9rem; }

/* ---------- game screen ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; max-width: 1100px; margin: 0 auto; padding: 4px var(--gutter); }
.topbar__title { font-family: var(--font-display); color: var(--choc); font-size: 1rem; }
.game { max-width: 1100px; margin: 0 auto; padding: 4px var(--gutter) 40px; display: grid; gap: 16px; align-items: start; grid-template-columns: 1fr; }
.col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

@media (max-width: 999px) {
  .game { display: flex; flex-direction: column; align-items: stretch; max-width: 700px; gap: var(--gap); }
  .col { display: contents; }
  .endbar { order: 0; }
  .g-status { order: 1; }
  .g-score { order: 2; }
  .g-opp { order: 3; }
  .g-board { order: 4; }
  .g-trick { order: 5; }
  .g-me { order: 6; }
  .g-log { order: 7; }
}

.status { display: flex; gap: 12px; align-items: center; background: var(--choc); color: var(--cream); border-radius: var(--radius-s); padding: 10px 14px; box-shadow: var(--shadow); }
.status__trick { text-align: center; line-height: 1; padding-right: 12px; border-right: 1px solid rgba(243, 227, 195, 0.35); }
.status__trick b { display: block; font: 400 1.15rem var(--font-display); color: var(--sand); white-space: nowrap; }
.status__trick span { font: 800 0.7rem var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; }
.status__main { flex: 1; min-width: 0; }
.status__line { margin: 0 0 6px; font-weight: 700; }
.tpips { display: flex; gap: 4px; }
.tpip { flex: 1; height: 6px; border-radius: 3px; background: rgba(243, 227, 195, 0.25); }
.tpip--done { background: var(--sand); }
.tpip--now { background: var(--cream); animation: pulse 1.4s ease-in-out infinite; }

.endbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; background: var(--cream); border: 2px solid var(--terra); border-radius: var(--radius-s); padding: 8px 12px; font-weight: 700; }
.endbar span { flex: 1 1 200px; }

/* seats */
.seat { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; background: var(--cream); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 12px; box-shadow: var(--shadow); }
.seat.is-turn { border-color: var(--terra); box-shadow: 0 0 0 3px rgba(184, 58, 38, 0.25), var(--shadow); }
.seat__role-img, .seat .asset-chip { width: 52px; height: 52px; flex: none; object-fit: contain; border-radius: 50%; }
.seat--whale .seat__role-img { background: #c9e3e5; padding: 6px; }
.seat__body { flex: 1; min-width: 0; }
.seat__name { line-height: 1.3; }
.seat__role { font-size: 0.85rem; color: var(--muted); line-height: 1.3; }
.seat__role b { color: var(--choc); }
.seat__side { min-width: 0; flex: 0 1 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 0.85rem; text-align: right; }
.seat__status { font-weight: 700; color: var(--terra); min-height: 1.2em; }
.seat__backs { display: flex; align-items: center; }
.seat__back { width: 14px; flex: none; }
.seat__back:last-of-type { width: 34px; }
.seat__back img, .seat__back .asset-chip { width: 34px; height: 47px; object-fit: cover; border-radius: 4px; border: 1px solid var(--choc); display: block; }
.seat__count { margin-left: 8px; font-weight: 800; color: var(--choc); }
.thinking i { display: inline-block; width: 5px; height: 5px; margin-left: 3px; border-radius: 50%; background: currentColor; animation: dot 1.1s infinite; }
.thinking i:nth-child(3) { animation-delay: 0.15s; }
.thinking i:nth-child(4) { animation-delay: 0.3s; }

/* the Whale card beside the Whale's seat: waiting side up until it is played, then it turns to Move Twice */
.seat__card { order: 3; flex: 0 0 100%; display: flex; align-items: center; gap: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
.wcard { --wc-w: 46px; flex: none; width: var(--wc-w); aspect-ratio: 1677 / 2400; perspective: 500px; }
.wcard__inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.7s var(--ease); }
.wcard[data-side='breach'] .wcard__inner { transform: rotateY(180deg); }
.wcard__face, .wcard .asset-chip { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: cover; border-radius: 7%/5%; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 2px 5px rgba(60, 30, 10, 0.3); }
.wcard .asset-chip { display: grid; font-size: 0.6rem; padding: 2px; }
.wcard__face--breach, .wcard .wcard__face--breach.asset-chip { transform: rotateY(180deg); }
.seat__cardtext { margin: 0; font-size: 0.85rem; line-height: 1.25; min-width: 0; }
.seat__cardtext b { display: block; color: var(--terra); font-size: 0.95rem; }
.seat__cardtext span { color: var(--muted); }
.wmini { --card-w: 78px; display: block; position: relative; flex: none; width: var(--card-w); aspect-ratio: 1677 / 2400; border-radius: 7%/5%; overflow: hidden; background: var(--paper); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 3px 6px rgba(60, 30, 10, 0.25); animation: deal 0.35s var(--ease); }
.wmini__img, .wmini .asset-chip { width: 100%; height: 100%; display: block; object-fit: cover; }
.wmini .asset-chip { display: grid; }
.trick--breach { border-color: var(--terra); }
.trick__arrows { display: flex; align-items: center; }

/* scoreboard */
.score { background: var(--cream); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 12px; box-shadow: var(--shadow); }
.score__title { font: 800 0.8rem var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--terra); margin: 0 0 4px; }
.score__title span { color: var(--muted); margin-left: 6px; letter-spacing: 0.04em; }
.score ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.score__seat { display: flex; align-items: center; gap: 10px; }
.score__role, .score .asset-chip { width: 32px; height: 32px; object-fit: contain; border-radius: 50%; flex: none; }
.score__who { flex: 1; min-width: 0; line-height: 1.2; }
.score__who small { display: block; color: var(--muted); }
.score__wins { display: flex; align-items: center; gap: 4px; }
.score__wins b { margin-left: 6px; font: 400 1.2rem var(--font-display); color: var(--choc); }
.pip { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--choc); background: transparent; }
.pip--won { background: var(--terra); border-color: var(--terra); }

/* board */
.g-board { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.board { position: relative; width: min(100%, var(--board-max), max(300px, calc(100svh - 380px))); aspect-ratio: 1; background: var(--deep); border-radius: 10px; container-type: inline-size; }
.board--mini { width: min(100%, 280px); margin: 0 auto; }
.board__img, .board > .asset-chip { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 10px; display: block; }
.board > .asset-chip { display: grid; }
.board__grid { position: absolute; inset: 17.45%; display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr); }
.ghosts { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.ghost { position: absolute; left: 0; top: 0; width: calc(100% / var(--n)); height: calc(100% / var(--n)); }
.ghost__dot { position: absolute; inset: 12%; display: grid; place-items: center; border-radius: 50%; background: rgba(251, 246, 236, 0.94); border: 3px solid var(--choc); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45); animation: pulse 1.2s ease-in-out infinite; }
.ghost__arrow, .ghost .asset-chip { width: 55%; height: 55%; object-fit: contain; }
.ghost--lose .ghost__dot { border-style: dashed; background: rgba(251, 246, 236, 0.8); }
.ghost--stays .ghost__dot { inset: 2%; background: rgba(184, 58, 38, 0.2); border: 3px dashed var(--terra); }
.ghost--stays .ghost__arrow { display: none; }
.ghost--mid .ghost__dot { inset: 30%; border-width: 2px; box-shadow: none; animation: none; opacity: 0.85; }
.ghost--mid .ghost__arrow, .ghost--mid .asset-chip { display: none; }

/* a Whale card trick stays marked on the chart: a dashed ring where the whale was, a numbered badge on each cell it crossed */
.trail { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.trail__from, .trail__step { position: absolute; left: 0; top: 0; width: calc(100% / var(--n)); height: calc(100% / var(--n)); }
.trail__from::after { content: ''; position: absolute; inset: 14%; border: 3px dashed #ffe9a8; border-radius: 50%; }
.trail__step b { position: absolute; right: 3%; top: 3%; width: 4.8cqw; height: 4.8cqw; min-width: 16px; min-height: 16px; display: grid; place-items: center; border-radius: 50%; background: var(--terra); color: #fff; border: 2px solid #fff; font: 800 max(10px, 2.9cqw)/1 var(--font-body); }
.whale { position: absolute; left: 0; top: 0; width: calc(100% / var(--n)); height: calc(100% / var(--n)); display: grid; place-items: center; z-index: 2; transition: transform var(--move-ms) var(--ease); will-change: transform; }
.whale__inner { width: 100%; height: 100%; display: grid; place-items: center; }
.whale__img, .whale .asset-chip { width: 88%; height: auto; max-height: 90%; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4)); }
.whale--open .whale__img { filter: drop-shadow(0 0 3px #ffe9a8) drop-shadow(0 0 6px var(--terra)); }
.whale--open::after { content: ''; position: absolute; inset: 8%; border-radius: 50%; border: 3px dotted var(--terra); animation: spin 14s linear infinite; pointer-events: none; }
.whale__inner--bump { animation: bump 0.5s var(--ease); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; font-size: 0.85rem; color: var(--choc); margin: 4px 0 0; }
.swatch { display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; border: 2px solid var(--choc); border-radius: 3px; }
.swatch--open { background: var(--teal); }
.swatch--range { background: var(--deep); }

/* trick area */
.trick { background: var(--cream); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.trick__cards { display: flex; align-items: flex-end; justify-content: center; gap: 16px; }
.trick__slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.trick__label { font: 800 0.7rem var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.trick__move { display: flex; flex-direction: column; align-items: center; gap: 2px; align-self: center; font-weight: 800; color: var(--terra); font-size: 0.85rem; }
.trick__arrow, .trick__move .asset-chip { width: 26px; height: 26px; object-fit: contain; }
.trick__line { margin: 8px 0 0; text-align: center; font-size: 0.95rem; }
.trick--done .trick__slot:first-child .card { animation: none; }

/* log */
.g-log { background: var(--cream); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 12px; box-shadow: var(--shadow); }
.log__title { font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--terra); margin: 0 0 4px; }
.log__empty { color: var(--muted); margin: 0; }
.log__list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.log__item { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; border-top: 1px solid var(--line); font-size: 0.92rem; line-height: 1.35; }
.log__item:first-child { border-top: 0; }
.log__item--breach { background: rgba(184, 58, 38, 0.1); border-radius: 6px; }
.log__n { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--choc); color: var(--cream); font: 700 0.75rem/22px var(--font-body); text-align: center; }
.log__arrow, .log__item .asset-chip { flex: none; width: 16px; height: 22px; object-fit: contain; }

/* ---------- cards ---------- */
.card {
  --card-w: 80px;
  position: relative;
  display: block;
  flex: none;
  width: var(--card-w);
  aspect-ratio: 420 / 582;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 7%/5%;
  background: var(--paper);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 3px 6px rgba(60, 30, 10, 0.25);
  container-type: inline-size;
  font: inherit;
  color: inherit;
}
.card__face, .card > .asset-chip { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: fill; border-radius: 7%/5%; }
.card > .asset-chip { display: grid; border-radius: 7%/5%; }
.card__corner { position: absolute; left: 0; top: 0; width: 18%; height: 25%; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 2cqw; gap: 1cqw; pointer-events: none; }
.card__corner--br { left: auto; top: auto; right: 0; bottom: 0; transform: rotate(180deg); }
.card__num { font: 700 15.5cqw/1 var(--font-num); color: var(--ink); }
.card__glyph, .card__corner .asset-chip { width: 12cqw; height: 12cqw; object-fit: contain; font-size: 6cqw; padding: 0; min-width: 0; border: 0; background: none; }
.suit-N .card__num { color: var(--suit-n); }
.suit-E .card__num { color: var(--suit-e); }
.suit-S .card__num { color: var(--suit-s); }
.suit-W .card__num { color: var(--suit-w); }
.card--empty { display: grid; place-items: center; background: transparent; border: 2px dashed var(--line); box-shadow: none; color: var(--muted); font: 700 1.4rem var(--font-body); }
.card--trick { --card-w: 78px; animation: deal 0.35s var(--ease); }
.card-back, .asset-chip.card-back { display: block; }

/* hand */
.g-me { display: flex; flex-direction: column; gap: var(--gap); }
.handbox { background: var(--cream); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 12px 10px; box-shadow: var(--shadow); }
.handbox__title { font: 800 0.8rem var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--terra); margin: 0; }
.handbox__title span { color: var(--muted); font-weight: 600; letter-spacing: 0.04em; margin-left: 6px; text-transform: none; }
.hand-wrap { container-type: inline-size; }
/* The hand is one row. The card width is the largest that still fits --cols cards with at most
   --overlap of each hidden; the cards are then spread over the whole row (a gap of up to 14px
   between them) and overlap only by the amount that is needed (not at all when the row is wide).
   --n is the number of cards in hand (inline style). Phones override this below with two wrapped
   rows. */
.hand {
  --cols: 12;
  --overlap: 0.42;
  --hand-cw: min(var(--cw-max, 100px), calc(100cqw / (1 + (var(--cols) - 1) * (1 - var(--overlap))) * 0.985));
  --step-gap: min(14px, calc((100cqw - var(--n) * var(--hand-cw)) / max(1, var(--n) - 1))); /* negative = overlap */
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  padding: 22px 0 8px;
}
.hand .card { --card-w: var(--hand-cw); margin: 0 0 0 var(--step-gap); cursor: pointer; transition: transform 0.15s var(--ease), box-shadow 0.15s; }
.hand .card:first-child { margin-left: 0; }
.hand .card.is-legal { transform: translateY(-8px); box-shadow: 0 0 0 2px var(--legal), 0 4px 8px rgba(60, 30, 10, 0.35); }
.hand .card.is-legal:hover, .hand .card.is-legal:focus-visible, .hand .card.is-selected { transform: translateY(-18px); z-index: 10; box-shadow: 0 0 0 3px var(--legal), 0 8px 14px rgba(60, 30, 10, 0.4); }
.hand .card:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; z-index: 11; }
.hand .card.is-blocked { opacity: 0.5; filter: saturate(0.35); cursor: not-allowed; }
.hand .card.is-blocked:hover, .hand .card.is-blocked:focus-visible { z-index: 10; opacity: 0.8; transform: translateY(-4px); }
.hand .card.is-wait { cursor: default; filter: saturate(0.85); }
.hand--breach .card.is-legal { box-shadow: 0 0 0 3px var(--terra), 0 4px 8px rgba(60, 30, 10, 0.35); }
.hand--breach .card.is-legal:hover, .hand--breach .card.is-legal:focus-visible, .hand--breach .card.is-selected { box-shadow: 0 0 0 4px var(--terra), 0 8px 14px rgba(60, 30, 10, 0.4); }
.breach { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; margin: 6px 0 0; padding: 6px 12px; border: 2px solid var(--choc); border-radius: var(--radius-s); background: var(--paper); color: var(--choc); font: 800 0.95rem/1.2 var(--font-body); text-align: left; cursor: pointer; box-shadow: 0 2px 0 var(--choc); }
.breach:hover { background: #fff; }
.breach__box { position: relative; flex: none; width: 22px; height: 22px; border: 2px solid var(--choc); border-radius: 5px; background: var(--paper); }
.breach__state { flex: none; margin-left: auto; padding: 2px 9px; border: 1.5px solid currentColor; border-radius: 999px; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.breach.is-on { background: var(--terra); border-color: var(--choc); color: #fff; }
.breach.is-on:hover { background: #c9462f; }
.breach.is-on .breach__box { background: #fff; }
.breach.is-on .breach__box::after { content: ''; position: absolute; left: 5px; top: 1px; width: 6px; height: 12px; border: solid var(--terra); border-width: 0 3px 3px 0; transform: rotate(45deg); }
.breach.is-idle { opacity: 0.6; cursor: not-allowed; box-shadow: none; }
.preview { min-height: 2.9em; margin: 4px 0 2px; font-size: 0.92rem; line-height: 1.35; color: var(--muted); }
.preview--on { color: var(--ink); font-weight: 600; }
.note { min-height: 1.4em; margin: 0; color: var(--terra); font-weight: 800; }
.note:not(:empty) { animation: nudge 0.35s; }
.hand__empty { margin: 8px 0; color: var(--muted); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: var(--gutter); overflow: auto; background: rgba(42, 31, 26, 0.6); }
.end, .dialog { position: relative; width: min(100%, 540px); max-height: calc(100svh - 2 * var(--gutter)); overflow: auto; background: var(--cream); border: 3px solid var(--choc); border-radius: var(--radius); padding: 18px var(--gutter) var(--gutter); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); text-align: center; }
.end__role, .end > .asset-chip { width: 64px; height: 64px; object-fit: contain; border-radius: 50%; margin: 0 auto 4px; display: block; }
.end__kicker { font: 800 0.8rem var(--font-body); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0; }
.end h2 { font-size: 1.9rem; margin: 2px 0 8px; }
.end__line { margin: 0 0 8px; }
.end__card { margin: 0 0 8px; color: var(--muted); font-size: 0.95rem; }
.end__board { margin: 8px 0; }
.end__seats { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin: 8px 0; }
.end__seats em { color: var(--muted); font-style: normal; }
.end .score { margin: 10px 0; text-align: left; }
.end__history { text-align: left; margin: 8px 0; padding-left: 22px; font-size: 0.92rem; }
.end__history span { color: var(--muted); }
.end__buttons, .dialog__buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.dialog { text-align: left; width: min(100%, 680px); }
.dialog__close { position: absolute; right: 8px; top: 6px; width: 44px; height: 44px; font-size: 1.8rem; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--choc); }
.overlay--dialog { z-index: 70; }

.cover { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--gutter); background: var(--navy); color: var(--cream); overflow: auto; }
.cover__card { width: min(100%, 460px); text-align: center; }
.cover__role, .cover .asset-chip { width: 96px; height: 96px; object-fit: contain; border-radius: 50%; background: var(--cream); padding: 6px; margin: 0 auto 8px; display: block; }
.cover__kicker { font: 800 0.8rem var(--font-body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--sand); margin: 0; }
.cover h2 { color: var(--sand); font-size: 2rem; margin: 4px 0; }
.cover__sub { margin: 12px 0 16px; }
.cover .linkbtn { color: var(--cream); }

/* ---------- animation ---------- */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes deal { from { transform: translateY(-14px) scale(0.92); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes bump {
  0%, 100% { transform: translate(0, 0); }
  35% { transform: translate(calc(var(--bx) * 22%), calc(var(--by) * 22%)); }
  60% { transform: translate(calc(var(--bx) * -6%), calc(var(--by) * -6%)); }
}

/* ---------- breakpoints ---------- */
@media (min-width: 640px) {
  .setup__seats { grid-template-columns: 1fr 1fr; }
  .card--trick, .wmini { --card-w: 92px; }
}
@media (max-width: 639px) {
  body { font-size: 16px; }
  /* phones: two rows of six, each card overlapping the next by 42% */
  .hand { --cols: 6; flex-wrap: wrap; row-gap: 10px; padding: 18px calc(var(--hand-cw) * var(--overlap)) 8px 0; }
  .hand .card, .hand .card:first-child { margin: 0 calc(var(--hand-cw) * var(--overlap) * -1) 0 0; }
  .card--trick, .wmini { --card-w: 64px; }
  .stats b { font-size: 1.1rem; }
  .stats svg { width: 24px; height: 24px; }
  .stats li { gap: 6px; }
  .seat { padding: 6px 10px; }
  .seat__role { display: none; }
  .seat__back { width: 8px; }
  .seat__back:last-of-type { width: 26px; }
  .seat__back img, .seat__back .asset-chip { width: 26px; height: 36px; }
  .seat__role-img, .seat .asset-chip { width: 42px; height: 42px; }
}
@media (min-width: 640px) and (max-width: 999px) {
  .hand { --cols: 12; }
}
@media (min-width: 640px) {
  .seat { flex-wrap: nowrap; }
  .seat__card { order: 0; flex: 0 1 auto; padding-top: 0; border-top: 0; max-width: 40%; }
  .wcard { --wc-w: 44px; }
}

/* Desktop (>= 1000px): the whole game fits one screen. The board takes the height that is left
   after the hand, the side column stacks status, opponent, trick, me and log beside it, and the
   hand runs the full width underneath. --board-size is worked out from the viewport height so the
   grid columns do not depend on their content. */
@media (min-width: 1000px) {
  :root { --topbar-h: 40px; }
  .topbar { max-width: 1360px; padding: 0 var(--gutter); min-height: var(--topbar-h); }
  .topbar .linkbtn { min-height: 36px; padding-top: 4px; padding-bottom: 4px; }
  .game {
    --cw-max: min(100px, 9.6svh);
    --bar-h: 0px;
    --hand-extra: 116px; /* handbox chrome around the cards: title, lift, preview line, padding */
    --board-size: min(
      clamp(300px, calc(100svh - var(--topbar-h) - 24px - var(--bar-h) - var(--cw-max) * 1.386 - var(--hand-extra) - 34px), 780px),
      calc((100vw - 2 * var(--gutter) - 24px) * 0.58)
    );
    display: grid;
    max-width: 1360px;
    height: max(calc(100svh - var(--topbar-h)), 640px);
    padding: 0 var(--gutter) 12px;
    grid-template-columns: var(--board-size) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto auto minmax(0, 1fr) auto;
    column-gap: 24px;
    row-gap: 0;
    align-items: start;
  }
  .game--ended { --bar-h: 58px; }
  .col, .g-me { display: contents; }
  .endbar { grid-area: 1 / 1 / 2 / -1; height: 50px; margin-bottom: 8px; flex-wrap: nowrap; }
  .g-board { grid-area: 2 / 1 / 8 / 2; width: var(--board-size); }
  .g-board .board { width: 100%; }
  .g-status { grid-area: 2 / 2; }
  .g-score { grid-area: 3 / 2; }
  .g-opp { grid-area: 4 / 2; }
  .g-trick { grid-area: 5 / 2; }
  .g-me > .seat { grid-area: 6 / 2; }
  .g-log { grid-area: 7 / 2; align-self: stretch; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
  .g-log .log__list { flex: 1 1 0; min-height: 0; max-height: none; }
  .g-me > .handbox { grid-area: 8 / 1 / 9 / -1; margin-top: var(--gap); width: 100%; display: grid; grid-template-columns: auto auto 1fr; column-gap: 16px; align-items: baseline; padding-top: 6px; padding-bottom: 6px; }
  .handbox__title { grid-column: 1; grid-row: 1; }
  .handbox .breach { grid-column: 2; grid-row: 1; width: auto; min-height: 30px; margin: 0; padding: 2px 10px; justify-self: start; align-self: center; font-size: 0.85rem; box-shadow: 0 1px 0 var(--choc); }
  .handbox .note { grid-column: 3; grid-row: 1; text-align: right; min-height: 1.4em; }
  .handbox .hand-wrap { grid-column: 1 / -1; grid-row: 2; }
  .handbox .preview { grid-column: 1 / -1; grid-row: 3; min-height: 2.7em; margin-top: 0; }
  .g-status, .g-score, .g-opp, .g-trick, .g-me > .seat { margin-bottom: var(--gap); }
  .g-score .score { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 0 20px; padding: 6px 12px; } /* tournament: title left, both seats side by side */
  .g-score .score__title { margin: 0; }
  .g-score .score__title span { display: block; margin: 0; }
  .g-score .score ul { grid-template-columns: 1fr 1fr; gap: 12px; }
  .seat { padding: 6px 12px; }
  .wcard { --wc-w: 34px; }
  .seat__role-img, .seat .asset-chip { width: 44px; height: 44px; }
  .trick { display: grid; grid-template-columns: auto 1fr; gap: 4px 20px; align-items: center; padding: 8px 14px; }
  .trick__line { margin: 0; text-align: left; }
  .card--trick, .trick .card--empty, .wmini { --card-w: min(92px, 7svh); }
  .seat__side { flex-direction: row-reverse; align-items: center; gap: 12px; }
  .seat__back { width: 12px; }
  .seat__back:last-of-type { width: 28px; }
  .seat__back img, .seat__back .asset-chip { width: 28px; height: 39px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- stats screen, bug reporter ---------- */
.st h3 { margin: 16px 0 4px; font-size: 1.05rem; }
.st__lead { font-size: 1.1rem; }
.st__empty { padding: 24px 0; text-align: center; color: var(--muted); }
.st__muted { color: var(--muted); font-size: 0.9rem; }
.st__small { color: var(--terra); font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.st__scroll { overflow-x: auto; }
.st__table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.st__table th, .st__table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.st__table thead th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.st__table td { font-variant-numeric: tabular-nums; }
.st__list { margin: 4px 0; padding-left: 20px; font-size: 0.92rem; }
.heat { list-style: none; margin: 8px auto; padding: 0; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 2px; width: min(100%, 320px); }
.heat__cell { aspect-ratio: 1; display: grid; place-items: center; font-size: 0.78rem; font-weight: 700; color: var(--choc); border-radius: 3px; background: color-mix(in srgb, var(--deep) calc(var(--a) * 85%), var(--paper)); }
.heat__cell--sea { outline: 1px dashed var(--line); }
.heat__cell--hot { color: #fff; }

.bug-button { position: fixed; right: 10px; bottom: 10px; z-index: 40; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--choc); background: var(--cream); font-size: 1.15rem; line-height: 1; cursor: pointer; opacity: 0.6; box-shadow: var(--shadow); }
.bug-button:hover, .bug-button:focus-visible { opacity: 1; }
.bug .field { display: block; margin: 8px 0; }
.bug .field span { display: block; font-weight: 700; font-size: 0.9rem; }
.bug input, .bug textarea { width: 100%; font: inherit; padding: 6px 8px; border: 2px solid var(--choc); border-radius: var(--radius-s); background: var(--paper); }
.bug__lead { color: var(--muted); }
.bug__past { margin-top: 12px; font-size: 0.9rem; }
.bug__past ul { list-style: none; padding: 0; margin: 4px 0 0; }
.bug__past li { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.bug__past .linkbtn { min-height: 32px; }
