:root {
  color-scheme: dark;
  --page: #172324;
  --panel: #202f2e;
  --line: #485650;
  --ink: #f3edda;
  --quiet: #b6c1b2;
  --player: #a8d7ca;
  --rival: #f1ae83;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: system-ui, sans-serif;
  background: var(--page);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; display: grid; place-items: center; }
button, select { font: inherit; color: inherit; }
button, select, label { cursor: pointer; }
:where(button, select, input):focus-visible { outline: 2px solid var(--player); outline-offset: 3px; }
[hidden] { display: none !important; }

main { width: min(100%, calc(100dvh * 16 / 9)); }
h1, h2, h3 { margin: 0; letter-spacing: -.035em; }
kbd { font: 700 .75rem var(--mono); white-space: nowrap; }
.secondary { padding: 6px 9px; border: 1px solid #6c7d72; background: #202f2ef5; font-size: .79rem; }
.secondary:hover { border-color: var(--quiet); }

.field { position: relative; aspect-ratio: 16 / 9; background: #a8c9c4; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
canvas:focus-visible { outline: 2px solid var(--player); outline-offset: -2px; }

.hud {
  position: absolute;
  inset: 0 0 auto;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(72px, 17vw, 190px) minmax(0, 1fr);
  align-items: start;
  gap: clamp(7px, 2.8vw, 30px);
  padding: clamp(7px, 1.5vw, 16px);
  background: linear-gradient(#172324f5, #172324e5 70%, #17232400);
  pointer-events: none;
}

.pilot, .flight { min-width: 0; }
.player { color: var(--player); }
.rival { color: var(--rival); }
.pilot-heading, .flight-heading { display: flex; justify-content: space-between; align-items: center; gap: 5px; margin-bottom: 5px; font-size: clamp(.62rem, 2.5vw, .84rem); font-weight: 750; line-height: 1.2; }
.pilot-heading output, .flight-heading output { font: 700 clamp(.59rem, 2vw, .74rem) var(--mono); white-space: nowrap; }
.health { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: clamp(2px, .7vw, 5px); }
.health i { height: 6px; background: #394943; }
.health i.active { background: currentColor; }
.flight { color: var(--ink); }
.flight.warning, #flight-state { color: #ffce8f; }
#flight-state { display: block; margin-top: 4px; text-align: center; font-size: clamp(.59rem, 1.8vw, .73rem); font-weight: 750; text-shadow: 0 1px 3px #172324; }
#speed-gauge { display: block; width: 100%; height: 6px; appearance: none; accent-color: currentColor; background: #394943; }
#speed-gauge::-webkit-meter-bar { height: 6px; border: 0; border-radius: 0; background: #394943; }
#speed-gauge::-webkit-meter-optimum-value { background: currentColor; }
#speed-gauge::-moz-meter-bar { border-radius: 0; background: currentColor; }
.arena-actions { position: absolute; z-index: 1; right: 7px; bottom: 7px; display: flex; gap: 6px; }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #1023244d; padding: 10px; }
.panel { text-align: center; background: #202f2ef5; border: 1px solid #72847b; padding: clamp(12px, 3vw, 28px) clamp(13px, 4vw, 40px); box-shadow: 4px 4px #17232480; }
.panel h1 { font-size: clamp(19px, 4vw, 34px); }
.panel p { max-width: 32ch; margin: 7px auto 15px; color: var(--quiet); font-size: clamp(.73rem, 2vw, .94rem); }
.panel button { background: var(--ink); color: var(--page); border: 0; padding: 10px 15px; font-weight: 800; }
.panel button:hover { background: white; }
.panel button kbd { border: 1px solid #777e72; margin-left: 6px; padding: 2px 4px; }

dialog { width: min(420px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 20px; border: 1px solid #72847b; background: var(--panel); color: var(--ink); }
dialog::backdrop { background: #10191cd1; }
.settings-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.settings-heading h2 { font-size: 1.5rem; }
.settings-options { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px 8px; margin: 18px 0; padding-bottom: 14px; border-bottom: 1px solid var(--line); font-size: .87rem; }
.settings-options select { padding: 5px 7px; border: 1px solid #6c7d72; background: var(--page); }
.pitch-preference { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; min-height: 24px; }
.pitch-preference input { margin: 0; accent-color: var(--player); width: 16px; height: 16px; }
dialog h3 { font-size: 1rem; }
.key-guide { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 12px 0 0; font-size: .86rem; }
.key-guide dt kbd { padding: 2px 5px; border: 1px solid var(--line); }
.key-guide dd { margin: 0; color: var(--quiet); }

.touch-controls { display: none; }
.control { min-height: 43px; padding: 5px 2px; border: 1px solid var(--line); background: var(--panel); color: var(--quiet); touch-action: none; user-select: none; font-size: clamp(.61rem, 2.35vw, .8rem); }
.control.active { background: #354c47; color: var(--ink); border-color: var(--player); }

@media (max-width: 450px) {
  .hud { padding: 7px 8px; }
  .pilot-heading, .flight-heading { gap: 3px; }
  .arena-actions { right: 4px; bottom: 4px; }
  .arena-actions .secondary { padding: 4px 6px; font-size: .69rem; }
  .panel p { margin: 5px auto 9px; }
  .panel button { padding: 6px 9px; }
}
@media (pointer: coarse) {
  main:has(.touch-controls:not([hidden])) { width: min(100%, calc((100dvh - 51px) * 16 / 9)); }
  .touch-controls { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; margin: 4px; }
  .panel button kbd { display: none; }
}
