:root {
  color-scheme: dark;
  --fg: #ffffff;
  --panel: rgba(0, 0, 0, 0.88);
  --muted: #8e8e8e;
  --app-w: 100vw;
  --app-h: 100vh;
  --game-w: min(100vw, 133.333vh);
  --game-h: min(100vh, 75vw);
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: var(--app-w);
  height: var(--app-h);
  overflow: hidden;
  background: #000;
  color: var(--fg);
  font-family: "Courier New", monospace;
  overscroll-behavior: none;
  touch-action: none;
}

button,
input {
  font: inherit;
}

input {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

#shell {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--app-w);
  height: var(--app-h);
  display: grid;
  place-items: center;
  background: #000;
}

#game {
  width: var(--game-w);
  height: var(--game-h);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  touch-action: none;
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(320px, calc(var(--app-w) - 32px));
  transform: translate(-50%, -50%);
  padding: 18px;
  border: 2px solid var(--fg);
  background: var(--panel);
  text-align: center;
}

.panel[hidden] {
  display: none;
}

.panel h1 {
  margin: 0 0 14px;
  color: var(--fg);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0;
}

#joinForm {
  display: grid;
  gap: 10px;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#nickname {
  min-width: 0;
  padding: 10px 8px;
  border: 1px solid var(--fg);
  border-radius: 0;
  background: #000;
  color: var(--fg);
  text-transform: uppercase;
}

#join button {
  padding: 10px 12px;
  border: 1px solid var(--fg);
  border-radius: 0;
  background: #000;
  color: var(--fg);
}

#join button:active,
#join button[aria-checked="true"] {
  background: var(--fg);
  color: #000;
}

.rooms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

#join .room-button {
  min-width: 0;
  padding: 7px 8px;
  color: var(--fg);
  font-size: 12px;
  overflow-wrap: anywhere;
}

#status {
  min-height: 18px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

#hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  display: flex;
  gap: 12px;
  padding: 5px 7px;
  background: rgba(0, 0, 0, 0.72);
  color: var(--fg);
  font-size: 14px;
  line-height: 1;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}

#hud:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

#score::before {
  content: "S ";
}

#players::before {
  content: "P ";
}

#side::before {
  content: "R ";
}

#latency::before {
  content: "L ";
}

#debugStats {
  position: fixed;
  top: calc(max(8px, env(safe-area-inset-top)) + 26px);
  left: max(8px, env(safe-area-inset-left));
  max-width: min(520px, calc(var(--app-w) - 16px));
  padding: 5px 7px;
  background: rgba(0, 0, 0, 0.72);
  color: var(--fg);
  font-size: 11px;
  line-height: 1.25;
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-shadow: 1px 1px 0 #000;
}

#debugStats[data-expanded="false"] {
  display: none;
}

#soloButtons {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: grid;
  gap: 8px;
}

#soloButtons[hidden] {
  display: none;
}

#soloButtons button {
  min-width: 46px;
  height: 32px;
  padding: 0 10px;
  border: 2px solid var(--fg);
  border-radius: 0;
  background: #000;
  color: var(--fg);
  font-size: 14px;
  line-height: 1;
  touch-action: manipulation;
}

#soloButtons button:active {
  background: var(--fg);
  color: #000;
}

#touchControls {
  position: fixed;
  inset: auto 0 max(14px, env(safe-area-inset-bottom)) 0;
  display: flex;
  justify-content: space-between;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none;
  touch-action: none;
}

#join:not([hidden]) ~ #touchControls {
  display: none;
}

.pad {
  position: relative;
  width: 66px;
  height: 148px;
  pointer-events: auto;
  touch-action: none;
}

.pad button {
  position: absolute;
  left: 0;
  width: 66px;
  height: 66px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.52);
  color: var(--fg);
  font-size: 14px;
  line-height: 1;
  touch-action: none;
}

.pad button:active,
.pad button.active {
  background: rgba(255, 255, 255, 0.92);
  color: #000;
}

.pad .up {
  top: 0;
}

.pad .down {
  bottom: 0;
}

@media (hover: hover) and (pointer: fine) {
  #touchControls {
    display: none;
  }
}
