:root {
  --bg: #04050a;
  --glass: rgba(10, 12, 20, 0.55);
  --line: rgba(255, 255, 255, 0.12);
  --fg: #f2f4f8;
  --dim: rgba(242, 244, 248, 0.62);
  --accent: #ffb703;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
canvas#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
canvas#map:active { cursor: grabbing; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; letter-spacing: 0.01em; }

.hud { position: fixed; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left));
  pointer-events: none; z-index: 2; }
.hud > * { pointer-events: auto; }
.top { top: 0; background: linear-gradient(to bottom, rgba(4, 5, 10, 0.55), transparent); }
.bottom { bottom: 0; align-items: flex-end; flex-wrap: wrap; gap: 10px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(4, 5, 10, 0.6), transparent); }

.brand { font-weight: 650; font-size: 17px; letter-spacing: 0.02em; display: flex; align-items: center; gap: 8px;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.6); }
.mark { font-size: 26px; line-height: 1; color: var(--accent); }
.depth { min-width: 0; max-width: 62vw; text-align: right; text-shadow: 0 1px 12px rgba(0, 0, 0, 0.7); }
#mag { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
#coords { color: var(--dim); max-width: 46vw; overflow-wrap: anywhere; }

.caption { position: fixed; left: 50%; top: 22%; transform: translate(-50%, 0); z-index: 2; pointer-events: none;
  font-size: clamp(22px, 4.6vw, 40px); font-weight: 650; letter-spacing: -0.01em; text-align: center; white-space: nowrap;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.85), 0 0 2px rgba(0, 0, 0, 0.6); opacity: 0; transition: opacity 0.9s ease; }
.caption.on { opacity: 1; }
.caption small { display: block; font-size: 0.42em; font-weight: 500; color: var(--dim); margin-top: 4px; letter-spacing: 0.04em; }

.hint { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 2; pointer-events: none;
  padding: 7px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 13px; color: var(--dim);
  opacity: 0; transition: opacity 0.6s ease; white-space: nowrap; }
.hint.on { opacity: 1; }

.stats { color: var(--dim); max-width: 520px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8); }
.controls { display: flex; gap: 6px; padding: 6px; border-radius: 16px; background: var(--glass);
  border: 1px solid var(--line); backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); margin-left: auto; }
.controls button { appearance: none; border: 0; background: transparent; color: var(--fg); font: inherit; font-size: 14px;
  padding: 9px 12px; border-radius: 11px; display: flex; align-items: center; gap: 7px; cursor: pointer; min-height: 40px;
  transition: background 0.15s ease; -webkit-tap-highlight-color: transparent; }
.controls button:hover { background: rgba(255, 255, 255, 0.09); }
.controls button[aria-pressed="true"] { background: rgba(255, 183, 3, 0.16); color: #ffd36a; }
.controls .ico { font-size: 15px; width: 16px; text-align: center; }

#progress { position: fixed; top: 0; left: 0; height: 2px; width: 0; z-index: 3; background: linear-gradient(90deg, #ffb703, #fb5607);
  transition: width 0.3s ease, opacity 0.4s ease; opacity: 0; }
#progress.on { opacity: 1; }

dialog#info { max-width: min(520px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 18px; padding: 22px 24px;
  background: rgba(12, 14, 22, 0.86); color: var(--fg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
dialog#info::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog#info h2 { margin: 0 0 10px; font-size: 22px; }
dialog#info p { margin: 0 0 12px; color: rgba(242, 244, 248, 0.88); }
dialog#info .dim { color: var(--dim); font-size: 13px; }
dialog#info button { margin-top: 6px; border: 0; border-radius: 10px; padding: 10px 18px; font: inherit; font-weight: 600;
  background: var(--accent); color: #1b1300; cursor: pointer; }

.trailmap { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1;
  opacity: 0; transition: opacity 0.6s ease; }
.trailmap.on { opacity: 1; }
.trailmap rect { fill: none; stroke: rgba(255, 255, 255, 0.6); stroke-width: 1; stroke-dasharray: 4 4; }
.trailmap rect.near { stroke: var(--accent); stroke-width: 2; stroke-dasharray: none; filter: drop-shadow(0 0 6px rgba(255, 183, 3, 0.8)); }

.here { position: fixed; left: max(16px, env(safe-area-inset-left)); bottom: 72px; z-index: 2; display: flex; align-items: center;
  gap: 12px; max-width: min(460px, calc(100vw - 32px)); padding: 10px 14px; border-radius: 14px; pointer-events: none;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); opacity: 0; transform: translateY(6px); transition: opacity 0.5s ease, transform 0.5s ease; }
.here.on { opacity: 1; transform: none; }
.here-meter { position: relative; flex: none; width: 6px; height: 40px; border-radius: 3px; overflow: hidden; background: rgba(255, 255, 255, 0.14); }
.here-meter span { position: absolute; left: 0; right: 0; bottom: 0; height: 8%; border-radius: 3px;
  background: linear-gradient(to top, #4cc9f0, #ffb703 60%, #fb5607); transition: height 0.7s ease; }
.here-text { display: flex; flex-direction: column; min-width: 0; }
.here-text b { font-size: 14.5px; font-weight: 650; }
.here-text span { font-size: 12.5px; color: var(--dim); }
.here-arrow { flex: none; font-size: 20px; line-height: 1; color: var(--accent); transition: transform 0.4s ease; }
dialog#info button.link { margin: 0; padding: 0; background: none; color: #ffd36a; font-weight: 500; text-decoration: underline; }

#toast { position: fixed; left: 50%; top: 84px; transform: translate(-50%, -8px); z-index: 4; padding: 8px 14px; border-radius: 10px;
  background: rgba(12, 14, 22, 0.9); border: 1px solid var(--line); font-size: 13.5px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.nogl[hidden] { display: none; }
.nogl { position: fixed; inset: 0; display: grid; place-items: center; padding: 32px; text-align: center; z-index: 5; }

@media (max-width: 640px) {
  .controls .lbl { display: none; }
  .controls button { padding: 9px 13px; }
  .bottom { flex-direction: column-reverse; align-items: center; }
  .controls { margin: 0; }
  .stats { width: 100%; text-align: center; font-size: 10.5px; overflow-wrap: anywhere; }
  #mag { font-size: 23px; }
  .hint { bottom: 108px; }
  .here { left: 50%; bottom: 122px; transform: translate(-50%, 6px); width: max-content; }
  .here.on { transform: translate(-50%, 0); }
}
