:root {
  --ui-lift: min(96px, 10vh);
  --accent: #f0f0f0;
  --accent-dim: #1c1c1c;
  --accent-border: rgba(255,255,255,0.28);
  --bg: #000000;
  --surface: #080808;
  --surface-strong: #141414;
  --card-bg: #0a0a0a;
  --glass: #0c0c10;
  --border: rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.12);
  --text: #f0f0f0;
  --muted: #7a7a7a;
  --outline-full: #ffffff;
  --hazard: #ff5f7e;
  --hazard-dim: #35141c;
  --hazard-border: rgba(255,95,126,0.5);
  --charge: #b78cff;
  --charge-dim: #2d213a;
  --charge-border: rgba(183,140,255,0.5);
  --surge: #5ad9e8;
  --prize: #ffd166;
  --go: #5fe39b;
  --go-border: rgba(95,227,155,0.5);
  --flare: #ff8f5a;
  --flare-border: rgba(255,143,90,0.5);
  --font: 'Inter','Segoe UI',system-ui,sans-serif;
  --display: 'Fraunces',Georgia,serif;
  --mono: 'JetBrains Mono',ui-monospace,SFMono-Regular,Menlo,monospace;
  --game: 'Inter','Segoe UI',system-ui,sans-serif;
}

html.light {
  --accent: #111111;
  --accent-dim: #dddddd;
  --accent-border: rgba(0,0,0,0.26);
  --bg: #f2f2f2;
  --surface: #eaeaea;
  --surface-strong: #dddddd;
  --card-bg: #ffffff;
  --glass: #ffffff;
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.14);
  --text: #0a0a0a;
  --muted: #666;
  --outline-full: #111111;
  --hazard: #d0203c;
  --hazard-dim: #f7dce2;
  --hazard-border: rgba(208,32,60,0.45);
  --charge: #6b3fd0;
  --charge-dim: #ede6fa;
  --charge-border: rgba(107,63,208,0.45);
  --surge: #0f8ba4;
  --prize: #b7791f;
  --go: #12855a;
  --go-border: rgba(18,133,90,0.45);
  --flare: #c2570f;
  --flare-border: rgba(194,87,15,0.45);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-x: clip;
}

body::before { display: none; }

.bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: -2; pointer-events: none;
}
html.light .bg-grid {
  background-image:
    linear-gradient(rgba(0,0,0,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.04) 1px, transparent 1px);
}
.menu-bg {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .5s ease;
}
.menu-bg.show { opacity: 1; }

.screen { display: none; }
.screen.active { display: block; }

.shell {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: 88px 24px 64px;
}
.screen.active:not(#screen-game),
.screen.measuring:not(#screen-game) {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: var(--ui-lift);
}
.screen.measuring {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}
#screen-home .shell { max-width: 940px; width: 100%; padding: 32px 24px; }
#screen-home .title-block { margin-top: 6px; margin-bottom: 48px; }
#screen-home .title,
#screen-lobby .title,
#screen-result .title { font-size: clamp(3.9rem, 10.5vw, 6.9rem); }

.title-block { text-align: center; margin-bottom: 44px; }
.title {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: clamp(2.6rem, 7vw, 4.6rem);
  font-weight: 800;
  letter-spacing: -0.085em;
  line-height: 1;
  color: var(--text);
  text-transform: uppercase;
}
.tetris-t {
  --cell-gap: .06em;
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: var(--cell-gap);
  width: 1.2em;
  height: .78em;
  margin-right: .04em;
  flex: 0 0 auto;
  vertical-align: -.02em;
}
.title-word { display: inline-block; }
.title.intro .tetris-t i { animation: title-drop 560ms cubic-bezier(.2,.86,.28,1) both; }
.title.intro .tetris-t i:nth-child(1) { animation-delay: 40ms; }
.title.intro .tetris-t i:nth-child(2) { animation-delay: 130ms; }
.title.intro .tetris-t i:nth-child(3) { animation-delay: 220ms; }
.title.intro .tetris-t i:nth-child(4) { animation-delay: 310ms; }
.title.intro .title-word { animation: title-word-in 620ms cubic-bezier(.2,.86,.28,1) 260ms both; }
@keyframes title-drop {
  0%   { opacity: 0; transform: translateY(-140%); }
  70%  { opacity: 1; transform: translateY(6%); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes title-word-in {
  0%   { opacity: 0; transform: translateY(-24%); letter-spacing: .04em; }
  100% { opacity: 1; transform: translateY(0); letter-spacing: inherit; }
}
@media (prefers-reduced-motion: reduce) {
  .title.intro .tetris-t i,
  .title.intro .title-word { animation: none; }
}
.tetris-t i { display: block; background: var(--accent); box-shadow: 0 0 10px rgba(255,255,255,.22); }
.tetris-t i:last-child { grid-column: 2; }
body.nav-focus :focus {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.subtitle {
  margin-top: 14px;
  color: var(--muted);
  font-size: .98rem;
  line-height: 1.65;
  max-width: 540px;
  margin-left: auto; margin-right: auto;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
#screen-home .panel-grid {
  grid-template-columns: repeat(2, minmax(0, 420px));
  justify-content: center;
  align-items: stretch;
  gap: 16px;
  width: 100%;
  margin: 0 auto;
}
@media (max-width: 920px) {
  .panel-grid,
  #screen-home .panel-grid { grid-template-columns: minmax(0, 420px); }
}
.home-left { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 24px;
}
.panel h2 {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--mono);
  font-size: 1.05rem; font-weight: 700;
  letter-spacing: -0.045em;
  color: var(--text);
  margin-bottom: 18px;
}
.panel h2 .icon { width: 17px; height: 17px; color: var(--muted); flex: 0 0 auto; }
.panel h3 {
  font-size: 1.02rem; font-weight: 700; letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field[hidden] { display: none; }
.field label {
  font-family: var(--mono);
  font-size: .82rem; font-weight: 600; letter-spacing: -0.03em;
  color: var(--text);
}
.field input[type="text"],
.field input[type="number"],
.field select {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-family: inherit;
  font-size: .92rem;
  padding: 11px 14px;
  outline: none;
  width: 100%;
  transition: border-color .2s, background .2s;
}
.field input:focus, .field select:focus {
  border-color: var(--accent-border);
  background: var(--surface-strong);
}
.field-hint { font-size: .74rem; color: var(--muted); line-height: 1.5; }


.avatar-build { display: flex; flex-direction: column; align-items: center; padding-top: 10px; }
.nametag {
  width: min(100%, 184px);
  margin-bottom: 9px;
  padding: 4px 10px 5px;
  background: #000;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 0;
  box-shadow: 2px 2px 0 rgba(0,0,0,.82);
}
.nametag input {
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #f0f0f0;
  font-family: var(--font);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .01em;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
  text-transform: none;
}
.nametag input::placeholder { color: #f0f0f0; opacity: .48; }
html.light .nametag { background: #000; border-color: rgba(255,255,255,.24); box-shadow: 2px 2px 0 rgba(0,0,0,.82); }
html.light .nametag input { color: #f0f0f0; }
html.light .nametag input::placeholder { color: #f0f0f0; }
.face-stack { position: relative; display: inline-flex; }

.swatches { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px;
  border-radius: 0;
  border: 2px solid transparent;
  background: none;
  cursor: pointer;
  padding: 3px;
  transition: transform .15s, border-color .2s;
}
.swatch span { display: block; width: 100%; height: 100%; border-radius: 0; }
.swatch:hover { transform: translateY(-2px); }
.swatch[aria-pressed="true"] { border-color: var(--text); }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--surface-strong); border-radius: 0; border: 1px solid var(--border); }
.seg button {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  appearance: none; border: none; background: none; cursor: pointer;
  font: inherit; font-size: .82rem; font-weight: 600;
  color: var(--muted);
  padding: 9px 14px; border-radius: 0;
  transition: color .2s, background .2s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { color: var(--bg); background: var(--text); }
.seg button .icon { width: 15px; height: 15px; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 18px; height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
  pointer-events: none;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font); font-weight: 700; font-size: .92rem;
  padding: 13px 26px; border-radius: 0;
  text-decoration: none; border: none; cursor: pointer;
  transition: opacity .2s, transform .2s, box-shadow .2s, background .2s, border-color .2s;
}
.btn-primary {
  background: var(--accent); color: #0a0a0a;
  box-shadow: 0 0 28px rgba(255,255,255,.24);
}
html.light .btn-primary { color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: .9; transform: translateY(-2px); box-shadow: 0 10px 40px rgba(255,255,255,.32); }
.btn-secondary {
  background: var(--surface-strong); color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-strong); transform: translateY(-2px); border-color: var(--border-strong); }
.btn[hidden] { display: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.is-busy { pointer-events: none; }
.btn.is-busy:disabled { opacity: .72; }
.btn.is-busy .icon { display: none; }
.btn.is-busy::before {
  content: "";
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  opacity: .85;
  animation: btn-spin 720ms linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
.btn-wide { width: 100%; }
.btn .icon { width: 17px; height: 17px; stroke-width: 2.1; opacity: .92; transition: transform .2s; }
.btn:hover:not(:disabled) .icon { transform: translateY(-1px); }
.btn-secondary .icon { color: var(--muted); }
.btn-secondary:hover:not(:disabled) .icon { color: var(--text); }

.notice {
  margin-top: 14px;
  font-size: .84rem; line-height: 1.55;
  color: var(--accent);
  min-height: 1.2em;
}
.notice:empty { display: none; }

.invite-row { display: flex; gap: 8px; align-items: stretch; }
.invite-row input {
  flex: 1;
  font-family: var(--mono); font-size: .82rem;
}
.join-section {
  margin-top: 21px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.create-panel .join-section { margin-top: auto; }
.create-panel .join-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 21px;
  font-family: var(--mono);
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: -0.035em;
}
.create-panel .join-heading .icon { width: 16px; height: 16px; color: var(--muted); }
.join-section .invite-row {
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  background: var(--surface-strong);
}
.join-section .invite-row input {
  min-width: 0;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: #fff;
}
.join-section .btn { padding: 10px 16px; border-color: transparent; }
.join-section .btn:hover:not(:disabled) { transform: none; }
.join-section .btn:hover:not(:disabled) .icon { transform: none; }
#openAchievementsBtn:hover:not(:disabled) { transform: none; }
#openAchievementsBtn:hover:not(:disabled) .icon { transform: none; }
.player-customizer {
  box-sizing: border-box;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  padding: 18px;
}
.customizer-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.customizer-heading h2 { margin-bottom: 0; }
.customizer-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
}
.home-topbar {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
}
.home-settings-btn { padding: 9px 16px; font-size: .82rem; }
.home-settings-btn .icon { width: 16px; height: 16px; }
@media (max-width: 620px) {
  .home-topbar { position: static; margin-bottom: 18px; }
}
.player-customizer .avatar-build { padding-top: 0; }
.player-customizer .field:last-child { margin-bottom: 0; }
.create-panel { box-sizing: border-box; display: flex; flex-direction: column; width: 100%; padding-bottom: 21px; }
.create-panel .field { margin-bottom: 18px; }
.create-panel .field-hint + .field-hint { margin-top: 2px; }

.lobby-players {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 18px;
  align-items: stretch;
  margin-bottom: 22px;
}
@media (max-width: 720px) { .lobby-players { grid-template-columns: 1fr; } }
.versus {
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font); font-size: 2.4rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); text-align: center;
}
@media (max-width: 720px) { .versus { font-size: 1.9rem; } }

.player-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 22px;
  text-align: center;
  position: relative;
}
.face-badge {
  width: 88px; height: 88px;
  margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  box-sizing: border-box;
  border-radius: 0;
  border: 2px solid var(--player-color, var(--accent));
  background: radial-gradient(circle, var(--surface-strong) 34%, color-mix(in srgb, var(--player-color, var(--accent)) 28%, var(--surface-strong)) 100%);
  font-family: var(--font);
  font-size: 1.5rem; font-weight: 700;
  letter-spacing: .02em;
  color: var(--text);
  position: relative;
  box-shadow: inset 0 0 22px color-mix(in srgb, var(--player-color, var(--accent)) 42%, transparent);
  transform: rotate(var(--face-rotation, 0deg));
  transition: transform .18s ease-out, border-color .2s, box-shadow .2s;
}
.face-badge.face-input {
  appearance: none;
  margin: 0;
  padding: 0 8px;
  font-family: var(--font);
  letter-spacing: 0;
  outline: none;
  text-align: center;
}
.face-badge.face-input:focus { box-shadow: 0 0 0 3px var(--accent-border), inset 0 0 22px color-mix(in srgb, var(--player-color, var(--accent)) 42%, transparent); }
.face-badge.small { width: 54px; height: 54px; font-size: 1rem; border-radius: 0; margin-bottom: 0; }
.rotate-btn {
  position: absolute;
  right: -9px; bottom: -9px;
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(0,0,0,.28);
  transition: transform .16s ease-out, background .2s;
}
.rotate-btn:hover { background: var(--accent); }
.rotate-btn:active { transform: scale(.96); }
.rotate-btn svg { width: 16px; height: 16px; }
.player-name { font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; }
.player-state { margin-top: 6px; font-size: .78rem; color: var(--muted); font-family: var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.player-state.ready { color: var(--accent); }

#screen-lobby .shell { max-width: 760px; }
#screen-lobby .player-state {
  margin-top: auto;
  padding-top: 16px;
  color: var(--hazard); font-weight: 700;
}
#screen-lobby .player-state.ready { color: var(--go); }
#screen-lobby .player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 22px 20px;
}
#screen-lobby .avatar-build { width: min(100%, 184px); padding-top: 0; }
#screen-lobby .nametag {
  box-sizing: border-box;
  display: flex; align-items: center;
  height: 30px;
  padding: 0 10px;
}
#screen-lobby .nametag input,
#screen-lobby .nametag .player-name { width: 100%; line-height: 1.2; }
#screen-lobby .face-badge { margin: 0; }
#screen-lobby .swatches { margin-top: 18px; }
#lobbyYouCard { border-color: var(--border-strong); }
#lobbyOpponentCard .nametag { opacity: .62; }
#lobbyOpponentCard .player-name {
  font-family: var(--font);
  font-size: .72rem; font-weight: 700;
  letter-spacing: .01em;
  color: #f0f0f0;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.lobby-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px 28px;
  width: 100%;
}
.lobby-cell { display: flex; flex-direction: column; min-width: 0; }
.lobby-cell h2 { margin-bottom: 14px; }
.lobby-cell .btn-wide,
.lobby-cell .invite-row { margin-top: auto; }
.lobby-countdown { text-align: center; margin-top: 20px; min-height: 1.5em; }
.lobby-notice { text-align: center; margin-top: 10px; }
.lobby-panel .invite-row {
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  background: var(--surface-strong);
}
.lobby-panel .invite-row input {
  min-width: 0;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--text);
}
.lobby-panel .invite-row .btn { padding: 10px 16px; border-color: transparent; }
@media (max-width: 720px) { .lobby-panel { grid-template-columns: 1fr; } }

