/* ML Interview Prep — engineering dashboard theme.
   CSS variables drive dark/light theming via [data-theme] on <html>. */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
  --topbar-h: 54px;
  --maxw: 860px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8fa;
  --bg-2: #ffffff;
  --bg-3: #eef1f5;
  --fg: #1c2330;
  --fg-2: #4b5568;
  --fg-3: #8a94a6;
  --line: #e2e7ee;
  --accent: #2563eb;
  --accent-soft: #e3edff;
  --good: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --code-bg: #f1f4f8;
  --card-shadow: 0 1px 3px rgba(16, 24, 40, .08);
  --hl-keyword: #7c3aed; --hl-string: #15803d; --hl-number: #b45309;
  --hl-comment: #8a94a6; --hl-func: #2563eb; --hl-type: #0e7490;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-2: #141b24;
  --bg-3: #1b2430;
  --fg: #e6edf3;
  --fg-2: #a9b4c4;
  --fg-3: #6b7688;
  --line: #26303d;
  --accent: #5b9dff;
  --accent-soft: #1a2c4d;
  --good: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --code-bg: #0a0e13;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --hl-keyword: #c792ea; --hl-string: #7ee787; --hl-number: #fbbf24;
  --hl-comment: #6b7688; --hl-func: #79c0ff; --hl-type: #56d4dd;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--fg);
  font-size: 15.5px; line-height: 1.65;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: 8px 14px; z-index: 200; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; color: var(--fg); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.icon-btn {
  background: none; border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; width: 36px; height: 36px; font-size: 17px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-3); }
