:root {
  --bg: #0f1420;
  --fg: #e8eaed;
  --muted: #8d96a8;
  --grid: #1f2733;
  --axis: #3a4252;
  --panel: #161c2a;
  --panel-2: #1c2434;
  --accent: #5dade2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

#app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--grid);
  height: 64px;
}

.title-block h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.3px; }
.title-block p  { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.controls { display: flex; gap: 8px; align-items: center; }
.controls input, .controls select, .controls button {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
.controls button { cursor: pointer; }
.controls button:hover { border-color: var(--accent); }
.controls input:focus, .controls select:focus { outline: none; border-color: var(--accent); }
.controls .check { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* Multi-select category filter */
.multiselect { position: relative; }
.multiselect-btn {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  min-width: 130px;
  text-align: left;
}
.multiselect-btn:hover { border-color: var(--accent); }
.multiselect-btn::after {
  content: ' ▾';
  color: var(--muted);
  font-size: 10px;
}
.multiselect-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 4px;
  min-width: 220px;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.multiselect-panel.hidden { display: none; }
.multiselect-panel .ms-actions {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-bottom: 1px solid var(--grid);
  margin-bottom: 4px;
}
.multiselect-panel .ms-actions button {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
}
.multiselect-panel .ms-actions button:hover { background: var(--panel-2); }
.multiselect-panel .ms-divider {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 8px 4px;
  margin-top: 4px;
  border-top: 1px solid var(--grid);
}
.multiselect-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  border-radius: 4px;
  user-select: none;
}
.multiselect-panel label:hover { background: var(--panel-2); }
.multiselect-panel label input { margin: 0; cursor: pointer; }
.multiselect-panel label .ms-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.multiselect-panel label .ms-count {
  margin-left: auto;
  font-size: 10px;
  color: var(--muted);
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 8px;
}
.multiselect-panel .ms-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--grid);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  margin: 0 0 4px;
}
.multiselect-panel .ms-search:focus {
  outline: none;
  border-color: var(--accent);
}
.multiselect-panel .ms-footer {
  font-size: 10px;
  color: var(--muted);
  padding: 6px 8px 2px;
  border-top: 1px solid var(--grid);
  margin-top: 4px;
}
#tag-filter .multiselect-panel {
  min-width: 280px;
  max-height: 70vh;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 2px 4px;
}
.zoom-controls button {
  background: transparent;
  border: none;
  color: var(--fg);
  width: 26px;
  height: 24px;
  padding: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.zoom-controls button:hover { background: var(--grid); border-color: transparent; }
.zoom-controls #zoom-reset, .zoom-controls #zoom-fit { width: auto; padding: 0 8px; font-size: 11px; font-weight: 500; }
#zoom-level {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tick.year { color: var(--muted); opacity: 0.7; font-size: 10px; }

#timeline-wrap {
  position: relative;
  /* fill everything below the 64px header */
  height: calc(100% - 64px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#timeline-area {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

#lane-labels-viewport {
  width: 130px;
  flex: 0 0 130px;
  background: var(--panel);
  border-right: 1px solid var(--grid);
  overflow: hidden;
  position: relative;
}
#lane-labels {
  position: relative;
}
.lane-label {
  position: absolute;
  left: 0; right: 0;
  padding: 0 12px;
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px dashed var(--grid);
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.lane-label .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
}
.lane-label .lane-count {
  margin-left: auto;
  font-size: 10px;
  color: var(--muted);
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

#timeline-scroll {
  flex: 1;
  overflow: auto;
  scroll-behavior: smooth;
}
/* Pretty scrollbars in webkit so vertical scroll feels intentional */
#timeline-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
#timeline-scroll::-webkit-scrollbar-track { background: var(--panel); }
#timeline-scroll::-webkit-scrollbar-thumb { background: var(--grid); border-radius: 6px; }
#timeline-scroll::-webkit-scrollbar-thumb:hover { background: var(--axis); }
#timeline-scroll.panning { cursor: grabbing; user-select: none; }
#timeline-scroll.panning .event-card { pointer-events: none; }

