:root {
  --bg: #0b0e14;
  --fg: #c9d1d9;
  --dim: #3a4250;
  --wall: #6b7686;
  --floor: #4a5363;
  --spark: #ffd75e;
  --enemy: #ff6b6b;
  --cap: #5ee0ff;
  --via: #7ee787;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

main {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  gap: 6px;
}

#hud .row { display: flex; align-items: center; gap: 12px; font-size: 16px; }
#hud .small { font-size: 13px; color: #8b949e; margin-top: 2px; justify-content: space-between; }
#hud a { color: inherit; }
.bar { flex: 1; height: 12px; border: 1px solid var(--wall); border-radius: 3px; overflow: hidden; }
#bar-fill { display: block; height: 100%; background: var(--spark); transition: width .15s; }
#bar-fill.low { background: var(--enemy); }

#map-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#map {
  margin: 0;
  font-family: var(--mono);
  line-height: 1.15;
  color: var(--floor);
}
#map .w { color: var(--wall); }
#map .m { color: var(--dim); }
#map .p { color: var(--spark); font-weight: bold; text-shadow: 0 0 6px var(--spark); }
#map .r { color: var(--enemy); font-weight: bold; }
#map .c { color: var(--cap); font-weight: bold; }
#map .v { color: var(--via); font-weight: bold; }

#log { min-height: 2.6em; font-size: 14px; line-height: 1.3; }
#log div:last-child { color: #fff; }

#pad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  justify-content: center;
  touch-action: none;
}
#pad button, .box button {
  font: inherit;
  font-size: 24px;
  color: var(--fg);
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  touch-action: none;
}
#pad button:active, #pad button.held { background: #30363d; }
#pad .arc { color: var(--spark); font-size: 15px; font-weight: bold; letter-spacing: 1px; }
#pad button[data-dir]::before { content: "↑"; display: inline-block; transform: rotate(var(--r)); }

#help { margin: 0; font-size: 12px; color: #8b949e; text-align: center; }
.keys { display: none; }

/* Desktop / mouse: keyboard first, the pad is still there but smaller. */
@media (hover: hover) and (pointer: fine) {
  .touch { display: none; }
  .keys { display: inline; }
  #pad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 40px); }
  #pad button { font-size: 18px; }
  #pad .arc { font-size: 11px; }
}

/* Phone in landscape: pad on the right of the map. */
@media (orientation: landscape) and (max-height: 500px) {
  main {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr auto;
    max-width: none;
  }
  #hud { grid-column: 1 / -1; }
  #map-wrap { grid-column: 1; grid-row: 2 / 4; }
  #pad { grid-column: 2; grid-row: 2; align-self: center; grid-template-rows: repeat(3, 52px); }
  #log { grid-column: 2; grid-row: 3; max-width: 220px; font-size: 12px; }
  #help { display: none; }
}

#over {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .7);
}
#over[hidden] { display: none; }
.box {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  max-width: 320px;
}
.box h2 { margin: 0 0 8px; color: var(--spark); }
.box button { display: block; width: 100%; margin-top: 10px; padding: 12px; font-size: 18px; }
.box .secondary { font-size: 15px; background: transparent; }
