:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #13161e;
  --line: #303542;
  --muted: #a5adbe;
  --text: #f4f6ff;
  --lime: #cefa69;
  --violet: #b79bff;
  --danger: #ff758c;
  --display: Impact, "Arial Narrow", "DejaVu Sans Condensed", sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  --view-height: 100vh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: var(--ui);
  background: var(--bg);
  color: var(--text);
}
/* A stable viewport keeps browser toolbar changes from moving a held control. */
@supports (height: 100svh) {
  :root {
    --view-height: 100svh;
  }
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-width: 280px;
}
button,
input,
select {
  font: inherit;
}
button,
summary,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}
button,
summary {
  cursor: pointer;
}
button {
  min-height: 44px;
  min-width: 44px;
  border: 1px solid transparent;
  padding: 10px 16px;
  font-weight: 750;
  color: inherit;
  background: transparent;
  border-radius: 4px;
  touch-action: manipulation;
}
button:disabled {
  opacity: 0.38;
  cursor: default;
}
button:focus-visible,
summary:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 4px;
}
button:not(:disabled):active {
  translate: 0 1px;
}
input,
select {
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  background: #0d1017;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 16px;
}
input:focus,
select:focus {
  outline: 2px solid var(--violet);
  outline-offset: 1px;
}
input[type="checkbox"] {
  accent-color: var(--lime);
  width: 20px;
  min-height: 20px;
  flex-shrink: 0;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--lime);
  padding: 0;
}
input[readonly] {
  color: var(--muted);
}
label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 8px;
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1 {
  font-size: clamp(26px, 4vw, 42px);
  letter-spacing: -0.05em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
h2 {
  font-size: 17px;
  letter-spacing: -0.02em;
}
h3 {
  font-size: 16px;
}
canvas {
  display: block;
  max-width: 100%;
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.primary {
  background: var(--lime);
  color: #17220a;
}
.secondary {
  background: #232834;
  border-color: #3e4556;
}
.quiet {
  color: var(--muted);
}
.topbar {
  height: calc(68px + var(--safe-top));
  padding: var(--safe-top) max(24px, var(--safe-right)) 0 max(24px, var(--safe-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid #242832;
}
.brand {
  display: flex;
  align-items: center;
  padding: 0 8px 0 0;
  font: italic 32px/1 var(--display);
  letter-spacing: -1px;
}
.brand-mark {
  font-style: normal;
  color: var(--lime);
  font-size: 30px;
  margin-right: 12px;
}
.brand-dot {
  color: var(--lime);
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.top-actions button,
.game-actions button {
  white-space: nowrap;
}
.topbar > .top-actions {
  margin-left: auto;
}
.game-actions {
  display: none;
  align-items: center;
  gap: 4px;
}
body[data-screen="game"] .game-actions {
  display: flex;
}
#connection {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--lime);
  white-space: nowrap;
}
#connection:empty {
  display: none;
}
main {
  max-width: 1440px;
  margin: auto;
  padding: 0 max(24px, var(--safe-right)) max(16px, var(--safe-bottom)) max(24px, var(--safe-left));
}
.eyebrow {
  font: 700 12px/1.5 var(--ui);
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 8px;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 32px;
}
.section-head > div:first-child {
  min-width: 0;
}
.section-head > .top-actions {
  flex-shrink: 0;
}
.lobby,
.room {
  max-width: 1056px;
  margin: 0 auto;
  padding: 48px 0;
}
.home {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  align-items: center;
  gap: clamp(32px, 6vw, 100px);
  max-width: 1136px;
  margin: auto;
  min-height: calc(var(--view-height) - 100px);
  padding: 36px 0 60px;
}
.home-menu {
  max-width: 470px;
  width: 100%;
}
.display-title {
  font: italic clamp(80px, 9vw, 136px)/0.92 var(--display);
  letter-spacing: -0.045em;
  margin: 10px 0 34px;
}
.display-title span {
  color: var(--lime);
}
.solo-choice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}
.solo-choice label {
  margin: 0;
  color: var(--text);
  font-size: 18px;
}
.solo-choice select {
  background: transparent;
  border: 0;
  text-align: right;
}
.mode-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  min-height: 86px;
  padding: 20px 26px;
  border-radius: 0;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%);
  font-size: clamp(22px, 2.4vw, 30px);
  letter-spacing: -0.045em;
}
.mode-button:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--text);
}
.mode-arrow {
  font: 40px/1 var(--ui);
  font-weight: 400;
}
.multi-button {
  background: #29223e;
  color: #e3d5ff;
  border: none;
  margin-top: 14px;
  min-height: 106px;
}
.mode-button small {
  display: block;
  margin-top: 8px;
  font: 500 13px/1.5 var(--ui);
  letter-spacing: 0;
  color: #c1b3dd;
}
.best-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  margin-top: 28px;
  padding: 18px 0;
  color: var(--muted);
  font-size: 13px;
}
.best-row strong {
  font: 24px var(--display);
  letter-spacing: 0.03em;
  color: var(--text);
}
.home-art {
  position: relative;
  height: 500px;
  isolation: isolate;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, #483b6128, transparent 65%);
}
.art-word {
  position: absolute;
  left: 0;
  bottom: 38px;
  font: italic clamp(96px, 12vw, 174px)/1 var(--display);
  letter-spacing: -0.055em;
  color: #cfd7ee0d;
  -webkit-text-stroke: 1px #59637b66;
  transform: rotate(-8deg);
  z-index: -1;
}
.art-orbit {
  position: absolute;
  width: 350px;
  height: 350px;
  left: 14%;
  top: 8%;
  border: 1px solid #66739225;
  transform: rotate(-18deg);
  background: linear-gradient(135deg, #33476913, transparent 60%);
}
.art-orbit::before,
.art-orbit::after {
  content: "";
  position: absolute;
  inset: 28px;
  border: 1px solid #6673921c;
}
.art-orbit::after {
  inset: 56px;
}
.art-piece {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 4px;
  transform: rotate(-12deg);
  filter: drop-shadow(0 16px 16px #0005);
}
.art-piece i {
  background: var(--piece);
  border: 2px solid #ffffff38;
  box-shadow:
    inset 5px 5px #ffffff20,
    inset -5px -5px #0002;
}
.piece-t {
  --piece: #a184ef;
  left: 24%;
  top: 15%;
}
.piece-t i:first-child,
.piece-s i:first-child {
  grid-column: 2;
}
.piece-t i:nth-child(2),
.piece-s i:nth-child(3) {
  grid-column: 1;
  grid-row: 2;
}
.piece-t i:nth-child(3),
.piece-s i:nth-child(4) {
  grid-column: 2;
  grid-row: 2;
}
.piece-t i:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}
.piece-i {
  --piece: #8bdded;
  grid-template-columns: repeat(4, 48px);
  grid-template-rows: 48px;
  left: 18%;
  top: 55%;
  transform: rotate(16deg);
}
.piece-s {
  --piece: #cefa69;
  left: 51%;
  top: 63%;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(2, 40px);
  transform: rotate(-14deg);
}
.piece-s i:nth-child(2) {
  grid-column: 3;
}
.lobby-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 48px;
}
.create-panel {
  border-right: 1px solid var(--line);
  padding-right: 32px;
}
.create-panel > input,
.create-panel form > input {
  width: 100%;
  margin-bottom: 20px;
}
.create-panel h2 {
  margin: 12px 0 20px;
}
.field-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.field-row > div {
  flex: 1;
  min-width: 0;
}
.field-row input,
.field-row select {
  width: 100%;
}
.field-row > button {
  flex-shrink: 0;
  white-space: nowrap;
}
.check {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  margin: 0;
  cursor: pointer;
  color: var(--text);
}
.room-options {
  margin: 16px 0;
}
.create-panel .primary {
  width: 100%;
}
#join-form {
  border-top: 1px solid var(--line);
  margin-top: 28px;
  padding-top: 22px;
}
.rooms-panel h2 {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}
#rooms-count {
  font: 16px var(--display);
  color: var(--violet);
  margin-left: 8px;
}
.room-entry {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}
.room-entry > div {
  min-width: 0;
}
.room-entry h3 {
  overflow-wrap: anywhere;
}
.room-entry p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  margin-top: 8px;
}
.room-entry button {
  flex-shrink: 0;
}
.empty {
  padding: 52px 0;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}
