/* Second Brain — Shared Design System */
/* Matches the visual pages' design language exactly */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #22223a;
  --text-primary: #e0e0e8;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.3);
  --accent-secondary: #00d4aa;
  --accent-secondary-glow: rgba(0, 212, 170, 0.3);
  --accent-warm: #ff6b6b;
  --accent-warm-glow: rgba(255, 107, 107, 0.3);
  --accent-orange: #ff9f43;
  --accent-orange-glow: rgba(255, 159, 67, 0.3);
  --border: #2a2a3e;
  --border-light: #3a3a52;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-primary: #f5f5fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f0f5;
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #8888a0;
  --accent: #5a52d5;
  --accent-glow: rgba(90, 82, 213, 0.15);
  --accent-secondary: #00a885;
  --accent-secondary-glow: rgba(0, 168, 133, 0.15);
  --accent-warm: #e05555;
  --accent-warm-glow: rgba(224, 85, 85, 0.15);
  --accent-orange: #e08830;
  --accent-orange-glow: rgba(224, 136, 48, 0.15);
  --border: #d8d8e8;
  --border-light: #e8e8f0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 72px; /* space for tab bar */
}

a { color: var(--accent); text-decoration: none; transition: var(--transition); }
a:hover { opacity: 0.85; }

/* --- NAV --- */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 52px;
  display: flex; align-items: center; justify-content: space-between;
}
[data-theme="light"] .nav { background: rgba(245, 245, 250, 0.85); }

.nav-brand {
  font-size: 0.85rem; font-weight: 600; color: var(--text-secondary);
  display: flex; align-items: center; gap: 0.5rem;
}
.nav-brand span { color: var(--accent); font-size: 1rem; }
.nav-back {
  display: flex; align-items: center; gap: 0.4rem;
  color: var(--accent); font-size: 0.85rem; font-weight: 500;
}
.nav-back svg { width: 16px; height: 16px; }
.nav-actions { display: flex; align-items: center; gap: 0.75rem; }

.theme-toggle {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 0.35rem 0.7rem; cursor: pointer;
  color: var(--text-secondary); font-size: 0.75rem; transition: var(--transition);
  font-family: var(--font);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* --- BOTTOM TAB BAR --- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
  height: 56px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
[data-theme="light"] .tab-bar { background: rgba(245, 245, 250, 0.92); }

.tab-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-muted); text-decoration: none;
  font-size: 0.65rem; font-weight: 500; padding: 0.4rem 0.8rem;
  transition: var(--transition); -webkit-tap-highlight-color: transparent;
}
.tab-item svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.tab-item.active { color: var(--accent); }
.tab-item.active svg { stroke: var(--accent); }

/* --- LAYOUT --- */
.page { max-width: 800px; margin: 0 auto; padding: 68px 1.25rem 1.5rem; }

/* --- SECTION HEADERS --- */
.section-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--accent); font-weight: 700; margin-bottom: 0.4rem;
}
.section-title {
  font-size: clamp(1.2rem, 3vw, 1.5rem); font-weight: 700; margin-bottom: 1.25rem;
}

/* --- STAT PILLS --- */
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.75rem; margin-bottom: 2rem;
}
.stat-pill {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  text-align: center; transition: var(--transition);
}
.stat-pill:hover { border-color: var(--border-light); }
.stat-number {
  font-size: 1.8rem; font-weight: 800; line-height: 1;
  margin-bottom: 0.25rem;
}
.stat-number.purple { color: var(--accent); }
.stat-number.green { color: var(--accent-secondary); }
.stat-number.orange { color: var(--accent-orange); }
.stat-number.red { color: var(--accent-warm); }
.stat-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }

/* --- CARDS (generic) --- */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  transition: var(--transition);
}
.card:hover { border-color: var(--border-light); }
.card + .card { margin-top: 0.75rem; }

/* --- TOPIC CARDS --- */
.topic-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem; margin-bottom: 2rem;
}
.topic-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  transition: var(--transition);
}
.topic-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.topic-name {
  font-size: 1.1rem; font-weight: 700; margin-bottom: 0.25rem;
}
.topic-meta {
  font-size: 0.78rem; color: var(--text-muted); margin-bottom: 1rem;
}
.topic-actions {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
}