#timeline {
  position: relative;
  height: 100%;
  min-height: 100%;
}

#relations-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#relations-svg path {
  fill: none;
  stroke-width: 1.5;
  opacity: 0.35;
  transition: opacity 0.15s, stroke-width 0.15s;
}
#relations-svg path.highlight {
  opacity: 1;
  stroke-width: 2.5;
}
#relations-svg path.dim {
  opacity: 0.05;
}

#events-layer {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
}

.event-card {
  position: absolute;
  width: 220px;
  background: var(--panel-2);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  font-size: 12px;
}
.event-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}
.event-card.dim { opacity: 0.25; }
.event-card.selected {
  outline: 2px solid var(--accent);
  box-shadow: 0 4px 18px rgba(93,173,226,0.5);
}
.event-card .ec-title { font-weight: 600; line-height: 1.25; margin-bottom: 4px; }
.event-card .ec-date  { color: var(--muted); font-size: 11px; }
.event-card .ec-span {
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin-top: 6px;
  opacity: 0.6;
}

#axis-grid {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}
.grid-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--grid);
  opacity: 0.5;
}
.grid-line.century { background: var(--axis); opacity: 0.7; }
.grid-line.major   { background: var(--accent); opacity: 0.35; }
.grid-line.minor   { opacity: 0.20; }
.grid-line.tiny    { opacity: 0.10; }

#axis-labels-bar {
  flex: 0 0 26px;
  position: relative;
  overflow: hidden;
  pointer-events: none;
  background: var(--panel);
  border-top: 1px solid var(--grid);
  padding-left: 130px;
  z-index: 6;
}
#axis-labels {
  position: relative;
  height: 100%;
  will-change: transform;
}
.tick-label {
  position: absolute;
  bottom: 4px;
  font-size: 11px;
  color: var(--muted);
  padding-left: 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tick-label.century { color: var(--fg); font-weight: 600; }
.tick-label.major   { color: var(--accent); font-weight: 600; }
.tick-label.year    { font-size: 10px; opacity: 0.7; }
.tick-label.month   { font-size: 9px; opacity: 0.65; text-transform: uppercase; letter-spacing: 0.4px; }
.tick-label.day     { font-size: 8px; opacity: 0.45; }

#minimap-wrap {
  flex: 0 0 52px;
  background: var(--panel);
  border-top: 1px solid var(--grid);
  display: flex;
  align-items: center;
  padding: 4px 8px 4px 130px;
  gap: 8px;
  position: relative;
}
#minimap { flex: 1; height: 40px; display: block; cursor: pointer; border-radius: 4px; }
#minimap-viewport {
  position: absolute;
  top: 6px;
  height: 40px;
  background: rgba(93,173,226,0.15);
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  pointer-events: none;
}

.scroll-hint {
  position: absolute;
  top: 8px;
  right: 16px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(15,20,32,0.7);
  padding: 4px 10px;
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease 1.5s;
  z-index: 5;
}
#timeline-wrap:hover .scroll-hint { opacity: 1; transition-delay: 0s; }

#detail-panel {
  position: fixed;
  top: 64px;
  right: 0;
  bottom: 0;
  width: 380px;
  background: var(--panel);
  border-left: 1px solid var(--grid);
  padding: 18px 20px;
  overflow-y: auto;
  transition: transform 0.2s ease-out;
  z-index: 10;
}
#detail-panel.hidden { transform: translateX(100%); }
#detail-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}
#detail-close:hover { color: var(--fg); }

#detail-copy-link {
  position: absolute;
  top: 14px; right: 44px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
#detail-copy-link:hover { color: var(--fg); background: var(--panel-2); }
#detail-copy-link.copied { color: #4ade80; }
#detail-title { margin: 0 0 10px; font-size: 18px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.pill {
  background: var(--panel-2);
  color: var(--fg);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}
