* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #0d1117;
  color: #e6edf3;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.setup {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.card {
  width: 100%;
  max-width: 520px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px;
  display: grid;
  gap: 12px;
  transition: border-color 0.15s;
}
.card.drag { border-color: #58a6ff; }
.card h1 { margin: 0; font-size: 1.5rem; }
.lead { margin: 0; color: #8b949e; font-size: 0.95rem; line-height: 1.45; }

.state { font-weight: 600; font-size: 0.95rem; }
.state.ready { color: #3fb950; }
.state.warn { color: #d29922; }
.state.bad { color: #f85149; }

.detail { color: #8b949e; font-size: 0.875rem; line-height: 1.4; }
.progress { display: grid; gap: 6px; }
progress { width: 100%; height: 8px; }

.message {
  padding: 10px 12px;
  border-radius: 8px;
  background: #1f2937;
  font-size: 0.875rem;
}
.message.warn { background: #352a14; color: #e3b341; }
.message.bad { background: #3b1c20; color: #ffa198; }

.webgpu-probe {
  position: fixed;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.launch-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 12px 16px;
  min-width: 0;
  margin: 0;
  padding: 10px 12px 12px;
  border: 1px solid #30363d;
  border-radius: 8px;
  color-scheme: dark;
  font-size: 0.9rem;
}
.launch-options legend { padding: 0 4px; }
.launch-field { display: grid; gap: 5px; }
.launch-nickname { grid-column: 1 / -1; }
.launch-check { display: flex; align-items: center; gap: 8px; }
.launch-check input { margin: 0; }
.launch-options:disabled { opacity: 0.6; }

.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.saved-replays { display: grid; gap: 8px; justify-items: start; }
.launch-field select, .launch-field input, .saved-replays select {
  width: 100%;
  min-width: 0;
  padding: 8px;
  background: #21262d;
  color: inherit;
  border: 1px solid #30363d;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
}
button {
  appearance: none;
  border: 1px solid #30363d;
  background: #21262d;
  color: #e6edf3;
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #30363d; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: #238636; border-color: #2ea043; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #2ea043; }

#game-view {
  position: fixed;
  inset: 0;
  container-type: size;
  background: #000;
  --game-top: env(safe-area-inset-top);
  --game-right: env(safe-area-inset-right);
  --game-bottom: env(safe-area-inset-bottom);
  --game-left: env(safe-area-inset-left);
  --touch-size: clamp(44px, 12vmin, 60px);
}

#game-view.rotated {
  inset: 0 auto auto 100dvw;
  width: 100dvh;
  height: 100dvw;
  transform-origin: top left;
  transform: rotate(90deg);
  --game-top: env(safe-area-inset-right);
  --game-right: env(safe-area-inset-bottom);
  --game-bottom: env(safe-area-inset-left);
  --game-left: env(safe-area-inset-top);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

#status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: rgba(13, 17, 23, 0.9);
  font-size: 1rem;
  z-index: 10;
}

#fs-toggle {
  position: absolute;
  top: max(12px, var(--game-top));
  right: max(12px, var(--game-right));
  padding: 4px 10px;
  font-size: 0.8rem;
  z-index: 20;
}
#touch-controls:not([hidden]) ~ #fs-toggle {
  right: calc(max(12px, var(--game-right)) + var(--touch-size) + 8px);
}
[hidden] { display: none !important; }

#touch-controls {
  position: absolute;
  inset: max(12px, var(--game-top)) max(12px, var(--game-right))
         max(12px, var(--game-bottom)) max(12px, var(--game-left));
  display: grid;
  grid-template-columns: auto auto;
  justify-content: space-between;
  align-content: end;
  align-items: center;
  padding-block-end: 30px;
  pointer-events: none;
}

.touch-directions, .touch-actions {
  display: grid;
  grid-template: repeat(3, var(--touch-size)) / repeat(3, var(--touch-size));
  gap: 3px;
}
.touch-directions [data-key="up"] { grid-area: 1 / 2; }
.touch-directions [data-key="left"] { grid-area: 2 / 1; }
.touch-directions [data-key="down"] { grid-area: 3 / 2; }
.touch-directions [data-key="right"] { grid-area: 2 / 3; }
.touch-neutral {
  grid-area: 2 / 2;
  border-radius: 6px;
  background: rgb(13 17 23 / 50%);
}
.touch-actions [data-key="weapons"] { grid-area: 1 / 2; }
.touch-actions [data-key="fire"] { grid-area: 2 / 1; }
.touch-actions [data-key="backspace"] { grid-area: 2 / 3; }
.touch-actions [data-key="enter"] { grid-area: 3 / 2; }
#touch-controls button {
  min-height: var(--touch-size);
  padding: 0;
  background: rgb(13 17 23 / 76%);
  border-color: rgb(230 237 243 / 55%);
  color: #fff;
  font-weight: 600;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.touch-directions button { font-size: 1.35rem; }
.touch-actions button, #touch-controls > [data-key="escape"] {
  border-radius: 50%;
  font-size: clamp(0.7rem, 3vmin, 0.9rem);
  line-height: 1;
}
#touch-controls > [data-key="escape"] {
  position: absolute;
  inset: 0 0 auto auto;
  width: var(--touch-size);
}
#touch-controls .pressed { background: #1f5d93; }

@container (max-aspect-ratio: 2 / 1) {
  .touch-actions {
    grid-template: repeat(2, var(--touch-size)) / repeat(2, var(--touch-size));
  }
  .touch-actions [data-key="weapons"] { grid-area: 1 / 1; }
  .touch-actions [data-key="fire"] { grid-area: 1 / 2; }
  .touch-actions [data-key="enter"] { grid-area: 2 / 1; }
  .touch-actions [data-key="backspace"] { grid-area: 2 / 2; }
}

/* Use the top safe-area edge in compact landscape to fit Esc above Fire
   and keep the D-pad clear of the pause menu's Volume slider. */
@container (min-aspect-ratio: 1 / 1) and (max-aspect-ratio: 2 / 1) {
  #touch-controls {
    top: var(--game-top);
    align-content: start;
    padding-block: calc(var(--touch-size) / 2) 0;
  }
}

#asset-status {
  position: absolute;
  inset: auto auto 12px 12px;
  max-width: min(520px, calc(100% - 24px));
  padding: 10px 12px;
  border: 1px solid #30363d;
  border-radius: 8px;
  background: #161b22;
  overflow-wrap: anywhere;
  z-index: 15;
}

#asset-status.asset-failed {
  border-color: #f85149;
}

#asset-status:not(.asset-failed) .buttons { display: none; }
