:root {
  color-scheme: light;
  --paper: #eeede7;
  --surface: #fafaf5;
  --ink: #20231f;
  --muted: #52584f;
  --accent: #c51647;
  --line: #c5c8bd;
  --pink: #ff3869;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  margin: 0;
}
main {
  max-width: 1296px;
  height: 100dvh;
  margin: auto;
  padding: max(28px, env(safe-area-inset-top))
    max(32px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom))
    max(32px, env(safe-area-inset-left));
  overflow: auto;
  scrollbar-color: #898e83 var(--paper);
}
::selection {
  background: #ffc6d4;
  color: var(--ink);
}
button,
input {
  font: inherit;
}
button,
input,
summary {
  outline-offset: 3px;
}
button:focus-visible,
input:focus-visible,
summary:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--accent);
}
canvas:focus-visible {
  outline-offset: -3px;
}
a {
  color: var(--accent);
  text-underline-offset: 3px;
}
button {
  min-height: 48px;
  border: 1px solid var(--ink);
  border-radius: 3px;
  padding: 10px 22px;
  background: var(--ink);
  color: var(--surface);
  cursor: pointer;
  font-weight: 650;
}
@media (hover: hover) {
  button:hover {
    background: #3f473b;
  }
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.55;
  cursor: wait;
}
.secondary {
  background: transparent;
  color: var(--ink);
}
@media (hover: hover) {
  .secondary:hover {
    background: #dcdfd3;
  }
}
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 28px;
}
h1 {
  font-size: clamp(32px, 4vw, 48px);
  line-height: 1.05;
  letter-spacing: -0.035em;
  margin: 0 0 10px;
  font-weight: 800;
}
.title-dot {
  color: var(--accent);
}
.masthead p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}
.edition {
  font-size: 11px;
  letter-spacing: 0.12em;
  font-weight: 750;
  border-block: 1px solid var(--ink);
  padding: 9px 0;
  white-space: nowrap;
}
.connection {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}
.connection label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  font-weight: 650;
}
.connection-actions {
  display: flex;
  gap: 8px;
}
input {
  width: 100%;
  min-height: 48px;
  /* Prevent automatic focus zoom on mobile Safari for both editable fields. */
  font-size: 16px;
  background: var(--surface);
  border: 1px solid #898e83;
  border-radius: 3px;
  padding: 10px 12px;
  caret-color: var(--accent);
  color: var(--ink);
}
#server {
  font-family: ui-monospace, monospace;
}
.field-help {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 16px;
  line-height: 1.5;
}
.connection-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px 24px;
  font-size: 13px;
  color: var(--muted);
}
#status {
  margin: 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
#status[data-error="true"] {
  color: #a31a32;
  border-left: 3px solid currentColor;
  padding-left: 10px;
}
details {
  max-width: 460px;
  min-width: min(240px, 100%);
}
summary {
  cursor: pointer;
  text-underline-offset: 3px;
  text-decoration: underline;
  line-height: 1.6;
}
details p {
  line-height: 1.7;
  background: var(--surface);
  padding: 12px;
  border: 1px solid var(--line);
}
code {
  font-size: 0.95em;
  overflow-wrap: anywhere;
}
.how-to-play {
  margin: 20px 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.how-to-play p {
  margin: 4px 0;
}
.how-to-play span {
  padding: 0 5px;
}
kbd {
  font-family: inherit;
  font-weight: 700;
  color: var(--ink);
}
.game {
  border: 1px solid var(--ink);
  background: var(--surface);
}
.scoreboard {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  gap: 12px;
}
.team {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  letter-spacing: 0.06em;
  font-weight: 700;
  flex: 1;
}
.team strong {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}
.white {
  justify-content: flex-end;
}
.swatch {
  flex: 0 0 16px;
  height: 16px;
  background: var(--ink);
  border: 1px solid var(--ink);
}
.white .swatch {
  background: var(--surface);
}
.round {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 96px;
}
.round span {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 650;
}
.round strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.coverage {
  flex-shrink: 0;
  height: 4px;
  background: #adb1a6;
  display: flex;
  justify-content: space-between;
}
.coverage span {
  width: 0;
  transition: width 0.15s linear;
}
#black-bar {
  background: var(--ink);
}
#white-bar {
  background: var(--surface);
}
.arena {
  position: relative;
  background: var(--paper);
  isolation: isolate;
}
/* Decorative frame is outside the physics canvas, never a paintable surface. */
.world-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 13/8;
}
#boundary {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#world {
  position: absolute;
  left: 1.923077%;
  top: 3.125%;
  width: 96.153846%;
  height: 93.75%;
  display: block;
  touch-action: none;
}