#detail-location { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
#detail-description { font-size: 13px; line-height: 1.5; }
#detail-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0; }
#detail-tags .tag {
  font-size: 11px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 2px 7px;
  border-radius: 8px;
}
#detail-panel section { margin-top: 14px; }
#detail-panel h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
#detail-panel ul { list-style: none; padding: 0; margin: 0; }
#detail-panel li {
  padding: 6px 8px;
  margin-bottom: 4px;
  background: var(--panel-2);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  border-left: 3px solid var(--accent);
}
#detail-panel li:hover { background: #232b3d; }
#detail-panel li .rel-type {
  display: inline-block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
#detail-panel li .rel-target { font-weight: 600; }
#detail-panel li .rel-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ───── View-mode toggle button ───── */
.view-toggle {
  background: var(--panel-2);
  border: 1px solid var(--grid);
  color: var(--fg);
  cursor: pointer;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
}
.view-toggle:hover { border-color: var(--accent); }
.view-toggle .view-icon { display: none; }
body:not(.list-view) .view-toggle .view-icon-list     { display: inline; }
body.list-view        .view-toggle .view-icon-timeline { display: inline; }

/* ───── List view ───── */
body.list-view #timeline-area    { display: none; }
body.list-view #axis-labels-bar  { display: none; }
body.list-view #minimap-wrap     { display: none; }
body.list-view #events-list      { display: block; }
body:not(.list-view) #events-list { display: none !important; }

.events-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px max(12px, env(safe-area-inset-left)) 24px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.events-list.hidden { display: none; }
.events-list::-webkit-scrollbar { width: 8px; }
.events-list::-webkit-scrollbar-track { background: var(--panel); }
.events-list::-webkit-scrollbar-thumb { background: var(--grid); border-radius: 4px; }

.list-empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 14px;
}

.list-decade {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.4px;
  font-weight: 600;
  margin: 18px 4px 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--grid);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}
.list-decade:first-child { margin-top: 4px; }

.list-card {
  background: var(--panel);
  border: 1px solid var(--grid);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 10px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
  position: relative;
}
.list-card:hover { background: var(--panel-2); }
.list-card:active { transform: scale(0.99); }
.list-card.selected {
  background: var(--panel-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 6px 18px rgba(93,173,226,0.15);
}
.list-card.dim { opacity: 0.45; }

.list-card .lc-row1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.list-card .lc-date {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.list-card .lc-cat {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 2px 7px;
  border-radius: 8px;
  margin-left: auto;
  white-space: nowrap;
}
.list-card .lc-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 6px;
  color: var(--fg);
}
.list-card .lc-desc {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.list-card .lc-loc {
  font-size: 11px;
  color: var(--muted);
  opacity: 0.75;
  margin-top: 6px;
}
.list-card .lc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.list-card .lc-tag {
  font-size: 10px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 6px;
}
.list-card .lc-tag.more { color: var(--accent); }

/* ───── Phone-only chrome (visible <= 768px) ───── */
.mobile-actions { display: none; }
.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--grid);
  color: var(--fg);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:active { background: var(--grid); }
.icon-btn:hover  { border-color: var(--accent); }
.icon-btn.active { background: var(--accent); color: #0c1320; border-color: var(--accent); }
.icon-btn .icon-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--accent);
  color: #0c1320;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--panel);
}
.icon-btn .icon-badge.hidden { display: none; }
#mobile-view-btn .view-icon-list-svg,
#mobile-view-btn .view-icon-timeline-svg { display: none; }
body:not(.list-view) #mobile-view-btn .view-icon-list-svg     { display: block; }
body.list-view        #mobile-view-btn .view-icon-timeline-svg { display: block; }

.active-chips { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--grid);
  color: var(--fg);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.chip .chip-x {
  font-size: 14px;
  color: var(--muted);
  line-height: 1;
}
.chip:active { background: var(--grid); }

/* Filter sheet (full-screen modal on phone) */
.filter-sheet { display: none; }
body.filter-sheet-open { overflow: hidden; }

