/* ===== Blueprint theme — design tokens ===== */
:root {
  --bg: #0d2236;
  --panel: #0a1b2c;
  --grid: rgba(255,255,255,0.06);
  --accent: #5fd0ff;     /* structure / links */
  --hot: #ffb454;        /* hot path / emphasis */
  --text: #cfe8ff;
  --text-strong: #ffffff;
  --muted: #9fc4dd;
  --line: rgba(255,255,255,0.10);
  --easy: #5fe39a; --med: #ffd479; --hard: #ff8a8a;
  --serif: 'Fraunces', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --maxw: 1240px;
}

/* ===== Self-hosted fonts ===== */
@font-face { font-family:'Fraunces'; src:url('../fonts/fraunces-700.woff2') format('woff2'); font-weight:700; font-display:swap; }
@font-face { font-family:'Fraunces'; src:url('../fonts/fraunces-600.woff2') format('woff2'); font-weight:600; font-display:swap; }
@font-face { font-family:'JetBrains Mono'; src:url('../fonts/jetbrains-mono-400.woff2') format('woff2'); font-weight:400; font-display:swap; }
@font-face { font-family:'JetBrains Mono'; src:url('../fonts/jetbrains-mono-600.woff2') format('woff2'); font-weight:600; font-display:swap; }
@font-face { font-family:'IBM Plex Sans'; src:url('../fonts/ibm-plex-sans-400.woff2') format('woff2'); font-weight:400; font-display:swap; }
@font-face { font-family:'IBM Plex Sans'; src:url('../fonts/ibm-plex-sans-600.woff2') format('woff2'); font-weight:600; font-display:swap; }

/* ===== Base ===== */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; color: var(--text); background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 16px 16px;
  font-family: var(--sans); line-height: 1.6; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); }
