/* =========================================================================
   Game pages — shared shell (loaded after stylesheet.css)
   ========================================================================= */

/* On game pages the site header scrolls away, so the play area can use the full window height. */
html.game-page { scroll-padding-top: 12px; }
html.game-page trusty-header { position: relative; }
.game-main { scroll-margin-block: 12px; }

.game-head { padding-block: clamp(18px, 3.5vw, 36px) clamp(12px, 2vw, 20px); }
@media (max-height: 760px) and (min-width: 561px) {
  .game-head { padding-block: 12px 12px; }
  .game-head .eyebrow { display: none; }
  .game-head .back-link { margin-bottom: 6px; }
  .game-title-row h1 { font-size: clamp(1.8rem, 3.6vw, 2.4rem); }
}
.game-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
}
.game-title-row h1 { margin: 0; font-size: clamp(2.1rem, 5vw, 3.3rem); }
.game-title-row .eyebrow { margin-bottom: .25rem; }
.game-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: clamp(20px, 3vw, 36px);
  align-items: start;
}
.game-main { min-width: 0; }
.game-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
@media (max-width: 960px) {
  .game-layout { grid-template-columns: 1fr; }
}

/* ---------- Stage: a fixed-aspect play area that always fits the screen ---------- */
/* svh, not dvh: on phones dvh changes every time the toolbar hides or shows, which resized the stage mid-scroll. */
.stage {
  --ar: 1.3333;
  --stage-room: 24px;
  position: relative;
  width: 100%;
  width: min(100%, calc((100svh - var(--stage-room)) * var(--ar)));
  min-width: min(100%, 300px);
  aspect-ratio: var(--ar);
  margin-inline: auto;
  border: 2px solid var(--ink);
  border-radius: 14px 10px 16px 12px / 12px 16px 10px 14px;
  box-shadow: var(--shadow-ink-lg);
  overflow: hidden;
  background: #fff;
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.stage > canvas { width: 100%; height: 100%; }
.stage:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }

.stage-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.6cqi, 12px);
  padding: 16px;
  text-align: center;
  background: rgba(251, 248, 240, .9);
  animation: overlay-in .2s var(--ease-out);
}
.stage-overlay[hidden] { display: none; }
@keyframes overlay-in { from { opacity: 0; } }
.overlay-kicker { margin: 0; font-family: var(--font-hand); font-weight: 700; font-size: clamp(1.1rem, 4cqi, 1.6rem); color: var(--red); line-height: 1; }
.overlay-title { margin: 0; font-family: var(--font-marker); font-weight: 400; font-size: clamp(1.5rem, 7cqi, 3rem); line-height: 1.05; }
.overlay-score { font-family: var(--font-marker); font-size: clamp(2.4rem, 13cqi, 5.5rem); line-height: .95; }
.overlay-sub { margin: 0; max-width: 34ch; color: var(--ink-soft); font-weight: 600; font-size: clamp(.85rem, 2.6cqi, 1.05rem); }
.overlay-badge {
  display: inline-block;
  padding: 3px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--highlight);
  font-weight: 800;
  font-size: .85rem;
  transform: rotate(-3deg);
}
.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 4px; }
.overlay-hint { margin: 0; font-size: .82rem; color: var(--pencil); }
@container (max-width: 440px) {
  .overlay-actions .btn { min-height: 38px; padding: .45em .95em; font-size: .92rem; }
  .overlay-hint { display: none; }
}

