:root {
  --bg: #000;
  --bg-card: rgba(8, 8, 12, .94);
  --border-subtle: rgba(212, 175, 55, .15);
  --border-glow: rgba(212, 175, 55, .35);
  --gold: #d4af37;
  --gold-dim: #a0882a;
  --gold-bright: #f5d76e;
  --text-pri: #e8e4dc;
  --text-sec: #aaa;
  --text-mut: #666;
  --cat-dragon-slayers: #e74c3c;
  --cat-eons: #9b59b6;
  --cat-salt: #3498db;
  --cat-shadows: #2ecc71;
  --cat-talinor: #e67e22;
  --cat-third-titans: #1abc9c;
  --cat-wardens: #f39c12;
  --cat-world: #ecf0f1;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text-pri);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.page-header { text-align: center; padding: 1.5rem 1rem 1rem; flex-shrink: 0; }
.page-header h1 {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  background: linear-gradient(135deg, var(--gold-bright), var(--gold), var(--gold-dim));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.page-header .subtitle {
  color: var(--text-sec);
  font-size: .85rem;
  margin-top: .3rem;
  font-weight: 300;
  letter-spacing: .15em;
}

/* ── Era Navigation ── */
.era-nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(0, 0, 0, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: .4rem 1rem;
  display: flex; justify-content: center; gap: .25rem; flex-wrap: wrap;
  flex-shrink: 0;
}
.era-link {
  padding: .25rem .7rem; border-radius: 6px;
  font-family: 'Cinzel', serif; font-size: .68rem; font-weight: 600;
  color: var(--text-sec); text-decoration: none; letter-spacing: .06em;
  transition: all .25s;
}
.era-link:hover, .era-link:focus-visible {
  color: var(--gold); background: rgba(212, 175, 55, .08); outline: none;
}

/* ── Controls ── */
.controls { max-width: 900px; margin: .8rem auto 0; padding: 0 1.5rem; flex-shrink: 0; width: 100%; }

.search-wrap { position: relative; margin-bottom: .6rem; }
.search-wrap input {
  width: 100%; padding: .6rem 1rem .6rem 2.5rem;
  background: rgba(10, 10, 10, .9);
  border: 1px solid var(--border-subtle); border-radius: 10px;
  color: var(--text-pri); font-size: .88rem; font-family: 'Inter', sans-serif;
  outline: none; transition: border-color .25s;
}
.search-wrap input:focus { border-color: var(--gold-dim); }
.search-wrap input::placeholder { color: var(--text-mut); }
.search-wrap .search-icon {
  position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
  color: var(--text-mut); font-size: 1rem; pointer-events: none;
}

.filter-bar { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; margin-bottom: .3rem; }
.filter-chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .28rem .7rem; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .03);
  color: var(--text-sec); font-size: .75rem; font-weight: 500;
  cursor: pointer; transition: all .25s; user-select: none;
}
.filter-chip .dot { width: .5rem; height: .5rem; border-radius: 50%; transition: all .25s; }
.filter-chip.active { border-color: var(--chip-border); background: var(--chip-bg); color: var(--text-pri); }
.filter-chip:hover { border-color: rgba(255, 255, 255, .2); }

.stats-bar {
  max-width: 900px; margin: .4rem auto 0; padding: 0 1.5rem;
  display: flex; justify-content: space-between;
  font-size: .75rem; color: var(--text-mut);
  flex-shrink: 0; width: 100%;
}

/* ── Timeline Viewport ── */
.timeline-viewport { flex: 1; position: relative; overflow: hidden; cursor: grab; }
.timeline-viewport.dragging { cursor: grabbing; }
.timeline-viewport canvas { display: block; width: 100%; height: 100%; }

/* ── Hover Tooltip ── */
.hover-tooltip {
  position: absolute; pointer-events: none;
  padding: .3rem .7rem; border-radius: 6px;
  background: rgba(8, 8, 12, .92); border: 1px solid var(--border-glow);
  color: var(--gold-bright); font-family: 'Cinzel', serif;
  font-size: .8rem; font-weight: 600; white-space: nowrap;
  opacity: 0; transition: opacity .15s; z-index: 20;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .5);
}
.hover-tooltip.visible { opacity: 1; }

