:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  color: #edf2fa;
  background: #10141b;
  --ink: #edf2fa;
  --line: #465875;
  --muted: #a9c9fa;
  --accent: #8abaff;
  --accent-fill: #244d81;
  --hunter: #57aaff;
  --target: #ffa02d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }

main {
  width: min(1080px, 100%);
  height: 100dvh;
  margin-inline: auto;
  padding: clamp(12px, 3vw, 28px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.banner-options, .legend, .group, .pickers, .picker-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

header {
  display: grid;
  margin-bottom: clamp(10px, 2vw, 20px);
  padding: 8px;
  background: #161a22;
  border: 1px solid #343d4b;
  border-radius: 12px;
}

.banner-options {
  flex-wrap: wrap;
  align-content: center;
}

.banner-options, .tools { grid-area: 1 / 1; }

.tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  align-content: center;
  width: min(100%, 410px);
  gap: 6px;
}

.tools button { padding-inline: 6px; }
.tools .role { flex-direction: row; }
.tools i { flex: none; }

[inert] { visibility: hidden; }

h1, h2 { margin: 0; line-height: 1; }
h1 { margin-inline-end: auto; font-size: clamp(1.4rem, 4vw, 2rem); letter-spacing: -.06em; }
h2 { font-size: 1.45rem; }

button {
  min-width: 44px;
  min-height: 44px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #253248;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:enabled:hover { border-color: var(--accent); }
button:focus-visible, canvas:focus-visible { outline: 3px solid #ffcc80; outline-offset: 2px; }
button:disabled { opacity: .65; cursor: wait; }
button[aria-pressed="true"], .primary {
  color: white;
  background: var(--accent-fill);
  border-color: var(--accent);
}

.arena {
  min-height: 0;
  container-type: size;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
  --board-clearance: 120px;
}

.field {
  min-width: 0;
  width: min(100cqw, max(110px, calc(100cqh - var(--board-clearance))), 640px);
  overflow: clip;
  border: 2px solid #343d4b;
  border-radius: 16px;
  background: #253248;
  box-shadow: 0 5px 0 #080b10;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: #161a22;
}

canvas.editing { touch-action: none; cursor: crosshair; }
canvas:focus-visible { outline-offset: -4px; }

.legend {
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 4px 8px;
  font-size: .875rem;
  font-weight: 700;
}

.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i, .role i { width: 11px; height: 11px; }
.hunter { background: var(--hunter); border-radius: 50%; }
.target { background: var(--target); transform: rotate(45deg); }
.exit { background: #ffe087; border-radius: 2px; }

.pickers { flex-wrap: wrap; }
.pickers button { flex: 1 1 auto; text-align: left; }
.pickers span { display: block; font-size: .875rem; font-weight: 400; }
.pickers strong { display: block; }
.group { flex-wrap: wrap; }
output { min-height: 1.25em; font-weight: 700; }
.round-info { display: flex; gap: 4px 12px; flex-wrap: wrap; align-items: baseline; justify-content: center; }
#clock { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.round-footer { display: contents; }

.arena[data-mode="play"] .round-footer {
  display: grid;
  width: min(100%, 420px);
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 0 8px;
  text-align: center;
}

#play-restart { grid-area: 1 / 1 / span 2; align-self: start; padding-inline: 8px; }
.arena[data-mode="play"] .round-footer :is(.legend, .round-info) {
  grid-column: 2;
}

.round-controls {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.round-controls[inert] { display: none; }

.round-controls > * { grid-row: 1; }
#transport, .directions { grid-column: 2; }
#transport { min-width: 96px; }
#restart { grid-column: 3; justify-self: start; padding-inline: 8px; }

.role {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-inline: 8px;
}

#role-hunter { grid-column: 1; justify-self: end; max-width: 100%; }
#role-target { grid-column: 3; justify-self: start; max-width: 100%; }

.directions {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: 24px 24px 44px;
  justify-content: center;
  column-gap: 4px;
  padding-block: 2px;
}

.directions button { height: 44px; font: 700 1.35rem system-ui, sans-serif; padding: 0; }
.directions [data-direction="0"] { grid-area: 1 / 2; }
.directions [data-direction="3"] { grid-area: 2 / 1; }
.directions [data-direction="1"] { grid-area: 2 / 3; }
.directions [data-direction="2"] { grid-area: 3 / 2; }

dialog {
  width: min(370px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 16px;
  border: 2px solid var(--accent-fill);
  border-radius: 16px;
  background: #10141b;
  color: var(--ink);
}

dialog::backdrop { background: #080b10b3; }
.picker-header { justify-content: space-between; margin-bottom: 12px; }
.choices { display: grid; gap: 8px; }
.choices button { text-align: left; }
.choices span { display: block; margin: 3px 0; font-size: .875rem; font-weight: 400; }
#picker-note { margin: 0 0 8px; }

@media (max-width: 640px) and (orientation: portrait) {
  .pickers { width: 100%; display: grid; grid-template-columns: 1fr 1.1fr auto; gap: 4px; }
  .pickers button { padding-inline: 6px; }
  .pickers strong { font-size: .875rem; }
}

@media (max-width: 380px) {
  .role { flex-direction: column; gap: 3px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  main { padding: 8px 12px; }
  header { margin-bottom: 8px; }
  .banner-options, .tools { gap: 6px; }
  header h1 { font-size: 1.4rem; }
  .pickers button { padding-inline: 6px; }
}

@media (min-width: 520px) and (max-height: 500px) and (orientation: landscape) {
  .arena[data-mode="play"] {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: max(110px, calc(100% - var(--board-clearance))) auto;
  }
  .arena[data-mode="play"] .field { grid-area: 1 / 2; }
  .arena[data-mode="play"] .round-controls { grid-area: 2 / 1 / 3 / 4; }
  .arena[data-mode="play"] .round-footer {
    grid-area: 1 / 1;
    grid-template-columns: minmax(0, 1fr);
    width: min(100%, 180px);
    align-self: start;
    gap: 4px;
  }

  .arena[data-mode="play"] .round-footer :is(.legend, .round-info) { grid-column: 1; }
  #play-restart { grid-area: auto; justify-self: center; order: 1; }
}