.stage-dark .stage-overlay { background: rgba(30, 31, 35, .82); color: #fff; }
.stage-dark .overlay-title, .stage-dark .overlay-score { color: #fff; }
.stage-dark .overlay-sub { color: rgba(255, 255, 255, .8); }

/* Focus mode: the stage takes over the screen (mainly for phones) */
html.game-focus { overflow: hidden; }
.stage.is-focus {
  position: fixed;
  inset: 0;
  z-index: 900;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  max-width: none;
  aspect-ratio: auto;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #1e1f23;
}
.stage.is-focus > canvas { object-fit: contain; }
.focus-hint { display: none; }
@media (orientation: portrait) {
  .stage.is-focus .focus-hint {
    display: block;
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: calc(28px + env(safe-area-inset-bottom));
    margin: 0;
    text-align: center;
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.5rem;
    color: rgba(255, 255, 255, .85);
    pointer-events: none;
  }
}
.focus-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  z-index: 3;
}

/* ---------- Toolbar buttons ---------- */
.btn .icon { width: 20px; height: 20px; flex: none; }
.mute-btn .icon-off { display: none; }
.mute-btn[aria-pressed="true"] .icon-on { display: none; }
.mute-btn[aria-pressed="true"] .icon-off { display: block; }

/* ---------- Touch controls (phones/tablets only) ---------- */
.touch-pad { display: none; justify-content: center; gap: 10px; margin-top: 16px; }
@media (pointer: coarse) {
  .touch-pad { display: flex; }
  .desktop-only { display: none !important; }
}
@media not all and (pointer: coarse) {
  .touch-only { display: none !important; }
}
.pad-btn {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 16px 12px 16px 12px / 12px 16px 12px 16px;
  background: #fff;
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--ink);
  font-size: 1.4rem;
  font-weight: 800;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.pad-btn svg { width: 28px; height: 28px; }
.pad-btn:active, .pad-btn.is-pressed { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); background: var(--note-yellow); }
.pad-btn.wide { width: auto; padding: 0 18px; font-size: 1rem; }
.dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 64px); gap: 8px; justify-content: center; }
.dpad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }

/* ---------- Side panels ---------- */
.how-to { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.how-to li { display: flex; align-items: baseline; gap: 10px; line-height: 1.45; }
.how-to .keys { display: inline-flex; flex-wrap: wrap; gap: 4px; flex: none; min-width: 5.2em; }
.how-to.bullets .keys { min-width: 1.2em; }
kbd {
  display: inline-block;
  min-width: 1.9em;
  padding: 1px 7px;
  border: 1.5px solid var(--ink);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #fff;
  font: 700 .78rem/1.4 var(--font-body);
  text-align: center;
  white-space: nowrap;
}
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  padding: 10px 12px;
  border: 1.5px dashed var(--grid-strong);
  border-radius: 10px;
  background: var(--paper);
  min-width: 0;
}
.stat-label { display: block; font-size: .7rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--pencil); }
.stat-value { display: block; font-family: var(--font-marker); font-size: 1.6rem; line-height: 1.15; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.side-note { margin: 12px 0 0; font-size: .9rem; color: var(--pencil); }
.side-note a { font-weight: 700; }
.panel .board { margin: 0 -6px; }
.panel .board-row { min-height: 42px; padding: 4px 8px; }
.panel-foot { margin-top: 10px; text-align: right; }

/* =========================================================================
   Flappy Trusty
   ========================================================================= */
.flappy-stage { --ar: 1.3333; cursor: pointer; }

/* =========================================================================
   Draw Trusty
   ========================================================================= */
.draw-stage {
  --ar: 1;
  --stage-room: 160px;
  max-width: 540px;
  background:
    linear-gradient(var(--card), var(--card));
  cursor: crosshair;
}
.draw-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 10% 10%;
  opacity: .6;
  pointer-events: none;
}
.draw-stage canvas { position: relative; }
.draw-hud {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 540px;
  margin: 0 auto 12px;
}
.draw-phase { flex: none; min-width: 7.5em; font-family: var(--font-marker); font-size: 1.2rem; }
.timer-bar {
  flex: 1;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}
.timer-fill { height: 100%; width: 100%; background: var(--highlight); transform-origin: left center; }
.timer-fill.is-memorize { background: var(--note-blue); }
.timer-fill.is-low { background: var(--red); }
.draw-time { flex: none; min-width: 2.6em; text-align: right; font-family: var(--font-marker); font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.draw-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
.score-breakdown { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 10px 0 0; font-size: .92rem; }
.score-breakdown dt { color: var(--pencil); }
.score-breakdown dd { margin: 0; font-weight: 800; text-align: right; }

/* =========================================================================
   Trusty Snake
   ========================================================================= */
.snake-stage { --ar: 1; --stage-room: 24px; max-width: 680px; }
@media (pointer: coarse) {
  .snake-stage { --stage-room: 190px; }
}
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
}
.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 14px 4px 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: .92rem;
}
.segmented button img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.segmented.compact button { justify-content: center; min-width: 38px; padding: 4px 12px; }
.segmented button:disabled { opacity: .35; cursor: not-allowed; }