.pause-overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: #000;
  z-index: 95;
  padding: 24px;
}
html.light .pause-overlay { background: #f2f2f2; }
.pause-overlay.show { display: flex; }
.pause-box {
  width: 100%; max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  padding: 28px;
  text-align: center;
}
.pause-box [hidden] { display: none; }
.pause-title {
  font-family: var(--game);
  font-size: 1.4rem; font-weight: 800;
  letter-spacing: -0.02em; text-transform: uppercase;
}
.pause-sub { margin-top: 8px; color: var(--muted); font-size: .82rem; }
.pause-votes {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px;
  margin: 22px 0;
}
.vote-chip {
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
  padding: 12px 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-strong);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: border-color .2s, background .2s;
}
.vote-who { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vote-state { color: var(--text); font-weight: 700; }
.vote-chip.ready { border-color: var(--go-border); background: color-mix(in srgb, var(--go) 12%, var(--card-bg)); }
.vote-chip.ready .vote-state { color: var(--go); }
.pause-count {
  font-family: var(--mono);
  font-size: 2.6rem; font-weight: 700;
  line-height: 1.1;
}
.pause-hint { margin-top: 14px; color: var(--muted); font-size: .74rem; line-height: 1.6; min-height: 1.6em; }

.crown[hidden] { display: none; }
.crown {
  position: absolute;
  top: -26px; left: 50%;
  width: 46px; height: 34px;
  transform: translateX(-52%) rotate(-15deg);
  color: var(--prize);
  filter: drop-shadow(0 4px 12px color-mix(in srgb, var(--prize) 45%, transparent));
}

#screen-game, #screen-result {
  --muted: #b4b4bb;
  --text: #e6e6ea;
  font-family: var(--game);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
html.light #screen-game, html.light #screen-result { --muted: #5b5b63; --text: #17171b; }
#screen-game .tile-label,
#screen-game .stat-key,
#screen-game .player-state,
#screen-result .breakdown-row span:first-child {
  font-family: var(--game);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
#screen-game .stat-value {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
#screen-game .player-name {
  font-family: var(--game);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
#screen-game .btn, #screen-result .btn {
  font-family: var(--game);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hold-btn { position: relative; overflow: hidden; }
.hold-btn .hold-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: color-mix(in srgb, var(--hazard) 85%, #ffffff);
  opacity: .55;
  pointer-events: none;
}
.hold-btn.holding { border-color: color-mix(in srgb, var(--hazard) 85%, #ffffff); }
.hold-btn .icon, .hold-btn .btn-label { position: relative; z-index: 1; }

.rejoin-panel {
  box-sizing: border-box;
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  width: min(480px, calc(100% - 32px));
  margin: 0;
  padding: 12px 14px;
}
.rejoin-panel[hidden] { display: none; }
.rejoin-panel h2 { margin-bottom: 0; font-size: .92rem; }
.rejoin-panel .invite-row { margin-left: auto; gap: 8px; }
.rejoin-panel .btn { flex: 0 0 auto; padding: 9px 14px; }
@media (max-width: 520px) {
  .rejoin-panel { flex-direction: column; align-items: stretch; gap: 10px; }
  .rejoin-panel .invite-row { margin-left: 0; }
  .rejoin-panel .btn { flex: 1 1 auto; justify-content: center; }
}

.btn-danger {
  background: color-mix(in srgb, var(--hazard) 50%, var(--surface-strong));
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid var(--hazard);
  color: #ffffff;
}
.btn-danger:hover { background: color-mix(in srgb, var(--hazard) 68%, var(--surface-strong)); border-color: var(--hazard); color: #ffffff; }
html.light .btn-danger { color: #ffffff; }

#screen-game.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.stage {
  display: grid;
  grid-template-columns: 150px minmax(240px, 420px) 118px 220px;
  gap: 18px;
  justify-content: center;
  align-items: start;
  padding: 20px;
  width: 100%;
}
@media (max-width: 1080px) {
  .stage { grid-template-columns: 132px minmax(200px, 330px) 104px; }
  .opponent-column { grid-column: 1 / -1; }
}

.column { display: flex; flex-direction: column; gap: 14px; }
.column.right { align-items: stretch; }

.tile {
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 12px;
}
.tile-label {
  font-size: .7rem; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.tile canvas { display: block; width: 100%; }
#holdCanvas { height: 62px; }
#queueCanvas { height: 235px; }
.queue-tile { padding: 9px; position: relative; overflow: hidden; }
.queue-column { gap: 10px; }
.hold-tile { position: relative; }
.hold-tile .keybind { right: 6px; bottom: 6px; top: auto; }

.stat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.stat-row + .stat-row { margin-top: 9px; }
.stat-key { font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-family: var(--mono); font-size: 1rem; font-weight: 700; }
.stat-value.big { font-size: 1.5rem; letter-spacing: -0.02em; }

.topbar { display: flex; align-items: stretch; gap: 10px; }
.score-bar {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--border);
  padding: 9px 14px;
}
.score-key {
  font-family: var(--game);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.score-value {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.roll-box {
  position: relative;
  width: 100%;
}
.roll-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.roll-caption {
  height: 38px;
  padding-top: 6px;
  text-align: center;
  overflow: hidden;
}
.roll-box .pocket,
.roulette-slot {
  position: relative;
  height: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px dashed var(--border-strong);
  border-radius: 0;
  transition: border-color .2s, box-shadow .2s, transform .18s cubic-bezier(.2,1.5,.4,1);
}
.roll-box .pocket { width: 100%; }
.roll-box .pocket.filled {
  border-style: solid;
  border-color: var(--outline-full);
  box-shadow: none;
}
.roll-box .pocket.ready {
  border-color: var(--hazard);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--hazard) 42%, transparent), 0 0 18px color-mix(in srgb, var(--hazard) 52%, transparent);
  animation: pocket-ready-pulse 1s ease-in-out infinite;
}
.roll-box.show .pocket { display: none; }
.roll-box.show .roll-caption { visibility: hidden; }
.roll-box .roulette-box { display: none; }
.roll-box.show .roulette-box { display: block; width: 100%; height: 100%; }

.keybind {
  position: absolute;
  right: 4px; top: 4px;
  min-width: 18px;
  padding: 1px 5px;
  background: #000;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .58rem;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: .04em;
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
}
html.light .keybind { background: #fff; }

.board-wrap {
  position: relative;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  overflow: hidden;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  aspect-ratio: 10 / 20;
}
.board-wrap canvas { display: block; width: 100%; height: 100%; }

#playerBoardWrap {
  height: min(calc(100vh - 150px), 840px);
  width: auto;
  max-width: 100%;
  margin: 0 auto;
}

.board-wrap.opponent { aspect-ratio: 10 / 20; }
.opponent-column { margin-left: 46px; }
.opponent-column .board-wrap { max-width: 220px; }
#screen-game #opponentScore::after { content: ' pts'; }

.combo-counter {
  position: absolute;
  left: 50%; top: 18%;
  transform: translate(-50%, 0) scale(.6);
  font-family: var(--game);
  font-weight: 800;
  font-size: 2.4rem;
  letter-spacing: -0.04em;
  color: var(--surge);
  text-shadow: 0 0 34px color-mix(in srgb, var(--surge) 45%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s cubic-bezier(.2,1.6,.4,1);
}
.combo-counter .combo-word {
  display: block;
  font-family: var(--mono);
  font-size: .5rem;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--text);
  opacity: .7;
  margin-top: -4px;
}
.combo-counter.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

.clear-banner {
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%, 6px);
  font-family: var(--game);
  font-size: 1.05rem; font-weight: 800; letter-spacing: -0.02em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 2px 24px rgba(0,0,0,.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .35s cubic-bezier(.16,1,.3,1);
  white-space: nowrap;
}
.clear-banner.show { opacity: 1; transform: translate(-50%, -8px); }
.clear-banner[data-tone="surge"] { color: var(--surge); text-shadow: 0 0 22px color-mix(in srgb, var(--surge) 55%, transparent), 0 2px 24px rgba(0,0,0,.8); }
.clear-banner[data-tone="charge"] { color: var(--charge); text-shadow: 0 0 22px color-mix(in srgb, var(--charge) 55%, transparent), 0 2px 24px rgba(0,0,0,.8); }
.clear-banner[data-tone="prize"] { color: var(--prize); text-shadow: 0 0 24px color-mix(in srgb, var(--prize) 60%, transparent), 0 2px 24px rgba(0,0,0,.8); }
.clear-banner[data-tone="hazard"] { color: var(--hazard); text-shadow: 0 0 24px color-mix(in srgb, var(--hazard) 60%, transparent), 0 2px 24px rgba(0,0,0,.8); }

.sabotage-warning {
  position: absolute;
  left: 50%; top: 12px;
  transform: translate(-50%, -12px) scale(.96);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 9px;
  max-width: calc(100% - 18px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border: 1px solid var(--hazard-border);
  box-shadow: 0 0 26px color-mix(in srgb, var(--hazard) 30%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .3s cubic-bezier(.16,1,.3,1);
}
.sabotage-warning.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
  animation: sabotage-warning-pulse .5s ease-in-out 3;
}
.sabotage-warning[data-category="visual"] { border-color: var(--charge-border); box-shadow: 0 0 26px color-mix(in srgb, var(--charge) 30%, transparent); }
.sabotage-warning[data-category="info"] { border-color: color-mix(in srgb, var(--surge) 50%, transparent); box-shadow: 0 0 26px color-mix(in srgb, var(--surge) 26%, transparent); }
.sabotage-warning-glyph {
  width: 30px; height: 30px;
  flex: 0 0 auto;
  color: var(--text);
  line-height: 0;
}
.sabotage-warning-glyph .sabotage-icon { width: 100%; height: 100%; display: block; }
.sabotage-warning-name {
  font-family: var(--game);
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text);
}
.sabotage-warning-counter {
  font-family: var(--mono);
  font-size: .6rem;
  color: var(--muted);
  margin-top: 2px;
}
@keyframes sabotage-warning-pulse {
  0%, 100% { box-shadow: 0 0 18px color-mix(in srgb, var(--hazard) 22%, transparent); }
  50% { box-shadow: 0 0 34px color-mix(in srgb, var(--hazard) 52%, transparent); }
}

.start-countdown {
  position: absolute; inset: 0;
  display: none;
  pointer-events: none;
  z-index: 9;
}
.start-countdown.show { display: block; }
.start-countdown.show::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 44%, rgba(0,0,0,.34), rgba(0,0,0,.66));
}
.count-beat {
  position: absolute;
  left: 50%; top: 44%;
  font-size: clamp(4rem, 17vh, 8.5rem);
  transform: translate(-50%, -50%) rotate(var(--tilt, 0deg));
}
.count-beat::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 38px; height: 38px;
  margin: -19px 0 0 -19px;
  border: 2px solid var(--tone);
  opacity: 0;
  animation: count-wave 1000ms ease-out both;
}
.count-glyph {
  display: block;
  font-family: var(--game);
  font-size: 100%;
  font-weight: 800;
  letter-spacing: -0.06em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--tone);
  text-shadow:
    0 0 26px color-mix(in srgb, var(--tone) 55%, transparent),
    0 0 74px color-mix(in srgb, var(--tone) 28%, transparent);
  animation: count-glyph 1000ms cubic-bezier(.2,.9,.3,1) both;
}
.count-go { font-size: clamp(3rem, 12vh, 6.4rem); }
.count-go .count-glyph { letter-spacing: -0.03em; }
.count-burst { position: absolute; left: 50%; top: 50%; }
.count-burst i {
  position: absolute;
  left: 0; top: 0;
  width: var(--size); height: var(--size);
  margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  background: var(--tone);
  box-shadow: 0 0 16px color-mix(in srgb, var(--tone) 66%, transparent);
  opacity: 0;
  animation: count-shard 1000ms cubic-bezier(.15,.85,.3,1) both;
}

