/* ============================================================================
   IITP · Semester I — design system
   Vercel-flavoured: neutral greys, 1px borders, tight type, no decoration.
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #fafafa;
  --bg-elev: #ffffff;
  --bg-sunken: #f2f2f2;
  --ink: #0a0a0a;
  --ink-2: #3d3d3d;
  --ink-3: #666666;
  --ink-4: #8f8f8f;
  --line: #eaeaea;
  --line-strong: #d4d4d4;
  --accent: #0072f5;
  --accent-ink: #ffffff;
  --accent-soft: #eaf3ff;
  --ok: #067647;
  --ok-soft: #e8f7ee;
  --warn: #b25e00;
  --violet: #7928ca;

  --radius: 10px;
  --radius-sm: 7px;
  --max: 1180px;
  --read: 74ch;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, .04), 0 12px 28px -16px rgba(0, 0, 0, .22);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI",
          Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display",
                  "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --bg-elev: #0a0a0a;
    --bg-sunken: #141414;
    --ink: #ededed;
    --ink-2: #c4c4c4;
    --ink-3: #8f8f8f;
    --ink-4: #6e6e6e;
    --line: #1f1f1f;
    --line-strong: #333333;
    --accent: #52a8ff;
    --accent-ink: #000000;
    --accent-soft: #0d1f33;
    --ok: #62d59b;
    --ok-soft: #0b2418;
    --warn: #f5b355;
    --violet: #a78bfa;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .6);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, .6), 0 12px 28px -16px rgba(0, 0, 0, .9);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-elev: #0a0a0a;
  --bg-sunken: #141414;
  --ink: #ededed;
  --ink-2: #c4c4c4;
  --ink-3: #8f8f8f;
  --ink-4: #6e6e6e;
  --line: #1f1f1f;
  --line-strong: #333333;
  --accent: #52a8ff;
  --accent-ink: #000000;
  --accent-soft: #0d1f33;
  --ok: #62d59b;
  --ok-soft: #0b2418;
  --warn: #f5b355;
  --violet: #a78bfa;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .6);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, .6), 0 12px 28px -16px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--bg);
  overflow-x: clip;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1, h2, h3, h4 {
  font-family: var(--font-display);
  letter-spacing: -.028em;
  line-height: 1.15;
  font-weight: 650;
  color: var(--ink);
}

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------- top bar --- */

.progress {
  position: fixed; inset: 0 auto auto 0; height: 2px; width: 0;
  background: var(--accent); z-index: 60; transition: width .08s linear;
}

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  height: 62px; padding: 0 max(20px, calc((100vw - var(--max)) / 2));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; flex: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px; flex: none;
  background: var(--ink);
  position: relative;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 20%, transparent);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 7px auto auto;
  width: 7px; height: 7px; border-radius: 2px;
  background: var(--accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 13.5px; letter-spacing: -.01em; font-weight: 650; }
.brand-text small { font-size: 11px; color: var(--ink-4); letter-spacing: .01em; }

.topnav { display: flex; gap: 2px; margin-left: auto; }
.topnav a {
  padding: 5px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 550;
  color: var(--ink-3); font-family: var(--mono); letter-spacing: -.02em;
}
.topnav a:hover { background: var(--bg-sunken); color: var(--ink); text-decoration: none; }

.theme-toggle {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0; cursor: pointer;
  background: transparent; color: var(--ink-3);
  border: 1px solid var(--line); border-radius: 7px;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
.theme-toggle svg { width: 15px; height: 15px; display: block; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

/* ---------------------------------------------------------------- shell --- */

.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding: 56px 20px 88px;
}

.eyebrow {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 11.5px; font-weight: 500; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-4);
}

.lede {
  margin: 16px 0 0;
  font-size: 17px; line-height: 1.6; color: var(--ink-3);
  max-width: 60ch;
  text-wrap: pretty;
}

/* ----------------------------------------------------------------- hero --- */

.hero { position: relative; padding: 32px 0 56px; }
.hero::before {
  content: ""; position: absolute; z-index: -1;
  left: 0; right: 0; top: -50%; height: 200%;
  background: radial-gradient(45% 45% at 30% 45%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%);
  pointer-events: none;
}
.hero h1 {
  margin: 0;
  font-size: clamp(34px, 5.4vw, 58px);
  font-weight: 680;
  letter-spacing: -.045em;
  line-height: 1.02;
}
.hero h1 em { font-style: normal; color: var(--ink-4); }

.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 30px; }
.stats span {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-elev);
  font-size: 12.5px; color: var(--ink-3);
}
.stats b {
  font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--ink);
}

/* --------------------------------------------------------- subject grid --- */

.subject-grid {
  display: grid; gap: 12px; margin-bottom: 72px;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
}

