/* Dewlight page chrome: HUD bar, stage, overlays and menus. The playfield itself is canvas. */

:root {
  --night: #04100f;
  --night-2: #0a1d1b;
  --panel: rgba(5, 18, 18, 0.86);
  --panel-edge: rgba(170, 220, 200, 0.22);
  --text: #e9e6d6;
  --text-dim: #9fbcb0;
  --glow: #f4e58a;
  --glow-soft: rgba(244, 229, 138, 0.35);
  --moss: #2c6b4a;
  --focus: #ffe79a;
  --danger: #f2a68f;
  --hud-height: 3rem;
  --field-size: min(100vw, 100vh);
  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-title: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(80, 130, 160, 0.16), transparent 60%),
    var(--night);
  color: var(--text);
  font: 15px/1.4 var(--font-ui);
  overflow: hidden;
}

/* HUD */

.hud {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.4rem 1.2rem;
  flex-wrap: wrap;
  width: 100%;
  max-width: max(var(--field-size), 22rem);
  min-height: var(--hud-height);
  margin: 0 auto;
  padding: 0.35rem 0.75rem;
  font-variant-numeric: tabular-nums;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.hud-label {
  color: var(--text-dim);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hud-value {
  font-size: 1.1rem;
  font-weight: 650;
  color: var(--glow);
  text-shadow: 0 0 8px var(--glow-soft);
}

.hud-level { flex: 1 1 auto; min-width: 0; }

.hud-maze {
  overflow: hidden;
  font-family: var(--font-title);
  font-style: italic;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.hud-back {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-decoration: none;
}

.hud-back:hover { color: var(--text); }

.hud-lives {
  display: flex;
  gap: 0.35rem;
  min-height: 1rem;
}

/* A tiny firefly: glowing body with two wings. */
.life-icon {
  position: relative;
  width: 0.9rem;
  height: 0.9rem;
}

.life-icon::before {
  content: "";
  position: absolute;
  left: 0.3rem;
  top: 0.3rem;
  width: 0.34rem;
  height: 0.48rem;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 70%, #ffffe0, #e9f37a 60%, #9cb23a);
  box-shadow: 0 0 6px 2px var(--glow-soft);
}

.life-icon::after {
  content: "";
  position: absolute;
  left: 0.05rem;
  top: 0.05rem;
  width: 0.8rem;
  height: 0.35rem;
  border-radius: 50% 50% 40% 40%;
  background:
    radial-gradient(ellipse at 25% 60%, rgba(210, 232, 255, 0.6) 0 45%, transparent 47%),
    radial-gradient(ellipse at 75% 60%, rgba(210, 232, 255, 0.6) 0 45%, transparent 47%);
}

.hud-sound {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.hud-sound.is-muted { color: var(--text-dim); text-decoration: line-through; }

/* Stage and playfield */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.playfield {
  position: relative;
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(150, 200, 190, 0.12), 0 10px 50px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(2, 10, 10, 0.55), rgba(2, 8, 8, 0.82));
}

.panel {
  width: min(100%, 26rem);
  margin: auto;
  padding: 1rem 1.25rem 1.2rem;
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 0 40px rgba(244, 229, 138, 0.06);
}

.panel-narrow { width: min(100%, 17rem); }

.game-title {
  margin: 0.1rem 0 0.4rem;
  font: italic 400 clamp(2rem, 7vw, 3rem)/1.05 var(--font-title);
  color: var(--glow);
  letter-spacing: 0.02em;
  text-shadow: 0 0 18px rgba(244, 229, 138, 0.55), 0 0 2px #fff7c2;
}

.screen-heading {
  margin: 0.1rem 0 0.6rem;
  font: italic 400 1.7rem/1.1 var(--font-title);
  color: var(--glow);
}

.lead {
  margin: 0 0 0.6rem;
  color: var(--text);
  font-size: 0.88rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 0.9rem;
  margin: 0 0 0.7rem;
  padding: 0;
  list-style: none;
  color: var(--text-dim);
  font-size: 0.8rem;
}

kbd {
  display: inline-block;
  min-width: 1.35em;
  margin: 0 0.08em;
  padding: 0 0.3em;
  border: 1px solid rgba(190, 225, 210, 0.3);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: 600 0.75rem/1.5 var(--font-ui);
}

.table-heading {
  margin: 0.2rem 0 0.3rem;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.scores { margin: 0 0 0.8rem; }

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.score-table th {
  padding: 0.15rem 0.4rem;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.score-table td { padding: 0.12rem 0.4rem; }
.score-table td:nth-child(2) { text-align: left; overflow-wrap: anywhere; }
.score-table th:nth-child(2) { text-align: left; }
.score-table td:nth-child(3) { color: var(--glow); }
.score-table tbody tr:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }

.score-table tr.is-player {
  background: rgba(244, 229, 138, 0.18);
  outline: 1px solid rgba(244, 229, 138, 0.5);
  font-weight: 700;
}

.score-message {
  margin: 0.3rem 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.result { margin: 0 0 0.7rem; }
.result strong { color: var(--glow); font-size: 1.15rem; }

.name-form { margin: 0 0 0.6rem; }

.name-form label {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.name-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.name-row input {
  width: 10rem;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
}

.name-error {
  min-height: 1.2em;
  margin: 0.3rem 0 0;
  color: var(--danger);
  font-size: 0.8rem;
}

.status {
  margin: 0 0 0.4rem;
  color: var(--text);
  font-size: 0.85rem;
}

.status:empty { display: none; }

/* Buttons and focus */

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: 600 0.92rem/1.2 var(--font-ui);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.button:hover { background: rgba(255, 255, 255, 0.09); }
.button:disabled { opacity: 0.6; cursor: default; }

.button-primary {
  border-color: rgba(244, 229, 138, 0.55);
  background: rgba(244, 229, 138, 0.14);
  color: #fff6c8;
}

.button-primary:hover { background: rgba(244, 229, 138, 0.24); }

.button:focus-visible,
.hud-sound:focus-visible,
.hud-back:focus-visible,
.name-row input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 12px rgba(255, 231, 154, 0.45);
}

/* Programmatic focus on menu buttons should also be visible for keyboard players. */
.overlay .button:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Small windows (phones): the maze can be much shorter than a menu panel, so the menus cover
   the whole window instead of just the maze (still scrolling inside themselves). */
@media (max-height: 560px), (max-width: 560px) {
  .overlay { position: fixed; z-index: 30; }
}

/* Touch devices (html.is-touch, shared/touch-controls.css): gestures, nothing reserved on screen;
   the pause button and the steering marker glow like the firefly. Landscape: one compact HUD line
   so the maze keeps its height. */
:root {
  --tc-ink: var(--glow);
  --tc-fill-solid: rgba(5, 18, 18, 0.9);
  --tc-edge: rgba(244, 229, 138, 0.45);
  --tc-pressed: rgba(244, 229, 138, 0.35);
  --tc-marker: var(--glow);
  --tc-marker-opacity: 0.35;
}

@media (orientation: landscape) and (max-height: 560px) {
  /* Sound stays in the pause menu; the bar must fit one line without widening the page. */
  html.is-touch .hud-sound { display: none; }
  html.is-touch .hud {
    flex-wrap: nowrap;
    max-width: none;
    min-height: 0;
    gap: 0.9rem;
    padding: 0.1rem 0.6rem;
  }
}

@media (max-width: 480px) {
  html.is-touch .hud { gap: 0.3rem 0.8rem; padding: 0.3rem 0.5rem; }
}

/* Portrait: the field sits under the HUD and the free space below it is where thumbs rest
   (nothing is reserved there; the field keeps its full width). */
@media (orientation: portrait) {
  html.is-touch .stage { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}