@keyframes count-glyph {
  0%   { opacity: 0; font-size: 34%; }
  14%  { opacity: 1; font-size: 118%; }
  26%  { font-size: 100%; }
  64%  { opacity: 1; font-size: 103%; }
  71%  { opacity: 1; font-size: 86%; }
  80%  { opacity: .62; font-size: 155%; }
  92%  { opacity: 0; font-size: 205%; }
  100% { opacity: 0; font-size: 215%; }
}
@keyframes count-wave {
  0%, 70% { opacity: 0; transform: scale(.22); }
  75%     { opacity: .75; transform: scale(1.1); }
  100%    { opacity: 0; transform: scale(5.2); }
}
@keyframes count-shard {
  0%, 71% { opacity: 0; transform: translate(0, 0) rotate(0deg) scale(.5); }
  76%     { opacity: 1; transform: translate(calc(var(--dx) * .42), calc(var(--dy) * .42)) rotate(calc(var(--spin) * .4)) scale(1); }
  96%     { opacity: .35; transform: translate(calc(var(--dx) * .94), calc(var(--dy) * .94)) rotate(calc(var(--spin) * .95)) scale(.4); }
  100%    { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--spin)) scale(.3); }
}

@media (prefers-reduced-motion: reduce) {
  .count-beat::after, .count-burst { display: none; }
  .count-glyph { animation: count-glyph-calm 1000ms ease-out both; }
}
body.fx-reduced .count-beat::after,
body.fx-reduced .count-burst { display: none; }
body.fx-reduced .count-glyph { animation: count-glyph-calm 1000ms ease-out both; }
@keyframes count-glyph-calm {
  0%   { opacity: 0; }
  12%  { opacity: 1; }
  78%  { opacity: 1; }
  100% { opacity: 0; }
}

.board-wrap.warning {
  --warn-glow: 0;
  box-shadow:
    inset 0 0 0 calc(4px * var(--warn-glow)) var(--hazard),
    0 0 calc(30px * var(--warn-glow)) color-mix(in srgb, var(--hazard) 55%, transparent);
}
.board-wrap.warning::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 42%, color-mix(in srgb, var(--hazard) 34%, transparent) 100%);
  opacity: var(--warn-glow, 0);
}

.pocket-slot {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1;
}
.pocket.filled .pocket-slot { color: var(--charge); }
.pocket-slot .sabotage-icon { width: 88%; height: 88%; display: block; }
.pocket-duration {
  position: absolute;
  left: 4px;
  bottom: 6px;
  max-width: calc(100% - 8px);
  padding: 2px 4px;
  background: color-mix(in srgb, #000 76%, var(--hazard) 24%);
  border: 1px solid color-mix(in srgb, var(--hazard) 58%, var(--border-strong));
  color: var(--text);
  font-family: var(--mono);
  font-size: .52rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: .02em;
  white-space: nowrap;
  pointer-events: none;
}

/* Icons inherit colour from whatever surface holds them. */
.sabotage-icon { color: inherit; shape-rendering: geometricPrecision; }
.pocket-name {
  font-family: var(--game);
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#screen-game .pocket-hint {
  font-family: var(--game);
  font-size: .56rem;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cooldown-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: var(--surface-strong);
  overflow: hidden;
}
.cooldown-bar i { display: block; height: 100%; background: var(--charge); width: 0%; transition: width .1s linear; }

@keyframes pocket-ready-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 1px color-mix(in srgb, var(--hazard) 42%, transparent), 0 0 18px color-mix(in srgb, var(--hazard) 52%, transparent); }
  50% { transform: scale(1.018); box-shadow: 0 0 0 2px color-mix(in srgb, var(--hazard) 62%, transparent), 0 0 28px color-mix(in srgb, var(--hazard) 72%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .roll-box .pocket.ready { animation: none; }
}

@keyframes drunk-sway {
  0%   { transform: rotate(-5.5deg) skewX(7deg) scale(1.1) translate(-2.4vmin, 1.4vmin); }
  18%  { transform: rotate(3.4deg) skewY(-5.5deg) scale(1.2) translate(3vmin, -2vmin); }
  37%  { transform: rotate(6.5deg) skewX(-8deg) scale(1.08) translate(-3.4vmin, -2.6vmin); }
  55%  { transform: rotate(-2.6deg) skewY(6.5deg) scale(1.22) translate(2.2vmin, 3vmin); }
  74%  { transform: rotate(5deg) skewX(5.5deg) scale(1.12) translate(3.6vmin, 1.2vmin); }
  100% { transform: rotate(-5.5deg) skewX(7deg) scale(1.1) translate(-2.4vmin, 1.4vmin); }
}
@keyframes drunk-blur {
  0%   { filter: blur(2.2px) hue-rotate(-30deg) saturate(1.7) contrast(.86) drop-shadow(11px -6px 0 rgba(120,190,255,.4)); }
  33%  { filter: blur(3.4px) hue-rotate(26deg) saturate(2) contrast(1.2) drop-shadow(-13px 8px 0 rgba(255,110,150,.42)); }
  66%  { filter: blur(1.6px) hue-rotate(-16deg) saturate(1.5) contrast(.8) drop-shadow(9px 10px 0 rgba(150,255,190,.38)); }
  100% { filter: blur(2.2px) hue-rotate(-30deg) saturate(1.7) contrast(.86) drop-shadow(11px -6px 0 rgba(120,190,255,.4)); }
}
@keyframes drunk-lurch {
  0%   { transform: translate(0, 0) rotate(0deg); }
  25%  { transform: translate(2.6vmin, -1.8vmin) rotate(2.4deg); }
  50%  { transform: translate(-3vmin, 1.2vmin) rotate(-3.2deg); }
  75%  { transform: translate(1.4vmin, 2.4vmin) rotate(1.6deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
body.fx-drunk {
  animation: drunk-sway 2.3s ease-in-out infinite, drunk-blur 1.7s ease-in-out infinite;
  transform-origin: 50% 50%;
  overflow: hidden;
  overflow: clip;
}
body.fx-drunk .stage { animation: drunk-lurch 1.3s cubic-bezier(.6,-0.4,.4,1.4) infinite; }

.fog-overlay {
  position: fixed; inset: 0;
  z-index: 80;
  pointer-events: none;
  opacity: 0;
  transition: opacity .28s ease;
  background: radial-gradient(
    circle var(--fog-r, 150px) at var(--fog-x, 50%) var(--fog-y, 50%),
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,0.12) 42%,
    rgba(0,0,0,0.72) 68%,
    rgba(0,0,0,0.985) 88%
  );
}
.fog-overlay.show { opacity: 1; }

.nuke-overlay {
  position: fixed; inset: 0;
  z-index: 82;
  pointer-events: none;
  display: none;
  overflow: hidden;
}
.nuke-overlay.show { display: block; }
.nuke-overlay i { position: absolute; display: block; }
.nuke-bomb {
  left: 50%; top: 0;
  width: 22px; height: 44px;
  margin-left: -11px;
  background: linear-gradient(180deg, #f2f5fb 0%, #c7cedd 46%, #7d8496 100%);
  clip-path: polygon(50% 100%, 100% 66%, 100% 18%, 50% 0, 0 18%, 0 66%);
  box-shadow: 0 0 22px rgba(255, 226, 170, .45);
  animation: nuke-fall 2000ms linear both;
}
.nuke-smoke {
  left: 50%; top: 54%;
  width: 60px; height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    #2e323b 0%,
    #3a4049 26%,
    #474d5b 44%,
    #565d6d 58%,
    rgba(86, 93, 109, .72) 74%,
    rgba(86, 93, 109, .28) 88%,
    rgba(86, 93, 109, 0) 100%
  );
  filter: blur(2px);
  opacity: 0;
  animation: nuke-smoke 2000ms cubic-bezier(.12, .84, .3, 1) both;
}
.nuke-billow {
  inset: -25%;
  background:
    radial-gradient(closest-side at 26% 40%, rgba(129,136,152,.95), rgba(129,136,152,0) 70%),
    radial-gradient(closest-side at 62% 24%, rgba(97,104,120,.92), rgba(97,104,120,0) 72%),
    radial-gradient(closest-side at 78% 62%, rgba(142,149,164,.9), rgba(142,149,164,0) 70%),
    radial-gradient(closest-side at 38% 78%, rgba(106,113,129,.95), rgba(106,113,129,0) 72%),
    radial-gradient(closest-side at 54% 54%, rgba(70,76,90,.98), rgba(70,76,90,0) 78%);
  background-size: 62% 54%, 48% 46%, 66% 58%, 54% 50%, 96% 96%;
  background-repeat: no-repeat;
  filter: blur(14px);
  opacity: 0;
  animation: nuke-billow 2000ms ease-out both;
}
@keyframes nuke-fall {
  0%   { transform: translateY(-42px) scale(.9); opacity: 0; }
  4%   { transform: translateY(-28px) scale(.9); opacity: 1; }
  8%   { transform: translateY(2vh) scale(.95); opacity: 1; }
  14%  { transform: translateY(20vh) scale(1.02); opacity: 1; }
  20%  { transform: translateY(46vh) scale(1.08); opacity: 1; }
  22%  { transform: translateY(48vh) scale(1.1); opacity: 0; }
  100% { transform: translateY(48vh) scale(1.1); opacity: 0; }
}
@keyframes nuke-smoke {
  0%, 20% { opacity: 0; transform: scale(.3); }
  22%     { opacity: 1; transform: scale(2.6); }
  26%     { opacity: 1; transform: scale(8); }
  32%     { opacity: 1; transform: scale(22); }
  38%     { opacity: 1; transform: scale(36); }
  76%     { opacity: 1; transform: scale(42); }
  100%    { opacity: 0; transform: scale(48) translateY(-5%); }
}
@keyframes nuke-billow {
  0%, 21% { opacity: 0; transform: scale(.32); }
  27%     { opacity: .7; transform: scale(.72); }
  34%     { opacity: .85; transform: scale(1.04); }
  76%     { opacity: .7; transform: scale(1.12) translateY(-2%); }
  100%    { opacity: 0; transform: scale(1.22) translateY(-7%); }
}
@media (prefers-reduced-motion: reduce) {
  .nuke-bomb, .nuke-billow { display: none; }
  .nuke-smoke { animation: nuke-smoke-calm 2000ms ease-out both; }
}
body.fx-reduced .nuke-bomb,
body.fx-reduced .nuke-billow { display: none; }
body.fx-reduced .nuke-smoke { animation: nuke-smoke-calm 2000ms ease-out both; }
@keyframes nuke-smoke-calm {
  0%   { opacity: 0; transform: scale(42); }
  8%   { opacity: 1; transform: scale(42); }
  82%  { opacity: 1; transform: scale(42); }
  100% { opacity: 0; transform: scale(42); }
}
.fog-overlay .fog-bank {
  position: absolute;
  inset: -30%;
  display: block;
  mix-blend-mode: screen;
  opacity: .5;
  background:
    radial-gradient(closest-side at 22% 34%, rgba(170,190,215,0.3), rgba(170,190,215,0) 70%),
    radial-gradient(closest-side at 61% 18%, rgba(140,165,195,0.26), rgba(140,165,195,0) 72%),
    radial-gradient(closest-side at 78% 62%, rgba(190,205,225,0.24), rgba(190,205,225,0) 70%),
    radial-gradient(closest-side at 38% 78%, rgba(150,170,200,0.28), rgba(150,170,200,0) 72%);
  background-size: 58% 46%, 44% 40%, 66% 52%, 50% 44%;
  background-repeat: no-repeat;
  filter: blur(14px);
  animation: fog-drift 19s linear infinite, fog-breathe 6.5s ease-in-out infinite;
}
.fog-overlay .fog-bank.alt {
  opacity: .34;
  filter: blur(26px);
  animation: fog-drift-alt 27s linear infinite, fog-breathe 9s ease-in-out infinite reverse;
}
@keyframes fog-drift {
  0%   { transform: translate3d(-4%, 1%, 0) scale(1.04); }
  50%  { transform: translate3d(5%, -3%, 0) scale(1.12); }
  100% { transform: translate3d(-4%, 1%, 0) scale(1.04); }
}
@keyframes fog-drift-alt {
  0%   { transform: translate3d(6%, -2%, 0) scale(1.16) rotate(1deg); }
  50%  { transform: translate3d(-7%, 4%, 0) scale(1.06) rotate(-1.5deg); }
  100% { transform: translate3d(6%, -2%, 0) scale(1.16) rotate(1deg); }
}
@keyframes fog-breathe {
  0%, 100% { opacity: .28; }
  50% { opacity: .62; }
}

.screen-fx {
  position: fixed; inset: 0;
  z-index: 78;
  pointer-events: none;
}
.screen-fx i {
  position: absolute;
  inset: 0;
  display: block;
  opacity: 0;
  transition: opacity .3s ease;
}
.fx-scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.05) 0px,
    rgba(255,255,255,0.05) 1px,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0) 5px
  );
  mix-blend-mode: overlay;
}
.fx-chroma {
  mix-blend-mode: screen;
  background:
    radial-gradient(120% 90% at 12% 30%, rgba(255,60,120,0.22), rgba(255,60,120,0) 60%),
    radial-gradient(120% 90% at 88% 68%, rgba(60,220,255,0.22), rgba(60,220,255,0) 60%);
}
body.fx-drunk .fx-scanlines { opacity: 1; animation: fx-roll 2.4s linear infinite; }
body.fx-drunk .fx-chroma { opacity: 1; animation: fx-chroma-swim 3.1s ease-in-out infinite; }
body.fx-camo .fx-chroma { opacity: .12; }
body.fx-camo .fx-scanlines { opacity: .28; animation: fx-roll 1.6s linear infinite; }
@keyframes fx-roll {
  0% { transform: translateY(0); }
  100% { transform: translateY(6px); }
}
@keyframes fx-chroma-swim {
  0%, 100% { transform: translate(-1.4vmin, 0.6vmin); }
  50% { transform: translate(1.6vmin, -0.9vmin); }
}
@keyframes fx-chroma-flick {
  0% { transform: translate(-0.9vmin, 0); opacity: .5; }
  50% { transform: translate(1.1vmin, .3vmin); opacity: .95; }
  100% { transform: translate(-0.5vmin, -0.2vmin); opacity: .6; }
}

