/* ── Variables ── */
:root {
  --ink:      #0f0e0d;
  --paper:    #f5f2ec;
  --paper2:   #ede9e0;
  --paper3:   #e4e0d6;
  --accent:   #00D4FF;
--midnight: #0A0F1A;
--cyan:     #00D4FF;
--violet:   #7B61FF;
  --muted:    #8a8278;
  --border:   rgba(15,14,13,0.12);
  --shadow:   0 2px 12px rgba(0,0,0,0.07);
--mono:     'Geist', sans-serif;
--serif:    'Geist', sans-serif;
  --radius:   4px;
  --trans:    all 0.18s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink:    #f0ece3;
    --paper:  #141210;
    --paper2: #1e1b17;
    --paper3: #282420;
    --accent: #e05a20;
    --muted:  #6a6560;
    --midnight: #f0ece3;
    --border: rgba(240,236,227,0.1);
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
  }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--mono); font-size: 13px; color: var(--ink); background: var(--paper); }
button { font-family: var(--mono); cursor: pointer; }
a { color: var(--accent); }
input { font-family: var(--mono); }

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ── */
#header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
  z-index: 10;
}

#brand-block {
  display: flex;
  align-items: center;
  gap: 24px;
  min-width: 0;
  flex: 1;
}

#logo {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--midnight);
  white-space: nowrap;
}

#logo .accent {
  color: var(--cyan);
}

#brand-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

#tagline {
  font-size: 14px;
  font-weight: 500;
  color: var(--midnight);
  line-height: 1.3;
}

#subheading {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.35;
}

#status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-left: 0;
  white-space: nowrap;
}

#pulse {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
#pulse.live {
  background: #22c55e;
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── Buttons ── */
.btn-ghost {
  font-size: 11px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  transition: var(--trans);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ink); }

.btn-primary {
  font-size: 12px;
  padding: 5px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  transition: var(--trans);
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Settings bar ── */
#settings-bar {
  display: none;
  background: var(--paper2);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
#settings-bar.open { display: block; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.settings-row label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.settings-row .hint { font-size: 11px; color: var(--muted); }

#key-input {
  flex: 1;
  max-width: 360px;
  min-width: 200px;
  padding: 5px 9px;
  font-size: 12px;
  background: var(--paper);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius);
}
#key-input:focus { outline: none; border-color: var(--accent); }

/* ── Filter bar ── */
#filter-bar {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}

.control-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 8px;
}

.control-row:has(#legend) {
  position: absolute;
  right: 56px;
  top: 76px;
  grid-template-columns: auto 1fr;
}

.control-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
  text-align: left;
}

#scope-filters { display: flex; gap: 4px; }
.scope-btn {
  font-size: 11px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 20px;
  transition: var(--trans);
}
.scope-btn:hover { color: var(--ink); }
.scope-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* Category filter buttons */
#category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.cat-btn {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--cat-color, #aaa);
  background: transparent;
  color: var(--cat-color, inherit);
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.cat-btn:hover,
.cat-btn.active {
  background: var(--cat-color, #aaa);
  color: #fff;
}

.cat-btn[data-cat="all"] {
  --cat-color: #888;
}

#view-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.view-btn {
  padding: 4px 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.view-btn.active {
  background: var(--ink);
  color: var(--paper);
}

#legend {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  color: var(--muted);
}

.legend-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.leg { display: flex; align-items: center; gap: 4px; }
.swatch {
  width: 22px; height: 7px;
  border-radius: 1px;
}
.swatch.light  { background: hsl(220, 30%, 75%); }
.swatch.dark   { background: hsl(220, 80%, 35%); }

/* ── Layout: top canvas / bottom panel ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

/* Bottom detail panel — hidden by default, slides up on open */
#panel {
  height: 0;
  overflow: hidden;
  background: var(--paper2);
  border-top: 1.5px solid rgba(0,0,0,0.08);
  transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

#panel.open {
  height: 48vh;
}