#nav-toggle { display: none; }
.search-wrap { position: relative; flex: 1; max-width: 520px; margin: 0 auto; }
#search {
  width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--fg); font-size: 14px; font-family: var(--font);
}
#search:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--card-shadow); max-height: 60vh; overflow: auto; z-index: 120;
}
.sr-item { display: block; padding: 9px 12px; border-bottom: 1px solid var(--line); color: var(--fg); }
.sr-item:last-child { border-bottom: none; }
.sr-item:hover, .sr-item.active { background: var(--accent-soft); text-decoration: none; }
.sr-item .sr-title { font-weight: 600; font-size: 14px; }
.sr-item .sr-meta { font-size: 12px; color: var(--fg-3); }
.sr-item .sr-snip { font-size: 13px; color: var(--fg-2); }
.sr-empty { padding: 12px; color: var(--fg-3); font-size: 14px; }
.top-links { display: flex; gap: 4px; margin-left: auto; }
.top-links a { color: var(--fg-2); font-size: 13.5px; padding: 7px 10px; border-radius: 8px; white-space: nowrap; }
.top-links a:hover { background: var(--bg-3); text-decoration: none; color: var(--fg); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr) 230px; align-items: start; }
.sidenav {
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h));
  overflow-y: auto; border-right: 1px solid var(--line); background: var(--bg-2);
  padding: 14px 10px 40px;
}
.nav-sec { margin-bottom: 6px; }
.nav-sec-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-top: 8px;
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3);
}
.nav-sec-head:hover { text-decoration: none; color: var(--fg-2); }
.nav-link {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 26px;
  border-radius: 7px; color: var(--fg-2); font-size: 14px;
}
.nav-link:hover { background: var(--bg-3); text-decoration: none; color: var(--fg); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link .done-dot { margin-left: auto; color: var(--good); font-size: 12px; }
.nav-special { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
.content { padding: 28px 32px 80px; min-width: 0; }
.content-inner { max-width: var(--maxw); margin: 0 auto; }
.tocside { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 28px 18px; font-size: 13px; }
.tocside:empty { display: none; }
#toc .toc-title { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-3); margin-bottom: 8px; }
#toc a { display: block; color: var(--fg-2); padding: 3px 0 3px 10px; border-left: 2px solid var(--line); }
#toc a.h3 { padding-left: 22px; }
#toc a:hover { text-decoration: none; color: var(--fg); }
#toc a.active { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90; }

/* ---------- page ---------- */
.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 30px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -0.01em; }
.page-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--fg-3); }
.tag { background: var(--bg-3); border: 1px solid var(--line); border-radius: 20px; padding: 2px 10px; font-size: 12px; color: var(--fg-2); }
.badge { border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.badge.p0 { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .badge.p0 { background: #4c1d1d; color: #fca5a5; }
.badge.status-interviewing { background: var(--accent-soft); color: var(--accent); }
.badge.label-verified { background: #dcfce7; color: #166534; }
[data-theme="dark"] .badge.label-verified { background: #14532d; color: #86efac; }
.badge.label-reported { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .badge.label-reported { background: #451a03; color: #fcd34d; }
.badge.label-representative { background: var(--bg-3); color: var(--fg-2); border: 1px solid var(--line); }
.badge.diff-easy { color: var(--good); } .badge.diff-medium { color: var(--warn); } .badge.diff-hard { color: var(--danger); }
.page-actions { margin: 14px 0 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--fg); border-radius: 8px; padding: 8px 14px;
  font-size: 14px; cursor: pointer; font-family: var(--font); font-weight: 600;
}
.btn:hover { background: var(--bg-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.done { border-color: var(--good); color: var(--good); }

.prose h2 { font-size: 22px; margin: 34px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line); letter-spacing: -0.01em; }
.prose h3 { font-size: 17.5px; margin: 26px 0 8px; }
.prose h4 { font-size: 15.5px; margin: 20px 0 6px; }
.prose p { margin: 10px 0; }
.prose ul, .prose ol { padding-left: 24px; margin: 10px 0; }
.prose li { margin: 5px 0; }
.prose li::marker { color: var(--fg-3); }
.prose blockquote { border-left: 3px solid var(--accent); margin: 14px 0; padding: 4px 16px; color: var(--fg-2); background: var(--bg-2); border-radius: 0 8px 8px 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 14px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
.prose th { background: var(--bg-3); font-weight: 700; }
.prose tr:nth-child(even) td { background: var(--bg-2); }
.prose img { max-width: 100%; border-radius: 8px; }
.prose hr { border: none; border-top: 1px solid var(--line); margin: 28px 0; }

/* callouts + collapse */
.callout { border-radius: var(--radius); padding: 14px 16px; margin: 16px 0; border: 1px solid var(--line); background: var(--bg-2); }
.callout-label { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.callout.tldr { border-left: 4px solid var(--accent); background: var(--accent-soft); }
.callout.tldr .callout-label { color: var(--accent); }
.callout.warn { border-left: 4px solid var(--warn); background: var(--bg-2); }
.callout.warn .callout-label { color: var(--warn); }
.callout-body > :first-child { margin-top: 0; } .callout-body > :last-child { margin-bottom: 0; }
details.collapse { border: 1px solid var(--line); border-radius: var(--radius); margin: 14px 0; background: var(--bg-2); }
details.collapse summary { cursor: pointer; padding: 12px 16px; font-weight: 650; list-style: none; }
details.collapse summary::-webkit-details-marker { display: none; }
details.collapse summary::before { content: "▸ "; color: var(--accent); }
details.collapse[open] summary::before { content: "▾ "; }
details.collapse summary:hover { background: var(--bg-3); border-radius: var(--radius); }
.collapse-body { padding: 4px 16px 14px; border-top: 1px solid var(--line); }

/* code */
.prose pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; font-size: 13.5px; line-height: 1.55; margin: 14px 0; }
.prose code { font-family: var(--mono); font-size: .88em; }
.prose :not(pre) > code { background: var(--code-bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--hl-string); }
.hljs-number, .hljs-literal { color: var(--hl-number); }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--hl-func); }
.hljs-type, .hljs-class .hljs-title, .hljs-attr, .hljs-attribute { color: var(--hl-type); }
.hljs-operator, .hljs-punctuation { color: var(--fg-2); }

/* task checkboxes */
.task-cb { width: 16px; height: 16px; accent-color: var(--accent); margin-right: 8px; vertical-align: -2px; cursor: pointer; }
li.task-done > :not(input) { text-decoration: line-through; color: var(--fg-3); }
.prose ul:has(> li > input.task-cb) { list-style: none; padding-left: 4px; }

/* mermaid */
.mermaid { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px 0; overflow-x: auto; text-align: center; }

/* math */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; }

/* ---------- dashboard ---------- */
.dash-hero { margin: 6px 0 22px; }
.dash-hero h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -0.01em; }
.dash-hero p { color: var(--fg-2); margin: 0 0 14px; max-width: 640px; }
.progress-wrap { background: var(--bg-3); border-radius: 8px; height: 10px; overflow: hidden; max-width: 420px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #7c3aed); border-radius: 8px; transition: width .4s; }
.progress-label { font-size: 13px; color: var(--fg-3); margin-top: 6px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin: 18px 0 30px; }
.dash-card {
  display: flex; flex-direction: column; gap: 6px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  color: var(--fg); box-shadow: var(--card-shadow);
}
.dash-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.dash-card .dc-icon { font-size: 22px; }
.dash-card .dc-title { font-weight: 700; font-size: 15.5px; }
.dash-card .dc-desc { font-size: 13px; color: var(--fg-2); flex: 1; }
.dash-card .dc-meta { font-size: 12px; color: var(--fg-3); display: flex; justify-content: space-between; align-items: center; }
.dash-card .mini-bar { height: 5px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.dash-card .mini-bar > div { height: 100%; background: var(--accent); }
.sec-title { font-size: 19px; font-weight: 750; margin: 30px 0 4px; }
.sec-sub { color: var(--fg-3); font-size: 13.5px; margin: 0 0 6px; }

/* section listing */
.page-list { display: grid; gap: 10px; margin: 16px 0; }
.page-row {
  display: flex; align-items: center; gap: 12px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; color: var(--fg);
}
.page-row:hover { text-decoration: none; border-color: var(--accent); }
.page-row .pr-title { font-weight: 650; }
.page-row .pr-tags { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.page-row.done .pr-title { color: var(--fg-3); }

/* ---------- flashcards ---------- */
.fc-controls { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 20px; align-items: center; }
select, .text-input {
  background: var(--bg-2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; font-family: var(--font);
}
.fc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.fc-card { perspective: 900px; cursor: pointer; min-height: 170px; }
.fc-inner {
  position: relative; width: 100%; height: 100%; min-height: 170px;
  transition: transform .45s; transform-style: preserve-3d;
}
.fc-card.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 15px; box-shadow: var(--card-shadow); overflow: auto;
}
.fc-back { transform: rotateY(180deg); background: var(--accent-soft); font-size: 14px; }
.fc-tags { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; }
.fc-hint { text-align: center; color: var(--fg-3); font-size: 13px; margin-top: 16px; }

/* ---------- mock + questions ---------- */
.mock-setup { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; max-width: 640px; }
.form-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: center; margin: 10px 0; }
.form-row label { font-weight: 600; font-size: 14px; }
.mock-stage { max-width: 760px; }
.mock-progress { font-size: 13px; color: var(--fg-3); margin-bottom: 8px; }
.mock-q { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; font-size: 17px; }
.mock-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.mock-answer { margin-top: 14px; }
.mock-answer .answer-body { background: var(--bg-3); border-radius: 8px; padding: 14px 16px; margin-top: 10px; }
.mock-nav { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.q-filters { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 18px; align-items: center; }
.q-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.q-card .q-text { font-weight: 600; margin-bottom: 8px; }
.q-card .q-meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; align-items: center; }
.empty-state { background: var(--bg-2); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--fg-2); }
.empty-state p { margin: 6px 0; }

/* 404 */
.center-404 { text-align: center; padding: 60px 20px; }
.center-404 h1 { font-size: 44px; margin-bottom: 8px; }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--line); padding: 18px 24px; display: flex; gap: 12px;
  justify-content: space-between; flex-wrap: wrap; color: var(--fg-3); font-size: 13px;
  background: var(--bg-2);
}

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr); }
  .tocside { display: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  #nav-toggle { display: inline-flex; }
  .sidenav {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: 280px; z-index: 95;
    transform: translateX(-105%); transition: transform .25s ease; height: auto;
  }
  body.nav-open .sidenav { transform: none; box-shadow: 4px 0 24px rgba(0,0,0,.25); }
  .content { padding: 20px 16px 60px; }
  .top-links a { padding: 7px 6px; font-size: 12.5px; }
  .brand { font-size: 14.5px; }
  .search-wrap { max-width: none; }
  .page-head h1, .dash-hero h1 { font-size: 24px; }
  .form-row { grid-template-columns: 1fr; gap: 4px; }
}
@media (min-width: 821px) { #sidenav-scrim { display: none !important; } }

/* ---------- print ---------- */
@media print {
  .topbar, .sidenav, .tocside, .footer, .page-actions, .search-wrap { display: none; }
  .layout { display: block; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .content { padding: 0; }
  a { color: #000; }
  details.collapse { break-inside: avoid; }
  details.collapse:not([open]) { display: none; }
}