body.fx-holdjam .hold-tile {
  border-color: var(--hazard-border);
  box-shadow: inset 0 0 0 1px var(--hazard-border);
}
body.fx-holdjam .hold-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    135deg,
    color-mix(in srgb, var(--hazard) 26%, transparent) 0px,
    color-mix(in srgb, var(--hazard) 26%, transparent) 9px,
    rgba(0,0,0,0) 9px,
    rgba(0,0,0,0) 20px
  );
}
body.fx-queuefake .queue-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}
body.fx-queuefake .queue-tile {
  border-color: var(--charge-border);
}
body.fx-queuefake .queue-tile::after {
  background: linear-gradient(to bottom, color-mix(in srgb, var(--charge) 18%, transparent), rgba(0,0,0,0) 55%);
  animation: queue-lie 1.4s ease-in-out infinite;
}
@keyframes queue-lie {
  0%, 100% { opacity: .3; transform: translateY(0); }
  50% { opacity: .85; transform: translateY(-3px); }
}

body.fx-reduced.fx-drunk,
body.fx-reduced.fx-drunk .stage { animation: none; }
body.fx-reduced.fx-drunk { filter: blur(1.1px) saturate(1.25); }
body.fx-reduced .screen-fx i { animation: none; opacity: .45; }
body.fx-reduced .fog-overlay .fog-bank { animation: none; opacity: .3; }

.roulette-title { display: none; }
.roulette-slots {
  display: flex;
  gap: 6px;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  counter-reset: rollslot;
}
.roulette-slot { counter-increment: rollslot; }
.roulette-slots:has(.roulette-slot + .roulette-slot) .roulette-slot { height: auto; width: calc(50% - 3px); }
.roulette-slot.pickable { cursor: pointer; }
.roulette-slot.pickable:hover { transform: translateY(-2px); border-color: var(--outline-full); box-shadow: none; }
.roulette-slot.landed { animation: slotLand .34s cubic-bezier(.2,1.7,.35,1); border-color: var(--outline-full); box-shadow: none; }
.roulette-slot { border-style: solid; border-color: var(--accent-border); }
@keyframes slotLand {
  0% { transform: scale(1.16); }
  60% { transform: scale(.96); }
  100% { transform: scale(1); }
}
.roulette-slot.pickable::after {
  content: counter(rollslot);
  position: absolute;
  top: 3px; right: 5px;
  font-family: var(--mono);
  font-size: .58rem;
  font-weight: 700;
  color: var(--muted);
}
.roulette-glyph {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  line-height: 0;
}
.roulette-glyph .sabotage-icon { width: 88%; height: 88%; display: block; }
.roulette-name {
  position: absolute;
  top: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  font-family: var(--game);
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
  text-shadow: 0 2px 10px rgba(0,0,0,.9);
  pointer-events: none;
}
.roulette-slots:has(.roulette-slot + .roulette-slot) .roulette-name { font-size: .5rem; letter-spacing: 0; }
.roulette-tier { display: none; }
.roulette-help { display: none; }

.disconnect-overlay {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  background: #000;
  z-index: 90;
  text-align: center;
}
html.light .disconnect-overlay { background: #f2f2f2; }
.disconnect-overlay.show { display: flex; }
.countdown-ring { width: 132px; height: 132px; }
.countdown-ring circle { fill: none; stroke-width: 6; }
.countdown-ring .track { stroke: var(--border-strong); }
.countdown-ring .value { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .2s linear; }
.countdown-number {
  font-family: var(--mono); font-size: 1.6rem; font-weight: 700;
  fill: var(--text);
}
.disconnect-text { font-size: .96rem; color: var(--muted); max-width: 340px; line-height: 1.6; }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
@media (max-width: 720px) { .result-grid { grid-template-columns: 1fr; } }
.result-headline {
  display: block;
  text-align: center;
  margin-bottom: 0;
}
.result-headline .win { color: var(--prize); }
.result-headline .lose { color: var(--hazard); }
.result-sub {
  text-align: center; color: var(--muted);
  font-family: var(--game); font-size: .62rem;
  letter-spacing: -0.02em; line-height: 1.7;
  margin-bottom: 0;
}
#screen-result .player-name { font-family: var(--game); font-size: .78rem; font-weight: 700; letter-spacing: -0.02em; }
.breakdown { margin-top: 18px; display: flex; flex-direction: column; gap: 7px; }
.breakdown-row { display: flex; justify-content: space-between; gap: 10px; font-size: .58rem; }
.breakdown-row span:first-child { color: var(--muted); }
.breakdown-row span:last-child { font-family: var(--game); font-weight: 700; letter-spacing: -0.015em; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
#screen-result .result-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
#screen-result .result-actions .btn { min-width: 0; padding-inline: 14px; }
#screen-result .result-actions .btn-wide { width: 100%; }
@media (max-width: 720px) {
  #screen-result .result-actions { grid-template-columns: 1fr; }
}

#screen-result.active {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: auto;
}
#screen-result .shell {
  flex: 1 1 auto;
  align-self: flex-start;
  width: 100%;
  max-width: 640px;
  padding: var(--menu-top, clamp(12px, 2.2vh, 28px)) 24px clamp(12px, 2.2vh, 28px);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: clamp(10px, 1.8vh, 20px);
}
#screen-result .title-block {
  position: relative;
  margin-bottom: max(0px, calc(var(--menu-title-gap, 48px) - clamp(10px, 1.8vh, 20px)));
}
#screen-result .result-sub {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: clamp(4px, 0.9vh, 10px);
  font-size: clamp(.78rem, 1.5vw, .96rem);
}
#screen-result .result-grid { margin-bottom: 0; }
.result-summary-panel { max-width: none; margin: 0; }

#screen-result { --beat: 1; }
body[data-outcome="lose"] #screen-result { --beat: 1.32; }

#screen-result.active .result-headline {
  animation: result-slam calc(460ms * var(--beat)) cubic-bezier(.16,1.1,.3,1) both;
}
#screen-result.active .result-sub {
  animation: result-rise calc(420ms * var(--beat)) ease-out calc(180ms * var(--beat)) both;
}
#screen-result.active .player-card {
  animation: result-enter-left calc(520ms * var(--beat)) cubic-bezier(.2,.9,.25,1) calc(220ms * var(--beat)) both;
}
#screen-result.active .player-card + .player-card {
  animation-name: result-enter-right;
}
#screen-result.active .crown:not([hidden]) {
  animation:
    result-crown-drop calc(560ms * var(--beat)) cubic-bezier(.24,1.6,.4,1) calc(480ms * var(--beat)) both,
    result-crown-sway 3.2s ease-in-out calc(1040ms * var(--beat)) infinite both;
  transform-origin: 50% 100%;
}
#screen-result.active .result-chip:not([hidden]) {
  animation: result-pop calc(380ms * var(--beat)) cubic-bezier(.2,1.7,.35,1) calc(700ms * var(--beat)) both;
}
#screen-result.active .breakdown-row {
  animation: result-rise calc(340ms * var(--beat)) ease-out both;
}
#screen-result.active .breakdown-row:nth-child(1) { animation-delay: calc(560ms * var(--beat)); }
#screen-result.active .breakdown-row:nth-child(2) { animation-delay: calc(630ms * var(--beat)); }
#screen-result.active .breakdown-row:nth-child(3) { animation-delay: calc(700ms * var(--beat)); }
#screen-result.active .breakdown-row:nth-child(4) { animation-delay: calc(770ms * var(--beat)); }
#screen-result.active .panel {
  animation: result-rise calc(420ms * var(--beat)) ease-out calc(820ms * var(--beat)) both;
}
#screen-result.active .result-actions {
  animation: result-rise calc(420ms * var(--beat)) ease-out calc(940ms * var(--beat)) both;
}

@keyframes result-slam {
  0% { opacity: 0; transform: scale(1.55); filter: blur(9px); }
  70% { opacity: 1; transform: scale(.97); filter: blur(0); }
  100% { opacity: 1; transform: scale(1); filter: blur(0); }
}
@keyframes result-rise {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: none; }
}
@keyframes result-enter-left {
  0% { opacity: 0; transform: translateX(-38px); }
  100% { opacity: 1; transform: none; }
}
@keyframes result-enter-right {
  0% { opacity: 0; transform: translateX(38px); }
  100% { opacity: 1; transform: none; }
}
@keyframes result-crown-drop {
  0% { opacity: 0; transform: translate(-52%, -34px) rotate(-46deg); }
  62% { opacity: 1; transform: translate(-52%, 4px) rotate(-8deg); }
  100% { opacity: 1; transform: translateX(-52%) rotate(-15deg); }
}
@keyframes result-crown-sway {
  0%, 100% { transform: translateX(-52%) rotate(-15deg); }
  50% { transform: translateX(-52%) rotate(11deg); }
}
@keyframes result-pop {
  0% { opacity: 0; transform: scale(.7); }
  100% { opacity: 1; transform: scale(1); }
}

.result-chip {
  display: inline-block;
  margin: 10px auto 0;
  padding: 4px 10px;
  border: 1px solid var(--prize);
  color: var(--prize);
  background: color-mix(in srgb, var(--prize) 12%, transparent);
  font-family: var(--game);
  font-size: .58rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
}
.result-chip[hidden] { display: inline-block; visibility: hidden; }
.player-card.loser .result-chip { border-color: var(--border-strong); color: var(--muted); background: none; }

#screen-result .player-card { transition: opacity .4s ease-out, filter .4s ease-out; }
#screen-result .player-card.winner {
  border-color: var(--prize);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--prize) 40%, transparent), 0 0 34px color-mix(in srgb, var(--prize) 22%, transparent);
}
#screen-result .player-card.loser { opacity: .58; filter: saturate(.55); }
#screen-result .player-card.loser .face-badge { filter: grayscale(.5); }

.result-burst {
  position: absolute;
  top: -26px; left: 50%;
  width: 220px; height: 220px;
  margin: -110px 0 0 -110px;
  pointer-events: none;
  opacity: 0;
  background:
    repeating-conic-gradient(from 0deg, var(--prize) 0deg 3deg, transparent 3deg 18deg);
  -webkit-mask-image: radial-gradient(circle, transparent 16%, #000 34%, transparent 68%);
  mask-image: radial-gradient(circle, transparent 16%, #000 34%, transparent 68%);
}
#screen-result.active .player-card.winner .result-burst {
  animation: result-burst 720ms cubic-bezier(.15,.85,.3,1) calc(480ms * var(--beat)) both;
}
@keyframes result-burst {
  0% { opacity: 0; transform: scale(.25) rotate(-14deg); }
  22% { opacity: .85; }
  100% { opacity: 0; transform: scale(1.7) rotate(16deg); }
}

.result-headline .win {
  display: inline-block;
  transform-origin: 50% 80%;
}
#screen-result.active .result-headline .win {
  animation: result-happy-shake 2.6s ease-in-out calc(760ms * var(--beat)) infinite both;
}
@keyframes result-happy-shake {
  0%, 62%, 100% { transform: rotate(0) scale(1); }
  66% { transform: rotate(-7deg) scale(1.1); }
  70% { transform: rotate(6deg) scale(1.12); }
  74% { transform: rotate(-5deg) scale(1.08); }
  78% { transform: rotate(4deg) scale(1.06); }
  82% { transform: rotate(-2deg) scale(1.03); }
  86% { transform: rotate(0) scale(1); }
}

.result-headline .lose { display: inline-block; }
#screen-result.active .result-headline .lose {
  animation: result-stutter 620ms steps(1, end) calc(460ms * var(--beat)) both;
}
@keyframes result-stutter {
  0%, 100% { opacity: 1; transform: none; }
  12% { opacity: .35; transform: translateX(-4px); }
  20% { opacity: 1; transform: translateX(3px); }
  34% { opacity: .5; transform: translateX(2px) skewX(6deg); }
  44% { opacity: 1; transform: none; }
  58% { opacity: .7; transform: translateX(-2px); }
  66% { opacity: 1; transform: none; }
}

body[data-outcome="lose"] #screen-result .shell { filter: saturate(.72); }
body[data-outcome="lose"] #screen-result::after {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at center, transparent 42%, rgba(0,0,0,.55) 100%);
  animation: result-rise 900ms ease-out both;
}
html.light body[data-outcome="lose"] #screen-result::after { background: radial-gradient(ellipse at center, transparent 46%, rgba(0,0,0,.2) 100%); }

@media (prefers-reduced-motion: reduce) {
  #screen-result.active .result-headline,
  #screen-result.active .result-sub,
  #screen-result.active .player-card,
  #screen-result.active .crown:not([hidden]),
  #screen-result.active .result-chip:not([hidden]),
  #screen-result.active .breakdown-row,
  #screen-result.active .panel,
  #screen-result.active .result-actions,
  #screen-result.active .result-headline .win,
  #screen-result.active .result-headline .lose,
  body[data-outcome="lose"] #screen-result::after {
    animation: none;
    opacity: 1;
  }
  #screen-result.active .player-card.winner .result-burst { animation: none; opacity: 0; }
  #screen-result .player-card.loser { opacity: .72; }
}

