/* ============================================================
   SoFi Study — Financial Terminal Theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=DM+Sans:wght@400;500;600&display=swap');

/* ── Custom Properties ───────────────────────────────────── */
:root {
  --bg:          #0c0e14;
  --surface:     #13151f;
  --surface-2:   #1a1d2e;
  --border:      rgba(255, 255, 255, 0.07);
  --accent:      #f59e0b;
  --accent-dim:  rgba(245, 158, 11, 0.10);
  --accent-glow: rgba(245, 158, 11, 0.20);
  --text:        #e8eaf0;
  --muted:       #5a6070;
  --success:     #10b981;
  --danger:      #ef4444;
  --code-bg:     #0f1219;

  --sidebar-w:   220px;
  --toc-w:       200px;
  --header-h:    48px;

  --radius:      6px;
  --radius-lg:   10px;

  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
  --font-body:   'DM Sans', system-ui, sans-serif;
}

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Typography ──────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-mono);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.2rem; margin: 1.75rem 0 0.75rem; color: var(--accent); }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
h4 { font-size: 0.9rem; margin: 1rem 0 0.4rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

p { margin-bottom: 0.85rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

strong { color: var(--text); font-weight: 600; }
em { color: var(--muted); }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

ul, ol { padding-left: 1.5rem; margin-bottom: 0.85rem; }
li { margin-bottom: 0.3rem; }
li:last-child { margin-bottom: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
th {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* ── Code ────────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--code-bg);
  color: #a8d8a0;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border);
}

pre {
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 0.75rem 0 1rem;
  position: relative;
}

pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
  color: inherit;
}

/* ── Layout Shell ────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--toc-w);
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "header header header"
    "sidebar main toc";
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────── */
#header {
  grid-area: header;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
}

.header-brand {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.header-brand span {
  color: var(--muted);
  font-weight: 400;
}

#countdown {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

#countdown .days-num {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
}

#countdown.urgent .days-num {
  color: var(--danger);
  animation: pulse-red 1.5s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.nav-section {
  padding: 0.25rem 0;
}

.nav-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0.5rem 1rem 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
}

.nav-item:hover {
  color: var(--text);
  background: var(--accent-dim);
  border-left-color: rgba(245, 158, 11, 0.4);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-left-color: var(--accent);
  font-weight: 500;
}

.nav-item .nav-icon {
  font-size: 0.9rem;
  width: 1rem;
  text-align: center;
  flex-shrink: 0;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}

/* Progress in sidebar */
.sidebar-progress {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.progress-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.progress-bar-wrap {
  background: var(--surface-2);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #fbbf24);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.progress-pct {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}

/* ── Main Content ────────────────────────────────────────── */
#main {
  grid-area: main;
  padding: 2rem 2.5rem;
  min-width: 0; /* prevents grid blowout */
}

.view {
  display: none;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}
.view.active { display: block; }

/* ── Day Cards ───────────────────────────────────────────── */
.day-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;

  /* entrance animation */
  opacity: 0;
  transform: translateY(12px);
  animation: card-enter 0.4s ease forwards;
}

.day-card:nth-child(1) { animation-delay: 0ms; }
.day-card:nth-child(2) { animation-delay: 75ms; }
.day-card:nth-child(3) { animation-delay: 150ms; }
.day-card:nth-child(4) { animation-delay: 225ms; }
.day-card:nth-child(5) { animation-delay: 300ms; }

@keyframes card-enter {
  to { opacity: 1; transform: translateY(0); }
}

.day-card.today {
  border-color: rgba(245, 158, 11, 0.4);
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.08);
}

.day-card details { width: 100%; }

.day-card summary {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background 0.15s ease;
}

.day-card summary::-webkit-details-marker { display: none; }

.day-card summary:hover {
  background: var(--accent-dim);
}

.day-card details[open] summary {
  border-bottom: 1px solid var(--border);
}

/* SVG progress ring */
.ring-wrap {
  flex-shrink: 0;
  position: relative;
  width: 44px;
  height: 44px;
}

.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring-bg {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 3;
}

.progress-ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease;
}

.ring-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent);
}

.day-meta {
  flex: 1;
  min-width: 0;
}

.day-title {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.day-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.day-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.2);
  white-space: nowrap;
  flex-shrink: 0;
}

.day-badge.today-badge {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.chevron {
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.day-card details[open] .chevron {
  transform: rotate(90deg);
}

.day-body {
  padding: 1.25rem 1.5rem;
}

/* ── Checklist ───────────────────────────────────────────── */
.task-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
}

.task-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.task-list li:last-child { border-bottom: none; }

.task-list input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 0.2rem;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  border-radius: 3px;
}

.task-list li.checked {
  color: var(--muted);
  text-decoration: line-through;
}

.task-list li.checked input { accent-color: var(--success); }

