:root {
  --ink: #e7edf3;
  --ink-soft: #8a97a4;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --panel: rgba(18, 23, 30, 0.84);
  --panel-solid: #161c24;
  --raise: #1c242e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 26px rgba(0, 0, 0, 0.45);
  --accent: #4d9fff;
  --accent-ink: #0b1118;
  --radius: 3px;
  --radius-sm: 2px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI",
    system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); -webkit-font-smoothing: antialiased; }
#map { position: absolute; inset: 0; background: #0f1620; }
.hidden { display: none !important; }
kbd { font: inherit; font-size: 10px; background: rgba(255,255,255,.1); border-radius: 3px; padding: 1px 4px; }
button { font-family: inherit; }

.card {
  background: var(--panel);
  -webkit-backdrop-filter: saturate(150%) blur(20px);
  backdrop-filter: saturate(150%) blur(20px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Guiding bar */
#guide { position: absolute; top: 10px; left: 10px; z-index: 6; width: 188px; padding: 8px 10px 9px; }
.guide-top { display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 9px; font-weight: 650; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-soft); }
.ghost-btn {
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink-soft);
  font-size: 10px; padding: 2px 6px; border-radius: var(--radius-sm); cursor: pointer;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--accent); }
#yearReadout { font-size: 25px; font-weight: 700; line-height: 1.05; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
#guide .sub { font-size: 11px; color: var(--ink-soft); margin-top: 1px; }
.snapshot {
  width: fit-content; max-width: 100%; margin-top: 5px; padding: 2px 5px;
  border: 1px solid rgba(255,255,255,0.12); border-radius: var(--radius-sm);
  color: #b6c0cb; background: rgba(255,255,255,0.045);
  font-size: 9.5px; font-weight: 650; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hoverline { font-size: 11.5px; color: var(--accent); margin-top: 5px; font-weight: 550; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hoverline:empty { display: none; }

/* Control rail — stays visible even when UI is hidden, so you can always get back */
#rail { position: absolute; top: 10px; right: 10px; z-index: 20; display: flex; flex-direction: column; gap: 5px; }
.rail-btn {
  width: 30px; height: 30px; border-radius: var(--radius); cursor: pointer;
  background: var(--panel); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: var(--shadow); color: var(--ink-soft); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.rail-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.rail-btn.active { color: var(--accent); border-color: var(--accent); background: var(--raise); }

/* Panels */
.panel { position: absolute; z-index: 6; width: 218px; }
#layers, #saved { top: 10px; right: 50px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; cursor: grab; user-select: none; border-bottom: 1px solid var(--line);
  font-size: 10px; font-weight: 650; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft);
}
.panel-head:active { cursor: grabbing; }
.panel.collapsed .panel-body { display: none; }
.panel.collapsed .panel-head { border-bottom: none; }
.collapse { border: none; background: none; color: var(--ink-soft); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.panel.collapsed .collapse { transform: rotate(-90deg); }
.panel-body { padding: 6px 8px 9px; }

/* Layer rows */
.layer-row { display: flex; align-items: center; gap: 8px; padding: 4px 5px; border-radius: var(--radius-sm); cursor: pointer; font-size: 12.5px; user-select: none; }
.layer-row:hover { background: rgba(255,255,255,0.05); }
.layer-row input { accent-color: var(--accent); width: 14px; height: 14px; }
.swatch { width: 14px; height: 14px; border-radius: var(--radius-sm); flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18); }
.labelswatch { display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: var(--ink-soft); background: rgba(255,255,255,0.08); }
.lowswatch {
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed #9aa8b8; color: #c6d0dc; background: rgba(150,170,190,0.12);
  font-size: 10px; font-weight: 800; box-shadow: none;
}
.layer-label { flex: 1; }
.layer-count { font-size: 10px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.hint { font-size: 10.5px; color: var(--ink-soft); margin-top: 8px; line-height: 1.45; padding: 0 5px; }
.legend { display: flex; gap: 11px; font-size: 10px; color: var(--ink-soft); margin-top: 8px; padding: 0 5px; }
.legend i { font-style: normal; display: inline-flex; align-items: center; gap: 5px; }
.legend .ln { width: 15px; height: 0; border-top: 1.5px solid #8a9aa8; }
.legend .ln.dash { border-top-style: dashed; }
.legend .ln.low { border-top-style: dashed; opacity: 0.55; }

/* Info cards — multiple, draggable, spawn near the click */
.info-card { position: absolute; z-index: 8; width: 212px; }
.info-card .panel-head { color: var(--accent); }
.ic-tools { display: flex; align-items: center; gap: 1px; }
.ic-locate { border: none; background: none; color: var(--ink-soft); cursor: pointer; font-size: 13px; line-height: 1; padding: 0 3px; }
.ic-locate:hover { color: var(--accent); }

/* Locate pulse on the map */
.map-pulse {
  width: 12px; height: 12px; border-radius: 50%;
  background: rgba(77, 159, 255, 0.7); box-shadow: 0 0 0 0 rgba(77, 159, 255, 0.6);
  animation: mappulse 1.6s ease-out forwards; pointer-events: none;
}
@keyframes mappulse {
  0% { box-shadow: 0 0 0 0 rgba(77, 159, 255, 0.55); }
  100% { box-shadow: 0 0 0 28px rgba(77, 159, 255, 0); }
}
.info-card .panel-body { padding: 8px 11px 11px; }
.info-title { font-size: 15px; margin: 0 0 3px; letter-spacing: -0.01em; line-height: 1.15; font-weight: 650; }
.info-dates { font-size: 11px; color: var(--ink-soft); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.info-certainty {
  display: inline-flex; align-items: center; max-width: 100%;
  margin: -2px 0 8px; padding: 2px 5px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  color: #c6d0dc; background: rgba(255,255,255,0.045);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.info-certainty.certainty-high { color: #bce3c6; border-color: rgba(100,205,130,0.35); background: rgba(70,150,90,0.12); }
.info-certainty.certainty-medium { color: #f0d69e; border-color: rgba(220,175,80,0.35); background: rgba(190,140,45,0.12); }
.info-certainty.certainty-low { color: #f0b0b0; border-color: rgba(230,100,100,0.42); background: rgba(190,55,55,0.14); }
.info-certainty.certainty-unknown { color: #b8c2ce; }
.info-desc { font-size: 12px; line-height: 1.5; margin: 0 0 10px; color: #c4ccd4; }
.info-actions { display: flex; gap: 6px; align-items: center; }
.btn-primary { text-decoration: none; font-size: 11px; font-weight: 600; color: var(--accent-ink); background: var(--accent); padding: 4px 8px; border-radius: var(--radius-sm); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { font-size: 11px; font-weight: 600; color: var(--ink-soft); cursor: pointer; background: transparent; border: 1px solid var(--line-strong); padding: 4px 7px; border-radius: var(--radius-sm); }
.btn-ghost:hover { color: var(--ink); }

/* Saved list */
.saved-list { display: flex; flex-direction: column; gap: 2px; }
.saved-item { padding: 5px 5px 7px; border-radius: var(--radius-sm); font-size: 12.5px; }
.saved-item:hover { background: rgba(255,255,255,0.05); }
.si-row { display: flex; align-items: center; gap: 8px; }
.si-go { flex: 1; min-width: 0; cursor: pointer; }
.si-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.si-sub { font-size: 10px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.si-del { border: none; background: none; color: var(--ink-soft); cursor: pointer; font-size: 14px; opacity: 0; }
.saved-item:hover .si-del { opacity: 1; }
.si-del:hover { color: #ff6b6b; }
.si-note {
  width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04); font: inherit; font-size: 11.5px; color: var(--ink);
  padding: 4px 6px; resize: none; overflow: hidden; line-height: 1.4;
}
.si-note:focus { outline: none; border-color: var(--accent); }

/* Transport controls shared by timeline + mini player */
.transport { display: flex; align-items: center; gap: 3px; }
.tbtn {
  border: 1px solid var(--line); background: var(--raise); color: var(--ink-soft); cursor: pointer;
  height: 26px; min-width: 26px; padding: 0 5px; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center;
}
.tbtn:hover { color: var(--ink); border-color: var(--line-strong); }
.tbtn.play { color: var(--ink); }
.speed { display: flex; gap: 2px; }
.speed .sp {
  border: 1px solid var(--line); background: var(--raise); color: var(--ink-soft);
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  width: 27px; height: 26px; border-radius: var(--radius-sm); cursor: pointer;
}
.speed .sp:hover { color: var(--ink); }
.speed .sp.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Main timeline */
#timeline {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  z-index: 6; width: min(720px, calc(100% - 24px));
  padding: 8px 12px; display: flex; align-items: center; gap: 10px;
}
.track-wrap { flex: 1; }
#yearSlider { width: 100%; accent-color: var(--accent); height: 4px; margin: 3px 0 0; }
#yearTicks { position: relative; height: 12px; margin-top: 4px; font-size: 9.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
#yearTicks .tk { position: absolute; transform: translateX(-50%); white-space: nowrap; }
#yearTicks .tk:first-child { transform: none; }
#yearTicks .tk:last-child { transform: translateX(-100%); }

/* Mini player — appears when the main UI is hidden / for a clean view */
#mini {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  z-index: 21; padding: 6px 9px; display: flex; align-items: center; gap: 8px;
}
#miniYear { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
#miniSpeed { cursor: pointer; }

/* Hover tooltip */
#tooltip {
  position: absolute; z-index: 9; pointer-events: none;
  background: rgba(8, 12, 18, 0.94); color: #fff; font-size: 11.5px; font-weight: 550;
  padding: 3px 7px; border-radius: var(--radius-sm); transform: translate(-50%, -150%);
  white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}

.maplibregl-ctrl-attrib { font-size: 9px; opacity: 0.55; }
.maplibregl-ctrl-attrib.maplibregl-compact { background: var(--panel); }
.maplibregl-ctrl-bottom-right { z-index: 4; }
.maplibregl-ctrl-group { background: var(--panel-solid); border: 1px solid var(--line); }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(0.85); }

/* Hide-UI mode: keep the rail, mini player, AND any open POI cards; hide the rest */
body.ui-hidden #guide, body.ui-hidden #layers, body.ui-hidden #saved,
body.ui-hidden #timeline { display: none !important; }
#mini { display: none; }
body.ui-hidden #mini { display: flex; }

@media (max-width: 720px) { .panel, .info-card { width: 190px; } }
