/* Dark "Dusk" theme, phone first. */
:root {
  --hud-h: 56px;
  --bg: #07090d;
  --glass: rgba(14, 18, 26, 0.72);
  --edge: rgba(255, 255, 255, 0.08);
  --text: #e9eef5;
  --dim: #6c7889;
  --neon: #c8ff2e;
  --neon-rgb: 200, 255, 46;
  --neon-glow: 0 0 18px rgba(var(--neon-rgb), 0.55);
  --pink: #ff3d8b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: clip; background: var(--bg); }
/* The map handles every pan and pinch itself, so the browser doesn't need to
   work out whether a touch is meant to scroll or zoom the page. */
html, body, #map { touch-action: none; overscroll-behavior: none; }
.list #route-list { touch-action: pan-y; }
body { font-family: "Space Grotesk", system-ui, sans-serif; color: var(--text); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
#map { position: absolute; inset: 0; }

/* Vignette over the map */
.vignette { position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,.55) 100%); }

.glass { background: var(--glass); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%); border: 1px solid var(--edge); }

/* Top HUD */
.hud-top {
  position: absolute; z-index: 3; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  height: var(--hud-h); padding: 0 14px; border-radius: 14px;
}
.tag { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--dim); }
.logo { display: flex; align-items: center; gap: 5px; font-family: Poppins, "Space Grotesk", sans-serif; font-weight: 800; letter-spacing: .02em; font-size: 16px; }
.hud-top .info { text-align: right; display: none; }
.show-results .hud-top .info { display: block; }
.show-results .hud-top .hint { display: none; }
.hint { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--neon); }
.has-start .hint .h1 { display: none; }
.hint .h2 { display: none; }
.has-start .hint .h2 { display: inline; }
.hud-top .now { font-size: 22px; font-weight: 700; color: var(--neon); text-shadow: var(--neon-glow); line-height: 1.05; }
.hud-top .now small { font-size: 12px; color: var(--dim); text-shadow: none; }

/* Bottom deck */
.deck {
  position: absolute; z-index: 3; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  border-radius: 22px; padding: 16px;
}
.setup { display: grid; gap: 14px; }

/* Back to the previous routes, shown only once there are some */
.back {
  display: none; align-items: center; justify-content: space-between;
  height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid rgba(var(--neon-rgb), .45); color: var(--neon);
  font-size: 13px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase;
}
.back:active { background: rgba(var(--neon-rgb), .1); }
.has-results .back { display: flex; }
.back kbd {
  font: 500 11px "JetBrains Mono", monospace; color: var(--dim);
  border: 1px solid var(--edge); border-radius: 6px; padding: 2px 6px;
}
@media (hover: none) { .back kbd { display: none; } }
.results { display: none; }
.show-results .setup { display: none; }
.show-results .results { display: grid; gap: 12px; }

.dial { display: flex; align-items: center; justify-content: space-between; }
.round {
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--edge); background: rgba(255,255,255,.04);
  display: grid; place-items: center; font-size: 22px; transition: background .15s, border-color .15s;
}
.round:active { background: rgba(var(--neon-rgb),.12); border-color: var(--neon); }
.readout { text-align: center; }
.readout input {
  width: 4.2ch; background: none; border: 0; outline: none; text-align: center; color: var(--text);
  font: 700 60px/1 "JetBrains Mono", monospace; letter-spacing: -0.04em; -moz-appearance: textfield;
}
.readout input::-webkit-inner-spin-button { -webkit-appearance: none; }
.readout .tag { margin-top: 2px; }

.chips { display: flex; gap: 6px; }
.chip {
  flex: 1; padding: 8px 0; border-radius: 10px; border: 1px solid var(--edge);
  font: 500 13px "JetBrains Mono", monospace; color: var(--dim);
}
.chip.active { color: var(--bg); background: var(--neon); border-color: var(--neon); box-shadow: var(--neon-glow); }

