:root {
  --ink: #16202e;
  --muted: #66718a;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --line: rgba(22, 32, 46, 0.08);
  --card-bg: rgba(255, 255, 255, 0.9);
  --card-shadow: 0 10px 30px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
}

/* ---------- header ---------- */

header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.logo { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text .title { font-weight: 750; font-size: 15.5px; letter-spacing: -0.01em; }
.brand-text .subtitle { color: var(--muted); font-size: 11px; }

#searchbox {
  position: relative;
  flex: 1;
  max-width: 520px;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  width: 16px; height: 16px;
  color: var(--muted);
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border: 1px solid #d4dae4;
  border-radius: 999px;
  font-size: 13.5px;
  background: #f6f8fb;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
#search-input:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

#suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  z-index: 1200;
  max-height: 330px;
  overflow-y: auto;
  padding: 6px;
}
.suggestion {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
}
.suggestion:hover, .suggestion.active { background: var(--accent-soft); }
.suggestion .s-main { font-size: 13.5px; font-weight: 600; }
.suggestion .s-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.suggestion.empty { cursor: default; color: var(--muted); font-size: 13px; }
.suggestion.empty:hover { background: none; }

#status {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
#status.error { color: #c0392b; }

.iconbtn {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 999px;
  border: 1px solid #d4dae4;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}
.iconbtn:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- map ---------- */

#map {
  position: absolute;
  top: 60px; bottom: 0; left: 0; right: 0;
  background: #e8ecf1;
}
.maplibregl-canvas-container.maplibregl-interactive { cursor: crosshair; }
.maplibregl-canvas-container.maplibregl-interactive:active { cursor: grabbing; }
#map.working .maplibregl-canvas-container,
#map.working .maplibregl-canvas-container.maplibregl-interactive { cursor: progress; }

/* custom marker: pulsing dot */
.pin {
  position: relative;
  width: 15px;
  height: 15px;
  background: var(--accent);
  border: 2.5px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.45);
  pointer-events: none;
}
.pin::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pin-pulse 1.8s ease-out infinite;
}
@keyframes pin-pulse {
  0% { transform: scale(0.7); opacity: 0.9; }
  70% { transform: scale(2.1); opacity: 0; }
  100% { transform: scale(2.1); opacity: 0; }
}

/* ---------- cards ---------- */

.card {
  position: absolute;
  z-index: 1000;
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 12px 14px;
}

.hidden { display: none !important; }

.close {
  position: absolute;
  top: 8px; right: 10px;
  border: 0; background: none;
  font-size: 17px; color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.close:hover { color: var(--ink); }

/* ---------- result panel ---------- */

#result {
  top: 74px;
  left: 14px;
  width: 330px;
  max-width: calc(100vw - 28px);
  max-height: calc(100% - 165px);
  overflow-y: auto;
}
#result-address { font-size: 12.5px; color: var(--muted); padding-right: 20px; line-height: 1.35; }
#result .big {
  margin: 8px 0 2px;
  font-size: 27px;
  font-weight: 750;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.tag { font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px; color: #fff; flex: none; }
.when { font-size: 11px; font-weight: 650; color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; flex: none; }
#result-quali { font-size: 12px; color: var(--muted); margin: 0 0 10px; }

#result .big .working-note,
#result .big .errnote {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.35;
}

#breakdown { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#breakdown td { padding: 3.5px 4px; }
#breakdown td:first-child { color: var(--muted); white-space: nowrap; }
#breakdown td:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.barcell { width: 100%; }
.track {
  height: 7px;
  border-radius: 4px;
  background: #e9edf3;
  overflow: hidden;
}
.bar {
  height: 100%;
  border-radius: 4px;
  width: 0;
  transition: width 0.35s ease, background-color 0.35s ease;
}

/* 24 h profile chart */
#hourchart-wrap { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.hourchart-title { font-size: 11.5px; font-weight: 650; }
.hourchart-hint { font-weight: 450; color: var(--muted); }
#hourchart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 54px;
  margin-top: 8px;
}
.hbar {
  flex: 1;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.12s;
}
.hbar:hover { opacity: 1; }
.hbar.current { outline: 2px solid var(--ink); outline-offset: 1px; opacity: 1; }
.hourchart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}
#hourchart-note { font-size: 11px; color: var(--muted); margin-top: 5px; }