#panel-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 40px 36px;
  height: 100%;
  overflow-y: auto;

  display: grid;
  grid-template-columns: 90px 34% 1fr;
  gap: 26px;
  align-content: start;
}

.panel-back {
  grid-column: 1;
  grid-row: 1;
  position: static;
  width: fit-content;
}

#panel-scope-tag {
  grid-column: 1;
  font-size: 11px;
  color: var(--muted);
}

#panel-title {
  grid-column: 1;
  font-size: 20px;
  line-height: 1.25;
  margin: 0;
}

#panel-summary {
  grid-column: 1;
  font-size: 14px;
  line-height: 1.65;
  max-width: 420px;
}

#panel-scores {
  grid-column: 2;
  display: flex;
  gap: 14px;
  margin-top: 8px;
}

#panel-articles {
  grid-column: 3;
  grid-row: 1 / span 6;
  border-left: 1px solid var(--border);
  padding-left: 28px;
  overflow-y: auto;
  min-height: 0;
}

#panel-url,
#panel-tags,
.ask-btn,
#panel-meta {
  display: none;
}

canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  cursor: crosshair;
}

/* ── Y axis ── */

#axis-title-y {
  position: absolute;
  left: 8px;
  top: 12px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
}

#y-axis {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  width: 78px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 36px 0 28px;
  z-index: 2;
}
.y-label {
  font-size: 10px;
  color: var(--muted);
  padding-left: 6px;
  opacity: 0.7;
  letter-spacing: 0.03em;
}

/* ── Tooltip ── */
#tooltip {
  position: absolute;
  display: none;
  pointer-events: none;
  z-index: 9999;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 11px;
  max-width: 220px;
  box-shadow: var(--shadow);
  line-height: 1.5;
}
#tooltip strong {
  font-family: var(--serif);
  font-size: 12px;
  font-weight: 300;
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
}
#tt-meta { font-size: 10px; color: var(--muted); }

/* ── Overlay ── */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}
#overlay.hidden { display: none; }
#overlay-content { text-align: center; max-width: 320px; }
.ov-icon { font-size: 32px; color: var(--muted); margin-bottom: 14px; animation: spin 8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ov-title { font-family: var(--serif); font-size: 17px; font-weight: 300; color: var(--ink); margin-bottom: 8px; }
.ov-body { font-size: 12px; color: var(--muted); line-height: 1.65; }
.ov-body strong { color: var(--ink); }

/* Loading state */
#overlay-content.loading .ov-icon { animation: spin .7s linear infinite; font-size: 20px; }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-bottom: 10px;
}



/* ── Status bar ── */
#status-bar {
  display: flex;
  justify-content: space-between;
  padding: 4px 16px;
  font-size: 10px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--paper2);
}

/* ── Error message ── */
.error-box {
  background: var(--paper2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--ink);
  line-height: 1.6;
  max-width: 340px;
  text-align: left;
}
.error-box strong { display: block; margin-bottom: 4px; }

#panel-url {
  display: flex;
  flex-direction: column;
  gap: 0;
  grid-column: 2 / 5;
}
.src-heading {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}
.src-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.src-row:last-child { border-bottom: none; }
.src-time {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  min-width: 42px;
  padding-top: 1px;
  flex-shrink: 0;
}
.src-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.src-title {
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.4;
}
.src-title:hover { color: var(--accent); }
.src-domain {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}
#panel-scores {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 220px;
}
.score-card {
  flex: 1;
  min-width: 0;
}

.score-card-top {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin-bottom: 6px;
}

.score-track {
  height: 4px;
  border-radius: 999px;
  background: var(--paper3);
  overflow: hidden;
}

.score-fill {
  height: 100%;
  background: var(--ink);
  border-radius: 999px;
}
.score-bar {
  position: relative;
  cursor: help;
}
.score-bar[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-size: 10px;
  padding: 4px 8px;
  border-radius: var(--radius);
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
}

/* Sprint 2 timeline override */

/* ── Sprint 2: Story Panel ── */

#panel.open {
  height: 48vh;
}