.settings-overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.68);
  z-index: 100;
  padding: 24px;
  overflow-y: auto;
}
html.light .settings-overlay { background: rgba(0,0,0,0.24); }
.settings-overlay.show { display: flex; }
.settings-box {
  width: 100%; max-width: 1040px;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: 0;
  padding: 28px;
  max-height: calc(100vh - 48px); overflow-y: auto;
}
.settings-shell {
  max-width: 940px;
  display: flex; flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.settings-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-strong);
}
.settings-body {
  display: grid;
  grid-template-columns: 214px minmax(0, 1fr);
  min-height: 0;
}
.settings-rail {
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px;
  background: var(--surface);
  border-right: 1px solid var(--border-strong);
}
.settings-tab {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px;
  border: 1px solid transparent; border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: color .18s, background .18s, border-color .18s, box-shadow .18s;
}
.settings-tab .icon { width: 17px; height: 17px; }
.settings-tab-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.settings-tab-name { font-size: .88rem; font-weight: 600; }
.settings-tab-hint { font-size: .68rem; letter-spacing: .05em; color: var(--muted); }
.settings-tab:hover { color: var(--text); background: var(--surface-strong); }
.settings-tab[aria-selected="true"] {
  color: var(--text);
  background: var(--card-bg);
  border-color: var(--border-strong);
  box-shadow: inset 3px 0 0 var(--accent);
}
.settings-panels {
  min-width: 0; padding: 22px;
  display: grid; align-items: start;
  overflow-y: auto; scrollbar-gutter: stable;
}
.settings-panel {
  grid-area: 1 / 1; min-width: 0;
  opacity: 1;
  transition: opacity 150ms ease-out 90ms, transform 150ms ease-out 90ms;
}
.settings-panel[hidden] {
  display: block; visibility: hidden; pointer-events: none;
  opacity: 0; transform: translateY(4px);
  transition: opacity 90ms ease-in, transform 90ms ease-in, visibility 0s linear 90ms;
}
body.fx-reduced .settings-panel,
body.fx-reduced .settings-panel[hidden] { transition: none; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .settings-panel,
  .settings-panel[hidden] { transition: none; transform: none; }
}
.settings-panel-head { margin-bottom: 12px; }
.settings-panel-title {
  margin: 0;
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
}
.settings-panel-note { margin: 7px 0 0; font-size: .78rem; line-height: 1.5; color: var(--muted); }
.set-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(190px, 244px);
  gap: 18px; align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; }
.set-copy { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.set-name { display: flex; align-items: center; gap: 8px; font-size: .9rem; font-weight: 600; color: var(--text); }
.set-icon { width: 15px; height: 15px; color: var(--muted); }
.set-hint { font-size: .75rem; line-height: 1.45; color: var(--muted); }
.set-control { display: flex; align-items: center; gap: 12px; }
.set-control input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.set-value { font-family: var(--mono); font-size: .76rem; min-width: 60px; text-align: right; }
.set-control-switch { justify-content: flex-end; }
.settings-switch {
  display: inline-flex; align-items: center; gap: 11px;
  padding: 0; border: 0; background: transparent;
  color: var(--muted); cursor: pointer;
  font-family: var(--font); font-size: .8rem; font-weight: 600;
}
.settings-switch-track {
  position: relative;
  width: 42px; height: 22px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  transition: background .18s, border-color .18s;
}
.settings-switch-knob {
  position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: var(--muted);
  transition: transform .18s, background .18s;
}
.settings-switch:hover .settings-switch-track { border-color: var(--accent-border); }
.settings-switch[aria-checked="true"] { color: var(--text); }
.settings-switch[aria-checked="true"] .settings-switch-track { background: var(--accent-dim); border-color: var(--accent-border); }
.settings-switch[aria-checked="true"] .settings-switch-knob { background: var(--accent); transform: translateX(20px); }
.settings-switch-state { min-width: 74px; text-align: left; }
.settings-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 15px 22px;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
}
.settings-footer-note { margin: 0; font-size: .74rem; color: var(--muted); }
.settings-footer .btn { padding: 11px 20px; font-size: .82rem; }
.bind-row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.bind-row:last-child { border-bottom: none; }
.bind-label { font-size: .88rem; }
.bind-key {
  font-family: var(--mono); font-size: .74rem;
  padding: 6px 12px; border-radius: 0;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  min-width: 74px; text-align: center;
  transition: border-color .2s, color .2s;
}
.bind-key:hover { border-color: var(--accent-border); }
.bind-key.listening { border-color: var(--accent); color: var(--accent); }

.slider-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.slider-row label { flex: 0 0 130px; font-size: .82rem; color: var(--muted); }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.slider-row output { font-family: var(--mono); font-size: .78rem; min-width: 62px; text-align: right; }

@media (max-width: 720px) {
  .settings-overlay { padding: 16px; }
  .settings-box { padding: 20px; max-height: calc(100vh - 32px); }
  .settings-shell { padding: 0; }
  .settings-topbar { padding: 15px 16px; }
  .settings-body { grid-template-columns: minmax(0, 1fr); }
  .settings-rail {
    flex-direction: row; gap: 6px;
    padding: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    border-right: 0;
    border-bottom: 1px solid var(--border-strong);
  }
  .settings-rail::-webkit-scrollbar { display: none; }
  .settings-tab { flex: 0 0 auto; padding: 9px 13px; }
  .settings-tab-hint { display: none; }
  .settings-tab[aria-selected="true"] { box-shadow: inset 0 -2px 0 var(--accent); }
  .settings-panels { padding: 18px 16px; scrollbar-gutter: auto; }
  .set-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .set-control-switch { justify-content: space-between; }
  .set-control-switch .settings-switch { width: 100%; flex-direction: row-reverse; justify-content: space-between; }
  .settings-footer { flex-direction: column; align-items: stretch; gap: 12px; padding: 14px 16px; }
  .settings-footer .btn { width: 100%; }
}


.help-keys { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px 18px; margin-top: 12px; }
.help-keys div { font-size: .78rem; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; }
.help-keys kbd {
  font-family: var(--mono); font-size: .68rem;
  background: var(--surface-strong); border: 1px solid var(--border);
  border-radius: 0; padding: 2px 7px; color: var(--text);
}

.seg-three button { padding-inline: 8px; letter-spacing: -.01em; }
.seg button[data-difficulty="easy"] { color: color-mix(in srgb, var(--go) 72%, var(--muted)); }
.seg button[data-difficulty="normal"] { color: color-mix(in srgb, var(--flare) 72%, var(--muted)); }
.seg button[data-difficulty="chaos"] { color: color-mix(in srgb, var(--charge) 72%, var(--muted)); }
.seg button[data-difficulty="easy"]:hover { color: var(--go); }
.seg button[data-difficulty="normal"]:hover { color: var(--flare); }
.seg button[data-difficulty="chaos"]:hover { color: var(--charge); }
.seg button[data-difficulty="easy"][aria-pressed="true"] { color: var(--bg); background: var(--go); }
.seg button[data-difficulty="normal"][aria-pressed="true"] { color: var(--bg); background: var(--flare); }
.seg button[data-difficulty="chaos"][aria-pressed="true"] { color: var(--bg); background: var(--charge); }

body[data-screen="lobby"],
body[data-screen="result"] { overflow-x: hidden; overflow-y: visible; overflow-x: clip; }
#screen-lobby.active {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: auto;
}
#screen-lobby .shell {
  flex: 1 1 auto;
  align-self: flex-start;
  width: 100%;
  max-width: 1120px;
  padding: var(--menu-top, clamp(12px, 2.2vh, 28px)) 24px clamp(12px, 2.2vh, 28px);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: clamp(10px, 1.8vh, 20px);
}
#screen-lobby .title-block { margin-bottom: max(0px, calc(var(--menu-title-gap, 48px) - clamp(10px, 1.8vh, 20px))); }
#screen-lobby .lobby-players { margin-bottom: 0; gap: 14px; }
#screen-lobby .player-card { padding: clamp(12px, 2vh, 20px); }
#screen-lobby .avatar-build { padding-top: 4px; }
#screen-lobby .lobby-countdown { margin-top: 0; }
#screen-lobby .lobby-notice { margin-top: 0; }

.lobby-columns { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 14px; align-items: stretch; }
@media (max-width: 860px) { .lobby-columns { grid-template-columns: 1fr; } }

.rules-panel { display: flex; flex-direction: column; padding: clamp(14px, 2.2vh, 22px); }
.rules-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.rules-head h2 { margin-bottom: 0; }
.rules-chip {
  font-family: var(--mono); font-size: .68rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--bg); background: var(--text);
  padding: 4px 10px;
}
.rules-panel .seg { margin-top: 12px; }
.rules-panel .field-hint { margin-top: 8px; }
.rules-panel #lobbyDifficultyHint {
  white-space: nowrap;
}
.rules-panel #editRulesBtn { margin-top: auto; }
.rules-panel .btn { margin-top: 12px; }
.rules-panel #rulesLockNote { margin-top: 8px; }
.lobby-panel {
  padding: clamp(14px, 2.2vh, 22px);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 12px;
}
.lobby-panel .lobby-cell:first-child { grid-column: 1 / -1; }
.lobby-cell h2 { margin-bottom: 10px; font-size: .92rem; }
.lobby-cell-bare { padding-top: 0; }
.invite-hint { margin-top: 8px; }
.lobby-panel .btn-wide { padding-inline: 12px; font-size: .88rem; white-space: nowrap; }
.rules-panel .btn-wide { white-space: nowrap; }
@media (max-width: 860px) { .lobby-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.rules-overlay { padding: 14px; overflow: hidden; }
.rules-deck {
  max-width: 1120px;
  max-height: calc(100vh - 28px);
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.overlay-title {
  display: flex; align-items: center; gap: 9px;
  font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em;
}

.rules-deck-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px clamp(14px, 1.6vw, 20px);
  border-bottom: 1px solid var(--border-strong);
}
.rules-deck-head .overlay-title { font-size: 1rem; }
.rules-deck-head .overlay-title .icon { width: 16px; height: 16px; color: var(--accent); }
.preset-cards {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border-strong);
}
.preset-card {
  flex: 1 1 0; min-width: 0;
  appearance: none; cursor: pointer; font: inherit; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 12px clamp(12px, 1.4vw, 20px) 13px;
  border: none; border-top: 3px solid transparent;
  background: var(--card-bg); color: var(--muted);
  transition: flex-grow .2s ease, background .2s ease, border-color .2s ease, color .2s ease;
}
.preset-head { display: flex; align-items: center; gap: 9px; }
.preset-card .icon { width: 21px; height: 21px; stroke-width: 2.1; }
.preset-name {
  font-size: 1.05rem; font-weight: 700; letter-spacing: -.02em;
  color: var(--muted);
  transition: color .2s ease;
}
.preset-note {
  visibility: hidden; opacity: 0;
  max-width: 100%;
  font-size: .69rem; line-height: 1.4; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: opacity .2s ease, color .2s ease, visibility 0s .2s;
}
.preset-card:hover:not(:disabled) { background: var(--surface-strong); }
.preset-card:hover:not(:disabled) .preset-name { color: var(--text); }
.preset-card:disabled { cursor: default; }
.preset-card:disabled:not([aria-pressed="true"]) { opacity: .4; }
.preset-card[data-difficulty="easy"] { color: var(--go); }
.preset-card[data-difficulty="normal"] { color: var(--flare); }
.preset-card[data-difficulty="chaos"] { color: var(--charge); }
.preset-card[aria-pressed="true"] {
  flex-grow: 1.9;
  background: color-mix(in srgb, currentColor 13%, var(--card-bg));
  border-top-color: currentColor;
}
.preset-card[aria-pressed="true"] .preset-name { color: currentColor; }
.preset-card[aria-pressed="true"] .preset-note {
  visibility: visible; opacity: 1; color: var(--text);
  transition: opacity .2s ease, color .2s ease, visibility 0s;
}

.rules-deck-body {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.72fr) minmax(0, 1fr);
  gap: 1px;
  background: var(--border);
}
.rules-column {
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--card-bg);
  overflow-y: auto;
}
.rules-card { flex: 0 0 auto; background: var(--card-bg); padding: 11px clamp(12px, 1.5vw, 18px) 13px; }
.rules-card + .rules-card { border-top: 1px solid var(--border); }
.rules-column-roster .rules-card { flex: 1 1 auto; }
.rules-card-head {
  display: flex; align-items: center; gap: 7px;
  margin: 0 0 9px;
  font-size: .64rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--muted);
}
.rules-card-head .icon { width: 14px; height: 14px; color: var(--accent); }
.rules-column-roster .rules-card-head {
  position: sticky; top: 0; z-index: 2;
  background: var(--card-bg);
  padding: 11px clamp(12px, 1.5vw, 18px) 9px;
  margin: -11px calc(-1 * clamp(12px, 1.5vw, 18px)) 0;
}