/* --- BUTTONS --- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  transition: var(--transition); border: none; font-family: var(--font);
  text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); color: #fff; }
.btn-secondary {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--accent); padding: 0.5rem 0.6rem; }
.btn-ghost:hover { background: var(--accent-glow); }
.btn-lg { padding: 0.75rem 1.75rem; font-size: 0.9rem; border-radius: var(--radius); }
.btn-block { display: flex; justify-content: center; width: 100%; }

/* --- STUDY CARD --- */
.study-container {
  display: flex; flex-direction: column; align-items: center;
  min-height: calc(100vh - 180px); justify-content: center;
}
.study-card {
  width: 100%; max-width: 500px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem;
  text-align: center; min-height: 250px;
  display: flex; flex-direction: column; justify-content: center;
  cursor: pointer; transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.study-card:hover { border-color: var(--border-light); }
.study-card.revealed { cursor: default; }
.study-label {
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 700; margin-bottom: 1rem;
}
.study-label.question { color: var(--accent); }
.study-label.answer { color: var(--accent-secondary); }
.study-text {
  font-size: 1.05rem; line-height: 1.7; white-space: pre-line;
}
.study-topic {
  font-size: 0.72rem; color: var(--text-muted); margin-top: 1rem;
  padding-top: 0.75rem; border-top: 1px solid var(--border);
}
.study-hint {
  font-size: 0.75rem; color: var(--text-muted); margin-top: 1rem;
}
.study-answer {
  margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border);
  text-align: left;
}
.study-answer .study-text { font-size: 0.92rem; color: var(--text-secondary); }
.study-progress {
  font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1.25rem;
}
.study-nav {
  display: flex; gap: 0.75rem; justify-content: center; margin-top: 1.5rem;
}
.study-controls {
  display: flex; gap: 0.75rem; justify-content: center; margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* --- SESSION SUMMARY --- */
.session-summary {
  text-align: center; padding: 2rem 0;
}
.session-summary h2 {
  font-size: 1.5rem; margin-bottom: 0.5rem;
}
.session-summary .stat-number {
  font-size: 3rem; margin: 1rem 0 0.25rem;
}

/* --- CARD LIST (compact) --- */
.card-list-item {
  display: flex; align-items: flex-start; gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.card-list-item + .card-list-item { margin-top: 0.5rem; }
.card-list-item:hover { border-color: var(--border-light); }
.card-list-q {
  font-size: 0.88rem; font-weight: 500; flex: 1;
}
.card-list-topic {
  font-size: 0.7rem; color: var(--accent); background: var(--accent-glow);
  padding: 0.15rem 0.5rem; border-radius: 8px; white-space: nowrap;
  font-weight: 600;
}

/* --- TOPIC DETAIL (rendered markdown) --- */
.topic-content h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 0.75rem; }
.topic-content h2 { font-size: 1.25rem; font-weight: 700; margin: 2rem 0 0.75rem; color: var(--accent); }
.topic-content h3 { font-size: 1.05rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
.topic-content h4 { font-size: 0.95rem; font-weight: 600; margin: 1.25rem 0 0.4rem; color: var(--text-secondary); }
.topic-content p { margin-bottom: 0.75rem; color: var(--text-secondary); }
.topic-content strong { color: var(--text-primary); }
.topic-content code {
  background: var(--bg-secondary); padding: 0.15em 0.4em;
  border-radius: 4px; font-family: var(--font-mono); font-size: 0.85em;
  border: 1px solid var(--border);
}
.topic-content ul {
  margin: 0.5rem 0 1rem 1.25rem; color: var(--text-secondary);
}
.topic-content li { margin-bottom: 0.35rem; }
.topic-content hr {
  border: none; border-top: 1px solid var(--border); margin: 2rem 0;
}
.topic-content table {
  width: 100%; border-collapse: collapse; margin: 1rem 0;
  font-size: 0.85rem; overflow-x: auto; display: block;
}
.topic-content th, .topic-content td {
  padding: 0.6rem 0.75rem; text-align: left;
  border: 1px solid var(--border);
}
.topic-content th {
  background: var(--bg-secondary); font-weight: 600;
  color: var(--text-primary);
}
.topic-content td { color: var(--text-secondary); }
.topic-content em { color: var(--text-muted); }

/* --- BAR CHART (CSS only) --- */
.bar-chart { margin: 1rem 0; }
.bar-row {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.bar-label {
  font-size: 0.8rem; color: var(--text-secondary);
  min-width: 120px; text-align: right;
}
.bar-track {
  flex: 1; height: 24px; background: var(--bg-secondary);
  border-radius: 6px; overflow: hidden; border: 1px solid var(--border);
}
.bar-fill {
  height: 100%; border-radius: 6px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; align-items: center; padding-left: 0.5rem;
  font-size: 0.72rem; font-weight: 700; color: #fff;
  min-width: fit-content;
}
.bar-fill.purple { background: var(--accent); }
.bar-fill.green { background: var(--accent-secondary); }
.bar-fill.orange { background: var(--accent-orange); }
.bar-fill.red { background: var(--accent-warm); }

/* --- GREETING --- */
.greeting {
  font-size: clamp(1.3rem, 4vw, 1.8rem); font-weight: 700;
  margin-bottom: 0.25rem;
}
.greeting-sub {
  font-size: 0.9rem; color: var(--text-muted); margin-bottom: 2rem;
}

/* --- EMPTY STATE --- */
.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state p { font-size: 0.9rem; margin-top: 0.5rem; }

/* --- RESPONSIVE --- */
@media (max-width: 640px) {
  .page { padding: 60px 1rem 1.25rem; }
  .topic-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .study-card { padding: 1.5rem; min-height: 200px; }
  .bar-label { min-width: 80px; font-size: 0.72rem; }
}

/* --- ANIMATIONS --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.4s ease forwards; }
.fade-in-delay-1 { animation-delay: 0.1s; opacity: 0; }
.fade-in-delay-2 { animation-delay: 0.2s; opacity: 0; }
.fade-in-delay-3 { animation-delay: 0.3s; opacity: 0; }