.go {
  height: 60px; border-radius: 16px; background: var(--neon); color: var(--bg);
  font-weight: 700; font-size: 18px; letter-spacing: .16em; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  box-shadow: 0 0 30px rgba(var(--neon-rgb),.35); position: relative; overflow: hidden;
}
.go:active { transform: scale(.98); }
.go svg { transition: transform .2s; }
.go:hover svg { transform: translateX(3px); }
.go .t2 { display: none; }
.loading .go .t1 { display: none; }
.loading .go .t2 { display: inline; }
.loading .go::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  transform: translateX(-100%); animation: sweep 1s linear infinite;
}
@keyframes sweep { to { transform: translateX(100%); } }

.nav { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; }
.nav .round { width: 64px; height: 56px; border-radius: 16px; }
.wide {
  height: 56px; border-radius: 16px; border: 1px solid var(--neon); color: var(--neon);
  font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.wide:active { background: rgba(var(--neon-rgb),.12); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ghost-btn {
  height: 44px; border-radius: 12px; border: 1px solid var(--edge); color: var(--dim);
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
}

/* Full-screen list on the phone */
.list {
  position: absolute; z-index: 4; inset: 0; padding: calc(70px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(7, 9, 13, .9); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; flex-direction: column; gap: 12px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.list-open .list { opacity: 1; pointer-events: auto; }
.list-head { display: flex; justify-content: space-between; align-items: center; }
.list-head h2 { margin: 0; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: var(--dim); font-weight: 500; }
#route-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.route-item {
  width: 100%; border: 1px solid var(--edge); border-radius: 14px; padding: 12px; text-align: left;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; background: rgba(255,255,255,.03);
}
.route-item .thumb { grid-column: 1 / 3; width: 100%; height: 72px; color: #3a4455; margin-bottom: 6px; }
.route-item.selected { border-color: var(--neon); box-shadow: inset 0 0 0 1px var(--neon), 0 0 22px rgba(var(--neon-rgb),.15); }
.route-item.selected .thumb { color: var(--neon); filter: drop-shadow(0 0 4px rgba(var(--neon-rgb),.7)); }
.thumb-start { fill: var(--pink); stroke: none; }
.ri-num { font: 500 11px "JetBrains Mono"; color: var(--dim); grid-column: 1; }
.ri-num::before { content: "#"; }
.ri-delta { font: 500 11px "JetBrains Mono"; color: var(--dim); grid-column: 2; grid-row: 2; text-align: right; }
.ri-dist { grid-column: 1 / 3; font: 700 20px "JetBrains Mono"; }
.ri-dist small { font-size: 11px; color: var(--dim); }

/* Start marker: pink with a radar pulse while searching */
.start-marker {
  width: 22px; height: 22px; border-radius: 50%; background: var(--pink);
  border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(255,61,139,.35), 0 0 22px var(--pink);
}
body:not(.show-results) .start-marker { cursor: grab; }
/* While planning, a slow pulse makes the start easy to spot. */
body:not(.show-results):not(.loading) .start-marker::before { animation: pulse 2.2s ease-out infinite; }
@keyframes pulse { from { transform: scale(.6); opacity: .8; } to { transform: scale(2.6); opacity: 0; } }
.start-marker::before, .start-marker::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 1px solid var(--pink); opacity: 0;
}
.loading .start-marker::before { animation: radar 1.6s ease-out infinite; }
.loading .start-marker::after { animation: radar 1.6s ease-out .8s infinite; }
@keyframes radar { from { transform: scale(.5); opacity: .9; } to { transform: scale(6); opacity: 0; } }

#toast {
  position: absolute; z-index: 6; left: 12px; right: 12px; top: calc(76px + env(safe-area-inset-top));
  padding: 12px 14px; border-radius: 12px; font-size: 14px;
  background: #24141d; border: 1px solid rgba(255, 61, 139, .55); color: #ffd3e4;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  opacity: 0; transform: translateY(-8px); transition: .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }

/* Map credits: the ⓘ sits in the top-right corner, centred on the top bar's
   row. On desktop the text slides out to its left. */
.credits {
  position: absolute; z-index: 4; top: max(12px, env(safe-area-inset-top)); right: 12px;
  height: var(--hud-h); display: flex; align-items: center; gap: 8px;
  /* fast taps count as double/triple clicks: don't select the text */
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.credits-btn { width: 24px; height: 24px; padding: 0; display: grid; place-items: center; color: var(--text); opacity: .85; }
.credits-btn:hover { opacity: 1; }
.credits-i { fill: var(--bg); }
.credits-text {
  font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden;
  background: rgba(16, 20, 28, .9); border: 1px solid var(--edge); border-radius: 8px;
  padding: 5px 10px; max-width: 320px; opacity: 1;
  transition: max-width .5s cubic-bezier(.2, .8, .2, 1), padding .5s cubic-bezier(.2, .8, .2, 1),
              opacity .35s ease, border-color .35s ease;
}
.credits-text a { color: inherit; text-decoration: none; }
.credits-text a:hover { color: var(--text); }
.credits:not(.open) .credits-text {
  max-width: 0; padding-left: 0; padding-right: 0; opacity: 0; border-color: transparent; pointer-events: none;
}

/* Phones: lighter to draw (no live blur behind panels, no edge overlay),
   and a more compact setup panel so more of the map shows. */
@media (max-width: 899px) {
  .glass { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(16, 20, 28, .94); }
  /* The list fills the whole screen, covering the top bar and the map credits. */
  .list {
    backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(7, 9, 13, .97);
    z-index: 5; padding-top: calc(12px + env(safe-area-inset-top));
  }
  .list-open .credits, .list-open .hud-top { visibility: hidden; }
  .vignette { display: none; }
  .hud-top { right: 48px; }
  /* Map credits: the top bar fills the row, so the text drops down below
     the ⓘ, and fades and lifts away when it closes. */
  .credits-text {
    position: absolute; top: calc(100% + 4px); right: 0; max-width: none;
    padding: 8px 12px; border-radius: 10px; background: rgba(16, 20, 28, .96);
    transform-origin: top right;
    transition: opacity .35s ease, transform .4s cubic-bezier(.2, .8, .2, 1);
  }
  .credits:not(.open) .credits-text {
    max-width: none; padding: 8px 12px; border-color: var(--edge);
    opacity: 0; transform: translateY(-8px) scale(.96);
  }

  .deck { padding: 12px; border-radius: 20px; }
  .setup { gap: 10px; }
  .back { height: 38px; }
  .round { width: 44px; height: 44px; font-size: 20px; }
  .readout input { font-size: 44px; }
  .readout .tag { margin-top: 0; font-size: 10px; }
  .chip { padding: 7px 0; }
  .go { height: 50px; font-size: 16px; }
  .show-results .results { gap: 10px; }
  .nav .round, .wide { height: 50px; }
  .ghost-btn { height: 38px; }
}

/* Narrow phones: keep the name and the hint on one line in the top bar. */
@media (max-width: 380px) {
  .hint { font-size: 10px; letter-spacing: .08em; }
  .logo { font-size: 14px; }
}

@media (min-width: 900px) {
  .hud-top { right: auto; width: 400px; }
  .show-results .credits { right: 364px; }
  #toast { right: auto; width: 400px; }
  .deck { right: auto; width: 400px; }
  .list {
    inset: auto; right: 12px; top: 12px; bottom: 12px; width: 340px; border-radius: 22px; padding: 16px;
    opacity: 1; pointer-events: auto; background: var(--glass); border: 1px solid var(--edge);
    transform: translateX(110%); transition: transform .35s cubic-bezier(.2,.8,.2,1);
  }
  .show-results .list { transform: none; }
  #list-toggle, #list-close { display: none; }
  .row2 { grid-template-columns: 1fr; }
}