/* ── Answer Blocks (Obsidian callout → <details>) ────────── */
details.answer-block {
  background: rgba(245, 158, 11, 0.03);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  margin: 0.75rem 0;
  transition: border-left-color 0.2s ease, background 0.2s ease;
  overflow: hidden;
}

details.answer-block[open] {
  border-left-color: var(--accent);
  background: rgba(245, 158, 11, 0.04);
  backdrop-filter: blur(8px);
}

details.answer-block > summary {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  transition: color 0.15s ease;
}

details.answer-block > summary::-webkit-details-marker { display: none; }

details.answer-block[open] > summary { color: var(--accent); }

details.answer-block > summary::before {
  content: '▶';
  font-size: 0.6rem;
  transition: transform 0.2s ease;
  display: inline-block;
}

details.answer-block[open] > summary::before {
  transform: rotate(90deg);
}

.answer-content {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.7;
}

.answer-content > *:first-child { margin-top: 0; }
.answer-content > *:last-child { margin-bottom: 0; }

/* ── Section header separators ───────────────────────────── */
.section-sep {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.section-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Content prose styles (for guide/practice views) ─────── */
.prose-content h1 {
  font-size: 1.4rem;
  color: var(--accent);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.prose-content h2 {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.prose-content h2:first-of-type { margin-top: 0; border-top: none; padding-top: 0; }

.prose-content h3 {
  color: var(--text);
  margin-top: 1.5rem;
}

.prose-content blockquote:not([class]) {
  border-left: 3px solid var(--accent-dim);
  padding: 0.5rem 1rem;
  color: var(--muted);
  font-style: italic;
  background: var(--surface-2);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0.75rem 0;
}

/* ── Loading spinner ─────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 2rem 0;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Highlight.js overrides ──────────────────────────────── */
.hljs {
  background: var(--code-bg) !important;
  padding: 0 !important;
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 767px),
       (max-height: 500px) and (orientation: landscape) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) auto 1fr;
    grid-template-areas:
      "header"
      "sidebar"
      "main";
  }

  #toc { display: none; }

  #sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 0;
  }

  .nav-section {
    display: flex;
    flex-direction: row;
    padding: 0;
  }

  .nav-label { display: none; }
  .nav-divider { display: none; }

  .nav-item {
    padding: 0.75rem 1rem;
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    font-size: 0.8rem;
  }

  .nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }

  .sidebar-progress { display: none; }

  #main {
    padding: 1.25rem 1rem;
  }

  table {
    display: block;
    overflow-x: auto;
    width: 100%;
  }
}

/* ── Tablet (768px – 1023px) ─────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar-w: 180px; }
  #app {
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-areas: "header header" "sidebar main";
  }
  #toc { display: none; }
  #main { padding: 1.5rem 1.25rem; }
  .view { max-width: 100%; }
}

/* ── Ultrawide (1600px+) ─────────────────────────────────── */
@media (min-width: 1600px) {
  :root { --sidebar-w: 240px; --toc-w: 220px; }
  .view { max-width: 960px; }
  #main { padding: 2.5rem 3rem; }
}

@media (min-width: 2200px) {
  :root { --sidebar-w: 270px; --toc-w: 240px; }
  .view { max-width: 1080px; }
  #main { padding: 3rem 4rem; }
}

/* ── Reference links ─────────────────────────────────────── */
a.ref-link {
  color: var(--accent);
  border-bottom: 1px dashed rgba(245, 158, 11, 0.45);
  font-family: var(--font-mono);
  font-size: 0.85em;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: border-bottom-color 0.15s ease;
}
a.ref-link:hover {
  border-bottom-color: var(--accent);
  text-decoration: none;
}

/* ── Term hover tooltips ─────────────────────────────────── */
.term {
  border-bottom: 1px dotted var(--muted);
  cursor: help;
  position: relative;
  display: inline;
}

.term::after {
  content: attr(data-def);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--text);
  white-space: normal;
  width: 280px;
  max-width: 80vw;
  pointer-events: none;
  opacity: 0;
  z-index: 300;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  transition: opacity 0.15s ease;
}

.term:hover::after {
  opacity: 1;
}

/* ── TOC secondary sidebar ───────────────────────────────── */
#toc {
  grid-area: toc;
  background: var(--surface);
  border-left: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 1.25rem 0;
}

.toc-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0 1rem 0.5rem;
}

.toc-link {
  display: block;
  padding: 0.3rem 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  border-right: 2px solid transparent;
  transition: color 0.15s ease, border-right-color 0.15s ease;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-link:hover { color: var(--text); text-decoration: none; }

.toc-link.active {
  color: var(--accent);
  border-right-color: var(--accent);
}

.toc-link.toc-sub {
  padding-left: 1.75rem;
  font-size: 0.72rem;
}

/* ── Utility ─────────────────────────────────────────────── */
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