.subject-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 20px 20px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  box-shadow: var(--shadow-1);
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.subject-card:hover {
  text-decoration: none;
  border-color: var(--line-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
}

.subject-code {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  letter-spacing: .02em; color: var(--ink-4);
}
.subject-name {
  font-size: 17px; font-weight: 620; letter-spacing: -.022em; line-height: 1.3;
  color: var(--ink);
}
.subject-blurb { font-size: 13.5px; line-height: 1.55; color: var(--ink-3); }
.subject-counts {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-4);
  font-family: var(--mono);
}
.subject-counts b { color: var(--ink-2); font-weight: 600; }

/* ---------------------------------------------------------------- lists --- */

.all-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 26px;
  padding-bottom: 16px; border-bottom: 1px solid var(--line);
}
.all-head h2 { margin: 0; font-size: 20px; letter-spacing: -.03em; }

.filter {
  flex: 1 1 240px; min-width: 190px; max-width: 380px; margin-left: auto;
  width: 100%;
  padding: 9px 13px;
  font-family: var(--font); font-size: 13.5px;
  color: var(--ink); background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.filter::placeholder { color: var(--ink-4); }
.filter:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.list-group { margin-bottom: 34px; }
.list-group:not(:has(li:not([hidden]))) { display: none; }
.list-group h3 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px; font-family: var(--mono);
  font-size: 11px; font-weight: 500; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-4);
}
.list-group h3 .subject-code { color: var(--ink-2); font-size: 11px; }

.doc-list {
  list-style: none; margin: 0; padding: 0; display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
}

.doc-card > a {
  display: flex; flex-direction: column; gap: 3px; height: 100%;
  padding: 13px 15px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: inherit;
  box-shadow: var(--shadow-1);
  transition: border-color .13s ease, background .13s ease;
}
.doc-card > a:hover {
  text-decoration: none;
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--accent) 3%, var(--bg-elev));
}

.doc-kind {
  font-family: var(--mono); font-size: 10px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase; color: var(--ink-4);
}
.kind-summary { color: var(--violet); }
.kind-quiz { color: var(--warn); }
.kind-assignment { color: var(--ok); }

.doc-title { font-size: 14.5px; font-weight: 600; letter-spacing: -.015em; }
.doc-sub {
  font-size: 13px; line-height: 1.5; color: var(--ink-3);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.doc-meta { font-family: var(--mono); font-size: 11px; color: var(--ink-4); margin-top: auto; padding-top: 6px; }

.empty { margin-top: 24px; color: var(--ink-4); font-size: 14px; }

/* -------------------------------------------------------------- subject --- */

.crumbs {
  display: flex; gap: 7px; flex-wrap: wrap; align-items: center;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-4);
}
.crumbs a { color: var(--ink-3); }
.crumbs a:hover { color: var(--accent); text-decoration: none; }

.subject-head { padding: 18px 0 36px; margin-bottom: 40px; border-bottom: 1px solid var(--line); }
.subject-head h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.04em; }
.subject-head .filter { display: block; margin: 26px 0 0; max-width: 420px; width: 100%; }

.collection { margin-bottom: 56px; }
.collection-head { display: flex; align-items: baseline; gap: 10px; }
.collection-head h2 { margin: 0; font-size: 19px; letter-spacing: -.03em; }
.count {
  font-family: var(--mono); font-size: 11px; color: var(--ink-4);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 8px;
}
.collection-note { margin: 7px 0 18px; color: var(--ink-4); font-size: 13px; }

/* ------------------------------------------------------------- document --- */

.doc-wrap { max-width: 1140px; }
.doc-head { padding: 20px 0 28px; margin-bottom: 36px; border-bottom: 1px solid var(--line); }
.doc-head h1 {
  margin: 0; font-size: clamp(25px, 3.4vw, 36px);
  letter-spacing: -.04em; max-width: 30ch;
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 16px; }
.chip {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  background: var(--bg-sunken); border-radius: 5px; padding: 3px 9px;
}
.source { margin: 16px 0 0; font-size: 11.5px; color: var(--ink-4); }
.source code { font-family: var(--mono); }

.doc-body { display: grid; gap: 52px; align-items: start; }
.doc-body.with-toc { grid-template-columns: 210px minmax(0, 1fr); }