.rules-deck .field { margin: 8px 0 0; }
.rules-deck .field label { font-size: .7rem; }
.rules-deck .field input[type="number"] { padding: 6px 10px; font-size: .82rem; }
.rules-deck .seg { padding: 3px; }
.rules-deck .seg button { font-size: .76rem; padding: 6px 8px; gap: 6px; }
.rules-deck .seg button .icon { width: 14px; height: 14px; }
.rules-deck .slider-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline; gap: 1px 10px;
  padding: 3px 0;
}
.rules-deck .slider-row label { flex: none; font-size: .72rem; color: var(--muted); }
.rules-deck .slider-row output { min-width: 0; font-family: var(--mono); font-size: .68rem; color: var(--text); text-align: right; }
.rules-deck .slider-row input[type="range"] { grid-column: 1 / -1; width: 100%; height: 14px; accent-color: var(--accent); }

.toggle-grid {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px;
  background: var(--border); border: 1px solid var(--border);
}
.rule-toggle {
  appearance: none; cursor: pointer; text-align: left; font: inherit;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 6px 10px;
  background: var(--surface); border: none;
  color: var(--muted);
  transition: color .18s, background .18s, box-shadow .18s;
}
.rule-toggle:hover:not(:disabled) { background: var(--surface-strong); color: var(--text); }
.rule-toggle[aria-pressed="true"] { color: var(--text); background: var(--glass); box-shadow: inset 2px 0 0 var(--accent); }
.rule-toggle:disabled { cursor: default; opacity: .55; }
.rule-toggle-name { font-size: .74rem; font-weight: 700; letter-spacing: -.02em; }
.rule-toggle-state { font-family: var(--mono); font-size: .6rem; color: var(--muted); }
.rule-toggle[aria-pressed="true"] .rule-toggle-state { color: var(--accent); }

.rule-switch {
  appearance: none; cursor: pointer; text-align: left; font: inherit;
  width: 100%; margin-top: 6px;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center; gap: 9px;
  padding: 7px 10px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted);
  transition: color .18s, background .18s, border-color .18s;
}
.rule-switch .icon { width: 15px; height: 15px; }
.rule-switch-copy { min-width: 0; display: flex; }
.rule-switch .btn-label { font-size: .74rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.rule-switch-track {
  position: relative; flex: 0 0 auto;
  width: 28px; height: 15px;
  background: var(--surface-strong); border: 1px solid var(--border-strong);
  transition: background .18s, border-color .18s;
}
.rule-switch-track::after {
  content: ""; position: absolute; top: 1px; left: 1px;
  width: 11px; height: 11px; background: var(--muted);
  transition: transform .18s, background .18s;
}
.rule-switch:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); }
.rule-switch:disabled { cursor: default; opacity: .55; }
.rule-switch[aria-pressed="true"] { color: var(--text); background: var(--glass); border-color: var(--accent-border); }
.rule-switch[aria-pressed="true"] .rule-switch-track { background: var(--accent); border-color: var(--accent); }
.rule-switch[aria-pressed="true"] .rule-switch-track::after { transform: translateX(13px); background: var(--bg); }

.rules-deck-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 9px clamp(14px, 1.6vw, 20px);
  border-top: 1px solid var(--border-strong);
}
.rules-deck-foot .notice { margin-top: 0; font-size: .72rem; min-height: 0; }
.rules-deck-actions { flex: 0 0 auto; margin-left: auto; display: flex; gap: 8px; }
.rules-deck-actions .btn { padding: 8px 13px; font-size: .78rem; }
.rules-deck-actions .btn .icon { width: 15px; height: 15px; }

#sabotageToggles { min-height: 0; display: flex; flex-direction: column; gap: 2px; }
.roster-head { display: flex; align-items: center; gap: 8px; margin: 7px 0 2px; }
.roster-head:first-child { margin-top: 0; }
.roster-title { font-size: .7rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.roster-count { font-family: var(--mono); font-size: .6rem; color: var(--muted); }
.roster-bulk { display: flex; gap: 4px; margin-left: auto; }
.roster-bulk-btn {
  appearance: none; cursor: pointer; font: inherit;
  font-family: var(--mono); font-size: .58rem; letter-spacing: .06em; text-transform: uppercase;
  padding: 1px 6px;
  background: none; border: 1px solid var(--border); color: var(--muted);
  transition: color .18s, border-color .18s;
}
.roster-bulk-btn:hover { color: var(--text); border-color: var(--border-strong); }

.roster-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; }
.roster-grid.muted { opacity: .45; }
.roster-item {
  appearance: none; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px;
  font: inherit;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted);
  transition: color .18s, border-color .18s, background .18s, opacity .18s;
  opacity: .5;
}
.roster-item:hover:not(:disabled) { border-color: var(--border-strong); }
.roster-item[aria-pressed="true"] { opacity: 1; color: var(--text); border-color: var(--accent-border); background: var(--glass); }
.roster-item:disabled { cursor: default; }
.roster-glyph { width: 17px; height: 17px; flex: 0 0 auto; display: block; }
.roster-glyph svg { width: 100%; height: 100%; display: block; }
.roster-text { display: flex; min-width: 0; }
.roster-name { font-size: .7rem; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tip {
  position: fixed; left: 0; top: 0;
  z-index: 200;
  width: max-content;
  max-width: min(280px, calc(100vw - 16px));
  padding: 6px 9px;
  background: var(--text); color: var(--bg);
  font-family: var(--font); font-size: .7rem; font-weight: 600;
  line-height: 1.4; letter-spacing: -.01em;
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
  pointer-events: none;
  opacity: 0;
  transition: opacity .1s;
}
.tip.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .tip { transition: none; }
}
body.fx-reduced .tip { transition: none; }

@media (max-width: 1020px) {
  .roster-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-height: 760px) {
  #screen-lobby.active { height: auto; min-height: 100vh; overflow-y: auto; }
}

.disco-overlay {
  position: fixed; inset: 0;
  z-index: 84;
  width: 100%; height: 100%;
  pointer-events: none;
  display: none;
}
.disco-overlay.show { display: block; }

#playerBoardWrap {
  transition: transform .22s ease;
  transform: translate(var(--shrink-x, 0), var(--shrink-y, 0)) scale(var(--shrink-scale, 1));
}

.ad-popup-layer {
  position: fixed; inset: 0;
  z-index: 86;
  pointer-events: none;
  overflow: hidden;
}
.ad-popup {
  position: absolute;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, rgba(28,32,44,0.98) 0%, rgba(14,17,24,0.98) 100%);
  box-shadow: 0 10px 26px rgba(0,0,0,.5);
  font-family: var(--game);
  transform-origin: 0 0;
  will-change: transform;
}
.ad-popup.shape-banner { flex-direction: row; align-items: stretch; flex-wrap: wrap; }
.ad-popup.shape-banner .ad-popup-bar { flex: 1 0 100%; }
.ad-popup.shape-banner .ad-popup-art { flex: 0 0 74px; margin: 8px 0 8px 8px; }
.ad-popup.shape-banner .ad-popup-body { flex: 1; align-self: center; }
.ad-popup.shape-banner .ad-popup-cta { flex: 0 0 82px; align-self: center; margin: 8px 8px 8px 0; }
.ad-popup.shape-tower .ad-popup-art { height: 108px; }
.ad-popup.shape-square .ad-popup-art { height: 88px; }

.ad-popup-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 4px 4px 8px;
  background: var(--ad-accent, #6f8dff);
  color: #0d1017;
}
.ad-popup-title {
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.ad-popup-close {
  width: 18px; height: 18px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0,0,0,.45);
  background: #dfe5f0;
  color: #0d1017;
  font-size: .62rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.ad-popup-close:hover { background: #fff; }
.ad-popup-body {
  margin: 0;
  padding: 8px 10px;
  font-size: .64rem;
  line-height: 1.35;
  color: var(--muted);
}
.ad-popup-cta {
  display: block;
  margin: 0 10px 10px;
  padding: 5px 0;
  text-align: center;
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .1em;
  color: #0d1017;
  background: var(--ad-accent, #ffd166);
  animation: ad-cta-blink 620ms steps(2, end) infinite;
}
@keyframes ad-cta-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.ad-popup-art {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 62px;
  margin: 8px 10px 0;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}
.ad-popup-art i,
.ad-popup-art u { display: block; }

.art-siren { align-items: center; }
.art-siren i {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fff 0 12%, var(--ad-accent) 45%, #4a0d1a 100%);
  animation: ad-pulse 700ms ease-in-out infinite;
}
.art-siren u {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255,95,126,.22) 0 8px, transparent 8px 16px);
}

.art-gift { align-items: center; }
.art-gift i {
  width: 44px; height: 34px;
  background: var(--ad-accent);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.35);
}
.art-gift u {
  position: absolute;
  width: 10px; height: 34px;
  background: #0d1017;
  animation: ad-sheen 1.4s linear infinite;
}

.art-bar { align-items: center; }
.art-bar i {
  width: 78%; height: 12px;
  background: linear-gradient(90deg, var(--ad-accent) 0 40%, rgba(255,255,255,.12) 40% 100%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.4);
  animation: ad-fill 1.8s ease-in-out infinite;
}

.art-face { align-items: center; }
.art-face i {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--ad-accent);
  box-shadow: inset -6px -8px 0 rgba(0,0,0,.18);
}
.art-face u {
  position: absolute;
  width: 46px; height: 46px;
  background:
    radial-gradient(circle at 34% 40%, #0d1017 0 3px, transparent 3px),
    radial-gradient(circle at 66% 40%, #0d1017 0 3px, transparent 3px);
}

.art-chart { align-items: flex-end; padding: 6px; }
.art-chart i {
  width: 12px;
  background: var(--ad-accent);
  opacity: .85;
}

.art-meter,
.art-stars { align-items: center; }
.art-meter i,
.art-stars i {
  width: 14px; height: 14px;
  background: rgba(255,255,255,.14);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.art-meter i { clip-path: none; width: 16px; height: 10px; }
.art-meter i.on,
.art-stars i.on { background: var(--ad-accent); }

.art-spinner { align-items: center; }
.art-spinner i {
  width: 34px; height: 34px;
  border: 4px solid rgba(255,255,255,.16);
  border-top-color: var(--ad-accent);
  border-radius: 50%;
  animation: ad-spin 900ms linear infinite;
}
.art-spinner u {
  position: absolute;
  bottom: 4px;
  width: 60%; height: 3px;
  background: var(--ad-accent);
  opacity: .5;
}

@keyframes ad-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: .82; }
}
@keyframes ad-spin {
  to { transform: rotate(360deg); }
}
@keyframes ad-fill {
  0%, 100% { background-position: 0 0; filter: none; }
  50% { filter: brightness(1.4); }
}
@keyframes ad-sheen {
  0% { transform: translateX(-22px); }
  100% { transform: translateX(22px); }
}

body.fx-reduced .ad-popup-cta,
body.fx-reduced .ad-popup-art i,
body.fx-reduced .ad-popup-art u { animation: none; }

.home-info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
  width: 100%;
  max-width: 856px;
  margin: 16px auto 0;
}
@media (max-width: 920px) {
  .home-info-grid { grid-template-columns: minmax(0, 420px); justify-content: center; }
}
.home-info-grid .panel { padding: 16px 20px 10px; display: flex; flex-direction: column; }
.home-info-grid .panel h2 { margin-bottom: 11px; font-size: .96rem; }

