:root {
  color-scheme: dark;
  --bg: #15171b;
  --paper: rgba(255, 255, 255, 0.09);
  --paper-strong: rgba(255, 255, 255, 0.15);
  --paper-soft: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.17);
  --text: #fff8ef;
  --muted: #c9c0b6;
  --ink: #17191e;
  --mint: #9bf38a;
  --pink: #ff8fb8;
  --yellow: #ffd66b;
  --blue: #72d7ff;
  --danger: #ff667e;
  --shadow: 0 26px 80px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 14% 12%, rgba(155, 243, 138, 0.16), transparent 30%),
    radial-gradient(circle at 85% 16%, rgba(255, 143, 184, 0.18), transparent 31%),
    radial-gradient(circle at 48% 96%, rgba(114, 215, 255, 0.13), transparent 34%),
    linear-gradient(135deg, #191b20, #0d0e12 55%, #1b1420);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--mint);
  cursor: pointer;
  font-weight: 850;
  transition: transform 150ms ease, filter 150ms ease, opacity 150ms ease, box-shadow 150ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  box-shadow: 0 10px 26px rgba(155, 243, 138, 0.16);
}

button:active {
  transform: translateY(1px) scale(0.98);
  filter: brightness(0.96);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  filter: none;
  box-shadow: none;
}

input {
  min-width: 0;
}

.shell {
  width: min(1260px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--mint);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 44px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.top-actions,
.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ghost-button,
.sound-toggle {
  color: var(--text);
  background: var(--paper-strong);
  border: 1px solid var(--line);
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  color: var(--muted);
  font-size: 13px;
}

.volume-control input {
  width: 94px;
  accent-color: var(--mint);
}

.room-chip {
  min-height: 38px;
  display: grid;
  place-items: center;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  color: var(--muted);
  white-space: nowrap;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(430px, 560px) minmax(330px, 1fr);
  gap: 16px;
  align-items: start;
}

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

.desk {
  display: grid;
  grid-template-columns: minmax(116px, 148px) minmax(260px, 420px) minmax(132px, 170px);
  gap: 12px;
  align-items: start;
  justify-content: center;
}

.left-rail,
.right-rail {
  display: grid;
  gap: 10px;
  align-content: start;
}

.preview-box,
.panel,
.stat-pill,
.action-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  backdrop-filter: blur(18px);
}

.preview-box {
  padding: 10px;
}

.preview-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.preview-box canvas {
  display: block;
  width: 100%;
  border-radius: 6px;
  background: rgba(4, 5, 8, 0.82);
}

.preview-box button {
  width: 100%;
  margin-top: 8px;
}

.next-list {
  display: grid;
  gap: 8px;
}

.stat-panel {
  display: grid;
  gap: 8px;
}

.stat-pill {
  min-width: 0;
  padding: 9px 10px;
}

.stat-pill span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.stat-pill strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--text);
  font-size: 22px;
  line-height: 1.05;
  text-overflow: ellipsis;
}

.stat-pill strong.bump {
  animation: stat-bump 260ms ease-out;
}

.action-panel {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.action-panel button {
  width: 100%;
  color: var(--text);
  background: var(--paper-strong);
}

.board-wrap {
  position: relative;
  width: min(100%, var(--board-width, 420px));
  justify-self: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: var(--shadow);
  transform: translate3d(0, 0, 0);
}

#gameCanvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
  border-radius: 6px;
  background: rgba(6, 7, 10, 0.94);
}

#fxCanvas {
  position: absolute;
  inset: 14px;
  z-index: 2;
  width: calc(100% - 28px);
  aspect-ratio: 1 / 2;
  pointer-events: none;
}

.board-wrap.hit {
  animation: board-hit 150ms ease-out;
}

.board-wrap.hard-hit {
  animation: board-hard-hit 220ms ease-out;
}

.board-wrap.line-hit {
  animation: board-line-hit 420ms ease-out;
}

.countdown,
.combo-banner,
.game-over {
  position: absolute;
  z-index: 4;
  text-align: center;
}