/* =========================================================================
   Trusty Fever
   ========================================================================= */
.fever-stage { --ar: 1.4533; --stage-room: 24px; }
@media (pointer: coarse) {
  .fever-stage { --stage-room: 110px; }
}
/* The computers play behind the start screen, so let them show through. */
.fever-stage #overlay-start { background: rgba(251, 248, 240, .78); }
/* Holding a side must never turn into a scroll, or the browser cancels the press mid-turn. */
.fever-pad { align-items: center; gap: 12px; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.fever-pad .fever-steer { width: 112px; }
.fever-pad .pad-word { width: auto; padding: 0 16px; font-size: .9rem; }

.fever-target { font-family: var(--font-hand); font-weight: 700; font-size: 1.25rem; color: var(--red); }
.fever-scores { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.fever-scores li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border: 1.5px dashed var(--grid-strong);
  border-radius: 10px;
  background: var(--paper);
  transition: opacity .2s;
}
.fever-scores li.is-leader { border: 1.5px solid var(--ink); background: var(--note-yellow); }
.fever-scores li.is-out { opacity: .5; }
.fever-swatch { flex: none; width: 16px; height: 16px; border: 2px solid var(--ink); border-radius: 50%; }
.fever-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.fever-who small { font-size: .78rem; font-weight: 600; color: var(--pencil); }
.fever-pts { font-family: var(--font-marker); font-size: 1.4rem; line-height: 1; font-variant-numeric: tabular-nums; }

.fever-setup { display: grid; gap: 14px; }
.setup-row { display: grid; justify-items: start; gap: 6px; }
.setup-label { font-weight: 700; font-size: .9rem; }

.panel .fever-legend-title { margin: 18px 0 0; font-size: 1rem; }
.fever-legend-title + .side-note { margin-top: 4px; }
.fever-legend { display: grid; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.fever-legend li { display: flex; align-items: center; gap: 10px; font-size: .92rem; line-height: 1.35; }
.fever-legend canvas { flex: none; width: 30px; height: 30px; }

.fever-final {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
  max-width: 36em;
  margin: 0;
  padding: 0;
  list-style: none;
  font-weight: 700;
  font-size: clamp(.8rem, 2.4cqi, 1rem);
}
.fever-final li { display: inline-flex; align-items: center; gap: 6px; }
.fever-final .fever-swatch { width: 12px; height: 12px; border-width: 1.5px; }

/* =========================================================================
   Trustis
   ========================================================================= */
.tetris {
  --side: 124px;
  --gap: 14px;
  --pad-room: 0px;
  --top-room: 0px;
  --board-w: min(420px, calc((100svh - 36px - var(--pad-room) - var(--top-room)) * .4545), calc(100% - 2 * var(--side) - 2 * var(--gap)));
  display: grid;
  grid-template-columns: var(--side) var(--board-w) var(--side);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "hold  board next"
    "stats board next";
  justify-content: center;
  align-items: start;
  gap: var(--gap);
}
.tetris-stage {
  --ar: .4545;
  grid-area: board;
  width: 100%;
  min-width: 0;
  max-width: none;
  margin: 0;
}
.tetris-hold { grid-area: hold; }
.tetris-next { grid-area: next; }
.tetris-stats { grid-area: stats; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tetris-box, .tetris-stats .stat {
  min-width: 0;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  box-shadow: 2px 2px 0 var(--ink);
}
.tetris-stats .stat-value { font-size: 1.3rem; }
.tetris-stats .stat-value.is-long { font-size: 1rem; }
.tetris-box canvas { display: block; width: 100%; margin-top: 6px; }
.hold-canvas { aspect-ratio: 100 / 60; }
.next-canvas { aspect-ratio: 100 / 280; }

/* Line clear call-outs ("Tetris!", "T-Spin Double", "+1,200") */
.action-text {
  position: absolute;
  inset: 24% 6px auto;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  pointer-events: none;
}
.action-text span { display: block; animation: action-pop 1.8s var(--ease-out) forwards; }
.action-text .big {
  font-family: var(--font-marker);
  font-size: clamp(1.1rem, 9cqi, 2.1rem);
  line-height: 1.1;
  color: var(--ink);
  text-shadow: 0 0 3px #fff, 0 0 8px #fff, 0 0 14px #fff;
}
.action-text .small {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(1rem, 7cqi, 1.6rem);
  line-height: 1;
  color: var(--red);
  text-shadow: 0 0 3px #fff, 0 0 8px #fff;
}
@keyframes action-pop {
  0% { opacity: 0; transform: scale(.7); }
  10% { opacity: 1; transform: scale(1.08); }
  18% { transform: scale(1); }
  70% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-12px); }
}
@keyframes action-fade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .action-text span { animation-name: action-fade; }
}

