:root {
  --bg: #0f1419;
  --bg-2: #1a2028;
  --fg: #e6edf3;
  --fg-muted: #8b949e;
  --accent: #ff7b3d;
  --border: #30363d;

  --c-polygon: #7cc36e;
  --c-admin:   #c1a5e0;
  --c-line:    #6ab0f3;
  --c-poi:     #f0a135;
  --c-route:   #e06b74;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
body { display: flex; flex-direction: column; height: 100vh; }
h1, h2 { margin: 0; font-weight: 500; }
h1 { font-size: 18px; color: var(--accent); }
h2 { font-size: 13px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.08em; }

.hidden { display: none !important; }
.muted  { color: var(--fg-muted); font-size: 12px; }

header {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.source { display: flex; align-items: center; gap: 12px; flex: 1; flex-wrap: wrap; }
.source label { display: flex; align-items: center; gap: 6px; color: var(--fg-muted); }
.source select, .source input[type=file] {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 8px; font: inherit;
}
.source input[type=file] { padding: 3px; max-width: 220px; }
.source button {
  background: var(--accent); color: #111; border: 0; border-radius: 4px;
  padding: 6px 14px; font-weight: 600; cursor: pointer;
}
.source button:hover { filter: brightness(1.08); }
.source button:disabled { opacity: 0.5; cursor: wait; }
.status { color: var(--fg-muted); font-size: 12px; }
.status.err { color: #e06b74; }

.summary {
  display: flex; gap: 24px; padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-2); flex-wrap: wrap;
}
.summary span { display: inline-flex; gap: 6px; }

.narrative-panel {
  display: flex; gap: 16px; padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-2); flex-wrap: wrap; align-items: center;
}
.narrative-panel fieldset {
  border: 1px solid var(--border); border-radius: 4px; padding: 4px 10px;
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  margin: 0;
}
.narrative-panel legend {
  color: var(--fg-muted); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0 6px;
}
.narrative-panel label {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-muted); font-size: 11px;
}
.narrative-panel output {
  color: var(--fg); font-variant-numeric: tabular-nums;
  min-width: 22px; text-align: right;
}
.narrative-panel input[type=range] {
  width: 90px; accent-color: var(--accent);
}
.n-mode { display: flex; gap: 4px; margin-left: auto; }
.n-toggle {
  background: var(--bg); color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 10px; font: inherit; font-size: 11px; cursor: pointer;
}
.n-toggle.active { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.n-reset {
  background: transparent; color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 8px; font: inherit; font-size: 11px; cursor: pointer;
}
.n-reset:hover { color: var(--fg); }

.grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: 1fr 528px;
  grid-template-areas:
    "map      details"
    "timeline timeline";
  flex: 1; min-height: 0;
  gap: 1px; background: var(--border);
}
#map { grid-area: map; background: #111; }
#timeline-panel { grid-area: timeline; background: var(--bg-2); display: flex; flex-direction: column; }
#details { grid-area: details; background: var(--bg-2); padding: 10px 16px; overflow-y: auto; }

/* Timeline */
.timeline-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
#timeline { flex: 1; overflow-y: auto; padding: 6px 0; }

.row {
  display: flex; align-items: center; padding: 2px 12px;
  position: relative; height: 22px;
}
.row-label {
  position: sticky; top: 0; z-index: 1;
  width: 60px; text-transform: uppercase; font-size: 10px; color: var(--fg-muted);
}
.row-track {
  flex: 1; position: relative; height: 17px;
  background: rgba(255,255,255,0.03); border-radius: 2px;
}
.row-header { padding: 6px 12px 2px 12px; color: var(--fg-muted); font-size: 11px;
              text-transform: uppercase; letter-spacing: 0.06em; }
.bar {
  position: absolute; top: 1px; bottom: 1px;
  border-radius: 2px; cursor: pointer; opacity: 0.85;
  min-width: 2px;
  display: flex; align-items: center; overflow: hidden;
  padding: 0 4px;
  font-size: 10px; font-weight: 600; color: rgba(0,0,0,0.82);
  line-height: 1; white-space: nowrap;
}
.bar:hover { opacity: 1; outline: 1px solid var(--fg); outline-offset: -1px; }
.bar.active { opacity: 1; outline: 2px solid #ff1744; outline-offset: -1px; z-index: 2; }

/* Visual cue for "inside" relation : inset white border that survives hover/active */
.bar[data-relation="inside"] {
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.88);
}

.bar[data-type="polygon"] { background: var(--c-polygon); }
.bar[data-type="admin"]   { background: var(--c-admin); }
.bar[data-type="line"]    { background: var(--c-line); }
.bar[data-type="poi"]     { background: var(--c-poi); }
.bar[data-type="route"]   { background: var(--c-route); }

/* Custom tooltip — no native `title` attribute (500+ ms delay). */
.tooltip {
  position: fixed; z-index: 1000;
  background: rgba(20, 24, 32, 0.97);
  color: var(--fg);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  pointer-events: none;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.tooltip .tt-type { font-weight: 600; }
.tooltip .tt-meta { color: var(--fg-muted); margin-left: 6px; }

.legend {
  padding: 8px 12px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 12px; font-size: 11px; color: var(--fg-muted);
}
.legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.legend .swatch[data-type="polygon"] { background: var(--c-polygon); }
.legend .swatch[data-type="admin"]   { background: var(--c-admin); }
.legend .swatch[data-type="line"]    { background: var(--c-line); }
.legend .swatch[data-type="poi"]     { background: var(--c-poi); }
.legend .swatch[data-type="route"]   { background: var(--c-route); }

/* Details */
#details h3 { margin: 0 0 4px; font-size: 14px; }
#details .meta { color: var(--fg-muted); font-size: 12px; margin-bottom: 8px; }
#details .included { font-size: 12px; }
#details .included li { margin: 2px 0; }

/* Leaflet tweaks */
.leaflet-container { background: #0d1117 !important; }
.trace-highlight   { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { stroke-opacity: 1; }
  50%      { stroke-opacity: 0.55; }
}