.pdfbtn {
  margin-top: 12px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.pdfbtn:hover { background: var(--accent); color: #fff; }
.pdfbtn:disabled { opacity: 0.55; cursor: wait; }

/* free-quota hint */
#free-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
#free-hint a { color: var(--accent); cursor: pointer; font-weight: 600; }

/* locked full-report box */
#report-gate {
  margin-top: 12px;
  border: 1px dashed #c8d0dc;
  border-radius: 10px;
  padding: 12px;
  background: #f8fafc;
}
.gate-title { font-size: 13px; font-weight: 700; }
.gate-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.gate-list {
  margin: 8px 0 10px;
  padding-left: 18px;
  font-size: 12px;
  color: var(--muted);
}
.gate-list li { margin: 2px 0; }
#report-gate .pdfbtn { margin-top: 0; background: var(--accent); color: #fff; }
#report-gate .pdfbtn:hover { opacity: 0.92; }

/* paywall modal */
#paywall-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
#paywall {
  position: relative;
  width: 350px;
  max-width: calc(100vw - 32px);
  padding: 18px 20px;
}
#paywall h3 { margin: 0 0 6px; font-size: 16px; }
.pw-sub { margin: 0 0 4px; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.pw-buy {
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
.pw-buy:hover { opacity: 0.92; }
.pw-or {
  margin: 12px 0 6px;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}
.pw-license { display: flex; gap: 6px; }
.pw-license input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #cbd2dd;
  border-radius: 8px;
  font-size: 12.5px;
}
.pw-license button {
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
}
.pw-license button:hover { background: var(--accent); color: #fff; }
#paywall-msg { margin-top: 8px; font-size: 11.5px; color: var(--muted); min-height: 14px; }
#paywall-msg.error { color: #c0392b; }

/* ---------- layer toggle ---------- */

#layers {
  top: 74px;
  right: 14px;
  display: flex;
  gap: 3px;
  padding: 5px;
}
.seg {
  border: 0;
  background: transparent;
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
}
.seg:hover { color: var(--ink); }
.seg.active { background: var(--accent); color: #fff; }

/* ---------- explore chips ---------- */

#chips {
  position: absolute;
  z-index: 1000;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  max-width: calc(100vw - 28px);
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
}
#chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.12);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.chip:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(15, 23, 42, 0.18); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- time bar ---------- */

#timebar {
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  width: min(520px, calc(100vw - 28px));
}
#play-pause { border: 0; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
#play-pause:hover { background: var(--accent); color: #fff; }
#time-display { display: flex; align-items: center; gap: 6px; flex: none; width: 76px; }
#time-icon { font-size: 17px; line-height: 1; }
#time-text { font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }

#scrubber {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg,
    #2b3a5e 0%, #2b3a5e 21%,
    #f6c573 29%, #cfe6f7 40%,
    #cfe6f7 62%, #f6a55c 76%,
    #2b3a5e 86%, #2b3a5e 100%);
  cursor: pointer;
  outline: none;
}
#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid var(--accent);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
}
#scrubber::-moz-range-thumb {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid var(--accent);
}
#scrubber:disabled { opacity: 0.45; cursor: default; }
#timebar .seg { flex: none; padding: 5px 10px; border: 1px solid var(--line); }

/* ---------- legend ---------- */

#legend {
  right: 14px;
  bottom: 22px;
  width: 205px;
  padding: 10px 13px;
}
.legend-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.legend-title { font-size: 11px; font-weight: 650; }
#probe-val { font-size: 11px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend-ramp {
  position: relative;
  height: 11px;
  border-radius: 6px;
  margin-top: 7px;
  background: linear-gradient(90deg,
    rgba(120,200,120,0.9) 0%,
    rgba(200,215,80,0.9) 22%,
    rgba(245,210,60,0.9) 40%,
    rgba(248,160,40,0.9) 56%,
    rgba(240,100,35,0.9) 70%,
    rgba(220,45,35,0.9) 84%,
    rgba(150,20,100,0.95) 100%);
}
#legend-cursor {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 17px;
  border-radius: 2px;
  background: var(--ink);
  border: 1px solid #fff;
  transform: translateX(-50%);
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 4px;
}

/* ---------- about ---------- */

#about {
  top: 74px;
  right: 14px;
  width: 360px;
  max-width: calc(100vw - 28px);
  z-index: 1150;
  font-size: 12.5px;
  line-height: 1.5;
}
#about h3 { margin: 0 0 8px; font-size: 14px; }
#about p { margin: 0 0 9px; color: var(--ink); }
#about .about-links { color: var(--muted); font-size: 11.5px; }
#about a { color: var(--accent); }

/* busy state */
.working-note::after {
  content: '';
  display: inline-block;
  width: 14px;
  text-align: left;
  animation: working-dots 1.2s steps(4, end) infinite;
}
@keyframes working-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ---------- mobile ---------- */

@media (max-width: 780px) {
  header { flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 8px; }
  .brand-text .subtitle { display: none; }
  #searchbox { order: 3; flex-basis: 100%; max-width: none; }
  #status { display: none; }
  #map { top: 104px; }
  #result {
    top: auto;
    bottom: 76px;
    left: 8px; right: 8px;
    width: auto;
    max-height: 46vh;
  }
  #layers { top: 118px; right: 8px; padding: 4px; }
  .seg { padding: 5px 8px; font-size: 11.5px; }
  #chips { bottom: 76px; left: 8px; right: 8px; transform: none; max-width: none; }
  body.has-result #chips { display: none; }
  #timebar { width: calc(100vw - 16px); gap: 8px; }
  #legend { display: none; }
}