.level-pick { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: clamp(.85rem, 3cqi, 1rem); }
.level-pick select {
  min-height: 36px;
  padding: 2px 8px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
}
.level-pick select:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.scoring-table { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; margin: 0; }
.scoring-table dt { font-weight: 600; }
.scoring-table dd { margin: 0; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }

/* Touch controls: move/drop on the left thumb, rotate/hold on the right */
.tetris-pad { justify-content: space-between; align-items: flex-end; gap: 12px; max-width: 460px; margin: 12px auto 0; }
.pad-cluster { display: grid; gap: 8px; }
.pad-move { grid-template-columns: repeat(3, 54px); grid-template-areas: ". drop ." "left soft right"; }
.pad-turn { grid-template-columns: repeat(2, 54px); grid-template-areas: "pause hold" "ccw cw"; }
.tetris-pad .pad-btn { width: 54px; height: 54px; font-size: 1.3rem; }
.tetris-pad .pad-word { font-size: .8rem; }
.tetris-pad [data-act="drop"] { grid-area: drop; }
.tetris-pad [data-act="left"] { grid-area: left; }
.tetris-pad [data-act="soft"] { grid-area: soft; }
.tetris-pad [data-act="right"] { grid-area: right; }
.tetris-pad [data-act="pause"] { grid-area: pause; }
.tetris-pad [data-act="hold"] { grid-area: hold; }
.tetris-pad [data-act="ccw"] { grid-area: ccw; }
.tetris-pad [data-act="cw"] { grid-area: cw; }

@media (pointer: coarse) {
  .tetris { --pad-room: 136px; }
}
@media (max-width: 560px) {
  .tetris {
    --side: 52px;
    --gap: 8px;
    --top-room: 58px;
    grid-template-rows: auto auto;
    grid-template-areas:
      "stats stats stats"
      "hold  board next";
  }
  .tetris-stats { display: grid; grid-template-columns: 1.5fr .8fr 1fr 1.5fr; gap: 6px; }
  .tetris-box, .tetris-stats .stat { padding: 4px 5px; border-radius: 8px; box-shadow: 1px 1px 0 var(--ink); text-align: center; }
  .tetris-box .stat-label, .tetris-stats .stat-label { font-size: .58rem; letter-spacing: .04em; }
  .tetris-stats .stat-value { font-size: 1.1rem; }
  .tetris-stats .stat-value.is-long { font-size: .9rem; }
  .tetris-box canvas { margin-top: 3px; }
}
/* Phones held sideways: the pad goes either side of the board */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  .tetris-main { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; }
  .tetris-main > .tetris { grid-column: 2; grid-row: 1; --side: 96px; --gap: 8px; --board-w: calc((100svh - 36px) * .4545); }
  .tetris-stats { gap: 6px; }
  .tetris-box, .tetris-stats .stat { padding: 4px 8px; box-shadow: 1px 1px 0 var(--ink); }
  .tetris-box .stat-label, .tetris-stats .stat-label { font-size: .6rem; }
  .tetris-stats .stat-value { font-size: 1.05rem; }
  .tetris-stats .stat-value.is-long { font-size: .85rem; }
  .tetris-box canvas { margin-top: 3px; }
  .tetris-pad { display: contents; }
  .pad-move { grid-column: 1; grid-row: 1; justify-self: center; }
  .pad-turn { grid-column: 3; grid-row: 1; justify-self: center; }
}

