/* bChess — navy base with the gold/orange of the logo as accents (the same
   navy-with-accents approach as Benny and Sh!thead). Board colours are CSS
   variables so themes can swap them later. Single stylesheet. */

:root {
  --bg-1: #0a1a3a;
  --bg-2: #122a57;
  --bg-3: #061127;
  --felt: radial-gradient(ellipse at 50% 0%, #1b3d7a 0%, #0f2452 45%, #061127 100%);
  --panel: rgba(255, 255, 255, 0.07);
  --panel-2: rgba(255, 255, 255, 0.12);
  --ink: #f6f3ea;
  --ink-dim: #b4bdd1;
  --accent: #ffc83d;
  --accent-deep: #f08a24;
  --accent-soft: rgba(255, 200, 61, 0.22);
  --gold: #ffd23f;
  --danger: #ff5d6c;
  --good: #46d39a;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  /* board theme */
  --sq-light: #eeeed2;
  --sq-dark: #769656;
  --sq-last: rgba(255, 221, 0, 0.45);
  --sq-selected: rgba(255, 200, 61, 0.65);
  --sq-hint: rgba(79, 195, 247, 0.6);
  --sq-check: radial-gradient(circle, rgba(255, 60, 60, 0.9) 0%, rgba(255, 60, 60, 0.5) 55%, transparent 75%);
  --pm-mine: rgba(79, 195, 247, 0.55);
  --pm-theirs: rgba(255, 99, 99, 0.55);
  --pm-both: rgba(176, 120, 255, 0.6);
  --coord-light: #779556;
  --coord-dark: #ebecd0;
  --board-texture: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, .btn, .seg button, .swatch, .icon-btn, .link, .trophy-btn, .saved-card { touch-action: manipulation; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--felt);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}
button { font: inherit; }

/* ---------------- screens ---------------- */
.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }
#screen-play, #screen-explore { min-height: 0; }
#screen-play.active { height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; overflow: hidden; }

/* ---------------- buttons ---------------- */
.btn {
  appearance: none; -webkit-appearance: none; border: 0; cursor: pointer;
  background: var(--panel-2); color: var(--ink);
  font-size: 1rem; font-weight: 650; padding: 12px 18px;
  border-radius: 999px; transition: transform .12s ease, filter .12s ease, opacity .12s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); color: #2a1600; box-shadow: 0 6px 18px rgba(240, 138, 36, 0.35); }