/* ── Card Overlay ── */
.card-overlay {
  position: absolute; width: 380px; max-height: 45vh; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border-glow); border-radius: 12px;
  padding: 0; color: var(--text-pri);
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, .6), 0 0 30px rgba(212, 175, 55, .08);
  z-index: 50; display: none;
  transition: opacity .2s, transform .2s; opacity: 0; transform: translateY(8px);
}
.card-overlay.visible { display: block; opacity: 1; transform: translateY(0); }
.card-overlay .card-close {
  position: absolute; top: .5rem; right: .6rem;
  background: none; border: none; color: var(--text-mut);
  font-size: 1.1rem; cursor: pointer; z-index: 2; transition: color .2s;
}
.card-overlay .card-close:hover { color: var(--gold-bright); }
.card-overlay .card-inner { padding: 1rem 1.25rem; }
.card-overlay .card-title {
  font-family: 'Cinzel', serif; font-weight: 700; font-size: 1.05rem;
  color: var(--gold-bright); margin-bottom: .3rem;
}
.card-overlay .card-date { font-size: .78rem; color: var(--gold-dim); margin-bottom: .4rem; font-variant-numeric: tabular-nums; }
.card-overlay .card-category {
  display: inline-block; font-size: .62rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  padding: .15rem .5rem; border-radius: 4px; margin-bottom: .6rem;
}
.card-overlay .card-notes { color: var(--text-sec); font-size: .85rem; line-height: 1.6; border-top: 1px solid var(--border-subtle); padding-top: .6rem; }
.card-overlay .card-notes p { margin-bottom: .3rem; }
.card-overlay .card-summary {
  font-size: .82rem; color: var(--gold-dim); font-style: italic;
  margin-bottom: .5rem; padding-bottom: .4rem;
  border-bottom: 1px solid var(--border-subtle);
}
.card-overlay .card-meta {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem;
}
.card-overlay .card-meta-tag {
  font-size: .65rem; padding: .12rem .4rem; border-radius: 4px;
  background: rgba(212, 175, 55, .08); border: 1px solid var(--border-subtle);
  color: var(--text-sec);
}
.card-overlay .card-nearby {
  margin-top: .5rem; padding-top: .4rem;
  border-top: 1px solid var(--border-subtle);
  font-size: .75rem; color: var(--text-mut);
}
.card-overlay .card-nearby a {
  color: var(--gold-dim); text-decoration: none; cursor: pointer;
}
.card-overlay .card-nearby a:hover { color: var(--gold-bright); text-decoration: underline; }
.card-overlay .edit-btn {
  background: none; border: 1px solid var(--border-subtle); border-radius: 6px;
  padding: .3rem .7rem; color: var(--text-mut); font-size: .72rem;
  cursor: pointer; font-family: 'Inter', sans-serif; transition: all .25s; margin-top: .5rem;
}
.card-overlay .edit-btn:hover { border-color: var(--gold-dim); color: var(--gold-dim); }

.card-lead-line {
  position: absolute; width: 1px;
  background: linear-gradient(to bottom, transparent, rgba(212, 175, 55, .25), transparent);
  z-index: 10; pointer-events: none; display: none;
}
.card-lead-line.visible { display: block; }

/* ── Wiki Links in Cards ── */
.card-overlay .wiki-link {
  color: var(--gold); text-decoration: none;
  border-bottom: 1px dotted var(--gold-dim);
  transition: color .2s, border-color .2s;
}
.card-overlay .wiki-link:hover { color: var(--gold-bright); border-bottom-color: var(--gold-bright); }

/* ── Inline Edit ── */
.inline-edit { padding: 1rem 1.25rem; }
.inline-edit .ie-row { display: flex; gap: .6rem; align-items: center; margin-bottom: .5rem; flex-wrap: wrap; }
.inline-edit .ie-label {
  color: var(--text-mut); font-size: .65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  min-width: 50px; flex-shrink: 0;
}
.inline-edit input,
.inline-edit select,
.inline-edit textarea {
  background: rgba(3, 3, 3, .9); border: 1px solid var(--border-subtle); border-radius: 6px;
  color: var(--text-pri); font-size: .82rem; font-family: 'Inter', sans-serif;
  outline: none; padding: .4rem .6rem; transition: border-color .25s;
}
.inline-edit input:focus,
.inline-edit select:focus,
.inline-edit textarea:focus { border-color: var(--gold-dim); }