.countdown {
  inset: 14px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.46);
  color: var(--yellow);
  font-size: clamp(54px, 15vw, 116px);
  font-weight: 1000;
  text-shadow: 0 8px 36px rgba(255, 214, 107, 0.32);
  animation: countdown-pop 720ms ease both;
}

.combo-banner {
  left: 50%;
  top: 27%;
  min-width: 150px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  color: var(--ink);
  background: linear-gradient(135deg, var(--yellow), var(--mint));
  box-shadow: 0 18px 50px rgba(255, 214, 107, 0.26);
  font-size: 23px;
  font-weight: 1000;
  translate: -50% 0;
  animation: combo-pop 820ms ease-out both;
}

.game-over {
  inset: 14px;
  display: grid;
  place-content: center;
  gap: 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.76);
}

.game-over strong {
  font-size: 28px;
}

.game-over span {
  color: var(--muted);
}

.game-over button {
  padding: 10px 16px;
}

.hidden {
  display: none !important;
}

.battle-strip {
  min-height: 42px;
  display: grid;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.2);
}

.battle-strip.danger {
  border-color: rgba(255, 102, 126, 0.55);
  background: rgba(255, 102, 126, 0.12);
}

.mobile-controls {
  display: none;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.mobile-controls button {
  min-height: 48px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.garbage-warning,
.victory-banner {
  position: absolute;
  left: 50%;
  z-index: 5;
  min-width: 178px;
  padding: 10px 14px;
  border-radius: 8px;
  text-align: center;
  translate: -50% 0;
  font-weight: 1000;
}

.garbage-warning {
  top: 16%;
  border: 1px solid rgba(255, 102, 126, 0.5);
  color: var(--text);
  background: rgba(255, 102, 126, 0.86);
  box-shadow: 0 18px 50px rgba(255, 102, 126, 0.28);
  animation: warning-pulse 760ms ease-in-out infinite alternate;
}

.victory-banner {
  top: 38%;
  color: var(--ink);
  background: linear-gradient(135deg, var(--yellow), var(--mint));
  box-shadow: 0 24px 70px rgba(255, 214, 107, 0.32);
  font-size: 30px;
  animation: victory-pop 900ms ease both;
}

.side-panel {
  display: grid;
  gap: 12px;
}

body.is-game-active {
  overflow: hidden;
}

body.is-game-active .shell {
  width: min(1280px, calc(100vw - 20px));
  height: 100svh;
  min-height: 0;
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  overflow: hidden;
}

@supports (height: 100dvh) {
  body.is-game-active .shell {
    height: 100dvh;
  }
}

body.is-game-active .topbar {
  min-height: 42px;
  margin-bottom: 8px;
}

body.is-game-active .topbar h1 {
  font-size: clamp(18px, 2.3vw, 28px);
}

body.is-game-active .game-layout {
  height: calc(100% - 50px);
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 10px;
  overflow: hidden;
}

body.is-game-active .stage {
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

body.is-game-active .battle-strip {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

body.is-game-active .desk {
  min-height: 0;
  height: 100%;
  grid-template-columns: clamp(118px, 14vw, 160px) var(--board-width, 300px) clamp(132px, 16vw, 190px);
  gap: clamp(8px, 1.1vw, 14px);
  align-items: start;
}

body.is-game-active .board-wrap {
  align-self: start;
  padding: 10px;
}

body.is-game-active #fxCanvas {
  inset: 10px;
  width: calc(100% - 20px);
}

body.is-game-active .preview-box {
  padding: 8px;
}

body.is-game-active .preview-title {
  margin-bottom: 6px;
  font-size: 11px;
}

body.is-game-active .preview-box button {
  min-height: 34px;
  margin-top: 7px;
}

body.is-game-active .stat-panel {
  gap: 6px;
}

body.is-game-active .stat-pill {
  padding: 7px 8px;
}

body.is-game-active .stat-pill span {
  font-size: 11px;
}

body.is-game-active .stat-pill strong {
  font-size: clamp(16px, 2.3vw, 22px);
}

body.is-game-active .action-panel {
  gap: 7px;
  padding: 8px;
}

body.is-game-active .action-panel button {
  min-height: 36px;
}

body.is-game-active .side-panel {
  max-height: 100%;
  gap: 8px;
  overflow: auto;
  scrollbar-width: thin;
}

body.is-game-active .settings-panel,
body.is-game-active .guide {
  display: none;
}

body.is-game-active .panel {
  padding: 10px;
}

body.is-game-active .panel-title {
  margin-bottom: 8px;
}

body.is-game-active .panel-title h2 {
  font-size: 15px;
}

body.is-game-active .panel-actions button,
body.is-game-active .emoji-row button {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 12px;
}

body.is-game-active .hint {
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.45;
}

body.is-game-active .players {
  grid-template-columns: 1fr;
  gap: 7px;
}

body.is-game-active .player-card {
  padding: 8px;
}

body.is-game-active .mini-board {
  display: none;
}

.panel {
  padding: 14px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-title button {
  padding: 8px 10px;
  font-size: 13px;
}

.hint,
.guide p,
.join-note {
  color: var(--muted);
  line-height: 1.65;
}

.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.player-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.player-card.offline {
  opacity: 0.58;
}

.player-card.ready {
  border-color: rgba(155, 243, 138, 0.5);
}

.player-card.eliminated {
  border-color: rgba(255, 102, 126, 0.45);
  background: rgba(255, 102, 126, 0.08);
}

.player-card header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.player-card strong,
.player-card span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-card span {
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 99px;
  background: var(--mint);
}

.offline .status-dot {
  background: var(--danger);
}

.mini-board {
  width: 100%;
  aspect-ratio: 1 / 2;
  border-radius: 6px;
  background: rgba(3, 4, 6, 0.9);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.dead {
  color: var(--danger);
}

.emoji-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.emoji-row button {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--text);
  background: var(--paper-strong);
  border: 1px solid var(--line);
}

.emoji-toast {
  position: fixed;
  right: 18px;
  top: 86px;
  z-index: 30;
  max-width: min(320px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.82);
  box-shadow: var(--shadow);
  animation: toast-in 220ms ease-out both;
}

.ranking-list {
  display: grid;
  gap: 8px;
}

.rank-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.rank-badge {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--paper-strong);
  font-weight: 1000;
}

.rank-row.rank-1 .rank-badge {
  background: var(--yellow);
  color: var(--ink);
}

.rank-row.rank-2 .rank-badge {
  background: #d9e5f2;
  color: var(--ink);
}

.rank-row.rank-3 .rank-badge {
  background: #dca976;
  color: var(--ink);
}

.rank-score {
  color: var(--muted);
  font-size: 13px;
}

.avatar-grid {
  display: grid;
  gap: 10px;
}

.avatar-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.16);
}

.avatar-preview {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(0, 0, 0, 0.28);
}

.avatar-controls {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 7px 8px;
  align-items: center;
}

.piece-type {
  color: var(--mint);
  font-weight: 1000;
}

.avatar-controls input[type="text"],
.join-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.24);
  outline: none;
}

