/* ==========================================================================================================
   Edgewise · shared game shell
   Used by every web game (via ui/shell.js and ui/cards.js) and the styleguide. Relies on the tokens in
   site.css; falls back to sensible values if a page forgets to load it.

   Structure (built by createGameShell):
     section.game[.game--compact]     (div.game[role=group] inside a /play/ section: { landmark: false })
       header.game__header > .game__titles(h3.game__title, p.game__subtitle) + .g-score
       div.game__stage.g-felt         felt table: .g-prompt, .card-row, .g-caption, .g-pot, .g-oval …
       div.game__controls             .g-actions > button.g-action--raise|call|fold|shove|neutral|primary
                                      .g-choices > button.g-choice
       div.game__feedback             .g-feedback--correct|mixed|minor|mistake|info
       div.game__footer               button.g-next, p.g-keys
   Components: .pcard / .card-row (cards.js), .g-freq, .g-range, .g-seg, .g-dots, .g-meter, .g-key,
               .g-seat, .g-pot, .g-stat
   ========================================================================================================== */

:root {
  --g-bg: var(--bg, #0A0F0D);
  --g-surface: var(--surface, #121A17);
  --g-surface-2: var(--surface-2, #1A2521);
  --g-stroke: var(--stroke, rgba(255, 255, 255, .08));
  --g-text: var(--text, #fff);
  --g-dim: var(--text-dim, rgba(255, 255, 255, .68));
  --g-faint: var(--text-faint, rgba(255, 255, 255, .6));
  --g-on-felt-dim: rgba(255, 255, 255, .86);
  --g-fold-band: color-mix(in srgb, var(--fold, #33424C) 55%, #0E1512);
  --g-radius: 28px;
  --g-pad: clamp(14px, 2.6vw, 26px);
  --g-gap: clamp(12px, 1.6vw, 16px);
  --g-font: var(--font-ui, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif);
}

/* Colour-blind palette, mirroring the app's setting (add .palette-cb to <html> or a .game). */
.palette-cb,
.palette-cb .game {
  --good: #56B4E9;
  --bad: #E69F00;
  --raise: #B85A0C;
  --call: #2F6FB5;
  --shove: #8E5BA8;
  --raise-text: #FFB060;
}

/* ── Container ─────────────────────────────────────────────────────────────────────────────────────── */

.game {
  container: game / inline-size;
  position: relative;
  isolation: isolate;
  display: grid;
  gap: var(--g-gap);
  padding: var(--g-pad);
  border-radius: var(--g-radius);
  color: var(--g-text);
  font-family: var(--g-font);
  font-variant-numeric: tabular-nums;
  text-align: start;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 255, 255, .045), transparent 60%),
    linear-gradient(180deg, #131D19 0%, #0E1613 100%);
  border: 1px solid var(--g-stroke);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .05),
    0 1px 2px rgba(0, 0, 0, .4),
    0 30px 80px -30px rgba(0, 0, 0, .75);
  outline: none;
}

.game:focus-visible {
  outline: 2px solid var(--gold, #E9B949);
  outline-offset: 3px;
}

.game--compact {
  --g-radius: 24px;
  --g-pad: clamp(12px, 2vw, 18px);
  --g-gap: 12px;
}

.game :where(h2, h3, h4, h5, h6, p, ul, ol) {
  margin: 0;
}

/* ── Header + score pill ───────────────────────────────────────────────────────────────────────────── */

.game__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  flex-wrap: wrap;
  min-height: 44px;
}

.game__titles {
  min-width: 0;
  flex: 1 1 12rem;
}

.game__title {
  font: 700 1.0625rem/1.2 var(--g-font);
  letter-spacing: -.01em;
  color: var(--g-text);
  text-wrap: balance;
}

.game--compact .game__title {
  font-size: 1rem;
}

.game__subtitle {
  margin-top: 3px;
  font: 500 .8125rem/1.35 var(--g-font);
  color: var(--g-dim);
}

.g-score {
  flex: none;
  display: inline-flex;
}

.g-score__visual {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .045);
  box-shadow: inset 0 0 0 1px var(--g-stroke);
  font: 600 .875rem/1 var(--g-font);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--g-dim);
}

.g-score__streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--g-dim);
  transition: color .3s;
}