.inline-edit .ie-title { flex: 1; font-family: 'Cinzel', serif; font-weight: 600; font-size: .95rem; }
.inline-edit .ie-year { width: 80px; }
.inline-edit .ie-month { flex: 1; min-width: 120px; appearance: none; cursor: pointer; }
.inline-edit .ie-day { width: 50px; }
.inline-edit .ie-category { min-width: 110px; appearance: none; cursor: pointer; }
.inline-edit textarea { width: 100%; min-height: 80px; resize: vertical; line-height: 1.6; font-size: .8rem; }
.inline-edit .ie-actions { display: flex; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.inline-edit .ie-actions button {
  padding: .4rem .8rem; border-radius: 6px; font-size: .72rem; font-weight: 600;
  cursor: pointer; font-family: 'Inter', sans-serif; transition: all .25s;
}
.ie-save { background: linear-gradient(135deg, var(--gold-dim), var(--gold)); border: none; color: #000; }
.ie-save:hover { filter: brightness(1.15); }
.ie-cancel { background: transparent; border: 1px solid var(--border-subtle); color: var(--text-mut); }
.ie-cancel:hover { border-color: var(--text-sec); color: var(--text-sec); }
.ie-status { font-size: .68rem; color: var(--gold-dim); margin-left: auto; align-self: center; }

/* ── Zoom Controls ── */
.zoom-controls {
  position: absolute; bottom: 1rem; right: 1rem;
  display: flex; flex-direction: column; gap: .3rem;
  z-index: 30;
}
.zoom-btn {
  width: 36px; height: 36px;
  background: rgba(8, 8, 12, .85);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--gold-dim);
  font-size: 1.1rem; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
  backdrop-filter: blur(8px);
}
.zoom-btn:hover { border-color: var(--gold); color: var(--gold-bright); background: rgba(212, 175, 55, .1); }

/* ── Minimap ── */
.minimap-container {
  position: relative;
  height: 44px;
  flex-shrink: 0;
  background: rgba(0, 0, 0, .95);
  border-top: 1px solid var(--border-subtle);
  cursor: pointer;
  overflow: hidden;
}
.minimap-container canvas {
  display: block; width: 100%; height: 100%;
}
.minimap-viewport-indicator {
  position: absolute; top: 0; height: 100%;
  border: 1px solid rgba(212, 175, 55, .5);
  background: rgba(212, 175, 55, .08);
  border-radius: 2px;
  pointer-events: none;
  transition: left .1s, width .1s;
}

/* ── Thread Legend ── */
.thread-legend {
  position: absolute; top: .8rem; right: .8rem;
  z-index: 30;
  font-size: .75rem;
}
.legend-toggle {
  background: rgba(8, 8, 12, .85);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--gold-dim);
  font-family: 'Cinzel', serif;
  font-size: .72rem; font-weight: 600;
  padding: .35rem .7rem;
  cursor: pointer;
  transition: all .2s;
  backdrop-filter: blur(8px);
}
.legend-toggle:hover { border-color: var(--gold); color: var(--gold-bright); }
.legend-content {
  display: none;
  flex-direction: column; gap: .25rem;
  background: rgba(8, 8, 12, .92);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: .6rem .8rem;
  margin-top: .3rem;
  backdrop-filter: blur(12px);
  max-height: 50vh; overflow-y: auto;
}
.legend-content.open { display: flex; }
.legend-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .2rem .3rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background .2s;
}
.legend-item:hover { background: rgba(255, 255, 255, .05); }
.legend-item .legend-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.legend-item .legend-name { color: var(--text-pri); font-weight: 500; }
.legend-item .legend-info {
  color: var(--text-mut); font-size: .65rem;
  margin-left: auto; white-space: nowrap;
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 2rem; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--gold-dim); color: #000;
  padding: .5rem 1.2rem; border-radius: 8px;
  font-size: .8rem; font-weight: 600; z-index: 600;
  transition: transform .3s; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: #c0392b; color: #fff; }

/* ── Footer ── */
.page-footer {
  text-align: center; padding: .8rem 1rem;
  color: var(--text-mut); font-size: .7rem;
  border-top: 1px solid var(--border-subtle); flex-shrink: 0;
}
.page-footer span { color: var(--gold-dim); }

/* ── Misc ── */
.note-image {
  display: block; max-width: 100%; max-height: 300px; height: auto;
  border-radius: 6px; margin: .5rem 0; object-fit: contain;
  border: 1px solid var(--border-subtle);
}

@media (max-width: 600px) {
  .card-overlay { width: calc(100vw - 2rem); left: 1rem !important; }
  .thread-legend { top: auto; bottom: 3.5rem; right: .5rem; }
  .zoom-controls { bottom: .6rem; right: .5rem; }
  .zoom-btn { width: 32px; height: 32px; font-size: .9rem; }
}
