/* ── Chronos v2: All of Human History, Mapped ─────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --panel-bg: rgba(10, 14, 26, 0.84);
  --panel-border: rgba(120, 160, 255, 0.25);
  --text: #e8ecf6;
  --dim: #9aa7c4;
  --accent: #ffd54f;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #000108;
  color: var(--text);
  /* no accidental text selection while dragging the globe */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* reading surfaces stay selectable */
#panelDesc, #panelContext, #panelTitle, #searchBox {
  user-select: text; -webkit-user-select: text;
}
canvas { outline: none; }

#map { position: absolute; inset: 0; }

/* ── Header ───────────────────────────────────────────────────── */
#topBar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; gap: 18px;
  padding: 14px 20px;
  pointer-events: none;
  z-index: 10;
}
#topBar > * { pointer-events: auto; }

#brand { display: flex; align-items: center; gap: 10px; }
#brand .logo { font-size: 34px; filter: drop-shadow(0 0 8px rgba(80,140,255,.8)); }
#brand h1 { font-size: 20px; letter-spacing: 4px; color: #fff; text-shadow: 0 1px 8px #000; }
#brand .tagline { font-size: 11px; color: var(--dim); letter-spacing: 1px; text-shadow: 0 1px 6px #000; }

#eraBanner {
  flex: 1; text-align: center; user-select: none;
  text-shadow: 0 2px 12px rgba(0,0,0,.95);
}
#eraDate { font-size: 26px; font-weight: 600; color: #fff; }
#eraName { font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: var(--accent); }

#searchWrap { position: relative; width: 270px; }
#searchBox {
  width: 100%; padding: 9px 12px; border-radius: 20px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg); color: var(--text);
  font-size: 13px; outline: none; backdrop-filter: blur(6px);
}
#searchBox:focus { border-color: var(--accent); }
#searchResults {
  position: absolute; top: 42px; left: 0; right: 0;
  max-height: 340px; overflow-y: auto;
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  border-radius: 12px; backdrop-filter: blur(10px); z-index: 30;
}
#searchResults .sr-item {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  display: flex; gap: 8px; align-items: baseline;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
#searchResults .sr-item:hover { background: rgba(120,160,255,.15); }
#searchResults .sr-date { margin-left: auto; font-size: 11px; color: var(--dim); white-space: nowrap; }

/* ── Legend ───────────────────────────────────────────────────── */
#legend {
  position: absolute; right: 16px; top: 80px; width: 205px;
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  border-radius: 14px; padding: 12px; backdrop-filter: blur(8px);
  z-index: 10; font-size: 12px;
  max-height: calc(100vh - 220px); overflow-y: auto;
}
.legend-title { font-weight: 600; letter-spacing: 1px; margin-bottom: 8px; display: flex; justify-content: space-between; }
#legendToggle { cursor: pointer; color: var(--dim); padding: 0 4px; }
.cat-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 8px; margin: 2px 0; border-radius: 8px;
  cursor: pointer; user-select: none;
  border: 1px solid transparent; transition: all .15s;
}
.cat-chip:hover { background: rgba(255,255,255,.07); }
.cat-chip.off { opacity: .3; filter: grayscale(.8); }
.cat-dot {
  width: 21px; height: 21px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; flex-shrink: 0; background: rgba(5,8,18,.7);
}
.cat-count { margin-left: auto; color: var(--dim); font-size: 10px; }
.layer-toggle {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 5px 8px 0; font-size: 11.5px; color: var(--dim);
}
.layer-toggle:hover { color: var(--text); }
.base-switch {
  display: flex; gap: 4px; margin: 10px 0 4px;
  border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px;
}
.base-switch button {
  flex: 1; background: transparent; color: var(--dim);
  border: 1px solid rgba(120,160,255,.25); border-radius: 8px;
  padding: 6px 4px; font-size: 11px; cursor: pointer; transition: all .15s;
}
.base-switch button:hover { color: var(--text); border-color: rgba(120,160,255,.5); }
.base-switch button.active { color: #06121f; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.legend-hint { margin-top: 10px; color: var(--dim); font-size: 10.5px; line-height: 1.5; border-top: 1px solid rgba(255,255,255,.08); padding-top: 8px; }
#legend.collapsed #legendBody, #legend.collapsed #lifeLegendBody, #legend.collapsed .legend-hint, #legend.collapsed .layer-toggle, #legend.collapsed .base-switch { display: none; }
/* legend swaps between human-history and deep-time (life) content */
.deep-only { display: none; }
body.deep .human-only { display: none; }
body.deep .deep-only { display: block; }
body.deep #legend.collapsed .deep-only { display: none; }

/* ── Map popups ───────────────────────────────────────────────── */
.tip .maplibregl-popup-content {
  background: var(--panel-bg); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 7px 11px; font-size: 12px; line-height: 1.4;
  backdrop-filter: blur(6px);
}
.tip .maplibregl-popup-content span { color: var(--dim); font-size: 11px; }
.tip .maplibregl-popup-tip { border-top-color: rgba(120,160,255,.35); border-bottom-color: rgba(120,160,255,.35); }

/* ── Event detail panel ───────────────────────────────────────── */
#eventPanel {
  position: absolute; left: 16px; top: 80px; bottom: 130px;
  width: 350px; overflow-y: auto;
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  border-radius: 16px; padding: 20px; backdrop-filter: blur(10px);
  z-index: 20; animation: slideIn .25s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } }
#closePanel {
  position: absolute; top: 10px; right: 12px;
  background: rgba(10,14,26,.7); border: none; color: var(--dim);
  font-size: 15px; cursor: pointer; border-radius: 50%;
  width: 28px; height: 28px; z-index: 2;
}
#closePanel:hover { color: #fff; }
#panelImg {
  width: calc(100% + 40px); margin: -20px -20px 12px; display: block;
  max-height: 190px; object-fit: cover;
  border-radius: 15px 15px 0 0;
}
#panelIcon { font-size: 36px; margin-bottom: 6px; }
#panelTitle { font-size: 20px; line-height: 1.25; margin-bottom: 6px; }
#panelMeta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.meta-chip {
  font-size: 10.5px; padding: 3px 9px; border-radius: 12px;
  border: 1px solid; letter-spacing: .4px;
}
.meta-date { font-size: 13px; color: var(--accent); font-weight: 600; }
#panelDesc { font-size: 13.5px; line-height: 1.6; color: var(--text); margin-bottom: 12px; }
#panelWar {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 23, 68, .12); border: 1px solid rgba(255, 82, 82, .5);
  border-radius: 10px; padding: 8px 12px; margin-bottom: 12px;
  font-size: 12.5px; cursor: pointer; transition: background .15s;
}
#panelWar:hover { background: rgba(255, 23, 68, .22); }
#panelWar .war-hint { margin-left: auto; color: #ff8a80; font-size: 10.5px; white-space: nowrap; }
.context-box {
  background: rgba(120,160,255,.1); border-left: 3px solid #7aa2ff;
  padding: 10px 12px; border-radius: 0 10px 10px 0;
  font-size: 13px; line-height: 1.55; color: #cdd8f0; margin-bottom: 14px;
}
.context-box::before { content: "💡 In context — "; font-weight: 600; color: #9db8ff; }
#panelLink {
  display: inline-block; margin-bottom: 16px; font-size: 12.5px;
  color: #7aa2ff; text-decoration: none;
}
#panelLink:hover { text-decoration: underline; }
#panelMeanwhile h3 { font-size: 13px; color: var(--dim); margin-bottom: 8px; letter-spacing: 1px; }
#meanwhileList { list-style: none; }
#meanwhileList li {
  padding: 7px 10px; margin: 4px 0; border-radius: 8px;
  background: rgba(255,255,255,.05); cursor: pointer;
  font-size: 12.5px; display: flex; gap: 7px; align-items: baseline;
}
#meanwhileList li:hover { background: rgba(120,160,255,.18); }
#meanwhileList .mw-title { flex: 1; }
#meanwhileList .mw-date { margin-left: auto; font-size: 10.5px; color: var(--dim); white-space: nowrap; padding-left: 6px; }
.rel-tag {
  font-size: 9.5px; padding: 1px 6px; border-radius: 8px; border: 1px solid;
  letter-spacing: .3px; white-space: nowrap; flex-shrink: 0; opacity: .95;
}

/* ── Timeline footer ──────────────────────────────────────────── */
#timeline {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 22px 26px;
  background: linear-gradient(transparent, rgba(2,4,12,.94) 45%);
  z-index: 15;
}
#controls { display: flex; gap: 8px; align-items: center; }
#playBtn, #speedBtn, #nowBtn, #modeBtn {
  background: var(--panel-bg); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 50%;
  width: 44px; height: 44px; font-size: 16px; cursor: pointer;
  transition: all .15s;
}
#speedBtn { font-size: 13px; }
#modeBtn, #nowBtn { width: auto; border-radius: 20px; padding: 0 13px; height: 36px; font-size: 12px; white-space: nowrap; }
#playBtn:hover, #speedBtn:hover, #nowBtn:hover, #modeBtn:hover { border-color: var(--accent); color: var(--accent); }
#playBtn.playing { color: var(--accent); border-color: var(--accent); box-shadow: 0 0 12px rgba(255,213,79,.4); }

