:root {
  --bg: #04060c;
  --panel: rgba(9, 13, 24, 0.78);
  --panel-solid: #0b1020;
  --line: rgba(148, 170, 220, 0.14);
  --line-strong: rgba(148, 170, 220, 0.28);
  --text: #e6ebf5;
  --muted: #8591a8;
  --faint: #556078;
  --accent: #ffb547;           /* signature amber */
  --accent-soft: rgba(255, 181, 71, 0.14);
  --ok: #3ddc97;
  --warn: #ffb547;
  --err: #ff5d6c;
  --radius: 14px;
  --font: "Space Grotesk", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

#globe { position: fixed; inset: 0; }
.mono { font-family: var(--mono); }

button { font: inherit; color: inherit; }

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  flex: none;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--line-strong); }
.icon-btn.small { width: 28px; height: 28px; font-size: 12px; border-radius: 8px; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#playIcon path { fill: currentColor; stroke: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 16px; left: 16px; right: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  pointer-events: none;
  z-index: 20;
}
.topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 12px; width: 280px; flex: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd89a, var(--accent) 45%, #6b3a00 100%);
  box-shadow: 0 0 18px rgba(255, 181, 71, 0.55);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 1px solid rgba(255, 181, 71, 0.45);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse { from { transform: scale(.85); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }
.brand-name { font-weight: 700; letter-spacing: .14em; font-size: 15px; }
.brand-name span { color: var(--accent); }
.brand-clock { font-size: 11px; color: var(--muted); margin-top: 2px; }

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 14px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.search:focus-within { border-color: rgba(255, 181, 71, 0.55); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; font-size: 15px;
}
.search input::placeholder { color: var(--faint); }
.search kbd {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  border: 1px solid var(--line-strong); border-radius: 5px; padding: 1px 6px;
}
.search-results {
  position: absolute; top: 52px; left: 0; right: 0;
  list-style: none; margin: 0; padding: 6px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  max-height: 340px; overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
}
.search-results:empty { display: none; }
.search-results li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px; cursor: pointer;
}
.search-results li img { width: 22px; height: 16px; border-radius: 3px; object-fit: cover; }
.search-results li small { margin-left: auto; color: var(--faint); font-size: 12px; }
.search-results li.active, .search-results li:hover { background: rgba(255, 255, 255, 0.07); }

.mobile-only { display: none; }

/* ---------- Layers panel ---------- */
.layers {
  position: fixed;
  top: 84px; left: 16px;
  width: 280px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding: 12px;
  z-index: 15;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); padding: 2px 4px 10px;
}
.panel-head.sub { padding-top: 16px; border-top: 1px solid var(--line); margin-top: 8px; }

.layer {
  display: grid;
  grid-template-columns: 10px 1fr auto 34px;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}
.layer:hover { background: rgba(255, 255, 255, 0.04); }
.layer .swatch { width: 10px; height: 10px; border-radius: 3px; }
.layer .name { font-weight: 500; line-height: 1.2; }
.layer .meta { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--faint); margin-top: 2px; }
.layer .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); flex: none; }
.layer .dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.layer .dot.loading { background: var(--warn); animation: blink 1s infinite; }
.layer .dot.stale { background: var(--warn); }
.layer .dot.error { background: var(--err); }
@keyframes blink { 50% { opacity: .3; } }
.layer .count { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.layer.off .name, .layer.off .count { opacity: .45; }

.switch {
  width: 34px; height: 20px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  position: relative; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform .2s;
}
.layer:not(.off) .switch { background: var(--accent); }
.layer:not(.off) .switch::after { transform: translateX(14px); background: #1a1206; }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px; padding: 3px; gap: 3px;
}
.segmented button {
  border: 0; background: transparent; padding: 7px 0;
  border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 13px;
}
.segmented button.active { background: var(--accent); color: #1a1206; font-weight: 600; }

.check {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); padding: 10px 4px 0; cursor: pointer;
}
.check input { accent-color: var(--accent); }

/* ---------- Card ---------- */
.card {
  position: fixed;
  top: 84px; right: 16px;
  width: 360px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  z-index: 15;
  padding: 0;
  animation: slideIn .35s cubic-bezier(.2, .8, .2, 1);
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }
.card-close { position: absolute; top: 12px; right: 12px; z-index: 2; background: rgba(0,0,0,.4); }

.card-hero {
  position: relative;
  height: 150px;
  background: linear-gradient(135deg, #1b2440, #0b1020);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
}
.card-hero img.photo { width: 100%; height: 100%; object-fit: cover; opacity: .75; }
.card-hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 35%, rgba(9, 13, 24, 0.95));
}
.card-title {
  position: absolute; left: 18px; right: 18px; bottom: 12px; z-index: 1;
  display: flex; align-items: center; gap: 12px;
}
.card-title img.flag { width: 40px; height: 30px; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.5); object-fit: cover; }
.card-title h2 { margin: 0; font-size: 22px; line-height: 1.1; }
.card-title p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.card-section { padding: 14px 18px; border-top: 1px solid var(--line); }
.card-section:first-of-type { border-top: 0; }
.card-section h3 {
  margin: 0 0 10px; font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted); font-weight: 500;
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat .v { font-family: var(--mono); font-size: 17px; font-weight: 600; }
.stat .k { font-size: 11px; color: var(--muted); margin-top: 3px; }
.stat .v.accent { color: var(--accent); }