.empty {
  position: absolute;
  inset: 3.125% 1.923077%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  pointer-events: none;
  background: #dde0d4f5;
  padding: 16px;
}
.empty p {
  font-size: clamp(26px, 4vw, 60px);
  font-weight: 750;
  letter-spacing: -0.035em;
  margin: 0 0 12px;
  line-height: 1.1;
  text-wrap: balance;
}
.empty span {
  font-size: clamp(12px, 1.5vw, 17px);
  line-height: 1.6;
  color: #414a3c;
}
.round-status {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 32px);
  width: max-content;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--ink);
  text-align: center;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 3px 3px 0 #20231f33;
  pointer-events: none;
}
.game-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 10px;
  min-height: 44px;
  font-size: 12px;
}
.game-info p {
  margin: 0;
}
.player-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
#you {
  font-weight: 600;
}
.you-accent {
  color: var(--accent);
  font-weight: 700;
}
#population {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#open-settings {
  flex: 0 0 40px;
  width: 40px;
  min-height: 40px;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--ink);
}
#open-settings svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: var(--surface);
  stroke: currentColor;
  stroke-width: 1.7;
}
.touch-controls,
.play-brand {
  display: none;
}
[hidden] {
  display: none !important;
}
/* Play uses the viewport. The canvas box itself stays 5:3. */
body.playing main {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.playing #setup {
  display: none;
}
body.playing #settings[open] #setup {
  display: block;
}
body.playing .game {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 0;
}
body.playing .scoreboard {
  flex-shrink: 0;
  padding: 10px 16px;
}
body.playing .arena {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}
body.playing .world-frame {
  width: min(100cqw, 162.5cqh);
}
body.playing .game-info {
  flex-shrink: 0;
}
#settings {
  width: min(720px, calc(100% - 24px));
  max-height: calc(
    100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
  );
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 4px;
  padding: 24px;
  scrollbar-color: #898e83 var(--paper);
}
#settings::backdrop {
  background: #10150fcc;
}
.settings-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.settings-heading h2 {
  font-size: 24px;
  letter-spacing: -0.025em;
  margin: 0 0 8px;
}
.settings-heading p {
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
  margin: 0;
  max-width: 34ch;
}
#resume {
  flex-shrink: 0;
}
#settings .masthead {
  display: none;
}
#settings .connection {
  grid-template-columns: 1fr;
}
#settings .connection-info {
  display: grid;
}
#settings .how-to-play {
  margin-bottom: 0;
}
@media (max-width: 650px) {
  main {
    padding: max(20px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(20px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
  .masthead {
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 24px;
  }
  .masthead p {
    font-size: 13px;
    max-width: 26ch;
  }
  .edition {
    font-size: 9px;
    padding: 7px 0;
    margin-top: 3px;
  }
  .connection {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .connection-actions button {
    flex: 1;
  }
  .connection-info {
    display: grid;
    gap: 10px;
  }
  .scoreboard,
  body.playing .scoreboard {
    padding: 10px;
    gap: 6px;
  }
  .team {
    gap: 6px;
    font-size: 10px;
  }
  .team strong {
    font-size: 18px;
  }
  .swatch {
    flex-basis: 12px;
    height: 12px;
  }
  .round {
    min-width: 64px;
  }
  .round strong {
    font-size: 21px;
  }
  .round span {
    font-size: 9px;
  }
  .game-info {
    padding: 2px 8px;
    font-size: 11px;
    gap: 8px;
  }
  .player-info {
    display: block;
    line-height: 1.6;
  }
  #population {
    font-size: 10px;
  }
  #settings {
    padding: 18px;
  }
  .settings-heading {
    flex-wrap: wrap;
    gap: 16px;
  }
  #resume {
    width: 100%;
  }
  .round-status {
    top: 12px;
    font-size: 12px;
    padding: 8px 12px;
  }
}
@media (any-pointer: coarse) {
  body.playing .touch-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 12px 12px max(12px, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }
  .touch-guide {
    text-align: center;
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
  }
  .touch-guide span {
    font-size: 11px;
    color: var(--muted);
  }
  .control-cross {
    display: grid;
    grid-template: repeat(3, 60px) / repeat(3, 60px);
    gap: 6px;
  }
  [data-control="jump"] {
    grid-area: 1 / 2;
  }
  [data-control="left"] {
    grid-area: 2 / 1;
  }
  [data-control="right"] {
    grid-area: 2 / 3;
  }
  [data-control="down"] {
    grid-area: 3 / 2;
  }
  .touch-controls button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 48px;
    min-height: 48px;
    padding: 4px;
    background: var(--surface);
    color: var(--ink);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    font-size: 11px;
  }
  .touch-controls button[data-control="jump"] {
    border-bottom: 3px solid var(--accent);
  }
  .touch-controls button[aria-pressed="true"] {
    background: var(--ink);
    color: var(--surface);
  }
  .touch-controls svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linejoin: miter;
    stroke-linecap: square;
  }
}
@media (any-pointer: coarse) and (orientation: portrait) {
  body.playing .play-brand {
    display: flex;
    align-items: center;
    padding: 16px;
    font-size: 23px;
    font-weight: 800;
    letter-spacing: -0.035em;
  }
  .play-brand .edition {
    margin-left: auto;
    letter-spacing: 0.12em;
    font-weight: 650;
  }
  body.playing .game {
    flex: none;
    margin-block: auto;
  }
  body.playing .arena {
    flex: none;
    aspect-ratio: 13/8;
  }
  body.playing .world-frame {
    width: 100%;
  }
}
@media (any-pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  body.playing main {
    padding-left: max(180px, calc(env(safe-area-inset-left) + 172px));
  }
  body.playing .touch-controls {
    position: absolute;
    left: env(safe-area-inset-left);
    top: env(safe-area-inset-top);
    bottom: env(safe-area-inset-bottom);
    width: 172px;
    padding: 8px;
    justify-content: center;
  }
  .touch-guide {
    display: none;
  }
  .control-cross {
    grid-template: repeat(3, 48px) / repeat(3, 48px);
    gap: 4px;
  }
  .touch-controls button {
    gap: 1px;
    padding: 2px;
    font-size: 10px;
  }
  .player-info {
    display: block;
    font-size: 10px;
    line-height: 1.4;
  }
  #population {
    font-size: 10px;
  }
}
@media (max-height: 450px) {
  body.playing .scoreboard {
    padding: 4px 8px;
  }
  body.playing .team strong,
  body.playing .round strong {
    font-size: 17px;
  }
  body.playing .round {
    gap: 1px;
  }
  body.playing .game-info {
    font-size: 10px;
  }
}
@media (any-pointer: coarse) and (orientation: portrait) and (max-height: 650px) {
  body.playing .play-brand {
    display: none;
  }
  body.playing .touch-controls {
    padding-block: 8px;
    gap: 6px;
  }
  .touch-guide {
    display: none;
  }
  .control-cross {
    grid-template: repeat(3, 48px) / repeat(3, 48px);
    gap: 4px;
  }
  .touch-controls button {
    gap: 1px;
    padding: 2px;
    font-size: 10px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