#sliderWrap { flex: 1; position: relative; padding-top: 26px; }
#tickRow { position: absolute; top: 0; left: 0; right: 0; height: 24px; pointer-events: none; }
.tick {
  position: absolute; transform: translateX(-50%);
  font-size: 10px; color: var(--dim); white-space: nowrap;
  text-align: center; user-select: none; text-shadow: 0 1px 4px #000;
  cursor: pointer; pointer-events: auto; transition: color .15s;
}
.tick:hover { color: var(--accent); }
.tick::after {
  content: ""; display: block; width: 1px; height: 6px;
  background: var(--dim); margin: 2px auto 0;
}

#timeSlider {
  width: 100%; -webkit-appearance: none; appearance: none; height: 6px;
  border-radius: 3px; outline: none; cursor: pointer;
  background: linear-gradient(90deg,
    #8d6e63 0%, #ffd54f 18%, #d7a86e 34%, #ab47bc 50%,
    #26c6da 66%, #42a5f5 80%, #ec407a 92%, #e040fb 100%);
}
#timeSlider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  box-shadow: 0 0 12px rgba(255,213,79,.8); cursor: grab;
}
#timeSlider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  box-shadow: 0 0 12px rgba(255,213,79,.8); cursor: grab;
}
#windowChips {
  position: absolute; left: 0; bottom: -20px;
  display: flex; gap: 4px; align-items: center;
}
.wlabel { font-size: 10px; color: var(--dim); margin-right: 2px; }
.wchip {
  background: transparent; border: 1px solid rgba(120,160,255,.25);
  color: var(--dim); font-size: 10px; border-radius: 10px;
  padding: 2px 8px; cursor: pointer;
}
.wchip:hover { color: var(--text); }
.wchip.active { color: var(--accent); border-color: var(--accent); }
#visibleCount { position: absolute; right: 0; bottom: -20px; font-size: 10.5px; color: var(--dim); }

/* ── Misc ─────────────────────────────────────────────────────── */
#hint {
  position: absolute; bottom: 100px; left: 50%; transform: translateX(-50%);
  font-size: 12.5px; color: var(--dim); background: var(--panel-bg);
  padding: 7px 16px; border-radius: 16px; border: 1px solid var(--panel-border);
  z-index: 12; animation: fadeHint 1s 1; pointer-events: none;
  transition: opacity .8s;
}
#hint.gone { opacity: 0; }
@keyframes fadeHint { from { opacity: 0; } }

#helpBtn {
  position: absolute; left: 18px; bottom: 128px; z-index: 16;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--panel-bg); color: var(--accent);
  border: 1px solid var(--panel-border); font-size: 16px; font-weight: 700;
  cursor: pointer; backdrop-filter: blur(6px);
}
#helpBtn:hover { border-color: var(--accent); }
#helpOverlay {
  position: absolute; inset: 0; z-index: 90;
  background: rgba(2,4,12,.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeHint .2s 1;
}
.help-card {
  position: relative; width: min(680px, 92vw);
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  border-radius: 18px; padding: 26px 28px; backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.help-card h2 { font-size: 20px; margin-bottom: 16px; letter-spacing: .5px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; }
.help-grid > div { font-size: 12.8px; line-height: 1.5; color: var(--dim); }
.help-grid b { color: var(--text); font-size: 13.2px; }
.help-grid i { color: #cdd8f0; font-style: normal; font-weight: 600; }
.help-foot { margin-top: 18px; font-size: 10.5px; color: var(--dim); text-align: center; border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
#helpClose {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--dim); font-size: 17px; cursor: pointer;
}
#helpClose:hover { color: #fff; }
@media (max-width: 640px) { .help-grid { grid-template-columns: 1fr; } }

#loadError {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: rgba(120,20,20,.92); padding: 20px 28px; border-radius: 12px;
  font-size: 15px; z-index: 100;
}
.hidden { display: none !important; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(120,160,255,.3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.maplibregl-ctrl-bottom-right { bottom: 90px; }
.maplibregl-ctrl-attrib {
  background: rgba(10,14,26,.6) !important; color: var(--dim);
  font-size: 10px;
}
.maplibregl-ctrl-attrib a { color: var(--dim) !important; }

@media (max-width: 900px) {
  #searchWrap { display: none; }
  #legend { display: none; }
  #eventPanel { width: min(350px, 86vw); }
  #eraDate { font-size: 18px; }
}
