*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  height: 100dvh;
}

body {
  background: #111;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Canvas fills the space between header and footer */
  justify-content: space-between;
  height: 100dvh;
  font-family: monospace;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#top-bar {
  width: 100%;
  max-width: 448px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px 4px;
  flex-shrink: 0;
}

#title {
  font-size: clamp(0.7rem, 3.5vw, 1rem);
  letter-spacing: 0.12em;
  color: #ffff00;
}

#score {
  font-size: clamp(0.8rem, 3.5vw, 1.1rem);
  letter-spacing: 0.05em;
  color: #fff;
}

/* ── Canvas ─────────────────────────────────────────────────────────────── */
#game {
  display: block;
  /* Aspect ratio of the pure maze (no HUD) = 448 : 592 */
  aspect-ratio: 448 / 592;
  /* Fill as much of the remaining vertical space as possible,
     while never exceeding the screen width */
  width:  min(96vw, calc((100dvh - 80px) * 448 / 592));
  height: auto;
  border: 2px solid #222;
  flex-shrink: 0;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
#bottom-bar {
  width: 100%;
  max-width: 448px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px 6px;
  flex-shrink: 0;
}

#lives {
  font-size: clamp(0.9rem, 4vw, 1.2rem);
  color: #ff4444;
  letter-spacing: 0.1em;
}

#controls-keyboard {
  font-size: 0.65rem;
  color: #444;
  text-align: right;
}

#controls-touch {
  display: none;
  font-size: 0.7rem;
  color: #444;
}

#status {
  display: none;
}

/* ── Touch devices: swap hints ──────────────────────────────────────────── */
@media (pointer: coarse) {
  #controls-keyboard { display: none; }
  #controls-touch    { display: block; }
}

/* ── Landscape mobile: tighten vertical spacing ─────────────────────────── */
@media (pointer: coarse) and (orientation: landscape) {
  #top-bar, #bottom-bar { padding: 2px 10px; }
  #title { display: none; }
  #game {
    width: min(96vw, calc((100dvh - 50px) * 448 / 592));
  }
}
