/* =========================
   THEME TOKENS (Design System)
   ========================= */
:root {
  /* Surfaces */
  --bg:            #0b1220;   /* default overridden by light theme below */
  --panel:         #0f172a;
  --panel-raised:  #0f1b35;
  --viz-bg-1:      #0f172a;
  --viz-bg-2:      #0b1220;

  /* Content */
  --text:          #e5e7eb;
  --muted:         #9ca3af;
  --border:        #233048;

  /* Accents / data */
  --accent:        #22d3ee;   /* cyan */
  --accent-2:      #a78bfa;   /* purple */
  --accent-3:      #10b981;   /* emerald */
  --danger:        #ef4444;
  --warn:          #f59e0b;

  /* Viz neutrals */
  --axis:          #233048;
  --grid:          #1b2640;

  /* Focus ring */
  --focus:         #60a5fa88;

  /* Semantic aliases */
  --card:          var(--panel);
  --chip:          #1f2937;
}

/* Light theme (default) */
:root,
[data-theme="light"] {
  --bg:           #f7fafc;
  --panel:        #ffffff;
  --panel-raised: #ffffff;
  --viz-bg-1:     #ffffff;
  --viz-bg-2:     #f5f7fb;

  --text:         #0b1220;
  --muted:        #4b5563;
  --border:       #e6e8ef;

  --axis:         #b6bfd3;
  --grid:         #e9ecf5;

  --card:         var(--panel);
  --chip:         #f3f4f6;
}

/* Dark theme */
[data-theme="dark"] {
  --bg:           #0b1220;
  --panel:        #0f172a;
  --panel-raised: #0f1b35;
  --viz-bg-1:     #0f172a;
  --viz-bg-2:     #0b1220;

  --text:         #e5e7eb;
  --muted:        #9ca3af;
  --border:       #233048;

  --axis:         #233048;
  --grid:         #1b2640;

  --card:         var(--panel);
  --chip:         #1f2937;
}

/* =========================
   BASE & PRIMITIVES
   ========================= */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
        "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
}

/* Headings + text helpers */
h1, h2, h3 { color: var(--text); margin-block: 0 0.5rem; }
.muted, .hint { color: var(--muted); }

/* Focus visibility */
:where(a, button, [role="button"], input, textarea, select):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* =========================
   LAYOUT
   ========================= */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.left {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Responsive */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .left { position: sticky; top: 0; z-index: 5; }
}

/* =========================
   SIDEBAR
   ========================= */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 8px;
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
  margin: 0;
}

.brand .pill {
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

/* Search */
.search { padding: 10px; }
.search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

/* Terms list */
.terms { overflow: auto; padding: 6px 8px; }

.term {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
}

.term:hover {
  background: var(--bg);
  border-color: var(--border);
}

.term.active {
  outline: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.term .tag {
  margin-left: auto;
  font-size: 11px;
  color: var(--accent-2);
  background: transparent;
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 999px;
}

/* =========================
   TOP BAR
   ========================= */
.topbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--bg), transparent);
}

.top-actions { display: flex; gap: 8px; }
.row { display: flex; gap: 10px; align-items: center; }
.recent { display: flex; gap: 6px; flex-wrap: wrap; }

/* =========================
   MAIN CONTENT
   ========================= */
.main {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr;
  gap: 16px;
  padding: 16px;
}

@media (max-width: 980px) {
  .main { grid-template-columns: 1fr; }
}

/* Cards & panels */
.panel,
.card,
.term,
.definition,
.viz-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.card h3 { margin: 0 0 8px 0; font-size: 16px; }

.term-title { font-size: 20px; font-weight: 800; margin: 0; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.chip {
  background: var(--chip);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}
.chip.active {
  color: var(--text);
  border-color: var(--accent);
}

/* =========================
   BUTTONS
   ========================= */
button,
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
button:hover,
.btn:hover { box-shadow: 0 0 0 3px var(--focus); }
button:active,
.btn:active { transform: translateY(0.5px); }

/* =========================
   VIZ AREA
   ========================= */
.viz-area {
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 8px;
  background:
    linear-gradient(180deg, var(--viz-bg-1), var(--viz-bg-2)),
    radial-gradient(1200px 400px at 50% 120%, color-mix(in srgb, var(--accent) 15%, transparent), transparent);
}

/* Make SVG/canvas responsive */
.viz-area svg,
.viz-area canvas { display: block; width: 100%; height: auto; }

/* Legend */
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* Keyboard hint */
.kbd {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-raised);
}

/* Notices */
.notice { font-size: 12px; color: var(--muted); }

/* =========================
   FOOTER
   ========================= */
.footer,
.site-footer {
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  color: var(--muted);
  font-size: 12px;
  background: var(--panel);
}