.g-score__streak.is-hot {
  color: var(--gold, #E9B949);
}

.g-score__count {
  color: var(--g-faint);
}

.g-score__best {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-left: 12px;
  border-left: 1px solid var(--g-stroke);
  color: var(--gold, #E9B949);
}

/* ── Felt stage ────────────────────────────────────────────────────────────────────────────────────── */

.g-felt {
  container-type: inline-size;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: calc(var(--g-radius) - 8px);
  color: #fff;
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(255, 255, 255, .09), transparent 60%),
    radial-gradient(ellipse 75% 95% at 50% 42%, var(--felt-top, #1D6A46) 0%, #155537 45%, var(--felt-bottom, #0C3A27) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .07),
    inset 0 1px 0 rgba(255, 255, 255, .08),
    inset 0 -40px 70px -30px rgba(0, 0, 0, .55),
    0 12px 30px -18px rgba(0, 0, 0, .8);
}

/* Felt fibre: fine noise + a whisper of weave. */
.g-felt::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .22;
  mix-blend-mode: overlay;
  background-image:
    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='.9' numOctaves='2' 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"),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .03) 0 1px, transparent 1px 3px);
}

.game__stage {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: clamp(10px, 2.4cqi, 18px);
  min-height: clamp(220px, 46cqi, 340px);
  padding: clamp(18px, 4cqi, 32px) clamp(14px, 3.5cqi, 28px);
  text-align: center;
}

.game--compact .game__stage {
  min-height: clamp(200px, 40cqi, 280px);
  padding: clamp(14px, 3cqi, 22px) clamp(12px, 3cqi, 20px);
}

.game__stage:empty {
  display: none;
}

/* Plain (non-felt) stage for menus/results. */
.g-plain {
  background: var(--g-surface-2);
  box-shadow: inset 0 0 0 1px var(--g-stroke);
}

.g-plain::before {
  display: none;
}

.g-prompt {
  display: grid;
  gap: 6px;
  justify-items: center;
  max-width: 34rem;
}

.g-prompt__eyebrow {
  font: 700 .6875rem/1.2 var(--g-font);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--g-on-felt-dim);
}

.g-prompt__text {
  font: 600 clamp(1rem, .95rem + .4cqi, 1.1875rem)/1.4 var(--g-font);
  color: #fff;
  text-wrap: balance;
}

.g-prompt__sub {
  font: 500 .875rem/1.45 var(--g-font);
  color: var(--g-on-felt-dim);
  text-wrap: pretty;
}

.g-caption {
  font: 600 .8125rem/1.3 var(--g-font);
  color: var(--g-on-felt-dim);
}

.g-caption--strong {
  color: #fff;
  font-size: .875rem;
}

.g-text-raise { color: var(--raise-text, #FF8A8D); }
.g-text-gold { color: var(--gold, #E9B949); }
.g-text-good { color: var(--good, #34C77B); }
.g-text-bad { color: var(--bad, #FF5D5D); }
.g-text-dim { color: var(--g-dim); }

.g-felt .g-text-raise { color: #FFB3B5; }

.g-stack {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.g-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(10px, 3cqi, 24px);
  width: 100%;
  align-items: start;
}

.g-divider {
  width: min(100%, 22rem);
  height: 1px;
  border: 0;
  margin: 2px 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .22), transparent);
}

/* Pot / bet pills on the felt */
.g-pot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .3);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1);
  font: 650 .8125rem/1 var(--g-font);
  font-variant-numeric: tabular-nums;
  color: #fff;
  white-space: nowrap;
}

.g-pot::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFE7A3, var(--gold, #E9B949) 55%, #A9801F);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .25), inset 0 0 0 1.5px rgba(255, 255, 255, .35);
}

.g-pot--plain::before {
  display: none;
}

/* Oval table (seat maps): place .g-seat children with --x / --y in % of the oval box. */
.g-oval {
  position: relative;
  width: min(100%, 30rem);
  aspect-ratio: 2.1 / 1;
  margin: 18px auto;
  border-radius: 999px;
  background: radial-gradient(ellipse at 50% 40%, var(--felt-top, #1D6A46), var(--felt-bottom, #0C3A27));
  box-shadow:
    0 0 0 6px #1A120D,
    0 0 0 7px rgba(233, 185, 73, .28),
    0 0 0 12px #0F0A07,
    inset 0 -20px 40px -16px rgba(0, 0, 0, .55),
    0 24px 50px -20px rgba(0, 0, 0, .9);
}

.g-seat {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  translate: -50% -50%;
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 44px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #0F1714;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14), 0 4px 10px -4px rgba(0, 0, 0, .8);
  font: 700 .6875rem/1 var(--g-font);
  letter-spacing: .02em;
  color: rgba(255, 255, 255, .86);
  white-space: nowrap;
}

button.g-seat {
  cursor: pointer;
  border: 0;
  min-height: 32px;
}

.g-seat__note {
  font-weight: 600;
  font-size: .625rem;
  color: var(--g-dim);
}

.g-seat--hero {
  background: var(--gold, #E9B949);
  color: #1A1405;
}

.g-seat--hero .g-seat__note { color: rgba(26, 20, 5, .75); }

.g-seat--action {
  background: var(--raise, #D8383D);
  color: #fff;
}

.g-seat--action .g-seat__note { color: rgba(255, 255, 255, .85); }

.g-seat--folded {
  opacity: .65; /* .5 left the 11px seat names under 4.5:1 */
}

.g-seat.is-correct { box-shadow: 0 0 0 2px var(--good, #34C77B), 0 4px 10px -4px rgba(0, 0, 0, .8); }
.g-seat.is-wrong { box-shadow: 0 0 0 2px var(--bad, #FF5D5D), 0 4px 10px -4px rgba(0, 0, 0, .8); }

.g-dealer {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  translate: -50% -50%;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FAFAF7;
  color: #111;
  font: 800 .625rem/1 var(--g-font);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .5), inset 0 0 0 2px rgba(0, 0, 0, .08);
}

/* ── Playing cards (ui/cards.js) ───────────────────────────────────────────────────────────────────── */

.pcard {
  --w: var(--card-w, 56px);
  --suit: #1A1A1A;
  position: relative;
  flex: none;
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  box-sizing: border-box;
  inline-size: var(--w);
  block-size: calc(var(--w) * 1.4);
  padding: calc(var(--w) * .07) calc(var(--w) * .1);
  border-radius: calc(var(--w) * .14);
  background: linear-gradient(165deg, #FFFFFF 0%, #FAFAF7 45%, #F0EFE8 100%);
  color: var(--suit);
  font-family: var(--g-font);
  line-height: 1;
  text-align: start;
  vertical-align: middle;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, .05),
    0 max(1.5px, calc(var(--w) * .035)) 0 rgba(0, 0, 0, .35),
    0 calc(var(--w) * .16) calc(var(--w) * .32) calc(var(--w) * -.12) rgba(0, 0, 0, .55);
  user-select: none;
  -webkit-user-select: none;
  transform-origin: 50% 100%;
}

.pcard--s { --suit: #1A1A1A; }
.pcard--h { --suit: #D32F2F; }
.pcard--d { --suit: #1E63D6; }
.pcard--c { --suit: #18773A; } /* a shade under the app's #1F8A3B: 4.5:1 on the face at small sizes */

/* Two-colour deck option */
.deck-2c .pcard--d { --suit: #D32F2F; }
.deck-2c .pcard--c { --suit: #1A1A1A; }

.pcard__rank {
  align-self: flex-start;
  font-size: calc(var(--w) * .42);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: .95;
}

.pcard--ten .pcard__rank {
  font-size: calc(var(--w) * .36);
  letter-spacing: -.07em;
  margin-inline-start: calc(var(--w) * -.02);
}

.pcard__suit {
  align-self: flex-end;
  font-size: calc(var(--w) * .55);
  line-height: .8;
  font-family: var(--g-font);
}

.pcard--back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .035) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .035) 0 2px, transparent 2px 6px),
    linear-gradient(135deg, #7A1F2B, #4A0F18);
  color: transparent;
}

.pcard--back::before {
  content: "";
  position: absolute;
  inset: calc(var(--w) * .08);
  border: max(1px, calc(var(--w) * .025)) solid rgba(233, 185, 73, .5);
  border-radius: calc(var(--w) * .1);
}

.pcard--back::after {
  content: "\2660\FE0E";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--w) * .3);
  color: rgba(233, 185, 73, .55);
}

.pcard--slot {
  background: none;
  box-shadow: none;
  border: 1px dashed rgba(255, 255, 255, .16);
}

.pcard.is-highlight {
  outline: 3px solid var(--hl, var(--gold, #E9B949));
  outline-offset: -1px;
}

.pcard.is-dimmed {
  /* Darken rather than fade: opacity .35 would drop the rank below 4.5:1 on the felt. */
  filter: brightness(.75) saturate(.6);
}

.card-row {
  --card-gap: 6px;
  --fit: calc((100cqi - (var(--n, 5) - 1) * var(--card-gap)) / var(--n, 5));
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--card-gap);
  max-width: 100%;
}

.card-row > .pcard {
  --w: min(var(--card-w, 56px), var(--fit));
}

.card-row--fan {
  gap: 0;
  padding-inline: calc(var(--card-w, 56px) * .08);
}

.card-row--fan > .pcard + .pcard {
  margin-inline-start: calc(var(--w) * -.18);
}

.card-row--fan > .pcard:first-child:not(:only-child) { rotate: -4deg; }
.card-row--fan > .pcard:last-child:not(:only-child) { rotate: 4deg; }

/* ── Controls ──────────────────────────────────────────────────────────────────────────────────────── */

.game__controls {
  display: grid;
  gap: 10px;
}

.game__controls:empty,
.game__feedback:empty,
.game__footer:empty {
  display: none;
}

/* Air around what shell.js scrolls into view: the result and Next after an answer, the new round's controls. */
.game__stage,
.game__controls button,
.game__feedback,
.g-next {
  scroll-margin-block: 16px;
}

.g-actions {
  container: g-actions / inline-size;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 10px;
}

/* Key chips only where the buttons are wide enough to hold them beside the label. */
@container g-actions (max-width: 250px) { .g-actions[data-count="2"] .g-action__key { display: none; } }
@container g-actions (max-width: 360px) { .g-actions[data-count="3"] .g-action__key { display: none; } }
@container g-actions (max-width: 470px) { .g-actions[data-count="4"] .g-action__key { display: none; } }
@container g-actions (max-width: 600px) { .g-actions[data-count="5"] .g-action__key, .g-actions[data-count="6"] .g-action__key { display: none; } }

@container game (max-width: 360px) {
  .g-actions[data-count="4"],
  .g-actions[data-count="5"],
  .g-actions[data-count="6"] {
    grid-auto-flow: row;
    grid-template-columns: 1fr 1fr;
  }
}

.g-action {
  --a-bg: var(--g-surface-2);
  --a-fg: #fff;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 54px;
  min-width: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, 0) 55%),
    var(--a-bg);
  color: var(--a-fg);
  font: 700 1.0625rem/1.1 var(--g-font);
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .2),
    inset 0 -2px 0 rgba(0, 0, 0, .2),
    0 8px 18px -10px rgba(0, 0, 0, .8);
  transition: transform .16s cubic-bezier(.2, .8, .2, 1), filter .16s, opacity .25s, box-shadow .2s;
}

.g-action:hover { filter: brightness(1.1) saturate(1.05); transform: translateY(-1px); }
/* A lighter (or more saturated) raise, call or shove fill would take the white label under 4.5:1: those only lift. */
.g-action--raise:hover,
.g-action--call:hover,
.g-action--shove:hover { filter: none; }
.g-action:active { transform: scale(.96); filter: brightness(.95); }

.g-action:focus-visible {
  outline: 2px solid var(--gold, #E9B949);
  outline-offset: 3px;
}

/* Raise, call and shove buttons sit a shade under --raise / --call / --shove so the white label clears 4.5:1
   under the sheen (raise needs the most); chart bands, frequency bars and seat chips keep the tokens. */
.g-action--raise { --a-bg: #C42B31; }
.g-action--call { --a-bg: #1A794A; }
.g-action--fold { --a-bg: var(--fold, #33424C); }
.g-action--shove { --a-bg: #BB3A67; }
.palette-cb .g-action--raise { --a-bg: #A34F0A; }
.palette-cb .g-action--call { --a-bg: #2E6CB0; }
.palette-cb .g-action--shove { --a-bg: #8755A1; }
.g-action--neutral { --a-bg: var(--g-surface-2); box-shadow: inset 0 0 0 1px var(--g-stroke), 0 8px 18px -10px rgba(0, 0, 0, .8); }
.g-action--primary { --a-bg: var(--gold, #E9B949); --a-fg: #14100A; }

.g-action__label {
  overflow-wrap: anywhere;
}

.g-action__sub {
  font: 600 .6875rem/1.2 var(--g-font);
  font-variant-numeric: tabular-nums;
}

.g-action__key {
  position: absolute;
  top: 6px;
  right: 6px;
}

.g-action[aria-disabled="true"] {
  cursor: default;
  filter: none;
  transform: none;
}

.game.is-answered .g-action:not(.is-chosen, .is-correct, .is-mixed),
.game.is-answered .g-choice:not(.is-chosen, .is-correct, .is-mixed) {
  opacity: .42;
}

.g-action.is-chosen {
  box-shadow:
    0 0 0 2px #0E1613,
    0 0 0 4px rgba(255, 255, 255, .92),
    0 8px 18px -10px rgba(0, 0, 0, .8);
}

.g-mark-slot:empty {
  display: none;
}

.g-mark {
  --icon-ink: #0E1613;
  position: absolute;
  top: -8px;
  left: -8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #0E1613;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .6);
  animation: g-pop .32s cubic-bezier(.2, 1.4, .4, 1) both;
}

.g-mark--correct { color: var(--good, #34C77B); }
.g-mark--wrong { color: var(--bad, #FF5D5D); }
.g-mark--mixed { color: var(--gold, #E9B949); }

/* Multiple-choice answers */
.g-choices {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

@container game (min-width: 380px) {
  .g-choices[data-count="2"],
  .g-choices[data-count="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container game (min-width: 460px) {
  .g-choices[data-count="3"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@container game (min-width: 640px) {
  .g-choices[data-count="4"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.g-choices--stack {
  grid-template-columns: 1fr;
}

.g-choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .015)), var(--g-surface-2);
  box-shadow: inset 0 0 0 1px var(--g-stroke), 0 8px 18px -12px rgba(0, 0, 0, .8);
  color: var(--g-text);
  font: 600 1rem/1.3 var(--g-font);
  text-align: start;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow .2s, background-color .2s, transform .16s cubic-bezier(.2, .8, .2, 1), opacity .25s;
}

.g-choice:hover {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2), 0 10px 22px -12px rgba(0, 0, 0, .9);
}

.g-choice:active { transform: scale(.98); }

.g-choice:focus-visible {
  outline: 2px solid var(--gold, #E9B949);
  outline-offset: 3px;
}

.g-choice[aria-disabled="true"] {
  cursor: default;
  transform: none;
}

.g-choice__key {
  flex: none;
}

.g-choice__body {
  display: grid;
  gap: 3px;
  flex: 1;
  min-width: 0;
  justify-items: start;
}

.g-choice__sub {
  font: 500 .8125rem/1.35 var(--g-font);
  color: var(--g-dim);
}

.g-choice .g-mark {
  position: static;
  flex: none;
  width: 22px;
  height: 22px;
  margin-inline-start: auto;
  background: none;
  box-shadow: none;
}

.g-choice.is-correct {
  background: color-mix(in srgb, var(--good, #34C77B) 14%, var(--g-surface-2));
  box-shadow: inset 0 0 0 1.5px var(--good, #34C77B);
}

.g-choice.is-wrong {
  background: color-mix(in srgb, var(--bad, #FF5D5D) 12%, var(--g-surface-2));
  box-shadow: inset 0 0 0 1.5px var(--bad, #FF5D5D);
}

.g-choice.is-mixed {
  box-shadow: inset 0 0 0 1.5px var(--gold, #E9B949);
}

.g-choice.is-chosen:not(.is-wrong, .is-correct, .is-mixed) {
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .9);
}

/* ── Feedback ──────────────────────────────────────────────────────────────────────────────────────── */

.g-feedback {
  --k: var(--g-dim);
  --icon-ink: #0E1613;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--k) 7%, var(--g-surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--k) 32%, transparent);
  animation: g-rise .38s cubic-bezier(.2, .8, .2, 1) both;
}

.g-feedback--correct { --k: var(--good, #34C77B); }
.g-feedback--mixed { --k: var(--gold, #E9B949); }
.g-feedback--minor { --k: var(--warn, #F5A524); }
.g-feedback--mistake { --k: var(--bad, #FF5D5D); }
.g-feedback--info { --k: rgba(255, 255, 255, .55); }

.g-feedback__icon {
  color: var(--k);
  margin-top: 1px;
}

.g-feedback__text {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.g-feedback__title {
  font: 700 .9375rem/1.3 var(--g-font);
  color: var(--k);
}

.g-feedback--info .g-feedback__title { color: var(--g-text); }

.g-feedback__body {
  display: grid;
  gap: 8px;
  font: 500 .875rem/1.55 var(--g-font);
  color: var(--g-dim);
  text-wrap: pretty;
}

.g-feedback__body strong {
  color: var(--g-text);
  font-weight: 650;
}

/* ── Footer: next button + key hints ───────────────────────────────────────────────────────────────── */

.game__footer {
  display: grid;
  gap: 12px;
}

.g-next {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #F2CB66 0%, var(--gold, #E9B949) 50%, #DDA93A 100%);
  color: #14100A;
  font: 700 1.0625rem/1 var(--g-font);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .45),
    inset 0 -2px 0 rgba(0, 0, 0, .12),
    0 12px 26px -14px rgba(233, 185, 73, .7);
  transition: transform .16s cubic-bezier(.2, .8, .2, 1), filter .16s;
  animation: g-rise .35s cubic-bezier(.2, .8, .2, 1) both;
}

.g-next[hidden] { display: none; }
.g-next:hover { filter: brightness(1.06); }
.g-next:active { transform: scale(.98); }

.g-next:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.g-next .g-key {
  margin-inline-start: 4px;
}

.g-key {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .24);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2), inset 0 -1px 0 rgba(0, 0, 0, .35);
  color: rgba(255, 255, 255, .9);
  font: 650 .6875rem/1 var(--g-font);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: uppercase;
}

.g-choice .g-key {
  min-width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, .06);
  color: var(--g-dim);
}

.g-key--on-gold {
  background: rgba(0, 0, 0, .1);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .22);
  color: rgba(20, 16, 10, .8);
}

.g-keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 14px;
  font: 500 .75rem/1.2 var(--g-font);
  color: var(--g-faint);
}

.g-keys__icon { opacity: .7; }

.g-keys__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.g-keys .g-key {
  background: rgba(255, 255, 255, .05);
  color: var(--g-dim);
}

/* Touch-only devices never see keyboard chips. */
@media (hover: none) and (pointer: coarse) {
  .g-key,
  .g-keys {
    display: none !important;
  }
}

/* ── Frequency bar ─────────────────────────────────────────────────────────────────────────────────── */

.g-freq {
  display: grid;
  gap: 8px;
  width: 100%;
}

.g-freq__track {
  display: flex;
  gap: 2px;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, .06);
}

.g-freq__seg {
  flex-basis: 0;
  min-width: 3px;
  background: var(--fold, #33424C);
  transform-origin: left center;
  animation: g-grow .6s cubic-bezier(.2, .8, .2, 1) both;
}

.g-freq__seg--raise { background: var(--raise, #D8383D); }
.g-freq__seg--call { background: var(--call, #1B7D4C); }
.g-freq__seg--shove { background: var(--shove, #C13C6A); }
.g-freq__seg--fold { background: #4A5C68; }

.g-freq__legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 14px;
  padding: 0;
  list-style: none;
  font: 500 .8125rem/1.3 var(--g-font);
  font-variant-numeric: tabular-nums;
  color: var(--g-dim);
}

.g-freq__item,
.g-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.g-freq__item.is-chosen {
  color: var(--g-text);
  font-weight: 700;
}

.g-freq__you {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  font: 700 .625rem/1.1 var(--g-font);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--g-text);
}

.g-swatch {
  flex: none;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: #4A5C68;
}

.g-freq__item--raise .g-swatch, .g-legend__item--raise .g-swatch { background: var(--raise, #D8383D); }
.g-freq__item--call .g-swatch, .g-legend__item--call .g-swatch { background: var(--call, #1B7D4C); }
.g-freq__item--shove .g-swatch, .g-legend__item--shove .g-swatch { background: var(--shove, #C13C6A); }

/* ── 13×13 range grid ──────────────────────────────────────────────────────────────────────────────── */

.g-range-wrap {
  display: grid;
  gap: 10px;
  width: 100%;
}

.g-range {
  container-type: inline-size;
  display: grid;
  gap: 1px;
  width: 100%;
  grid-template-rows: repeat(13, minmax(0, 1fr));
  aspect-ratio: 1;
  padding: 1px;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, .45);
  box-shadow: 0 0 0 1px var(--g-stroke);
}

.g-range__row {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 1px;
}

.g-range__cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  background: var(--g-fold-band);
  outline: none;
}

.g-range__label {
  font: 650 max(6px, calc(100cqi / 13 * .36))/1 var(--g-font); /* widest label ("AKo") fills ≤ 92% of a cell */
  letter-spacing: -.02em;
  color: #fff; /* 4.6:1 on the raise band */
  text-shadow: 0 1px 1px rgba(0, 0, 0, .35);
  white-space: nowrap;
  pointer-events: none;
}

.g-range--interactive .g-range__cell {
  cursor: pointer;
}

.g-range--interactive .g-range__cell:hover {
  filter: brightness(1.18);
}

.g-range__cell.is-highlight {
  z-index: 1;
  box-shadow: inset 0 0 0 2.5px #fff, 0 0 0 1px #000;
}

.g-range__cell:focus-visible {
  z-index: 2;
  box-shadow: inset 0 0 0 2px var(--gold, #E9B949), 0 0 0 2px #000;
}

.g-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 0;
  list-style: none;
  font: 500 .75rem/1.3 var(--g-font);
  font-variant-numeric: tabular-nums;
  color: var(--g-dim);
}

/* ── Segmented control ─────────────────────────────────────────────────────────────────────────────── */

.g-seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
  box-shadow: inset 0 0 0 1px var(--g-stroke);
  max-width: 100%;
}

.g-seg__opt {
  position: relative;
  flex: 1 1 auto;
  display: flex;
}

.g-seg__input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.g-seg__label {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  font: 600 .8125rem/1.1 var(--g-font);
  color: var(--g-dim);
  white-space: nowrap;
  transition: background-color .2s, color .2s, box-shadow .2s;
  pointer-events: none;
}

.g-seg__opt:hover .g-seg__label {
  color: var(--g-text);
}

.g-seg__input:checked + .g-seg__label {
  background: linear-gradient(180deg, #2A3934, #22302B);
  color: var(--g-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 2px 6px -2px rgba(0, 0, 0, .6);
}

.g-seg__input:focus-visible + .g-seg__label {
  outline: 2px solid var(--gold, #E9B949);
  outline-offset: 1px;
}

/* ── Progress dots, meter, stats ───────────────────────────────────────────────────────────────────── */

.g-dots-wrap {
  display: flex;
  justify-content: center;
}

.g-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.g-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  transition: background-color .25s, width .3s cubic-bezier(.2, .8, .2, 1), border-radius .3s;
}

.g-dot.is-current {
  width: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .85);
}

.g-dot.is-correct { background: var(--good, #34C77B); }
.g-dot.is-mixed { background: var(--gold, #E9B949); }

/* Wrong answers are hollow rings, so results never rely on colour alone. */
.g-dot.is-wrong {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--bad, #FF5D5D);
}

.g-meter {
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, .08);
}

.g-meter__fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #DDA93A, var(--gold, #E9B949), #F6D98A);
  transform-origin: left center;
  transform: scaleX(var(--value, 0));
  transition: transform .3s linear;
}

.g-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
  gap: 10px;
}

.g-stat {
  display: grid;
  gap: 4px;
  padding: 14px;
  border-radius: 16px;
  background: var(--g-surface-2);
  box-shadow: inset 0 0 0 1px var(--g-stroke);
}

.g-stat__value {
  font: 700 1.5rem/1.1 var(--g-font);
  font-variant-numeric: tabular-nums;
  color: var(--g-text);
}

.g-stat__label {
  font: 500 .75rem/1.3 var(--g-font);
  color: var(--g-dim);
}

.g-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  font: 700 .6875rem/1 var(--g-font);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--g-dim);
}

.g-tag--gold { background: var(--gold, #E9B949); color: #14100A; }
.g-tag--raise { background: color-mix(in srgb, var(--raise, #D8383D) 22%, transparent); color: var(--raise-text, #FF8A8D); }

/* ── Motion ────────────────────────────────────────────────────────────────────────────────────────── */

@keyframes g-rise {
  from { opacity: 0; translate: 0 8px; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes g-pop {
  from { opacity: 0; scale: .4; }
  to { opacity: 1; scale: 1; }
}

@keyframes g-grow {
  from { scale: 0 1; }
  to { scale: 1 1; }
}

@media (prefers-reduced-motion: reduce) {
  .g-feedback,
  .g-next,
  .g-mark,
  .g-freq__seg {
    animation: none;
  }

  .g-action,
  .g-choice,
  .g-dot,
  .g-meter__fill {
    transition: none;
  }

  .g-action:active,
  .g-choice:active,
  .g-next:active {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  .game {
    --g-stroke: rgba(255, 255, 255, .25);
    --g-dim: rgba(255, 255, 255, .85);
    --g-faint: rgba(255, 255, 255, .75);
  }
}

@media (forced-colors: active) {
  .g-action,
  .g-choice,
  .g-next,
  .g-seg__label,
  .pcard {
    border: 1px solid CanvasText;
  }

  .g-range__cell.is-highlight {
    outline: 2px solid Highlight;
  }

  /* The checked segment would otherwise look like the rest, and the text backplate paints over Highlight. */
  .g-seg__input:checked + .g-seg__label {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }

  /* Action colours are the information in charts, frequency bars and their legends: keep them. */
  .g-range__cell,
  .g-freq__seg,
  .g-swatch {
    forced-color-adjust: none;
  }

  .g-seat--hero {
    outline: 2px solid Highlight;
  }
}

/* Very small screens (320px) */
@container game (max-width: 330px) {
  .g-score__visual {
    gap: 9px;
    padding: 0 11px;
    font-size: .8125rem;
  }

  .g-action {
    font-size: 1rem;
  }

}