.btn.big { font-size: 1.1rem; padding: 15px 24px; width: 100%; }
.btn.small { font-size: .9rem; padding: 9px 14px; }
.btn.ghost { background: transparent; border: 1px solid var(--panel-2); }
.btn.danger { background: rgba(255, 93, 108, 0.2); color: #ffb3bb; }
.link { appearance: none; background: none; border: 0; color: var(--ink-dim); text-decoration: underline; cursor: pointer; font-size: .95rem; padding: 6px 8px; }
.link:hover { color: var(--ink); }
.danger-link { color: #ffb3bb; }
.icon-btn { appearance: none; background: var(--panel); border: 0; color: var(--ink); width: 40px; height: 40px; border-radius: 12px; font-size: 1.2rem; cursor: pointer; display: grid; place-items: center; }
.muted { color: var(--ink-dim); }
small.muted { display: block; margin-top: 4px; font-size: .8rem; }

/* ---------------- start screen ---------------- */
.start-wrap { width: 100%; max-width: 520px; margin: 0 auto; padding: calc(24px + env(safe-area-inset-top, 0px)) 18px calc(40px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 18px; align-items: stretch; }
.hero-logo { width: min(300px, 68%); margin: 6px auto 0; display: block; filter: drop-shadow(0 12px 28px rgba(0, 0, 0, .45)); }
.home-section { display: flex; flex-direction: column; gap: 10px; }
.section-title { margin: 0; font-size: .85rem; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-dim); }
.setup-card { background: var(--panel); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.player-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.player-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.player-label { font-size: .78rem; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .08em; }
.player-name { appearance: none; background: none; border: 0; color: var(--ink); font-size: 1.35rem; font-weight: 750; text-align: left; padding: 0; cursor: pointer; text-decoration: underline dotted var(--ink-dim); text-underline-offset: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rung-badge { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 84px; padding: 8px 12px; border-radius: 14px; background: linear-gradient(135deg, var(--accent), var(--accent-deep)); color: #2a1600; box-shadow: 0 6px 18px rgba(240, 138, 36, 0.35); }
.rung-num { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.rung-num::before { content: "Rung "; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; display: block; opacity: .75; margin-bottom: 2px; }
.rung-tier { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.rung-help { margin: 0; color: var(--ink-dim); font-size: .9rem; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .85rem; color: var(--ink-dim); }
.field.stacked { gap: 8px; }
.seg { display: flex; background: var(--bg-3); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; appearance: none; -webkit-appearance: none; border: 0; background: transparent; color: var(--ink-dim); padding: 9px 6px; border-radius: 9px; cursor: pointer; font-weight: 650; font-size: .95rem; }
.seg button.on { background: var(--panel-2); color: var(--ink); }
.house-rules { background: var(--bg-3); border-radius: 12px; padding: 10px 14px; }
.house-rules summary { cursor: pointer; font-weight: 650; color: var(--ink-dim); }
.house-rules[open] summary { margin-bottom: 8px; }
.toggle { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; cursor: pointer; font-size: .95rem; line-height: 1.35; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin-top: 1px; }
.start-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 8px; }
.app-version { color: var(--ink-dim); opacity: .7; font-size: 12px; margin: 2px 0 0; text-align: center; }
.app-version.stale { color: var(--danger); opacity: .95; }
.tagline { text-align: center; color: var(--ink-dim); margin: 0; font-style: italic; }
#install-btn[hidden] { display: none; }

.trophy-btn { display: flex; align-items: center; gap: 12px; width: 100%; appearance: none; border: 0; cursor: pointer; padding: 14px 16px; border-radius: var(--radius); background: linear-gradient(135deg, rgba(255, 210, 63, .22), rgba(240, 138, 36, .18)); color: var(--ink); text-align: left; box-shadow: var(--shadow); }
.trophy-btn-icon { font-size: 1.4rem; }
.trophy-btn-text { flex: 1; font-weight: 700; }
.trophy-btn-count { background: var(--gold); color: #2a1600; font-weight: 800; font-size: .8rem; padding: 3px 9px; border-radius: 999px; }
.trophy-btn-count[hidden] { display: none; }
.trophy-btn-chev { color: var(--ink-dim); font-size: 1.4rem; }

.saved-card { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; column-gap: 10px; appearance: none; border: 0; cursor: pointer; text-align: left; width: 100%; padding: 14px 16px; border-radius: var(--radius); background: var(--panel-2); color: var(--ink); box-shadow: var(--shadow); }
.saved-main { font-weight: 750; font-size: 1.05rem; }
.saved-sub { color: var(--ink-dim); font-size: .88rem; grid-column: 1; }
.saved-chev { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 1.5rem; color: var(--ink-dim); }
#saved-section .danger-link { align-self: center; }

/* ---------------- play screen ---------------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 8px; flex: none; }
.turn-pill { background: var(--panel-2); padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: .95rem; white-space: nowrap; transition: background .2s; }
.turn-pill.thinking { background: rgba(79, 195, 247, .22); }
.turn-pill.check { background: rgba(255, 93, 108, .3); }
.turn-pill.over { background: var(--accent-soft); }
.play-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 10px calc(10px + env(safe-area-inset-bottom, 0px)); width: 100%; max-width: 560px; margin: 0 auto; }
.seat { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; width: 100%; padding: 4px 6px; }
.seat-avatar { grid-row: 1 / span 2; font-size: 1.5rem; width: 38px; height: 38px; display: grid; place-items: center; background: var(--panel); border-radius: 10px; }
.seat-name { font-weight: 750; line-height: 1.15; }
.seat-sub { color: var(--ink-dim); font-size: .82rem; line-height: 1.15; }
.seat.active .seat-avatar { box-shadow: 0 0 0 2px var(--accent); }
.board-frame { width: 100%; flex: none; }

.board { position: relative; width: 100%; height: 0; padding-bottom: 100%; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow); background-color: var(--sq-dark); background-image: var(--board-texture); background-size: cover; background-position: center; }
.board-squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::after, .sq.selected::after, .sq.hint::after, .sq.check::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.sq.last::after { background: var(--sq-last); }
.sq.hint::after { background: var(--sq-hint); }
.sq.selected::after { background: var(--sq-selected); }
.sq.check::after { background: var(--sq-check); }
.sq.pm-mine::after, .sq.pm-theirs::after, .sq.pm-both::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 3px var(--pm-colour); background: var(--pm-fill); }
.sq.pm-mine { --pm-colour: var(--pm-mine); --pm-fill: rgba(79, 195, 247, 0.18); }
.sq.pm-theirs { --pm-colour: var(--pm-theirs); --pm-fill: rgba(255, 99, 99, 0.18); }
.sq.pm-both { --pm-colour: var(--pm-both); --pm-fill: rgba(176, 120, 255, 0.22); }
.sq.last.pm-mine::after, .sq.last.pm-theirs::after, .sq.last.pm-both::after { background: var(--sq-last); }
.pm-legend { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; font-size: .78rem; color: var(--ink-dim); width: 100%; }
.pm-legend[hidden] { display: none; }
.pm-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.pm-legend .m { background: var(--pm-mine); } .pm-legend .t { background: var(--pm-theirs); } .pm-legend .b { background: var(--pm-both); }
.sq.target::before { content: ""; position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(0, 0, 0, .18); z-index: 2; pointer-events: none; }
.sq.target.capture::before { width: 100%; height: 100%; background: transparent; border: 5px solid rgba(0, 0, 0, .18); border-radius: 50%; box-sizing: border-box; }
.sq.over::before { background: rgba(0, 0, 0, .3); }
.coord { position: absolute; font-size: clamp(8px, 1.9vmin, 12px); font-weight: 700; pointer-events: none; opacity: .9; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }
.sq.light .coord { color: var(--coord-light); }
.sq.dark .coord { color: var(--coord-dark); }
body.no-coords .coord { display: none; }
.board-pieces { position: absolute; inset: 0; pointer-events: none; }
.piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; -webkit-user-drag: none; -webkit-touch-callout: none; will-change: transform; transition: transform .18s ease; z-index: 3; pointer-events: none; }
.piece.no-anim, body.no-anim .piece { transition: none; }
.piece.dragging { z-index: 5; transform-origin: center; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .4)); scale: 1.12; }
.piece.captured { opacity: 0; transition: opacity .18s ease; }
.board.locked { cursor: default; }
.board-promo { position: absolute; top: 0; left: calc(var(--col, 0) * 12.5%); width: 12.5%; display: flex; flex-direction: column; background: #fff; border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .5); z-index: 10; overflow: hidden; }
.board-promo.bottom { top: auto; bottom: 0; flex-direction: column-reverse; }
.board-promo[hidden] { display: none; }
.promo-choice, .promo-cancel { appearance: none; -webkit-appearance: none; border: 0; background: #fff; padding: 0; width: 100%; aspect-ratio: 1 / 1; cursor: pointer; display: grid; place-items: center; }
@supports not (aspect-ratio: 1 / 1) { .promo-choice { height: 44px; } .promo-cancel { height: 24px; } }
.promo-choice img { width: 90%; height: 90%; }
.promo-choice:hover { background: #ffe9a8; }
.promo-cancel { aspect-ratio: 2 / 1; color: #333; font-weight: 700; background: #eee; }
.promo-choice img { -webkit-user-drag: none; }

.moves { width: 100%; flex: 1; min-height: 44px; max-height: 120px; overflow-y: auto; background: var(--panel); border-radius: 12px; padding: 8px 12px; font-size: .92rem; line-height: 1.5; font-variant-numeric: tabular-nums; }
.moves .mv-num { color: var(--ink-dim); margin-right: 4px; }
.moves .mv { display: inline-block; padding: 0 5px; border-radius: 5px; margin-right: 2px; }
.moves .mv.current { background: var(--accent-soft); font-weight: 700; }
.moves .mv-pair { display: inline-block; margin-right: 8px; white-space: nowrap; }
.moves .empty { color: var(--ink-dim); font-style: italic; }
.action-bar { display: flex; gap: 8px; width: 100%; justify-content: center; flex-wrap: wrap; flex: none; }
/* Five equal columns so the row never wraps a lone button onto its own line
   at phone widths; labels shrink a little under 480px. */
.play-actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.play-actions .btn { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 6px; padding-right: 6px; }
@media (max-width: 480px) { .play-actions .btn { font-size: .82rem; padding: 10px 4px; } }
@media (max-width: 360px) { .play-actions .btn { font-size: .7rem; padding: 10px 2px; letter-spacing: -.01em; } }

/* ---------------- explore / opening book ---------------- */
.trophy-btn-sub { display: none; }
/* Every child is pinned to its cell: with auto-placement Safari put the
   chevron next to the icon and the title on the far right. */
.explore-btn { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 12px; row-gap: 2px; align-items: center; background: linear-gradient(135deg, rgba(79, 195, 247, .2), rgba(155, 123, 224, .18)); }
.explore-btn .trophy-btn-icon { grid-column: 1; grid-row: 1 / span 2; }
.explore-btn .trophy-btn-text { grid-column: 2; grid-row: 1; }
.explore-btn .trophy-btn-sub { display: block; grid-column: 2; grid-row: 2; color: var(--ink-dim); font-size: .82rem; }
.explore-btn .trophy-btn-chev { grid-column: 3; grid-row: 1 / span 2; }
.opening-line { width: 100%; display: flex; align-items: baseline; gap: 8px; padding: 2px 6px; min-height: 24px; }
.opening-eco { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; color: var(--accent); font-weight: 700; }
.opening-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explore-controls { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; flex: 1 1 180px; }
.field.inline .select { width: auto; flex: 1; padding: 8px 10px; }
.explore-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.explore-moves { flex: 1; max-height: none; min-height: 90px; padding: 6px 8px; }
.book-row { display: grid; grid-template-columns: 3.2rem 1fr auto; gap: 8px; align-items: center; padding: 6px 6px; border-radius: 8px; cursor: pointer; appearance: none; -webkit-appearance: none; border: 0; background: transparent; color: var(--ink); width: 100%; text-align: left; font: inherit; }
.book-row:hover { background: var(--panel-2); }
.book-row.flash { animation: book-flash .6s ease; }
@keyframes book-flash { 0% { background: rgba(255, 93, 108, .4); } 100% { background: transparent; } }
.book-san { font-weight: 750; font-size: 1rem; }
.book-bar { height: 16px; border-radius: 4px; overflow: hidden; display: flex; background: var(--bg-3); }
.book-bar i { display: block; height: 100%; }
.book-bar .w { background: #f4f1e6; }
.book-bar .d { background: #8d97a5; }
.book-bar .b { background: #2d3542; }
.book-bar .share { background: linear-gradient(90deg, var(--accent), var(--accent-deep)); }
.book-n { font-size: .8rem; color: var(--ink-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.book-meta { margin: 0; width: 100%; font-size: .78rem; color: var(--ink-dim); text-align: center; }
.book-empty { color: var(--ink-dim); font-style: italic; padding: 6px; }
.trainer { width: 100%; background: var(--panel); border-radius: 12px; padding: 10px 12px; }
.trainer[hidden] { display: none; }
.trainer-setup, .trainer-live { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.trainer-live[hidden], .trainer-setup[hidden] { display: none; }
.seg-inline { flex: 0 0 auto; padding: 3px; }
.seg-inline button { padding: 7px 14px; }
.trainer-status { font-weight: 700; flex: 1; }
.trainer-status.good { color: var(--good); }
.trainer-status.bad { color: var(--danger); }
.trainer-score { color: var(--ink-dim); font-size: .85rem; font-variant-numeric: tabular-nums; }
#screen-explore.active { height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; overflow: hidden; }
.explore-wrap { overflow-y: auto; }

/* ---------------- game over ---------------- */
.over-wrap { width: 100%; max-width: 480px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top, 0px)) 18px calc(40px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; flex: 1; justify-content: center; }
.over-icon { font-size: 3.4rem; }
.over-wrap h2 { margin: 0; font-size: 2rem; }
.over-reason { margin: 0; color: var(--ink-dim); font-size: 1.05rem; }
.rung-change { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-radius: 14px; background: var(--panel); font-weight: 700; font-size: 1.1rem; }
.rung-change .arrow { color: var(--ink-dim); }
.rung-change .up { color: var(--good); }
.rung-change .down { color: var(--danger); }
.rung-change .same { color: var(--ink-dim); }
.rung-change .note { font-weight: 500; color: var(--ink-dim); font-size: .85rem; }
.earned { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.earned h3 { margin: 8px 0 0; font-size: .85rem; text-transform: uppercase; letter-spacing: .12em; color: var(--gold); }
.over-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 12px; }

/* ---------------- achievements / stats ---------------- */
.achievement-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--panel); text-align: left; }
.achievement-card.is-locked { opacity: .5; filter: grayscale(.6); }
.achievement-icon { font-size: 1.5rem; width: 38px; text-align: center; flex: none; }
.achievement-info { flex: 1; min-width: 0; }
.achievement-name { font-weight: 750; }
.achievement-desc { color: var(--ink-dim); font-size: .85rem; }
.achievement-tier { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-dim); flex: none; }
.achievement-tier.rare { color: var(--gold); }
.achievement-tier.hard { color: #ff9f6b; }
.progress-bar { height: 6px; background: var(--bg-3); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress-bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-deep)); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 6px 0 12px; }
.stat { background: var(--panel); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { font-size: .78rem; color: var(--ink-dim); }
.stats-sub { margin: 14px 0 6px; font-size: .8rem; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-dim); }
.history { display: flex; flex-direction: column; gap: 6px; }
.history-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; background: var(--panel); border-radius: 10px; padding: 8px 10px; font-size: .9rem; }
.history-row .res { font-weight: 800; width: 24px; text-align: center; }
.history-row .res.win { color: var(--good); }
.history-row .res.loss { color: var(--danger); }
.history-row .res.draw { color: var(--ink-dim); }
.history-row .meta { color: var(--ink-dim); font-size: .8rem; }
.history-row .dl { appearance: none; border: 0; background: var(--panel-2); color: var(--ink); border-radius: 8px; padding: 5px 9px; cursor: pointer; font-size: .8rem; }
.history-row .dl:disabled { opacity: .3; cursor: default; }
.achievement-list { display: flex; flex-direction: column; gap: 6px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-row button { appearance: none; border: 0; background: var(--panel-2); color: var(--ink); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .9rem; }
.rung-setter { display: flex; align-items: center; gap: 12px; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.swatch { appearance: none; border: 2px solid transparent; background: var(--bg-3); color: var(--ink); border-radius: 12px; padding: 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .8rem; }
.swatch.on { border-color: var(--accent); }
.swatch-board { width: 56px; height: 56px; border-radius: 4px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; overflow: hidden; background-size: cover; }
.swatch-board i { display: block; }
.swatch-piece { width: 44px; height: 44px; background: linear-gradient(135deg, #eeeed2 50%, #769656 50%); border-radius: 6px; display: grid; place-items: center; }
.swatch-piece img { width: 38px; height: 38px; }
.custom-board { display: flex; flex-direction: column; gap: 10px; background: var(--bg-3); border-radius: 12px; padding: 12px; }
.custom-board .row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.custom-board label { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.custom-board input[type="color"] { width: 44px; height: 32px; border: 0; background: none; padding: 0; cursor: pointer; }
.custom-board input[type="file"] { display: none; }
.custom-board .btn.small { padding: 7px 12px; }
.rung-setter input[type="range"] { flex: 1; accent-color: var(--accent); }
.rung-setter-val { font-weight: 800; font-size: 1.2rem; min-width: 2ch; text-align: right; }

/* ---------------- modals ---------------- */
.modal { position: fixed; inset: 0; background: rgba(3, 8, 22, .72); display: flex; align-items: center; justify-content: center; padding: 18px; z-index: 50; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.modal-box { background: var(--bg-2); border-radius: 18px; padding: 22px; max-width: 460px; width: 100%; max-height: 86vh; max-height: 86dvh; overflow-y: auto; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.modal-box h2 { margin: 0 0 4px; }
.modal-box p { margin: 0; line-height: 1.5; }
.howto-body { display: flex; flex-direction: column; gap: 10px; color: var(--ink-dim); }
.howto-body b { color: var(--ink); }
.howto-body a { color: var(--accent); }
.select, .text-input, #welcome-name { width: 100%; appearance: none; -webkit-appearance: none; background: var(--bg-3); color: var(--ink); border: 1px solid var(--panel-2); border-radius: 10px; padding: 11px 12px; font-size: 16px; }
.feedback-textarea { resize: vertical; font-family: inherit; }
.hp-field { position: absolute; left: -9999px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }
.confirm-actions .btn { flex: 1; }
#welcome-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------------- toast / banner ---------------- */
.toast-host { position: fixed; bottom: 90px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 60; }
.toast { background: var(--bg-3); color: var(--ink); padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: .3s; font-weight: 600; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: none; }
.engine-banner { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 70; background: #3a1620; color: #ffd4d9; border: 1px solid var(--danger); border-radius: 12px; padding: 12px 14px; font-size: .92rem; line-height: 1.45; box-shadow: var(--shadow); }
.engine-banner[hidden] { display: none; }
.update-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; appearance: none; -webkit-appearance: none; margin: 0; width: 100%; border: 0; cursor: pointer; background: var(--accent-deep); color: #2a1600; font-weight: 700; padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px; text-align: center; }
.update-banner[hidden] { display: none; }
body.update-pending .screen.active { padding-top: calc(44px + env(safe-area-inset-top, 0px)); }

/* ---------------- responsive ---------------- */
@media (min-width: 700px) and (min-height: 700px) {
  .play-wrap { max-width: 640px; }
  /* Keep the whole play column (seats, moves, actions) on screen: the board
     gives way before anything below it does. */
  .board-frame { width: min(100%, calc(100dvh - 330px)); }
}
@media (max-height: 700px) {
  .moves { max-height: 70px; }
  .seat-avatar { width: 32px; height: 32px; font-size: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  .piece { transition: none; }
  .btn { transition: none; }
}