/* ───── Mobile / phone view ───── */
@media (max-width: 768px) {
  html, body { overflow: hidden; height: 100dvh; }
  body {
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
  }

  /* ── Compact header ── */
  #app-header {
    height: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px 8px;
    gap: 8px;
    flex-shrink: 0;
    background: var(--panel);
    border-bottom-color: rgba(255,255,255,0.06);
  }
  .title-block {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
  }
  .title-block h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.1px;
    flex: 1;
    margin: 0;
  }
  .title-block p { display: none; }
  .mobile-actions {
    display: flex;
    gap: 8px;
  }

  /* ── Hide all desktop controls except search ── */
  .controls > .multiselect,
  .controls > .view-toggle,
  .controls .check,
  .controls .zoom-controls,
  .controls > button#jump-start,
  .controls > button#jump-end {
    display: none !important;
  }
  .controls {
    margin: 0;
    padding: 0;
  }
  .controls input#search {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    padding: 10px 14px 10px 38px;
    font-size: 15px;
    border-radius: 12px;
    background: var(--panel-2);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238d96a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 16px;
  }
  .controls input#search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(93,173,226,0.18);
  }

  /* ── Active filter chip strip ── */
  .active-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    margin: 0 -12px;
    padding: 2px 12px 2px;
    -webkit-overflow-scrolling: touch;
  }
  .active-chips.hidden { display: none; }
  .active-chips::-webkit-scrollbar { display: none; }
  .active-chips .chip-clear {
    background: transparent;
    border-color: transparent;
    color: var(--accent);
    font-weight: 500;
  }

  /* ── Hide minimap, hint, zoom on phone ── */
  .zoom-controls    { display: none; }
  #scroll-vert-hint { display: none; }
  #minimap-wrap     { display: none; }

  /* ── Timeline area (still available via toggle) ── */
  #timeline-wrap { height: auto; flex: 1 1 auto; min-height: 0; }
  #lane-labels-viewport { width: 60px; flex: 0 0 60px; }
  .lane-label { padding: 0 5px; font-size: 8px; letter-spacing: 0.2px; }
  .lane-label .lane-count { display: none; }
  .lane-label .dot { width: 6px; height: 6px; margin-right: 4px; }
  #axis-labels-bar { padding-left: 60px; flex-basis: 22px; }
  .tick-label { font-size: 10px; }
  .event-card {
    width: 150px;
    padding: 6px 8px;
    font-size: 11px;
    border-left-width: 3px;
  }
  .event-card .ec-title { line-height: 1.2; font-size: 11px; }
  .event-card .ec-date  { font-size: 10px; }

  /* ── List-view: phone-first redesign ── */
  .events-list {
    padding: 4px 12px calc(40px + env(safe-area-inset-bottom));
    background: var(--bg);
  }
  .list-decade {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1.4px;
    font-weight: 700;
    margin: 16px 0 8px;
    padding: 6px 4px;
    border-bottom: none;
    background: var(--bg);
  }
  .list-card {
    background: var(--panel);
    border: 1px solid rgba(255,255,255,0.04);
    border-left: none;
    border-radius: 14px;
    padding: 0;
    margin: 0 0 10px;
    overflow: hidden;
    display: flex;
    align-items: stretch;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  }
  .list-card::before {
    content: '';
    width: 4px;
    flex: 0 0 4px;
    background: var(--accent);
    background: var(--cat-color, var(--accent));
  }
  .list-card .lc-inner {
    flex: 1;
    padding: 12px 14px 13px;
    min-width: 0;
  }
  .list-card .lc-row1 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
  }
  .list-card .lc-date {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    letter-spacing: 0;
  }
  .list-card .lc-cat {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    background: transparent;
    color: var(--cat-color, var(--accent));
    padding: 0;
    margin-left: auto;
    font-weight: 700;
    border: none;
  }
  .list-card .lc-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    margin: 0 0 6px;
    color: var(--fg);
  }
  .list-card .lc-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--muted);
    margin: 0;
    -webkit-line-clamp: 3;
  }
  .list-card .lc-loc {
    font-size: 11px;
    color: var(--muted);
    opacity: 0.65;
    margin-top: 6px;
  }
  .list-card .lc-tags { margin-top: 10px; gap: 4px; }
  .list-card .lc-tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    color: var(--muted);
  }
  .list-card.selected {
    background: var(--panel-2);
    box-shadow: 0 0 0 2px var(--cat-color, var(--accent)), 0 6px 18px rgba(0,0,0,0.4);
  }

  /* ── Filter sheet (phone full-screen modal) ── */
  .filter-sheet { display: none; }
  .filter-sheet:not(.hidden) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 250;
  }
  .filter-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
  }
  .filter-sheet-panel {
    position: absolute;
    inset: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .filter-sheet-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--grid);
    background: var(--panel);
  }
  .filter-sheet-header h2 {
    flex: 1;
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    padding-right: 36px;  /* balance the back button */
  }
  .filter-sheet-back { flex: 0 0 38px; }
  .filter-sheet-clear {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 14px;
    font-weight: 500;
    padding: 8px 10px;
    cursor: pointer;
  }
  .filter-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px 24px;
    -webkit-overflow-scrolling: touch;
  }
  .filter-sheet-body .ms-section-title {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1.4px;
    font-weight: 700;
    margin: 16px 4px 8px;
  }
  .filter-sheet-body .ms-section-title:first-child { margin-top: 4px; }
  .filter-sheet-body .multiselect-panel {
    position: static;
    max-height: none;
    box-shadow: none;
    border: 1px solid var(--grid);
    border-radius: 12px;
    background: var(--panel);
    margin-bottom: 14px;
    padding: 6px;
    overflow: visible;
  }
  .filter-sheet-body .multiselect-panel.hidden { display: block; }
  .filter-sheet-body .multiselect-panel label { padding: 12px 14px; font-size: 15px; }
  .filter-sheet-body .multiselect-panel .ms-search { padding: 11px 14px; font-size: 15px; border-radius: 10px; }
  .filter-sheet-body .multiselect-panel .ms-divider { font-size: 11px; padding: 14px 12px 8px; }

  /* ── Detail panel = polished bottom sheet ── */
  #detail-panel {
    top: auto;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 88vh;
    height: calc(88dvh - env(safe-area-inset-bottom, 0px));
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.08);
    border-radius: 18px 18px 0 0;
    padding: 32px 18px calc(28px + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 36px rgba(0,0,0,0.6);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 200;
  }
  #detail-panel.hidden { transform: translateY(100%); }
  #detail-panel::before {
    content: '';
    position: absolute;
    top: 10px; left: 50%;
    width: 36px; height: 4px;
    background: var(--axis);
    border-radius: 2px;
    transform: translateX(-50%);
  }
  #detail-close {
    top: 18px; right: 14px;
    font-size: 22px;
    width: 36px; height: 36px;
    line-height: 22px;
    text-align: center;
    border-radius: 18px;
    background: var(--panel-2);
    color: var(--muted);
  }
  #detail-close:active { background: var(--grid); }
  #detail-copy-link {
    top: 22px; right: 60px;
    font-size: 16px;
    width: 36px; height: 32px;
  }
  #detail-title {
    font-size: 19px;
    margin: 8px 50px 10px 0;
    line-height: 1.25;
    font-weight: 700;
  }
  .meta { font-size: 13px; gap: 8px; }
  #detail-description { font-size: 14px; line-height: 1.6; }
  #detail-tags { margin: 12px 0; }
  #detail-tags .tag { font-size: 12px; padding: 3px 9px; border-radius: 10px; }
  #detail-panel li {
    padding: 12px 14px;
    font-size: 14px;
    border-radius: 8px;
  }
  #detail-panel h3 { font-size: 11px; letter-spacing: 1.2px; }

  /* Touch scroll polish */
  #timeline-scroll, .events-list, .filter-sheet-body { -webkit-overflow-scrolling: touch; }
}

/* Very narrow phones — squeeze more */
@media (max-width: 380px) {
  .title-block h1 { font-size: 15px; }
  .event-card { width: 130px; }
  #lane-labels-viewport { width: 50px; flex: 0 0 50px; }
  #axis-labels-bar { padding-left: 50px; }
  .lane-label { padding: 0 4px; font-size: 8px; }
  .list-card .lc-title { font-size: 15px; }
  .list-card .lc-desc { font-size: 12px; }
}