/* =========================================================================
   Blackjack
   ========================================================================= */
.casino {
  position: relative;
  padding: clamp(18px, 3vw, 32px);
  border: 2px solid var(--ink);
  border-radius: 28px 22px 30px 24px / 24px 30px 22px 28px;
  box-shadow: var(--shadow-ink-lg);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, .14), transparent 60%),
    #1f6b43;
  color: #fff;
}
.casino::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px dashed rgba(255, 255, 255, .25);
  border-radius: 22px 16px 24px 18px / 18px 24px 16px 22px;
  pointer-events: none;
}
.table-row { position: relative; z-index: 1; display: grid; gap: 10px; justify-items: center; }
.table-row + .table-row { margin-top: clamp(18px, 3vw, 28px); }
.hand-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--font-marker);
  font-weight: 400;
  font-size: 1.2rem;
  color: #fff;
}
.hand-value {
  min-width: 2.2em;
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .28);
  font-family: var(--font-body);
  font-size: .95rem;
  font-weight: 800;
  text-align: center;
}
.dealer-avatar { width: 64px; height: 50px; border-radius: 10px; background: #fff; padding: 4px; }
.cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 124px; }
.card-face {
  --suit: var(--ink);
  position: relative;
  width: 84px;
  height: 118px;
  padding: 6px 8px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--suit);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .25);
  font-family: var(--font-marker);
  animation: deal .35s var(--ease-out) backwards;
}
.card-face.red { --suit: var(--red); }
.card-corner { display: flex; flex-direction: column; align-items: center; width: fit-content; line-height: 1; font-size: 1.25rem; }
.card-corner span:last-child { font-size: 1rem; }
.card-corner.bottom { position: absolute; right: 8px; bottom: 6px; transform: rotate(180deg); }
.card-pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.4rem; pointer-events: none; }
.card-back {
  background:
    url("/images/mobile-icon.png") center / 46px no-repeat,
    repeating-linear-gradient(45deg, #fff 0 8px, #f2ecdd 8px 16px);
  background-blend-mode: multiply;
}
@keyframes deal { from { opacity: 0; transform: translateY(-24px) rotate(-6deg) scale(.9); } }
.casino-status {
  position: relative;
  z-index: 1;
  min-height: 2.2em;
  margin: clamp(16px, 3vw, 24px) 0 0;
  text-align: center;
  font-family: var(--font-marker);
  font-size: clamp(1.3rem, 3.5vw, 1.8rem);
  color: var(--highlight);
}
.casino-controls { display: grid; gap: 14px; }
.game-side .chips { gap: 6px; }
.game-side .chip-btn { width: 48px; height: 48px; font-size: .88rem; }
.game-side .chip-btn[data-amount="all"] { font-size: .66rem; }
.bankroll { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; }
.bankroll-amount { font-family: var(--font-marker); font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1; }
.bet-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 3px dashed #fff;
  border-radius: 50%;
  background: var(--chip, var(--red));
  box-shadow: 0 0 0 2px var(--ink), 2px 3px 0 2px var(--ink);
  color: #fff;
  font-family: var(--font-marker);
  font-size: .95rem;
  touch-action: manipulation;
}
.chip-btn:active { transform: translateY(2px); }
.chip-btn:disabled { opacity: .4; cursor: not-allowed; }
.chip-btn[data-amount="5"] { --chip: #d6334b; }
.chip-btn[data-amount="10"] { --chip: #1f4fbf; }
.chip-btn[data-amount="25"] { --chip: #23824a; }
.chip-btn[data-amount="50"] { --chip: #1b1b1f; }
.chip-btn[data-amount="all"] { --chip: #b58900; font-size: .72rem; }
.bet-input { width: 7.5em; }
.action-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.action-row #deal-btn { grid-column: 1 / -1; }
/* Phones and tablets, where the controls sit under the table: what you can do right now comes first, right under
   the cards (Deal between rounds, Hit/Stand/Double/Split during one), and controls you can't use yet are hidden,
   so the table and your buttons fit on one screen. render() sets data-phase. */
@media (max-width: 960px) {
  .casino-controls .insurance { order: -2; }
  .casino-controls .action-row { order: -1; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .casino-controls .action-row .btn { padding-inline: .3em; }
  .casino-controls[data-phase="bet"] .action-row > :not(#deal-btn),
  .casino-controls[data-phase="play"] #deal-btn,
  .casino-controls:not([data-phase="bet"]) #bet-row,
  .casino-controls[data-phase="insurance"] .action-row { display: none; }
}

/* Player hands: one normally, up to four after splitting */
.hands { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 18px; }
.hand { display: grid; justify-items: center; gap: 8px; padding: 8px; border: 2px dashed transparent; border-radius: 14px; }
.hand.is-active { border-color: var(--highlight); background: rgba(255, 255, 255, .08); }
.hand-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; min-height: 1.6em; }
.hand-meta .hand-value:empty { display: none; }
.hand-bet { font-weight: 800; font-size: .88rem; color: rgba(255, 255, 255, .85); }
.hand-result { padding: 1px 10px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; color: var(--ink); font-weight: 800; font-size: .85rem; }
.hand-result.win, .hand-result.blackjack { background: var(--highlight); }
.hand-result.lose, .hand-result.bust { background: var(--red); color: #fff; }
.hands.is-split .cards { flex-wrap: nowrap; gap: 0; }
.hands.is-split .card-face + .card-face { margin-left: -46px; }
@media (max-width: 560px) {
  .hands.is-split .card-face + .card-face { margin-left: -38px; }
}

.insurance { display: grid; gap: 10px; padding: 12px 14px; border: 2px solid var(--ink); border-radius: 12px; background: var(--note-yellow); box-shadow: 3px 3px 0 var(--ink); }
.insurance[hidden] { display: none; }
.insurance p { margin: 0; font-weight: 700; }
.insurance .btn-row { gap: 8px; }
@media (max-width: 560px) {
  .card-face { width: 64px; height: 92px; padding: 4px 6px; }
  .card-pip { font-size: 1.8rem; }
  .card-corner { font-size: 1.05rem; }
  .cards { min-height: 96px; gap: 8px; }
  .chip-btn { width: 48px; height: 48px; }
  /* A shorter table, so the cards and the buttons under it fit on a phone screen together */
  .casino { padding: 12px 10px; }
  .casino::after { inset: 6px; }
  .table-row { gap: 6px; }
  .table-row + .table-row { margin-top: 6px; }
  .hand-label { gap: 8px; font-size: 1rem; }
  .dealer-avatar { width: 40px; height: 31px; padding: 2px; border-radius: 7px; }
  .casino-status { min-height: 2.4em; margin-top: 8px; font-size: 1.15rem; line-height: 1.2; }
  .hand { gap: 6px; padding: 4px; }
  .hands { gap: 8px 10px; }
  /* A split hand is only as wide as its cards (its total, bet and result wrap under them), so two fit side by side */
  .hands.is-split .hand-meta { width: 0; min-width: 100%; }
  /* Long hands overlap instead of wrapping onto a second row, so the table doesn't grow mid-round */
  .cards { flex-wrap: nowrap; }
  .cards:has(> :nth-child(5)) .card-face + .card-face { margin-left: -28px; }
  .cards:has(> :nth-child(7)) .card-face + .card-face { margin-left: -46px; }
  .hands.is-split .card-face + .card-face { margin-left: -38px; }
}

/* =========================================================================
   Trustle
   ========================================================================= */
.trustle {
  --tile-gap: 6px;
  width: 100%;
  max-width: 540px;
  margin-inline: auto;
  container-type: inline-size;
}

/* Trusty's face and what he says */
.trustle-talk { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.trustle-face { flex: none; width: 60px; height: 60px; transform-origin: 50% 90%; transition: transform .4s var(--ease-out); }
.trustle-face.is-happy { animation: trustle-hop .5s var(--ease-out) 3; }
.trustle-face.is-shaking { animation: trustle-no .4s ease-in-out; }
.trustle-face.is-sad { transform: rotate(-14deg) translateY(4px); }
@keyframes trustle-hop { 40% { transform: translateY(-14px) rotate(-6deg); } }
@keyframes trustle-no { 20%, 60% { transform: rotate(-10deg); } 40%, 80% { transform: rotate(10deg); } }
.trustle-speech { margin: 0; line-height: 1.35; }

.trustle-meta { margin: 12px 0; }

/* The board: tiles shrink to fit long words and short screens. svh, not dvh: on phones dvh changes every time
   the browser's toolbar hides or shows, so the board would grow and shrink while you scroll. */
.trustle-board {
  --tile: min(62px, (100cqi - (var(--len, 5) - 1) * var(--tile-gap)) / var(--len, 5), max(40px, (100svh - 380px) / 6.6));
  display: grid;
  justify-content: center;
  gap: var(--tile-gap);
}
.trustle-row { display: grid; grid-template-columns: repeat(var(--len, 5), var(--tile)); gap: var(--tile-gap); }
.trustle-row.is-shaking { animation: trustle-shake .45s ease-in-out; }

.trustle-tile {
  --tile-bg: #fff;
  --tile-fg: var(--ink);
  --tile-line: var(--ink);
  position: relative;
  display: grid;
  place-items: center;
  width: var(--tile);
  height: var(--tile);
  border: 2px solid var(--grid-strong);
  border-radius: 7px 5px 8px 6px / 6px 8px 5px 7px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-marker);
  font-size: calc(var(--tile) * .54);
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}
.trustle-tile[data-filled] { border-color: var(--ink); animation: tile-pop .12s ease-out; }
.trustle-tile[data-state] { background: var(--tile-bg); color: var(--tile-fg); border-color: var(--tile-line); animation: none; }
.trustle-tile[data-state="correct"] { --tile-bg: var(--green); --tile-fg: #fff; }
.trustle-tile[data-state="present"] { --tile-bg: var(--highlight); }
.trustle-tile[data-state="absent"] { --tile-bg: #d5d8dd; --tile-fg: var(--pencil); --tile-line: #aeb2b9; }
.trustle-tile.is-flipping { animation: tile-flip .48s ease-in-out var(--delay, 0s) both; }
.trustle-tile.is-bouncing { animation: tile-bounce .6s ease-in-out calc(var(--i, 0) * 90ms) both; }
@keyframes tile-pop { 50% { transform: scale(1.1); } }
/* Turns over, and shows its colour once it's edge-on */
@keyframes tile-flip {
  0% { transform: rotateX(0); background: #fff; color: var(--ink); border-color: var(--ink); }
  49.9% { background: #fff; color: var(--ink); border-color: var(--ink); }
  50% { transform: rotateX(90deg); background: var(--tile-bg); color: var(--tile-fg); border-color: var(--tile-line); }
  100% { transform: rotateX(0); background: var(--tile-bg); color: var(--tile-fg); border-color: var(--tile-line); }
}
@keyframes tile-bounce {
  0%, 100% { transform: none; }
  35% { transform: translateY(-28%); }
  60% { transform: translateY(6%); }
  80% { transform: translateY(-3%); }
}
@keyframes trustle-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* On-screen keyboard */
.trustle-keys { display: grid; gap: 8px; margin-top: 18px; user-select: none; -webkit-user-select: none; }
.trustle-key-row { display: flex; justify-content: center; gap: 6px; }
.trustle-key {
  display: grid;
  place-items: center;
  flex: 1 1 0;
  min-width: 0;
  max-width: 46px;
  height: 54px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 9px 6px 10px 7px / 7px 10px 6px 9px;
  background: #fff;
  color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  font: 800 1.05rem/1 var(--font-body);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s, transform .08s;
}
.trustle-key:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.trustle-key-wide { flex-grow: 1.6; max-width: 74px; font-size: .72rem; letter-spacing: .03em; text-transform: uppercase; }
.trustle-key .icon { width: 24px; height: 24px; }
.trustle-key-spacer { flex: .5 1 0; max-width: 23px; }
.trustle-key[data-state="correct"] { background: var(--green); color: #fff; }
.trustle-key[data-state="present"] { background: var(--highlight); }
.trustle-key[data-state="absent"] { background: #d5d8dd; color: var(--pencil); border-color: #9ea2a9; box-shadow: 2px 2px 0 #9ea2a9; }
@media (hover: hover) {
  .trustle-key:not([data-state]):hover { background: var(--paper-deep); }
}
@media (max-width: 420px) {
  .trustle-keys { gap: 7px; }
  .trustle-key-row { gap: 4px; }
  .trustle-key { height: 52px; font-size: 1rem; }
  .trustle-key-wide { font-size: .6rem; letter-spacing: 0; }
}

/* After the game */
.trustle-result { margin-top: 20px; text-align: center; transform: rotate(-.8deg); }
.trustle-result h2 { font-size: 2rem; }
.trustle-result-label { margin: 0; font-size: .74rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--pencil); }
.trustle-answer { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: 6px 0 12px; }
.trustle-answer span {
  display: grid;
  place-items: center;
  width: 1.9em;
  height: 1.9em;
  border: 2px solid var(--ink);
  border-radius: 7px 5px 8px 6px / 6px 8px 5px 7px;
  background: var(--green);
  color: #fff;
  font-family: var(--font-marker);
  font-size: clamp(1rem, 5cqi, 1.5rem);
  line-height: 1;
}
.trustle-result-actions { justify-content: center; margin: 16px 0 12px; }
.trustle-next { margin: 0; font-weight: 650; color: var(--ink-soft); }
.trustle-next strong { font-family: var(--font-marker); font-weight: 400; font-size: 1.2rem; font-variant-numeric: tabular-nums; }

/* Side panels */
.panel > .trustle-dist-title { margin: 18px 0 8px; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--pencil); }
.trustle-dist { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.trustle-dist li { display: grid; grid-template-columns: 1em minmax(0, 1fr); align-items: center; gap: 8px; font-weight: 800; font-size: .88rem; }
.trustle-dist-bar {
  width: max(1.9em, var(--w, 0%));
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--pencil-light);
  color: #fff;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.trustle-dist .is-today .trustle-dist-bar { background: var(--green); }
/* How everyone else did (a dialog from the result note) */
.trustle-everyone-lead { margin: 0 0 14px; font-family: var(--font-hand); font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.trustle-everyone .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.trustle-everyone .trustle-dist-title { margin: 18px 0 8px; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--pencil); }
.trustle-everyone .trustle-dist li { grid-template-columns: 1em minmax(0, 1fr) 3em; }
.trustle-you { font-family: var(--font-hand); font-size: 1.15rem; font-weight: 700; line-height: 1; white-space: nowrap; }
.trustle-how-lead { margin: 0 0 12px; }
.trustle-how { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.trustle-how li { display: flex; align-items: center; gap: 10px; font-size: .95rem; line-height: 1.35; }
.trustle-how .trustle-tile { --tile: 34px; flex: none; }

/* =========================================================================
   Arcade (externally hosted games)
   ========================================================================= */
.arcade-stage { --ar: 1.6; --stage-room: 24px; touch-action: auto; background: #111; }
.arcade-stage.ar-4-3 { --ar: 1.3333; }
.arcade-stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #000; }
.arcade-facade {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #111;
}
.arcade-facade img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .45; filter: blur(2px) saturate(.9); }
.arcade-facade-inner { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; color: #fff; }
.arcade-facade-inner p { margin: 0; max-width: 36ch; font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.arcade-notes { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; margin-top: 14px; font-size: .9rem; color: var(--pencil); }