.label { font-family: var(--mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== App shell ===== */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; background: rgba(13,34,54,.9); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-family: var(--serif); font-weight: 700; color: var(--text-strong); font-size: 1.05rem; }
.layout { display: grid; grid-template-columns: 240px minmax(0,1fr); gap: 0; max-width: var(--maxw); margin: 0 auto; }
.sidebar { border-right: 1px solid var(--line); padding: 16px 12px; height: calc(100vh - 52px); position: sticky; top: 52px; overflow: auto; }
.sidebar .cat { display: flex; justify-content: space-between; padding: 5px 8px; border-radius: 6px; color: var(--muted); cursor: pointer; font-size: .9rem; }
.sidebar .cat:hover { background: rgba(255,255,255,.04); color: var(--text); }
.sidebar .cat.active { color: var(--text-strong); border-left: 2px solid var(--hot); background: rgba(255,180,84,.06); }
.main { padding: 20px 24px 80px; min-width: 0; }

/* ===== Catalog ===== */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.filters input[type=search] { flex: 1 1 220px; min-width: 160px; background: var(--panel); border: 1px solid var(--line); color: var(--text); padding: 8px 12px; border-radius: 8px; font-family: var(--mono); }
.chip { font-family: var(--mono); font-size: .75rem; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: transparent; cursor: pointer; }
.chip.active { border-color: var(--accent); color: var(--accent); }
.cat-group { margin: 18px 0; }
.cat-group > h2 { font-family: var(--mono); font-size: .8rem; letter-spacing: .14em; color: var(--accent); text-transform: uppercase; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.qrow { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.qrow:hover { background: rgba(255,255,255,.03); }
.qrow .qtitle { font-family: var(--serif); font-weight: 600; color: var(--text-strong); flex: 1; }
.diff { font-family: var(--mono); font-size: .72rem; padding: 2px 8px; border-radius: 4px; }
.diff.Easy { color: var(--easy); border: 1px solid var(--easy); }
.diff.Medium { color: var(--med); border: 1px solid var(--med); }
.diff.Hard { color: var(--hard); border: 1px solid var(--hard); }
.freq { color: var(--hot); font-size: .8rem; letter-spacing: 1px; }
.companies { color: var(--muted); font-size: .75rem; font-family: var(--mono); }

/* ===== Reading screen ===== */
.reader { display: grid; grid-template-columns: minmax(0,1fr) 200px; gap: 24px; }
.article { min-width: 0; }
.crumb { font-family: var(--mono); font-size: .75rem; color: var(--muted); }
.article h1 { font-family: var(--serif); color: var(--text-strong); font-size: 1.9rem; margin: 6px 0; }
.meta { font-family: var(--mono); font-size: .8rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tldr { border-left: 3px solid var(--hot); background: rgba(255,180,84,.06); padding: 12px 16px; border-radius: 8px; margin: 16px 0; }
.tldr .label { color: var(--hot); }
.skim-toggle { margin-left: auto; font-family: var(--mono); font-size: .78rem; border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 4px 12px; background: transparent; cursor: pointer; }

details.section { border-top: 1px solid var(--line); padding: 6px 0; }
details.section > summary { cursor: pointer; list-style: none; padding: 8px 0; font-family: var(--mono); color: var(--text); font-size: .95rem; display: flex; align-items: center; gap: 8px; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: '▸'; color: var(--accent); }
details.section[open] > summary::before { content: '▾'; }
details.section .body { padding: 6px 0 14px; }
details.section.hero { border: 1px solid rgba(95,208,255,.35); border-radius: 10px; background: var(--panel); padding: 10px 14px; margin: 14px 0; }
.body :is(h3) { font-family: var(--serif); color: var(--text-strong); }
.body code { font-family: var(--mono); background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 4px; }
.body pre { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; }
.body table { border-collapse: collapse; width: 100%; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; font-size: .92rem; }

/* mermaid host: clickable for lightbox */
.diagram { background: var(--panel); border: 1px solid rgba(95,208,255,.35); border-radius: 10px; padding: 18px; margin: 14px 0; overflow: auto; cursor: zoom-in; text-align: center; }
.diagram svg { width: 100% !important; max-width: 100% !important; height: auto; }
.diagram .hint { display: block; margin-top: 8px; font-family: var(--mono); font-size: .68rem; color: var(--muted); opacity: .7; }
.diagram.failed { cursor: default; }

/* TOC rail */
.toc { position: sticky; top: 64px; align-self: start; font-family: var(--mono); font-size: .8rem; }
.toc .label { display: block; margin-bottom: 8px; }
.toc a { display: block; color: var(--muted); padding: 3px 0; border-left: 2px solid transparent; padding-left: 8px; }
.toc a.active { color: var(--text-strong); border-left-color: var(--hot); }

.prevnext { display: flex; justify-content: space-between; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: .85rem; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(5,12,20,.92); display: none; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.lightbox.open { display: flex; }
.lightbox svg { max-width: 96vw; max-height: 92vh; height: auto; }
.lightbox .close { position: absolute; top: 16px; right: 20px; color: var(--text); font-family: var(--mono); cursor: pointer; }

/* states */
.notice { padding: 24px; font-family: var(--mono); color: var(--muted); }
.notice.error { color: var(--hard); }

/* ===== Study Mode ===== */
.study-link {
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--accent);
  border: 1px solid rgba(95,208,255,.4);
  border-radius: 999px;
  padding: 3px 12px;
  margin-left: 4px;
}
.study-link:hover { background: rgba(95,208,255,.08); text-decoration: none; }

.study-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 0 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.study-back { font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.study-back:hover { color: var(--text); }
/* Card-back answer panel — own typography so it never inherits the
   muted/small/mono control-bar link styles above. */
.study-back-panel { font-family: var(--sans); font-size: 1rem; color: var(--text); }
.study-cat-select {
  font-family: var(--mono);
  font-size: .8rem;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.study-shuffle-btn { font-size: .78rem; padding: 5px 12px; }
.progress-wrap { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.progress {
  width: 120px;
  height: 6px;
  background: rgba(255,255,255,.1);
  border-radius: 999px;
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .3s ease;
}
.progress-label { font-family: var(--mono); font-size: .75rem; color: var(--muted); white-space: nowrap; }

.study-card {
  max-width: 760px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid rgba(95,208,255,.2);
  border-radius: 14px;
  padding: 32px 36px 28px;
  min-height: 340px;
}
.study-card h1 {
  font-family: var(--serif);
  font-size: 1.85rem;
  color: var(--text-strong);
  margin: 0 0 10px;
}

.prompt-label {
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}
.recall-label {
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--hot);
  margin-bottom: 10px;
}
.study-body { margin-bottom: 14px; }
.study-body p, .study-body li { color: var(--text); }
.study-body code { font-family: var(--mono); background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 4px; }
.study-body pre { background: rgba(0,0,0,.2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; }

.reveal-btn {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity .15s;
}
.reveal-btn:hover { opacity: .88; }

.grade-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.grade {
  flex: 1;
  padding: 12px;
  font-family: var(--mono);
  font-size: .9rem;
  font-weight: 600;
  background: transparent;
  border: 2px solid;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
.grade.got { color: var(--easy); border-color: var(--easy); }
.grade.got:hover { background: rgba(95,227,154,.08); }
.grade.review { color: var(--hot); border-color: var(--hot); }
.grade.review:hover { background: rgba(255,180,84,.08); }

.study-full-link {
  display: inline-block;
  margin-top: 6px;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--accent);
}

.kbd-hint {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: .7rem;
  color: var(--muted);
  opacity: .65;
  text-align: center;
}

.session-done {
  max-width: 480px;
  margin: 60px auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(95,208,255,.2);
  border-radius: 14px;
  padding: 40px 32px;
}
.session-done-title {
  font-family: var(--serif);
  font-size: 1.6rem;
  color: var(--text-strong);
  margin-bottom: 10px;
}
.session-done-stats {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 28px;
}
.session-done-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.session-done-actions .reveal-btn { max-width: 300px; }
.session-done-actions .grade { min-width: 200px; }

/* ===== Responsive ===== */
.menu-btn { display: none; background: transparent; border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 10px; font-family: var(--mono); cursor: pointer; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 52px; bottom: 0; width: 250px; background: var(--bg); transform: translateX(-100%); transition: transform .2s; z-index: 30; height: auto; }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-block; }
  .reader { grid-template-columns: 1fr; }
  .toc { display: none; }
}
@media (max-width: 600px) {
  .study-card { padding: 20px 16px 18px; border-radius: 10px; }
  .study-card h1 { font-size: 1.4rem; }
  .progress { width: 80px; }
  .grade-row { flex-direction: column; }
  .study-bar { gap: 8px; }
  .progress-wrap { margin-left: 0; }
}