.toc {
  position: sticky; top: 84px;
  max-height: calc(100vh - 120px); overflow: auto;
  padding-right: 8px;
}
.toc-title {
  margin: 0 0 10px; font-family: var(--mono);
  font-size: 10.5px; font-weight: 500; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-4);
}
.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.toc a {
  display: block; padding: 4px 9px; border-radius: 5px;
  border-left: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.4; color: var(--ink-3);
  transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.toc a:hover { color: var(--ink); text-decoration: none; background: var(--bg-sunken); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 550; }
.toc-h3 a { padding-left: 18px; font-size: 12px; color: var(--ink-4); }

/* ----------------------------------------------------------------- prose --- */

.prose { max-width: var(--read); min-width: 0; font-size: 16px; }
.prose > :first-child { margin-top: 0; }
.prose > h2:first-child { border-top: 0; padding-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { scroll-margin-top: 90px; }

.prose h1 { margin: 0 0 18px; font-size: 26px; letter-spacing: -.035em; }
.prose h2 {
  margin: 44px 0 14px; padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 20px; letter-spacing: -.03em;
}
.prose h3 { margin: 30px 0 8px; font-size: 16px; letter-spacing: -.02em; font-weight: 620; }
.prose h4 {
  margin: 24px 0 6px; font-size: 11.5px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-4); font-family: var(--mono);
  font-weight: 500;
}

.prose p { margin: 0 0 15px; color: var(--ink-2); text-wrap: pretty; }
.prose strong { color: var(--ink); font-weight: 620; }
.prose em { color: var(--ink-2); }

.prose ul, .prose ol { margin: 0 0 18px; padding-left: 20px; color: var(--ink-2); }
.prose li { margin-bottom: 7px; }
.prose li::marker { color: var(--ink-4); }
.prose li > p { margin-bottom: 6px; }
.prose ul ul, .prose ol ol { margin-top: 7px; }

.prose hr { border: 0; border-top: 1px solid var(--line); margin: 36px 0; }
.prose hr + h2, .prose hr + h3 { border-top: 0; padding-top: 0; margin-top: 24px; }

.prose blockquote {
  margin: 20px 0; padding: 14px 18px;
  background: var(--bg-sunken); border-left: 2px solid var(--line-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink-2);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose code {
  font-family: var(--mono); font-size: .86em;
  background: var(--bg-sunken); border-radius: 4px; padding: 1.5px 5px;
  color: var(--ink);
}
.prose pre {
  margin: 0 0 20px; padding: 16px 18px; overflow-x: auto;
  background: var(--bg-sunken); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12.5px; line-height: 1.6;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }

.prose table {
  display: table; width: 100%;
  margin: 0; border-collapse: collapse;
  font-size: 13.5px; background: var(--bg-elev);
}
.prose .table-wrap {
  margin: 0 0 22px; overflow-x: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-elev);
}
.prose thead th {
  position: sticky; top: 0;
  background: var(--bg-sunken); color: var(--ink-4);
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: .05em; text-transform: uppercase; text-align: left;
  white-space: nowrap;
}
.prose th, .prose td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose tbody tr:last-child td { border-bottom: 0; }
.prose tbody tr:hover { background: color-mix(in srgb, var(--accent) 3%, transparent); }
.prose img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }

/* verified answer lines: "✅ d) ... — explanation" */
.prose p.answer {
  margin: 0 0 14px; padding: 10px 14px;
  background: var(--ok-soft); border-left: 2px solid var(--ok);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14.5px; color: var(--ink-2);
}
.prose p.answer strong { color: var(--ok); }

.plain-ref { color: var(--ink-3); border-bottom: 1px dotted var(--line-strong); }

/* ----------------------------------------------------------------- pager --- */

.pager {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--line);
}
.pager a {
  display: grid; gap: 2px; max-width: 47%;
  padding: 12px 16px; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .13s ease;
}
.pager a:hover { text-decoration: none; border-color: var(--line-strong); }
.pager span {
  font-family: var(--mono); font-size: 10px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-4);
}
.pager b { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.pager-next { margin-left: auto; text-align: right; }

/* ----------------------------------------------------------------- 404 --- */

.notfound { padding-top: 96px; }
.notfound h1 { margin: 0; font-size: clamp(30px, 4.6vw, 46px); letter-spacing: -.04em; }
.nf-actions { margin: 30px 0 0; }
.nf-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 34px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px;
  background: var(--ink); color: var(--bg);
  font-size: 13.5px; font-weight: 600; letter-spacing: -.01em;
}
.btn:hover { text-decoration: none; opacity: .88; }

.btn-ghost {
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px; font-weight: 500;
}
.btn-ghost:hover { border-color: var(--line-strong); color: var(--ink); opacity: 1; }

/* ---------------------------------------------------------------- footer --- */
.footer {
  max-width: var(--max); margin: 0 auto; padding: 26px 20px 56px;
  border-top: 1px solid var(--line);
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: space-between;
  font-size: 11.5px; color: var(--ink-4);
}

/* ------------------------------------------------------------ responsive --- */

@media (max-width: 940px) {
  .doc-body.with-toc { grid-template-columns: 1fr; gap: 28px; }
  .toc {
    position: static; max-height: none; padding: 0 0 18px;
    border-bottom: 1px solid var(--line);
  }
  .toc ol { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .toc a { border-left: 0; }
  .toc a.active { background: var(--bg-sunken); }
  .toc-h3 { display: none; }
}

@media (max-width: 720px) {
  .topbar { height: 56px; gap: 10px; }
  .brand { min-width: 0; }
  .brand-text small { display: none; }
  .topnav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .topnav::-webkit-scrollbar { display: none; }
  .wrap { padding: 36px 16px 64px; }
  .doc-list { grid-template-columns: 1fr; }
  .pager a { max-width: 100%; }
  .pager-next { margin-left: 0; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

@media print {
  .topbar, .toc, .pager, .footer, .progress, .filter { display: none !important; }
  .doc-body.with-toc { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; }
  .prose { max-width: none; }
}