#panel-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 40px 36px 40px;
  height: 100%;
  overflow-y: auto;

  display: grid;
  grid-template-columns: 80px 1fr 1fr;
  gap: 42px;
  align-content: start;
  position: relative;
}

.panel-back {
  position: static;
  grid-column: 1;
  grid-row: 1;
  width: fit-content;
}

#panel-scope-tag,
#panel-title,
#panel-summary,
#panel-scores {
  grid-column: 2;
}

#panel-scope-tag {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: -6px;
}

#panel-title {
  font-size: 19px;
  line-height: 1.22;
  margin: 0;
}

#panel-summary {
  font-size: 14px;
  line-height: 1.6;
  max-width: 760px;
  margin-top: -4px;
}

#panel-scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 4px;
}

.score-card {
  min-width: 0;
}

.score-label-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  margin-bottom: 5px;
}

.score-label-row strong {
  font-size: 10px;
}

.score-mini-track {
  height: 4px;
  border-radius: 999px;
  background: var(--paper3);
  overflow: hidden;
}

.score-mini-fill {
  height: 100%;
  background: var(--ink);
  border-radius: 999px;
}

#panel-articles {
  grid-column: 3;
  grid-row: 1 / span 6;
  border-left: 1px solid var(--border);
  padding-left: 30px;
  overflow-y: auto;
  min-height: 0;
}

.panel-section {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.panel-section h3 {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 14px;
}

.timeline-item {
  position: relative;
  display: flex;
  gap: 14px;
  padding: 8px 0 16px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 18px;
  bottom: -8px;
  width: 1px;
  background: var(--border);
}

.timeline-item:last-child::before {
  display: none;
}

.timeline-dot {
  position: relative;
  z-index: 1;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex-shrink: 0;
}

.timeline-content {
  flex: 1;
}

.timeline-date {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
}

.timeline-title {
  display: block;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink) !important;
  text-decoration: none;
  margin-bottom: 4px;
}

.timeline-title:hover {
  color: var(--accent);
}

.timeline-source {
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
}

.has-tooltip {
  position: relative;
  cursor: help;
}

.has-tooltip:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: 260px;
  padding: 8px 10px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  font-size: 10px;
  line-height: 1.5;
  z-index: 999;
  box-shadow: var(--shadow);
}

.has-tooltip:hover::before {
  content: "";
  position: absolute;
  left: 18px;
  bottom: calc(100% + 3px);
  border-width: 5px 5px 0 5px;
  border-style: solid;
  border-color: var(--ink) transparent transparent transparent;
  z-index: 999;
}

/* ── Sprint 7: First-visit welcome modal ── */

.welcome-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 14, 13, 0.38);
  backdrop-filter: blur(6px);
}

.welcome-modal.hidden {
  display: none;
}

.welcome-card {
  width: min(420px, calc(100vw - 32px));
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 28px;
  border-radius: 8px;
}

.welcome-kicker {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

.welcome-card h1 {
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1.1;
  margin-bottom: 14px;
}

.welcome-card p {
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
  margin-bottom: 10px;
}

.welcome-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ── Sprint 7 Walkthrough ── */

.tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 11000;
  pointer-events: none;
}

.tour-overlay.hidden {
  display: none;
}

.tour-card {
  position: absolute;
  width: 280px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  pointer-events: auto;
}

#tour-step {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

#tour-text {
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 14px;
}

.tour-actions {
  display: flex;
  justify-content: flex-end;
}

/* ── Sprint 7.6 Feedback ── */

#feedback-btn {
  position: fixed;
  right: 18px;
  bottom: 42px;

  z-index: 9000;

  padding: 10px 14px;

  border-radius: 999px;

  background: var(--ink);
  color: var(--paper);

  text-decoration: none;

  font-size: 12px;

  box-shadow: var(--shadow);

  transition: all 0.15s ease;
}

#feedback-btn:hover {
  transform: translateY(-1px);
}

.header-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Sprint 7.6D: Story status in panel ── */

.panel-story-status {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}