:root {
  color-scheme: dark;
  font-family: system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --background: #0e1724;
  --panel: #152233;
  --border: #324459;
  --wall: #142336;
  --floor: #2d4058;
  --text: #f2f7fc;
  --muted: #bbc9d9;
  --mint: #75e3c7;
  --amber: #ffd183;
  --exit: #a5c6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(ellipse at top left, #21344f, var(--background) 55%);
  min-height: 100vh;
}

h1, h2, p, dl, dd { margin: 0; }

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled { cursor: default; }

button:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
}

.layout {
  max-width: 990px;
  padding: clamp(22px, 6vw, 64px) clamp(12px, 4vw, 32px) 32px;
  margin-inline: auto;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 22px;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  letter-spacing: -0.07em;
  line-height: 1.1;
}

h2 {
  font-size: 1.05rem;
  letter-spacing: -0.025em;
}

.masthead div p,
.goal {
  color: var(--muted);
  line-height: 1.6;
  word-break: keep-all;
}

.masthead div p { margin-top: 10px; }

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8125rem;
}

.connection::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
}

.connection[data-online="true"]::before { background: var(--mint); }

.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(215px, 0.47fr);
  align-items: start;
  gap: 16px;
}

.map-panel,
.controls-panel {
  min-width: 0;
  padding: clamp(10px, 2.5vw, 22px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.maze {
  display: grid;
  grid-template-columns: repeat(var(--maze-width, 9), minmax(0, 1fr));
  gap: clamp(2px, 0.6vw, 5px);
  margin-top: 14px;
  padding: clamp(4px, 1vw, 9px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0b1421;
}

.maze:empty { aspect-ratio: 1; }

.tile {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  font-weight: 800;
  font-size: clamp(12px, 3.6vw, 22px);
  background: var(--floor);
  touch-action: manipulation;
}

.wall {
  background: repeating-linear-gradient(135deg, var(--wall) 0 5px, #18293e 5px 7px);
}

.tile:not(:disabled):not(.wall) {
  border-color: var(--mint);
  background: #2d5966;
}

.tile:not(:disabled):not(.wall):hover { background: #3b7281; }

.tile[data-marker="explorer"], .explorer { color: var(--mint); }
.tile[data-marker="relic"], .relic { color: var(--amber); }
.tile[data-marker="exit"], .exit { color: var(--exit); }
.tile[data-marker="exit"][data-locked] { color: #9dacc0; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 12px;
  font-size: 0.8125rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-block: 14px 10px;
}

.metrics div {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 0;
}

.metrics dt { color: var(--muted); font-size: 0.8125rem; }

.metrics dd {
  margin-top: 4px;
  font-size: 1.25rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

#relic-progress {
  display: block;
  width: 100%;
  height: 8px;
  margin-bottom: 9px;
  accent-color: var(--amber);
}

.goal { font-size: 0.875rem; }

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 48px));
  justify-content: center;
  gap: 5px;
  margin-top: 16px;
}

.direction-pad button,
.next-run {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--floor);
  font-weight: 750;
}

.direction-pad button:first-child { grid-column: 2; }
.direction-pad button:nth-child(2) { grid-column: 1; }
.direction-pad button:disabled { opacity: 0.5; }
.direction-pad button:not(:disabled):hover { border-color: var(--mint); }

.next-run {
  width: 100%;
  margin-top: 12px;
  padding: 6px 11px;
  color: var(--background);
  background: var(--mint);
}

.next-run:disabled { opacity: 0.5; }

@media (max-width: 680px) {
  .game { grid-template-columns: minmax(0, 1fr); gap: 10px; }
}