.weather { display: flex; align-items: center; gap: 14px; }
.weather .icon { font-size: 34px; line-height: 1; }
.weather .temp { font-family: var(--mono); font-size: 28px; font-weight: 600; }
.weather .desc { color: var(--muted); font-size: 12px; }

.summary { color: #c3cadb; line-height: 1.55; font-size: 13px; margin: 0; }
.summary a, .card a { color: var(--accent); text-decoration: none; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text) !important;
  font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { background: rgba(255, 255, 255, 0.09); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1206 !important; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.wide { grid-column: span 2; }

.skeleton {
  height: 12px; border-radius: 6px; margin: 6px 0;
  background: linear-gradient(90deg, rgba(255,255,255,.05), rgba(255,255,255,.12), rgba(255,255,255,.05));
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Timeline ---------- */
.timeline {
  position: fixed;
  left: 50%; bottom: 30px;
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  z-index: 15;
}
.timeline-track { flex: 1; position: relative; }
.timeline-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); }
#timeLabel { color: var(--accent); font-weight: 600; }
#quakeHistogram { width: 100%; height: 28px; display: block; margin-top: 4px; }
#timeSlider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; margin: -6px 0 0;
  background: transparent; cursor: pointer; display: block;
}
#timeSlider::-webkit-slider-runnable-track { height: 2px; background: var(--line-strong); }
#timeSlider::-moz-range-track { height: 2px; background: var(--line-strong); }
#timeSlider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -6px;
  border-radius: 50%; background: var(--accent); border: 3px solid #1a1206;
  box-shadow: 0 0 0 1px var(--accent);
}
#timeSlider::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 3px solid #1a1206;
}

/* ---------- Misc ---------- */
.tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: var(--panel-solid); border: 1px solid var(--line-strong);
  padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 500;
  transform: translate(14px, 14px);
}
.toast {
  position: fixed; left: 50%; top: 76px; transform: translateX(-50%);
  z-index: 40; background: var(--panel-solid); border: 1px solid var(--line-strong);
  padding: 8px 14px; border-radius: 10px; font-size: 13px;
}
.credits {
  position: fixed; right: 12px; bottom: 6px; z-index: 10;
  font-size: 10px; color: var(--faint);
}