.howto-steps { display: grid; flex: 1; min-height: 0; list-style: none; }
.howto-step {
  --step: var(--text);
  display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px;
  align-items: stretch; min-height: 42px;
}
.howto-step[hidden] { display: none; }
.howto-step--lobby { --step: var(--go); }
.howto-step--clear { --step: var(--prize); }
.howto-step--sabotage { --step: var(--charge); }
.howto-step--survive { --step: var(--hazard); }
.howto-scene {
  position: relative; display: block; box-sizing: border-box;
  width: 100%; height: 100%; min-height: 0;
  background: var(--surface-strong); border: 1px solid var(--border-strong);
  overflow: hidden;
}
.howto-scene::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(120% 90% at 50% 120%, var(--step), transparent 68%);
  opacity: .16;
}
.howto-art { position: relative; display: block; width: 100%; height: 100%; }
.howto-art g, .howto-art rect, .howto-art use, .howto-art path { transform-box: fill-box; transform-origin: center; }
.howto-art .art-well { stroke: var(--border-strong); stroke-width: 1; }
.howto-art .art-wellbg { fill: rgba(255,255,255,.018); }
.howto-art .art-grid { fill: none; stroke: rgba(255,255,255,.055); stroke-width: 1; }
html.light .howto-art .art-wellbg { fill: rgba(0,0,0,.03); }
html.light .howto-art .art-grid { stroke: rgba(0,0,0,.07); }
.howto-art .c-i { color: #5ad9e8; }
.howto-art .c-j { color: #6f8dff; }
.howto-art .c-l { color: #ff8f5a; }
.howto-art .c-o { color: #ffd166; }
.howto-art .c-s { color: #b8f5c4; }
.howto-art .c-t { color: #b78cff; }
.howto-art .c-z { color: #ff5f7e; }
.howto-art .c-x { color: #8f8f8f; }

.howto-art .art-wire { fill: none; stroke: var(--step); stroke-width: 1.4; stroke-dasharray: 5 5; opacity: .5; animation: howto-wire 2.6s linear infinite; }
.howto-art .art-packet { fill: var(--step); animation: howto-send 2.6s cubic-bezier(.4, 0, .2, 1) infinite; }
.howto-art .art-packet-mark { stroke: var(--bg); stroke-width: 1.6; }
.howto-art .art-ack { fill: none; stroke: var(--step); stroke-width: 2; animation: howto-ack 2.6s ease-out infinite; }

.howto-art .art-drop { animation: howto-drop 3s linear infinite; }
.howto-art .art-line { animation: howto-linegone 3s steps(1, end) infinite; }
.howto-art .art-settle { animation: howto-settle 3s steps(1, end) infinite; }
.howto-art .art-flash { fill: #fff; opacity: 0; animation: howto-flash 3s steps(1, end) infinite; }
.howto-art .art-prize { fill: none; stroke: var(--step); stroke-width: 1.4; opacity: .4; animation: howto-payout 3s ease-out infinite; }
.howto-art .art-spark { fill: none; stroke: var(--step); stroke-width: 1.6; stroke-linecap: round; opacity: .4; animation: howto-payout 3s ease-out infinite; }

.howto-art .art-bolt { fill: var(--step); animation: howto-throw 2.6s cubic-bezier(.4, 0, .2, 1) infinite; }
.howto-art .art-shove { animation: howto-shove 2.6s steps(1, end) infinite; }

.howto-art .art-rising { animation: howto-climb 3s linear infinite; }
.howto-art .art-limit { fill: none; stroke: var(--step); stroke-width: 1.4; stroke-dasharray: 3 3; opacity: .4; animation: howto-alarm 3s steps(1, end) infinite; }
.howto-text { align-self: center; font-size: .74rem; color: var(--muted); line-height: 1.42; }
.howto-text b { display: block; font-size: .86rem; color: var(--step); font-weight: 700; letter-spacing: -0.035em; }
@keyframes howto-wire { to { stroke-dashoffset: -20; } }
@keyframes howto-send {
  0%, 8% { opacity: 0; transform: translateX(0); }
  16% { opacity: 1; transform: translateX(1px); }
  48% { opacity: 1; transform: translateX(15px); }
  56%, 100% { opacity: 0; transform: translateX(15px); }
}
@keyframes howto-ack {
  0%, 50% { opacity: 0; }
  58% { opacity: 1; }
  88%, 100% { opacity: 0; }
}
@keyframes howto-drop {
  0% { opacity: 1; transform: translateY(-91px); animation-timing-function: steps(13, end); }
  34%, 46% { opacity: 1; transform: translateY(0); }
  50%, 88% { opacity: 0; transform: translateY(0); }
  90%, 100% { opacity: 1; transform: translateY(-91px); }
}
@keyframes howto-linegone {
  0%, 46% { opacity: 1; }
  50%, 88% { opacity: 0; }
  90%, 100% { opacity: 1; }
}
@keyframes howto-flash {
  0%, 40% { opacity: 0; }
  43% { opacity: .85; }
  46% { opacity: .35; }
  49%, 100% { opacity: 0; }
}
@keyframes howto-settle {
  0%, 50% { transform: translateY(0); }
  54% { transform: translateY(7px); }
  58%, 88% { transform: translateY(14px); }
  90%, 100% { transform: translateY(0); }
}
@keyframes howto-payout {
  0%, 52% { opacity: .35; transform: scale(1); }
  60% { opacity: 1; transform: scale(1.1); }
  72% { opacity: 1; transform: scale(1); }
  88%, 100% { opacity: .35; transform: scale(1); }
}
@keyframes howto-throw {
  0%, 8% { opacity: 0; transform: translateX(-14px) scale(.6); }
  18% { opacity: 1; transform: translateX(-10px) scale(1); }
  40% { opacity: 1; transform: translateX(12px) scale(1); }
  46%, 100% { opacity: 0; transform: translateX(16px) scale(1); }
}
@keyframes howto-shove {
  0%, 42% { transform: translateY(0); }
  46%, 90% { transform: translateY(-7px); }
  94%, 100% { transform: translateY(0); }
}
@keyframes howto-climb {
  0% { opacity: 0; transform: translateY(0); }
  6% { opacity: 1; transform: translateY(0); animation-timing-function: steps(4, end); }
  66% { transform: translateY(-28px); }
  94% { opacity: 1; transform: translateY(-28px); }
  100% { opacity: 0; transform: translateY(-28px); }
}
@keyframes howto-alarm {
  0%, 70% { opacity: .4; }
  74% { opacity: 1; }
  78% { opacity: .4; }
  82% { opacity: 1; }
  90%, 100% { opacity: .4; }
}
body.fx-reduced .howto-art * { animation: none; }
.howto-dots { display: flex; gap: 7px; justify-content: center; margin-top: auto; padding-top: 10px; }
.howto-dot {
  position: relative;
  width: 7px; height: 7px; padding: 0; border: 0; border-radius: 999px;
  background-color: var(--border-strong);
  background-image: linear-gradient(var(--text), var(--text));
  background-repeat: no-repeat;
  background-position: left center;
  background-size: 0% 100%;
  cursor: pointer;
  transition: background-color 160ms ease-out, transform 160ms ease-out, width 220ms ease-out;
}
.howto-dot[aria-current="true"] { width: 18px; }
.howto-dot[aria-current="true"].filling { animation: howto-fill 5000ms linear forwards; }
@keyframes howto-fill {
  from { background-size: 0% 100%; }
  to { background-size: 100% 100%; }
}
.howto-dot:active { transform: scale(.94); }
@media (hover: hover) and (pointer: fine) {
  .howto-dot:not([aria-current="true"]):hover { background-color: var(--text); }
}
body.fx-reduced .howto-dot { transition: none; }
body.fx-reduced .howto-dot[aria-current="true"] { animation: none; background-size: 100% 100%; }

.record-tally { display: flex; align-items: baseline; justify-content: center; gap: 14px; padding: 0 0 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.record-tally-value { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.record-tally-value.wins { color: var(--go); }
.record-tally-value.losses { color: var(--hazard); }
.record-tally-divider { color: var(--muted); font-size: 2.1rem; font-weight: 700; line-height: 1; }
.record-details { display: flex; flex: 1; flex-direction: column; padding-bottom: 15px; }
.record-detail { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 0 8px; min-width: 0; }
.record-detail + .record-detail { padding: 8px 0 0; border-top: 1px solid var(--border); }
.record-detail dt { font-size: .84rem; color: var(--muted); }
.record-detail dd { font-size: .92rem; font-weight: 600; color: var(--text); text-align: right; }
.record-detail.hot dd { color: var(--go); }
.record-detail.cold dd { color: var(--hazard); }

.achievement-meter { display: flex; flex-direction: column; gap: 8px; }
.achievement-count { font-size: 1.24rem; font-weight: 700; letter-spacing: -0.02em; }
.achievement-track { display: block; height: 6px; background: var(--surface-strong); border: 1px solid var(--border); }
.achievement-track i { display: block; height: 100%; width: 0; background: var(--prize); transition: width .4s ease; }
.achievements-panel .btn { margin-top: auto; }
.achievements-panel .btn-wide { margin-top: 22px; }

.achievements-overlay .settings-box {
  max-width: 680px;
  max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
}
.achievements-topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.achievements-topbar .overlay-title { margin-bottom: 0; }
.achievements-topbar .icon { width: 18px; height: 18px; }
.achievements-tools { display: flex; align-items: center; gap: 10px; }
.achievements-close {
  width: 28px; height: 28px; padding: 0;
  display: grid; place-items: center;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.achievements-close .icon { display: block; width: 16px; height: 16px; stroke-width: 2; }
.achievements-close:active { transform: scale(.95); }
@media (hover: hover) and (pointer: fine) {
  .achievements-close:hover { color: var(--text); border-color: var(--border-strong); }
}
.achievement-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
  overflow-y: auto;
  padding: 2px 8px 2px 2px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) var(--surface-strong);
}
.achievement-grid::-webkit-scrollbar { width: 8px; }
.achievement-grid::-webkit-scrollbar-track { background: var(--surface-strong); border-left: 1px solid var(--border); }
.achievement-grid::-webkit-scrollbar-thumb { background: var(--border-strong); border: 2px solid var(--surface-strong); }
.achievement-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px;
  align-items: start;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  min-height: 130px;
  padding: 16px;
}
.achievement-card .achievement-icon { width: 38px; height: 38px; flex: 0 0 auto; }
.achievement-card > div:last-child { min-width: 0; display: flex; flex-direction: column; align-self: stretch; }
.achievement-name { font-size: .94rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.achievement-desc { font-size: .78rem; color: var(--muted); line-height: 1.45; margin-top: 4px; }
.achievement-tag {
  font-family: var(--mono); font-size: .58rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted); margin-top: auto; padding-top: 7px; display: block;
}
.achievement-card.unlocked { border-color: var(--border-strong); }
.achievement-card.unlocked .achievement-tag { color: var(--prize); }
.achievement-card.locked { opacity: .62; }
.achievement-card.locked .achievement-desc { font-family: var(--mono); letter-spacing: .06em; }
@media (max-width: 580px) {
  .achievements-overlay { padding: 16px; }
  .achievements-overlay .settings-box { max-height: calc(100vh - 32px); padding: 20px; }
  .achievement-grid { grid-template-columns: 1fr; }
}

.unlock-toasts {
  position: fixed;
  right: 24px; bottom: 24px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.unlock-toast {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  padding: 12px 16px;
  min-width: 240px;
  animation: unlock-in .34s ease both;
}
.unlock-toast.out { animation: unlock-out .3s ease both; }
.unlock-toast .achievement-icon { width: 30px; height: 30px; }
.unlock-toast .achievement-tag { color: var(--prize); margin-top: 0; }
@keyframes unlock-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
@keyframes unlock-out {
  to { opacity: 0; transform: translateY(-8px); }
}
body.fx-reduced .unlock-toast { animation: none; }

.rotate-gate { display: none; }
.touch-controls { display: none; }

@media (max-width: 900px), (pointer: coarse) {
  html { overscroll-behavior: none; overflow-x: hidden; }
  body {
    overscroll-behavior: none;
    overflow-x: hidden;
    overflow-y: visible;
    overflow-x: clip;
  }
  #screen-home .title { font-size: min(13vw, 3.9rem); }
  html, body, body * { touch-action: pan-x pan-y; -webkit-tap-highlight-color: transparent; }
  input[type="range"] { touch-action: none; }
  body, body *:not(input):not(textarea) {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  input, textarea { -webkit-user-select: text; user-select: text; }
  body[data-screen="game"] {
    overflow: hidden;
    position: fixed;
    inset: 0;
    width: 100%;
  }
  body[data-screen="game"] #screen-game,
  body[data-screen="game"] #screen-game *,
  body[data-screen="game"] .pause-overlay,
  body[data-screen="game"] .pause-overlay *,
  body[data-screen="game"] .disconnect-overlay,
  body[data-screen="game"] .disconnect-overlay *,
  .ad-popup-layer,
  .ad-popup-layer *,
  .fog-overlay,
  .nuke-overlay,
  .disco-overlay,
  .screen-fx { touch-action: none; }

  #screen-game.active {
    display: block;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
  }

  #screen-game .stage {
    height: 100vh;
    height: 100dvh;
    padding: calc(4px + env(safe-area-inset-top)) calc(4px + env(safe-area-inset-right)) 0 calc(4px + env(safe-area-inset-left));
    gap: 4px;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) 72px;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "stats score score"
      "board board hold"
      "board board rail"
      "board board opp"
      "pad   pad   pad";
    align-items: stretch;
  }

  #screen-game .hud-column,
  #screen-game .board-column,
  #screen-game .topbar { display: contents; }
  #screen-game .stats-tile { grid-area: stats; }
  #screen-game .score-bar { grid-area: score; }
  #screen-game .hold-tile { grid-area: hold; }
  #screen-game #playerBoardWrap { grid-area: board; }
  #screen-game .queue-column {
    grid-area: rail;
    min-height: 0;
    gap: 4px;
  }
  #screen-game .opponent-column {
    grid-area: opp;
    margin-left: 0;
    gap: 4px;
  }
  #touchControls { grid-area: pad; }

  #screen-game .hold-tile { padding: 4px; }
  #screen-game .hold-tile .tile-label { display: none; }
  #screen-game #holdCanvas { height: 34px; }
  #screen-game .keybind { display: none; }

  #screen-game .stats-tile {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 3px 8px;
  }
  #screen-game .stat-row { flex: 0 0 auto; justify-content: flex-start; gap: 5px; }
  #screen-game .stat-row + .stat-row { margin-top: 0; }
  #screen-game .stat-key { font-size: .52rem; letter-spacing: .06em; }
  #screen-game .stat-value { font-size: .8rem; }

  #screen-game .score-bar { padding: 3px 8px; gap: 8px; }
  #screen-game .score-key { font-size: .52rem; letter-spacing: .06em; }
  #screen-game .score-value { font-size: .8rem; line-height: 1.2; }
  #screen-game #opponentScore::after { content: none; }

  #screen-game #playerBoardWrap {
    min-height: 0;
    height: auto;
    width: auto;
    max-width: 100%;
    margin: 0;
    justify-self: center;
    align-self: stretch;
  }

  #screen-game .roll-box { flex: 0 0 auto; }
  #screen-game .roll-caption { height: 26px; padding-top: 2px; }
  #screen-game .pocket-name { font-size: .52rem; letter-spacing: 0; }
  #screen-game .pocket-hint { font-size: .46rem; letter-spacing: .02em; margin-top: 2px; }
  #screen-game .queue-tile { flex: 1 1 auto; min-height: 0; padding: 5px; }
  #screen-game #queueCanvas { height: 100%; }

  #screen-game .opponent-tile { padding: 6px; }
  #screen-game .opponent-tile .face-badge.small { display: none; }
  #screen-game .opponent-tile .player-name { font-size: .6rem; }
  #screen-game .opponent-column .board-wrap { max-width: 100%; }
  #screen-game #pauseBtn { display: none; }
  #screen-game #quitBtn { padding: 6px; font-size: .58rem; }
  #screen-game #quitBtn .icon { display: none; }

  #screen-game .roll-box.show .roll-frame { aspect-ratio: auto; height: auto; }
  .roll-box.show .roulette-box { height: auto; }
  .roll-box.show .roulette-slots { flex-direction: column; gap: 4px; height: auto; }
  .roulette-slots:has(.roulette-slot + .roulette-slot) .roulette-slot { width: 100%; height: auto; }
  .roll-box.show .roulette-help {
    display: block;
    margin: 4px 0 0;
    font-family: var(--game);
    font-size: .48rem;
    line-height: 1.25;
    letter-spacing: .04em;
    text-transform: uppercase;
    text-align: center;
    color: var(--muted);
  }
  .roulette-slot.pickable::after { display: none; }
  .roulette-slot.pickable {
    border-color: var(--hazard);
    animation: pocket-ready-pulse 1s ease-in-out infinite;
  }
  .roll-box.show .roulette-name {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    transform: none;
    padding: 6px 1px 2px;
    font-size: .46rem;
    background: linear-gradient(to top, rgba(0,0,0,.94), rgba(0,0,0,0));
  }
  html.light .roll-box.show .roulette-name {
    color: #ffffff;
  }
  #screen-game .pocket { cursor: pointer; }
  #screen-game .hold-tile { cursor: pointer; }
  #screen-game .pocket.is-down,
  #screen-game .hold-tile.is-down { border-color: var(--outline-full); transform: scale(.96); }

  body.fx-drunk,
  body.fx-drunk .stage { animation: none; }
  body.fx-drunk #playerCanvas {
    animation: drunk-sway 2.3s ease-in-out infinite, drunk-blur 1.7s ease-in-out infinite;
    transform-origin: 50% 50%;
  }
  body.fx-reduced.fx-drunk { filter: none; }
  body.fx-reduced.fx-drunk #playerCanvas { animation: none; filter: blur(1.1px) saturate(1.25); }

  .touch-controls {
    --dpad-size: min(33vw, 19dvh, 150px);
    --face-size: min(15vw, 8.6dvh, 70px);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "dpad sys face";
    position: relative;
    z-index: 88;
    background: var(--bg);
    align-items: center;
    justify-items: center;
    gap: 4px;
    height: auto;
    max-height: min(38dvh, 260px);
    padding: 4px 10px calc(4px + env(safe-area-inset-bottom));
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .touch-btn {
    appearance: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-family: var(--game);
    font-weight: 700;
    text-transform: lowercase;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .touch-btn.is-down {
    background: color-mix(in srgb, var(--text) 26%, var(--glass));
    border-color: var(--text);
    transform: scale(.94);
  }

  .touch-dpad {
    grid-area: dpad;
    display: grid;
    width: var(--dpad-size);
    height: var(--dpad-size);
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    filter: drop-shadow(0 3px 6px rgba(0,0,0,.55));
  }
  .touch-btn.dpad {
    background: linear-gradient(180deg, color-mix(in srgb, var(--text) 12%, var(--surface-strong)), var(--surface-strong));
    color: var(--muted);
  }
  .touch-btn.dpad.is-down { color: var(--text); transform: none; }
  .dpad-up { grid-area: 1 / 2 / 2 / 3; border-bottom: none; border-radius: 12px 12px 0 0; }
  .dpad-left { grid-area: 2 / 1 / 3 / 2; border-right: none; border-radius: 12px 0 0 12px; }
  .dpad-hub {
    grid-area: 2 / 2 / 3 / 3;
    position: relative;
    background: var(--surface-strong);
    border: 1px solid var(--border-strong);
    border-left: none;
    border-right: none;
  }
  .dpad-hub::after {
    content: '';
    position: absolute;
    left: 50%; top: 50%;
    width: 46%; height: 46%;
    transform: translate(-50%, -50%);
    border-radius: 999px;
    background: color-mix(in srgb, #000 45%, var(--surface-strong));
    box-shadow: inset 0 1px 2px rgba(0,0,0,.6);
  }
  .dpad-right { grid-area: 2 / 3 / 3 / 4; border-left: none; border-radius: 0 12px 12px 0; }
  .dpad-down { grid-area: 3 / 2 / 4 / 3; border-top: none; border-radius: 0 0 12px 12px; }

  .touch-arrow {
    width: calc(var(--dpad-size) * .12);
    height: calc(var(--dpad-size) * .12);
    background: currentColor;
    display: block;
  }
  .touch-arrow.up { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
  .touch-arrow.down { clip-path: polygon(0 0, 100% 0, 50% 100%); }
  .touch-arrow.left { clip-path: polygon(100% 0, 100% 100%, 0 50%); }
  .touch-arrow.right { clip-path: polygon(0 0, 0 100%, 100% 50%); }

  .touch-face {
    grid-area: face;
    position: relative;
    width: calc(var(--face-size) * 2.24);
    height: calc(var(--face-size) * 2.24);
  }
  .touch-face .face {
    border-radius: 999px;
    font-size: 1.05rem;
    text-transform: uppercase;
    background: radial-gradient(circle at 34% 28%, color-mix(in srgb, #fff 34%, var(--charge)), color-mix(in srgb, #000 38%, var(--charge)));
    border: none;
    color: var(--bg);
    box-shadow: 0 3px 6px rgba(0,0,0,.55);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .touch-face .face.is-down {
    background: radial-gradient(circle at 34% 28%, color-mix(in srgb, #fff 12%, var(--charge)), color-mix(in srgb, #000 52%, var(--charge)));
    box-shadow: 0 1px 2px rgba(0,0,0,.5);
    transform: scale(.94);
  }
  .face-a { position: absolute; right: 0; top: 0; width: var(--face-size); height: var(--face-size); }
  .face-b { position: absolute; left: 0; top: calc(var(--face-size) * .58); width: var(--face-size); height: var(--face-size); }
  .touch-face .face-sabo {
    position: absolute;
    right: calc(var(--face-size) * .17);
    bottom: 0;
    width: calc(var(--face-size) * .78);
    height: calc(var(--face-size) * .78);
    border-radius: 999px;
    font-size: .58rem;
    letter-spacing: .04em;
    background: radial-gradient(circle at 34% 28%, color-mix(in srgb, #fff 34%, var(--hazard)), color-mix(in srgb, #000 40%, var(--hazard)));
  }
  .touch-face .face-sabo.is-down {
    background: radial-gradient(circle at 34% 28%, color-mix(in srgb, #fff 12%, var(--hazard)), color-mix(in srgb, #000 54%, var(--hazard)));
  }

  .touch-system {
    grid-area: sys;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 0 6px;
  }
  .touch-btn.sys {
    width: 100%;
    max-width: 118px;
    height: 24px;
    border-radius: 999px;
    font-size: .58rem;
    letter-spacing: .12em;
    color: var(--muted);
  }

  .rotate-gate { display: none; }
}

@media (max-width: 900px), (pointer: coarse) {
  .ad-popup-close {
    position: relative;
    width: 28px;
    height: 28px;
    font-size: .8rem;
  }
  .ad-popup-close::after {
    content: '';
    position: absolute;
    inset: calc(-10px / var(--ad-scale, 1)) calc(-10px / var(--ad-scale, 1)) calc(-10px / var(--ad-scale, 1)) calc(-14px / var(--ad-scale, 1));
  }
  .howto-dots { gap: 16px; }
  .howto-dot {
    position: relative;
    height: 10px;
    width: 10px;
  }
  .howto-dot[aria-current="true"] { width: 22px; }
  .howto-dot::after {
    content: '';
    position: absolute;
    inset: -17px -8px;
  }
  .rotate-btn { width: 40px; height: 40px; }
  .swatches { gap: 10px; }
  .swatch { position: relative; }
  .swatch::after {
    content: '';
    position: absolute;
    inset: -7px -5px;
  }
  input[type="text"],
  input[type="number"],
  input[type="email"],
  textarea { font-size: 16px; }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  #page-content > :not(.rotate-gate) { display: none; }
  .rotate-gate {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
    text-align: center;
  }
  .rotate-gate-icon {
    display: block;
    width: 42px;
    height: 66px;
    margin: 0 auto 18px;
    border: 2px solid var(--text);
    border-radius: 6px;
    animation: rotate-gate-tip 2.4s ease-in-out infinite;
  }
  .rotate-gate-title { font-family: var(--game); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin: 0; }
  .rotate-gate-sub { color: var(--muted); font-size: .82rem; margin: 8px 0 0; }
  .rotate-gate-note {
    margin: 12px auto 0;
    max-width: 30ch;
    font-family: var(--game);
    font-size: .6rem;
    line-height: 1.5;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--hazard);
  }
  .rotate-gate-note[hidden] { display: none; }
}

@keyframes rotate-gate-tip {
  0%, 40% { transform: rotate(90deg); }
  60%, 100% { transform: rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-gate-icon { animation: none; }
}

.browser-gate {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.browser-gate[hidden] { display: none; }
.browser-gate-inner {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.browser-gate-title {
  font-family: var(--game);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 0;
}
.browser-gate-sub {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.5;
  margin: 0;
}
.browser-gate-open { justify-content: center; }
.browser-gate-steps {
  margin: 0;
  padding-left: 20px;
  text-align: left;
  color: var(--text);
  font-size: .84rem;
  line-height: 1.7;
}
.browser-gate-steps[hidden] { display: none; }
.browser-gate-row { display: flex; gap: 8px; align-items: stretch; }
.browser-gate-row input {
  flex: 1;
  min-width: 0;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 11px 14px;
  outline: none;
  text-align: left;
  font-family: var(--mono);
  font-size: .78rem;
}
.browser-gate-row input:focus { border-color: var(--accent-border); }
.browser-gate-skip {
  align-self: center;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: .76rem;
  text-decoration: underline;
  padding: 4px 8px;
}
.browser-gate-skip:hover:not(:disabled) { color: var(--text); transform: none; box-shadow: none; }

.touch-legend { display: none; }

@media (pointer: coarse) {
  .settings-keybinds > .settings-panel-head,
  .settings-keybinds > #bindList { display: none; }
  .touch-legend { display: block; margin-top: 0; }
  .touch-legend-list { margin: 0; display: grid; gap: 6px; }
  .touch-legend-list > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 5px;
  }
  .touch-legend-list > div:last-child { border-bottom: none; padding-bottom: 0; }
  .touch-legend-list dt { font-family: var(--mono); font-size: .76rem; color: var(--text); }
  .touch-legend-list dd { margin: 0; font-size: .72rem; color: var(--muted); text-align: right; }
}

@media (max-width: 900px), (pointer: coarse) {
  #screen-lobby.active {
    display: block;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
    padding-bottom: 0;
  }
  #screen-lobby .shell {
    max-width: 100%;
    justify-content: flex-start;
    padding: var(--menu-top, 16px) 14px calc(24px + env(safe-area-inset-bottom));
  }
  #screen-lobby .lobby-players { grid-template-columns: 1fr; }
  #screen-result.active {
    display: block;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
    padding-bottom: 0;
  }
  #screen-result .shell {
    max-width: 100%;
    justify-content: flex-start;
    padding: var(--menu-top, 16px) 14px calc(24px + env(safe-area-inset-bottom));
  }
  .lobby-columns { grid-template-columns: 1fr; }
  .lobby-panel { grid-template-columns: 1fr; }
  .lobby-panel .btn-wide,
  .rules-panel .btn-wide { white-space: normal; }
  .rules-panel #lobbyDifficultyHint { white-space: normal; }

  .rules-overlay { padding: 10px; overflow-y: auto; align-items: flex-start; }
  .rules-deck {
    max-height: none;
    overflow: visible;
    display: block;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .rules-deck-head { padding: 12px 14px; }
  .preset-cards { flex-direction: column; }
  .preset-card { align-items: flex-start; text-align: left; padding: 11px 14px; gap: 3px; }
  .preset-card[aria-pressed="true"] { flex-grow: 1; }
  .preset-note { white-space: normal; text-wrap: balance; }
  .preset-name { font-size: .98rem; }
  .rules-deck-body { display: block; overflow: visible; background: none; }
  .rules-column { display: block; overflow: visible; background: none; }
  .rules-card { padding: 13px 14px; border-top: 1px solid var(--border); }
  .rules-column:first-child .rules-card:first-child { border-top: 0; }
  .rules-column-roster .rules-card-head { position: static; margin: 0 0 9px; padding: 0; }
  .rules-deck .slider-row { padding: 6px 0; }
  .rules-deck .slider-row input[type="range"] { height: 22px; }
  .rule-toggle { padding: 11px 12px; }
  .rule-switch { padding: 11px 12px; }
  .rule-switch-track { width: 34px; height: 20px; }
  .rule-switch-track::after { width: 16px; height: 16px; }
  .rule-switch[aria-pressed="true"] .rule-switch-track::after { transform: translateX(14px); }
  .roster-grid { grid-template-columns: 1fr; gap: 4px; }
  .roster-item { padding: 9px 10px; }
  .roster-bulk-btn { padding: 6px 10px; }
  .rules-deck-foot { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 14px; }
  .rules-deck-actions { margin: 0; flex-wrap: wrap; }
  .rules-deck-actions .btn { flex: 1 1 auto; padding: 13px 16px; font-size: .84rem; }
}