.avatar-controls input[type="text"]:focus,
.join-card input:focus {
  border-color: rgba(155, 243, 138, 0.62);
  box-shadow: 0 0 0 3px rgba(155, 243, 138, 0.12);
}

.file-label {
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--paper-strong);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.file-label:hover {
  filter: brightness(1.08);
}

.file-label input {
  display: none;
}

.avatar-message {
  grid-column: 1 / -1;
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
}

.join-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 30%, rgba(155, 243, 138, 0.2), transparent 32%),
    rgba(4, 5, 7, 0.84);
  z-index: 10;
}

.join-card {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 19, 23, 0.92);
  box-shadow: var(--shadow);
}

.join-card h2 {
  margin-bottom: 0;
  font-size: 30px;
}

.join-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.join-card button {
  padding: 12px 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  translate: -50% 0;
  max-width: min(560px, calc(100vw - 28px));
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.84);
  z-index: 20;
  animation: toast-in 220ms ease-out both;
}

@keyframes board-hit {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  34% { transform: translate3d(2px, 2px, 0) scale(0.996); }
  68% { transform: translate3d(-1px, 0, 0) scale(1.002); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes board-hard-hit {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  25% { transform: translate3d(0, 6px, 0) scale(0.992); }
  55% { transform: translate3d(-3px, -1px, 0) scale(1.004); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes board-line-hit {
  0% { box-shadow: var(--shadow), 0 0 0 rgba(255, 214, 107, 0); }
  38% { transform: translate3d(0, -2px, 0) scale(1.01); box-shadow: var(--shadow), 0 0 46px rgba(255, 214, 107, 0.42); }
  100% { transform: translate3d(0, 0, 0) scale(1); box-shadow: var(--shadow), 0 0 0 rgba(255, 214, 107, 0); }
}

@keyframes countdown-pop {
  0% { opacity: 0; transform: scale(0.82); }
  22% { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes combo-pop {
  0% { opacity: 0; transform: translateY(18px) scale(0.82); }
  16% { opacity: 1; transform: translateY(0) scale(1.08); }
  70% { opacity: 1; transform: translateY(-8px) scale(1); }
  100% { opacity: 0; transform: translateY(-24px) scale(0.96); }
}

@keyframes stat-bump {
  0% { transform: scale(1); color: var(--text); }
  42% { transform: scale(1.18); color: var(--mint); }
  100% { transform: scale(1); color: var(--text); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes warning-pulse {
  from { transform: scale(0.98); opacity: 0.78; }
  to { transform: scale(1.04); opacity: 1; }
}

@keyframes victory-pop {
  0% { opacity: 0; transform: translateY(20px) scale(0.82); }
  18% { opacity: 1; transform: translateY(0) scale(1.08); }
  100% { opacity: 1; transform: translateY(-8px) scale(1); }
}

@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .desk {
    grid-template-columns: minmax(104px, 132px) minmax(240px, 380px) minmax(116px, 150px);
    justify-content: center;
  }

  body.is-game-active .game-layout {
    grid-template-columns: 1fr;
  }

  body.is-game-active .side-panel {
    display: none;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 18px, 520px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .room-chip,
  .volume-control,
  .ghost-button {
    flex: 1 1 auto;
  }

  .desk {
    grid-template-columns: 64px minmax(180px, 300px) 64px;
    align-items: start;
  }

  .mobile-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-actions {
    width: 100%;
  }

  .panel-actions button {
    flex: 1;
  }

  .avatar-controls {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .file-label {
    grid-column: 1 / -1;
  }

  body.is-game-active .shell {
    width: 100%;
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  }

  body.is-game-active .topbar {
    min-height: 30px;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
  }

  body.is-game-active .topbar > div:first-child {
    min-width: 0;
  }

  body.is-game-active .topbar .eyebrow {
    display: none;
  }

  body.is-game-active .topbar h1 {
    max-width: 34vw;
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.is-game-active .top-actions {
    flex: 1;
    justify-content: flex-end;
    gap: 5px;
    flex-wrap: nowrap;
    min-width: 0;
  }

  body.is-game-active .volume-control {
    display: none;
  }

  body.is-game-active .ghost-button,
  body.is-game-active .room-chip {
    flex: 0 1 auto;
    min-height: 28px;
    padding: 4px 7px;
    font-size: 12px;
  }

  body.is-game-active .game-layout {
    height: calc(100% - 34px);
    display: block;
    overflow: hidden;
  }

  body.is-game-active .stage {
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 5px;
  }

  body.is-game-active .battle-strip {
    min-height: 26px;
    padding: 4px 7px;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.is-game-active .desk {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 5px;
    align-items: start;
    justify-content: center;
    min-height: 0;
    height: 100%;
  }

  body.is-game-active .left-rail,
  body.is-game-active .right-rail,
  body.is-game-active .primary-stats,
  body.is-game-active .battle-stats {
    display: contents;
  }

  body.is-game-active .primary-stats .stat-pill:nth-child(1) { grid-column: 1; }
  body.is-game-active .primary-stats .stat-pill:nth-child(2) { grid-column: 2; }
  body.is-game-active .primary-stats .stat-pill:nth-child(3) { grid-column: 3; }
  body.is-game-active .battle-stats .stat-pill:nth-child(1) { grid-column: 4; }
  body.is-game-active .battle-stats .stat-pill:nth-child(2) { grid-column: 5; }
  body.is-game-active .battle-stats .stat-pill:nth-child(3) { grid-column: 6; }

  body.is-game-active .stat-pill {
    grid-row: 1;
    min-height: 32px;
    padding: 4px 3px;
    text-align: center;
  }

  body.is-game-active .stat-pill span {
    font-size: 10px;
    line-height: 1;
  }

  body.is-game-active .stat-pill strong {
    margin-top: 1px;
    font-size: clamp(12px, 3.5vw, 16px);
  }

  body.is-game-active .hold-box {
    grid-column: 1;
    grid-row: 2;
  }

  body.is-game-active .board-wrap {
    grid-column: 2 / 6;
    grid-row: 2;
    width: min(100%, var(--board-width, 230px));
    padding: 5px;
    align-self: start;
  }

  body.is-game-active #fxCanvas {
    inset: 5px;
    width: calc(100% - 10px);
  }

  body.is-game-active .next-box {
    grid-column: 6;
    grid-row: 2;
  }

  body.is-game-active .preview-box {
    min-width: 0;
    padding: 5px;
  }

  body.is-game-active .preview-title {
    margin-bottom: 4px;
    font-size: 10px;
    text-align: center;
  }

  body.is-game-active .preview-box button {
    min-height: 28px;
    margin-top: 5px;
    padding: 3px;
    font-size: 11px;
  }

  body.is-game-active .next-list {
    gap: 4px;
  }

  body.is-game-active .action-panel {
    grid-column: 1 / -1;
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
    padding: 0;
    border: 0;
    background: transparent;
    backdrop-filter: none;
  }

  body.is-game-active .action-panel button {
    min-height: 30px;
    font-size: 12px;
  }

  body.is-game-active .mobile-controls {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  body.is-game-active .mobile-controls button {
    min-height: clamp(40px, 7.4svh, 52px);
    padding: 6px 4px;
    font-size: 14px;
  }

  body.is-game-active .countdown,
  body.is-game-active .game-over {
    inset: 5px;
  }

  body.is-game-active .combo-banner {
    min-width: 112px;
    padding: 7px 10px;
    font-size: 18px;
  }
}

@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  body.is-game-active .shell {
    padding: 4px 6px max(4px, env(safe-area-inset-bottom));
  }

  body.is-game-active .topbar {
    min-height: 26px;
    margin-bottom: 3px;
  }

  body.is-game-active .topbar h1 {
    display: none;
  }

  body.is-game-active .top-actions {
    justify-content: space-between;
  }

  body.is-game-active .game-layout {
    height: calc(100% - 29px);
  }

  body.is-game-active .stage {
    grid-template-columns: minmax(0, 1fr) clamp(148px, 25vw, 184px);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 4px 6px;
  }

  body.is-game-active .battle-strip {
    grid-column: 1 / -1;
    min-height: 22px;
    padding: 3px 7px;
  }

  body.is-game-active .desk {
    grid-column: 1;
    grid-row: 2;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 4px;
  }

  body.is-game-active .hold-box,
  body.is-game-active .next-box {
    grid-row: 2;
  }

  body.is-game-active .board-wrap {
    grid-row: 2;
    align-self: start;
    padding: 4px;
  }

  body.is-game-active #fxCanvas {
    inset: 4px;
    width: calc(100% - 8px);
  }

  body.is-game-active .action-panel {
    display: none;
  }

  body.is-game-active .mobile-controls {
    grid-column: 2;
    grid-row: 2;
    align-self: stretch;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 1fr;
    gap: 5px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  body.is-game-active .mobile-controls button {
    min-height: 0;
    padding: 4px;
    font-size: 13px;
  }
}