/* globe.gl hover labels */
.scene-tooltip, .float-tooltip-kap {
  font-family: var(--font) !important;
  background: var(--panel-solid) !important;
  border: 1px solid var(--line-strong);
  border-radius: 8px !important;
  padding: 6px 10px !important;
  font-size: 12px !important;
  line-height: 1.45;
}
.tip-title { font-weight: 600; font-size: 13px; }
.tip-sub { color: var(--muted); font-family: var(--mono); font-size: 11px; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar { top: 10px; left: 10px; right: 10px; gap: 10px; }
  .brand { width: auto; }
  .brand > div { display: none; }
  .search { height: 40px; }
  .search kbd { display: none; }
  .mobile-only { display: inline-grid; }

  .layers {
    top: auto; left: 10px; right: 10px; bottom: 10px;
    width: auto; max-height: 60vh;
    transform: translateY(calc(100% + 20px));
    transition: transform .3s ease;
    z-index: 25;
  }
  .layers.open { transform: none; }

  .card {
    top: auto; left: 10px; right: 10px; bottom: 10px;
    width: auto; max-height: 55vh;
    z-index: 22;
  }
  .card-hero { height: 110px; }

  .timeline { bottom: 22px; padding: 8px 10px; }
  body.card-open .timeline { display: none; }
  .credits { left: 10px; right: 10px; bottom: 4px; font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .timeline { bottom: 20px; }
}

/* ================= v3 additions ================= */
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; width: 280px; justify-content: flex-end; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.pill-btn:hover { border-color: var(--line-strong); background: rgba(30, 38, 60, .85); }
.pill-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pill-btn.active, .icon-btn.active { background: var(--accent); color: #1a1206; border-color: var(--accent); }
.pill-btn.floating { position: fixed; right: 16px; bottom: 112px; z-index: 14; box-shadow: 0 8px 30px rgba(0,0,0,.45); }
body.card-open .pill-btn.floating { right: 392px; }

/* search rows */
.search-results li .ph { width: 22px; text-align: center; flex: none; }
.search-results li .two { display: flex; flex-direction: column; min-width: 0; }
.search-results li .two em { font-style: normal; color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results li.muted { color: var(--faint); cursor: default; font-size: 13px; }
.search-results li.muted:hover { background: transparent; }

/* cards */
.card.wide { width: 440px; }
.hint { color: var(--faint); font-size: 12px; margin: 10px 0 0; }
.follow-head h2 { margin: 6px 0 2px; font-size: 21px; padding-right: 30px; }
.follow-head .sub { margin: 0; color: var(--muted); font-size: 12px; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: 3px 9px;
}
.live-pill span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; }
.route { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.route > div:not(.route-line) { display: flex; flex-direction: column; }
.route > div:last-child { text-align: right; }
.route b { font-size: 20px; }
.route span { color: var(--muted); font-size: 12px; }
.route-line { color: var(--accent); font-size: 18px; }

.cmp-top h3 { margin-bottom: 12px; }
.cmp-heads { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.cmp-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 5px; }
.cmp-head .flag { width: 44px; height: 33px; border-radius: 4px; object-fit: cover; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.cmp-head b { font-size: 16px; }
.cmp-head span { color: var(--muted); font-size: 11px; }
.vs { font-family: var(--mono); color: var(--faint); font-size: 12px; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cmp th { color: var(--muted); font-weight: 400; font-size: 11px; text-align: center; padding: 7px 4px; white-space: nowrap; }
table.cmp td { width: 38%; padding: 7px 6px; font-family: var(--mono); text-align: center; border-radius: 6px; }
table.cmp tr + tr th, table.cmp tr + tr td { border-top: 1px solid var(--line); }
table.cmp td.win { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
table.cmp td.wxcell { font-family: var(--font); }

/* tour */
.tour-caption {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px)); z-index: 26;
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  animation: rise .4s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.tour-step { color: var(--accent); font-size: 12px; flex: none; }
.tour-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tour-text b { font-size: 15px; }
.tour-text span { color: var(--muted); font-size: 12px; }
body.touring .timeline { display: none; }

/* terrain */
.terrain { position: fixed; inset: 0; z-index: 24; background: #04060c; }
#terrainMap { position: absolute; inset: 0; }
.terrain-bar {
  position: absolute; top: 16px; left: 16px; right: 16px; z-index: 2;
  display: flex; align-items: center; gap: 10px; pointer-events: none;
}
.terrain-bar > * { pointer-events: auto; }
.terrain-title {
  flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center;
  text-shadow: 0 1px 8px rgba(0,0,0,.8); pointer-events: none !important;
}
.terrain-title b { font-size: 17px; }
.terrain-title span { font-size: 11px; color: #c9d3e6; }
body.terrain-open .timeline, body.terrain-open .layers, body.terrain-open .topbar,
body.terrain-open .card, body.terrain-open .credits { display: none !important; }
.maplibregl-ctrl-group { background: var(--panel-solid) !important; border: 1px solid var(--line-strong); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line) !important; }
.maplibregl-ctrl-icon { filter: invert(1) brightness(1.4); }
.maplibregl-ctrl-attrib { background: rgba(4,6,12,.6) !important; color: var(--muted) !important; font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }

@media (max-width: 760px) {
  .top-actions { width: auto; }
  .pill-btn span { display: none; }
  #tourBtn { padding: 0 10px; }
  .card.wide { width: auto; }
  .pill-btn.floating, body.card-open .pill-btn.floating { right: 10px; bottom: 96px; }
  .tour-caption { bottom: 14px; }
  .terrain-title span { display: none; }
}

/* ================= installable app ================= */
.pill-btn.install { border-color: rgba(255, 181, 71, 0.45); color: var(--accent); }
.pill-btn.install:hover { background: var(--accent); color: #1a1206; }
.ios-help {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px)); z-index: 45; padding: 14px 44px 14px 16px; font-size: 14px;
}
.ios-help p { margin: 6px 0 0; color: var(--muted); line-height: 1.5; }
.ios-help p b { color: var(--text); }
.ios-help .icon-btn { position: absolute; top: 10px; right: 10px; }
.ios-share { display: inline-grid; place-items: center; width: 22px; height: 22px; border: 1px solid var(--line-strong); border-radius: 6px; font-size: 12px; }

/* Respect notches / home indicator when running as an installed app */
.topbar { top: max(16px, env(safe-area-inset-top)); }
.timeline { bottom: max(30px, calc(env(safe-area-inset-bottom) + 12px)); }
@media (max-width: 760px) {
  .topbar { top: max(10px, env(safe-area-inset-top)); }
  .timeline { bottom: max(22px, calc(env(safe-area-inset-bottom) + 8px)); }
}