.members {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 24px 0;
}
.member {
  padding: 20px 22px 20px 28px;
  background: var(--panel);
  border-left: 3px solid #515b70;
}
.member strong {
  display: block;
  overflow-wrap: anywhere;
}
.member small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}
.member.is-ready {
  border-color: var(--lime);
  background: #17201a;
}
.waiting-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 24px 0;
}
.waiting-actions p {
  margin-right: auto;
  color: var(--muted);
}
.invite-box {
  margin: 24px 0;
  padding: 20px;
  border: 1px solid var(--line);
}
.invite-box input {
  width: 100%;
}
#invite-status {
  display: block;
  color: var(--lime);
  font-size: 13px;
  margin-top: 8px;
}
/* Board fills the viewport height after topbar, game-top, hint and battle rows; width guard keeps the side columns on screen. */
.arena {
  --extra-height: 0px;
  --board-width: min(
    560px,
    calc((var(--view-height) - 204px - var(--extra-height) - var(--safe-top) - var(--safe-bottom)) / 2),
    calc(100vw - 380px - var(--safe-left) - var(--safe-right))
  );
  max-width: 1250px;
  margin: auto;
  padding-top: 16px;
}
.arena.multiplayer-game {
  --extra-height: 56px;
}
.arena:has(#inventory:not([hidden])) {
  --extra-height: 96px;
}
.game-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 620px;
  margin: 0 auto 14px;
  min-height: 44px;
}
#mode-label {
  font-weight: 750;
  font-size: 14px;
}
#survivors {
  font-size: 12px;
  font-weight: 700;
  color: var(--lime);
  white-space: nowrap;
}
.game-layout {
  display: grid;
  grid-template-columns: 120px var(--board-width) 100px;
  justify-content: center;
  gap: 12px;
  align-items: start;
}
.left-rail,
.right-rail {
  min-width: 0;
}
.piece-box {
  background: #080d16;
  border-top: 2px solid #5e6d89;
  padding-top: 10px;
}
.piece-box h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font: 14px var(--display);
  letter-spacing: 0.09em;
  padding: 0 10px;
  color: #cbd5e9;
}
.piece-box canvas {
  width: 100%;
  height: auto;
}
.stats {
  margin: 20px 0 0;
}
.stats > div {
  margin: 0 0 16px;
}
.stats dt {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
}
.stats dd {
  margin: 0;
  font: 24px/1.1 var(--display);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  letter-spacing: 0.02em;
}
.stats .score-row dd {
  color: var(--lime);
  font-size: 29px;
}
.board-wrap {
  position: relative;
  border: 1px solid #74839c;
  border-top: 2px solid #e6ecf8;
  border-bottom: 2px solid var(--lime);
  box-shadow:
    0 0 0 5px #171d284d,
    0 18px 56px #0006;
  min-width: 0;
}
#board {
  width: 100%;
  height: auto;
  aspect-ratio: 1/2;
}
.garbage-track {
  position: absolute;
  left: -8px;
  top: -2px;
  bottom: -2px;
  width: 4px;
  background: #242333;
  display: flex;
  align-items: flex-end;
}
#garbage {
  width: 100%;
  background: var(--danger);
  box-shadow: 0 0 12px #ff758c55;
  transition: height 0.1s linear;
}
.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 18px;
  gap: 18px;
  text-align: center;
  background: #070b13e8;
  z-index: 3;
  overflow: auto;
}
.board-overlay h2 {
  font: italic clamp(24px, 3.2vw, 44px)/1.05 var(--display);
  letter-spacing: -0.02em;
  max-width: 100%;
  overflow-wrap: anywhere;
}
#overlay-kicker {
  font-size: 10px;
  color: var(--lime);
  letter-spacing: 0.15em;
}
#overlay-detail {
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.board-overlay p:empty {
  display: none;
}
.callout {
  position: absolute;
  left: -15%;
  right: -15%;
  top: 43%;
  text-align: center;
  font: italic clamp(30px, 4vw, 54px)/1 var(--display);
  color: var(--lime);
  text-shadow:
    3px 3px 0 #0b0d12,
    -1px -1px 0 #0b0d12;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
  white-space: nowrap;
}
.callout small {
  display: block;
  font: 700 11px/1.5 var(--ui);
  margin-top: 10px;
  color: var(--text);
  letter-spacing: 0.05em;
}
.callout.pop {
  animation: clear-pop 0.85s both;
}
.inventory {
  grid-column: 1/4;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.inventory h2 {
  font-size: 12px;
  color: var(--muted);
  margin-right: 4px;
}
.inventory button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 8px;
  background: #211e30;
  border-color: #4c405f;
  font-size: 12px;
}
.inventory button:not(:disabled) {
  color: #e3d5ff;
}
.defense {
  font-size: 11px;
  line-height: 1.8;
  color: var(--violet);
}
.defense span {
  display: block;
}
kbd {
  font: 10px var(--ui);
  color: var(--muted);
  border: 1px solid #3a4355;
  border-radius: 3px;
  padding: 2px 4px;
}
.opponents {
  min-width: 0;
  border-top: 1px solid var(--line);
}
.opponents summary {
  min-height: 44px;
  padding: 12px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 750;
  list-style: none;
}
.opponents summary::-webkit-details-marker {
  display: none;
}
.opponents summary span {
  color: var(--violet);
}
.opponents details[open] summary span {
  rotate: 90deg;
}
.opponents-content {
  padding: 0 0 12px;
}
.opponents-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.opponents-head label {
  margin: 0;
  white-space: nowrap;
}
.opponents select {
  font-size: 16px;
  max-width: 100%;
}
#atlas {
  width: 100%;
  height: auto;
  cursor: crosshair;
}
#target-select-row {
  margin-top: 12px;
}
#target-player {
  width: 100%;
}
.battle-feed {
  grid-column: 1/4;
  min-height: 18px;
  line-height: 1.4;
  font-size: 12px;
  color: var(--violet);
  overflow-wrap: anywhere;
}
.battle-feed:empty {
  display: none;
}
.multiplayer-game .game-top {
  max-width: 100%;
}
.multiplayer-game .game-layout {
  grid-template-columns: 110px var(--board-width) 90px minmax(230px, 1fr);
  column-gap: 16px;
}
.multiplayer-game .opponents {
  grid-column: 4;
  grid-row: 1/4;
  margin-left: 12px;
  max-height: calc(var(--board-width) * 2 + 8px);
  overflow: auto;
  scrollbar-width: thin;
}
.keyboard-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin: 18px 0 0;
  line-height: 2;
}
.keyboard-hint span {
  margin-left: 12px;
}
.touch-controls {
  display: none;
}
.error {
  max-width: 650px;
  margin: 18px auto;
  padding: 14px 18px;
  background: #301722;
  border-left: 3px solid var(--danger);
  color: #ffd0d9;
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
dialog {
  border: 1px solid #4b5264;
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  width: min(460px, calc(100% - 28px));
  max-height: calc(var(--view-height) - 32px - var(--safe-top) - var(--safe-bottom));
  padding: 24px;
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: #02040ac9;
}
dialog .section-head {
  margin-bottom: 24px;
}
dialog label:not(.check) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
dialog output {
  color: var(--lime);
  font-variant-numeric: tabular-nums;
}
dialog input[type="range"] {
  margin: 0 0 22px;
  min-height: 44px;
}
dialog select {
  width: 100%;
  margin-bottom: 18px;
}
dialog .check {
  margin-bottom: 14px;
}
dialog summary {
  padding: 14px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
  min-height: 44px;
}
dialog details p {
  font-size: 13px;
  line-height: 1.9;
  color: var(--muted);
  margin-bottom: 16px;
}
@keyframes clear-pop {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.92);
  }
  15%,
  70% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-12px);
  }
}
@media (hover: hover) {
  .primary:hover {
    background: #dfff8d;
  }
  .secondary:hover {
    background: #343949;
  }
  .multi-button:hover {
    background: #382d51;
  }
  .quiet:hover {
    color: var(--text);
    background: #ffffff09;
  }
  .mode-button:hover .mode-arrow {
    translate: 3px -3px;
  }
  .mode-arrow {
    transition: translate 0.15s;
  }
}
@media (max-width: 960px) {
  .home {
    gap: 36px;
  }
  .home-art {
    height: 420px;
  }
  .art-piece {
    scale: 0.85;
  }
  .art-orbit {
    left: 0;
    width: 300px;
    height: 300px;
  }
  .piece-t {
    left: 16%;
  }
  .piece-s {
    left: 45%;
  }
}
@media (max-width: 640px) {
  .topbar {
    height: calc(58px + var(--safe-top));
    padding-left: max(12px, var(--safe-left));
    padding-right: max(12px, var(--safe-right));
  }
  .brand {
    font-size: 26px;
  }
  .brand-mark {
    font-size: 24px;
    margin-right: 8px;
  }
  .top-actions {
    gap: 2px;
  }
  .top-actions button {
    padding: 8px 10px;
    font-size: 12px;
  }
  #connection {
    font-size: 10px;
    max-width: 62px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  main {
    padding-left: max(12px, var(--safe-left));
    padding-right: max(12px, var(--safe-right));
  }
  .home {
    display: block;
    min-height: 0;
    padding: 36px 0;
  }
  .home-menu {
    max-width: 470px;
    margin: auto;
  }
  .home-art {
    display: none;
  }
  .display-title {
    font-size: 88px;
    margin: 8px 0 28px;
  }
  .mode-button {
    min-height: 80px;
    padding: 18px 22px;
    font-size: 25px;
  }
  .multi-button {
    min-height: 96px;
  }
  .best-row {
    margin-top: 24px;
  }
  .lobby,
  .room {
    padding: 28px 0;
  }
  .section-head {
    gap: 12px;
    margin-bottom: 24px;
  }
  .lobby-layout {
    display: flex;
    flex-direction: column;
    gap: 32px;
  }
  .create-panel {
    border-right: 0;
    padding-right: 0;
  }
  .room-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
  }
  .rooms-panel {
    border-top: 1px solid var(--line);
    padding-top: 24px;
  }
  .members {
    grid-template-columns: 1fr;
  }
  .waiting-actions {
    flex-wrap: wrap;
  }
  .waiting-actions p {
    flex-basis: 100%;
  }
}
/* Desktop scale: rails and display type grow with the board. */
@media (min-width: 961px) and (pointer: fine) {
  .game-top {
    max-width: calc(var(--board-width) + 304px);
  }
  .game-layout {
    grid-template-columns: 150px var(--board-width) 130px;
  }
  .multiplayer-game .game-layout {
    grid-template-columns: 150px var(--board-width) 130px minmax(260px, 1fr);
  }
  .piece-box h2 {
    font-size: 16px;
  }
  .stats dd {
    font-size: 30px;
  }
  .stats .score-row dd {
    font-size: 36px;
  }
  .callout {
    font-size: clamp(38px, 4.6vw, 68px);
  }
  .board-overlay h2 {
    font-size: clamp(32px, 3.4vw, 56px);
  }
}
/* One input layout for phones, tablets and touch-enabled laptops. */
@media (max-width: 960px), (any-pointer: coarse) {
  body[data-screen="game"] .topbar {
    height: calc(48px + var(--safe-top));
    gap: 6px;
  }
  body[data-screen="game"] .brand {
    display: none;
  }
  body[data-screen="game"] .topbar > .top-actions {
    margin: 0 auto 0 0;
    gap: 2px;
  }
  body[data-screen="game"] .topbar button {
    padding: 6px;
    font-size: 12px;
  }
  body[data-screen="game"] #connection {
    max-width: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
  }
  body[data-screen="game"] main {
    padding-bottom: max(8px, var(--safe-bottom));
    display: flex;
    flex-direction: column;
    min-height: calc(var(--view-height) - 48px - var(--safe-top) - var(--safe-bottom));
  }
  .arena {
    --rail-left: 58px;
    --rail-right: 50px;
    --board-width: min(
      320px,
      calc((var(--view-height) - 242px - var(--extra-height) - var(--safe-top) - var(--safe-bottom)) / 2),
      calc(100vw - 156px - var(--safe-left) - var(--safe-right))
    );
    padding-top: 0;
    display: flex;
    flex-direction: column;
    flex: 1;
  }
  .arena.multiplayer-game {
    --extra-height: 80px;
  }
  .arena:has(#inventory:not([hidden])) {
    --extra-height: 132px;
  }
  .game-top,
  .multiplayer-game .game-top {
    min-height: 20px;
    margin: auto auto 8px;
    gap: 4px;
    max-width: 480px;
  }
  #mode-label {
    font-size: 12px;
  }
  .game-top .top-actions {
    gap: 0;
  }
  .game-top button {
    padding: 8px;
    font-size: 12px;
  }
  #survivors {
    font-size: 10px;
  }
  .game-layout,
  .multiplayer-game .game-layout {
    grid-template-columns: var(--rail-left) var(--board-width) var(--rail-right);
    gap: 8px;
    justify-content: center;
    margin-bottom: auto;
  }
  .left-rail {
    display: contents;
  }
  .left-rail > .piece-box {
    grid-column: 1;
    grid-row: 2;
  }
  .right-rail {
    grid-column: 3;
    grid-row: 2;
  }
  .board-wrap {
    grid-column: 2;
    grid-row: 2;
    box-shadow: 0 0 0 3px #171d284d;
  }
  .stats {
    grid-column: 1/4;
    grid-row: 1;
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 8px;
    margin: 0;
    min-height: 32px;
  }
  .stats > div {
    margin: 0;
    min-width: 0;
  }
  .stats dt {
    font-size: 10px;
    margin-bottom: 2px;
  }
  .stats dd,
  .stats .score-row dd {
    font: 600 14px/1.15 var(--ui);
    letter-spacing: -0.02em;
    white-space: nowrap;
  }
  .piece-box {
    padding-top: 7px;
  }
  .piece-box h2 {
    font-size: 11px;
    letter-spacing: 0.04em;
    padding: 0 5px;
  }
  .piece-box kbd {
    display: none;
  }
  .garbage-track {
    left: -5px;
    width: 3px;
  }
  .defense {
    grid-column: 1;
    grid-row: 2;
    align-self: end;
    font-size: 10px;
  }
  .inventory {
    gap: 6px;
  }
  .inventory h2,
  .inventory kbd {
    display: none;
  }
  .inventory button {
    min-height: 44px;
    padding: 8px 4px;
    font-size: 11px;
    gap: 5px;
  }
  /* Opponent boards stay visible beside the board; the summary toggles only attack targeting. */
  .multiplayer-game .opponents {
    position: static;
    grid-column: 1;
    grid-row: 2;
    align-self: start;
    margin: 70px 0 0;
    max-height: none;
    overflow: visible;
    border-top: 0;
  }
  .multiplayer-game .opponents summary {
    padding: 6px 0;
    font-size: 10px;
  }
  .multiplayer-game .opponents summary span {
    display: none;
  }
  .opponents-content {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 0 0 6px;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  .opponents-head select {
    width: 100%;
  }
  #atlas {
    width: 100%;
    height: auto;
    max-height: none;
    margin: 0;
  }
  .battle-feed {
    grid-column: 1/4;
    min-height: 18px;
    max-height: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
  }
  .multiplayer-game .battle-feed:empty {
    display: block;
  }
  .game-layout {
    position: relative;
  }
  .callout {
    font-size: clamp(22px, 7vw, 34px);
    left: -18%;
    right: -18%;
  }
  .callout small {
    font-size: 9px;
    white-space: normal;
  }
  .board-overlay {
    padding: 10px;
    gap: 10px;
  }
  .board-overlay h2 {
    font-size: 24px;
  }
  #overlay-detail {
    font-size: 12px;
  }
  .board-overlay button {
    padding: 8px 12px;
    flex-shrink: 0;
  }
  .keyboard-hint {
    display: none;
  }
  .touch-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "move rotate" "hold drop";
    gap: 10px 18px;
    width: min(480px, 100%);
    margin: 14px auto 0;
    padding-bottom: 4px;
    user-select: none;
    -webkit-user-select: none;
  }
  .touch-controls button {
    min-width: 44px;
    min-height: 48px;
    padding: 4px;
    border: 1px solid #40495a;
    background: #1c2330;
    color: #e3eaff;
    border-radius: 7px;
    touch-action: none;
    box-shadow: 0 3px 0 #06090e;
  }
  .touch-controls button span {
    font: 26px/1 var(--ui);
  }
  .touch-move {
    grid-area: move;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .touch-rotate {
    grid-area: rotate;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .touch-rotate button {
    background: #29243b;
    border-color: #53476e;
    color: #e0d1ff;
  }
  .hold-key {
    grid-area: hold;
    font-size: 12px;
    letter-spacing: 0.1em;
  }
  .touch-controls .drop-key {
    grid-area: drop;
    background: var(--lime);
    border-color: var(--lime);
    color: #1a250c;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.06em;
  }
  .touch-controls button.is-pressed {
    background: #e1f2ff;
    color: #17202c;
    border-color: #fff;
    box-shadow: 0 0 0 2px #ffffff3b;
    translate: 0 2px;
  }
  .touch-controls .drop-key.is-pressed {
    background: #e5ffa8;
    color: #17220a;
  }
  .touch-controls[data-layout="left"] {
    grid-template-areas: "rotate move" "drop hold";
  }
  .error {
    margin: 12px auto;
    font-size: 13px;
  }
}
/* Low landscape: board in the middle, thumbs at the sides, no orientation lock. */
@media (orientation: landscape) and (max-height: 540px) and (max-width: 960px),
  (orientation: landscape) and (max-height: 540px) and (any-pointer: coarse) {
  body[data-screen="game"] .topbar {
    height: calc(44px + var(--safe-top));
    border-bottom: 0;
  }
  .arena,
  .arena.multiplayer-game,
  .arena:has(#inventory:not([hidden])) {
    --extra-height: 0px;
    --rail-left: 42px;
    --rail-right: 38px;
    --board-width: min(
      200px,
      calc((var(--view-height) - 82px - var(--extra-height) - var(--safe-top) - var(--safe-bottom)) / 2),
      calc(100vw - 376px - var(--safe-left) - var(--safe-right))
    );
    position: relative;
    padding: 0 118px;
    min-height: max(234px, calc(var(--view-height) - 52px - var(--safe-top) - var(--safe-bottom)));
  }
  .arena.multiplayer-game {
    --extra-height: 24px;
  }
  .arena:has(#inventory:not([hidden])) {
    --extra-height: 76px;
  }
  .game-top,
  .multiplayer-game .game-top {
    position: absolute;
    left: 0;
    top: 0;
    width: 104px;
    max-width: none;
    margin: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  .game-top #mode-label {
    font-size: 10px;
  }
  .game-layout,
  .multiplayer-game .game-layout {
    position: static;
    padding-top: 0;
    margin: 0;
  }
  .stats {
    min-height: 16px;
    gap: 4px;
  }
  .stats dt {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .stats dd,
  .stats .score-row dd {
    font-size: 11px;
  }
  .touch-controls {
    display: block;
    width: auto;
    margin: 0;
    padding: 0;
  }
  .touch-controls button {
    min-height: 44px;
  }
  .touch-move,
  .touch-rotate,
  .touch-controls .hold-key,
  .touch-controls .drop-key {
    position: absolute;
    width: 104px;
  }
  .touch-move {
    left: 0;
    top: 44px;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "left right" "down down";
  }
  .touch-move [data-action="left"] {
    grid-area: left;
  }
  .touch-move [data-action="right"] {
    grid-area: right;
  }
  .touch-move [data-action="down"] {
    grid-area: down;
  }
  .touch-rotate {
    right: 0;
    top: 44px;
  }
  .touch-controls .hold-key {
    left: 0;
    top: 144px;
  }
  .touch-controls .drop-key {
    right: 0;
    top: 94px;
  }
  .touch-controls[data-layout="left"] .touch-move,
  .touch-controls[data-layout="left"] .hold-key {
    left: auto;
    right: 0;
  }
  .touch-controls[data-layout="left"] .touch-rotate,
  .touch-controls[data-layout="left"] .drop-key {
    right: auto;
    left: 0;
  }
  .inventory {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
  }
  .multiplayer-game .opponents {
    position: absolute;
    top: 144px;
    right: 0;
    width: 104px;
    margin: 0;
  }
  .arena:has(.touch-controls[data-layout="left"]) .opponents {
    left: 0;
    right: auto;
  }
  .opponents-content {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 0 0 4px;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  #atlas {
    max-height: 150px;
    width: auto;
    max-width: 100%;
    margin: auto;
  }
  .battle-feed {
    position: absolute;
    left: 118px;
    right: 118px;
    bottom: 0;
    font-size: 10px;
  }
  .arena:has(#inventory:not([hidden])) .battle-feed {
    bottom: 52px;
  }
  .board-overlay {
    gap: 6px;
    padding: 6px;
  }
  .board-overlay h2 {
    font-size: 18px;
  }
  #overlay-kicker {
    font-size: 8px;
  }
  #overlay-detail {
    font-size: 10px;
  }
  .callout {
    font-size: 24px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    transition: none !important;
  }
  .callout.pop {
    animation: none;
    opacity: 1;
    transform: none;
  }
}
.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation: none !important;
  transition: none !important;
}
.reduce-motion .callout.pop {
  opacity: 1;
  transform: none;
}
