:root {
  --blue: #184090;
  --blue-ink: #0F2B6B;
  --gold: #F8B010;
  --bg: #F5F7FB;
  --card: #FFFFFF;
  --ink: #0F1B3D;
  --mute: #566282;
  --line: #D9E0EE;
  --soft: #EAF0FB;
  --link: #184090;
  --btn: #184090;
  --btn-ink: #FFFFFF;
  --serif: ui-serif, "Iowan Old Style", Georgia, "Noto Serif", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: 16px;
  --max: 760px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1226;
    --card: #131C38;
    --ink: #E9EEFB;
    --mute: #9BA8C9;
    --line: #25314F;
    --soft: #1A2547;
    --link: #8FB0FF;
    --btn: #3B6BDD;
    --btn-ink: #FFFFFF;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--link); }
img { display: block; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
main:focus { outline: none; }

/* ---------- top band ---------- */
.band {
  background: var(--blue);
  color: #fff;
  border-bottom: 4px solid var(--gold);
  padding-top: env(safe-area-inset-top);
}
.band-in { max-width: var(--max); margin: 0 auto; padding: 14px var(--gutter) 18px; }
body[data-view="home"] .band-in { padding-bottom: 44px; }   /* room for the search box that overlaps the band */
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.badge { background: #fff; border-radius: 12px; padding: 4px; flex: none; }
.badge img { width: 44px; height: 44px; }
.brand-name { display: block; font: 700 1.35rem/1.15 var(--serif); letter-spacing: .005em; }
.brand-sub { display: block; font-size: .85rem; opacity: .85; margin-top: 2px; }
#bandExtra:empty { display: none; }
#bandExtra { margin-top: 14px; }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: #fff; text-decoration: none; font-size: .95rem; min-height: 44px; margin: -8px 0 0 -4px; padding: 0 4px; }
.crumb svg { width: 18px; height: 18px; }
.page-title { margin: 0; font: 700 1.4rem/1.25 var(--serif); }
.page-sub { margin: 4px 0 0; font-size: .9rem; opacity: .85; }

/* ---------- layout ---------- */
main { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter) 24px; flex: 1; }
.loading { color: var(--mute); padding: 32px 0; text-align: center; }

/* ---------- search ---------- */
.search { position: relative; margin-top: -26px; }
.search.flat { margin-top: 14px; }
.search.sticky { position: sticky; top: 0; z-index: 5; margin: 0 calc(var(--gutter) * -1); padding: 10px var(--gutter); background: var(--bg); border-bottom: 1px solid var(--line); }
.search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--mute); pointer-events: none; }
.search input {
  width: 100%; height: 52px; padding: 0 44px 0 44px;
  font: inherit; font-size: 1.05rem; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 14px;
  box-shadow: 0 6px 18px rgba(15, 27, 61, .12);
  -webkit-appearance: none; appearance: none;
}
.search.sticky input { box-shadow: none; }
.search input::placeholder { color: var(--mute); }
.search input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(248, 176, 16, .45); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border: 0; background: none; color: var(--mute); cursor: pointer; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
}
.clear.on { display: flex; }
.clear svg { position: static; transform: none; width: 18px; height: 18px; }

/* ---------- home: table of contents ---------- */
.toc-head { font: 700 1.1rem/1.3 var(--serif); margin: 26px 0 4px; }
.toc { list-style: none; margin: 0; padding: 0; }
.toc li { border-bottom: 1px solid var(--line); }
.toc a { display: block; padding: 14px 2px 13px; color: inherit; text-decoration: none; min-height: 64px; }
.toc a:active { background: var(--soft); }
.toc .row { display: flex; align-items: flex-end; gap: 8px; }
.toc .name { font: 600 1.05rem/1.3 var(--serif); }
.toc .dots { flex: 1 1 18px; min-width: 18px; border-bottom: 2px dotted var(--mute); opacity: .55; margin-bottom: .32em; }
.toc .n { font: 600 1.05rem/1.3 var(--serif); font-variant-numeric: tabular-nums; color: var(--blue); }
.toc .blurb { display: block; color: var(--mute); font-size: .88rem; margin-top: 3px; padding-right: 3.5rem; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toc .n { color: var(--gold); } }
.toc a:hover .name { text-decoration: underline; text-decoration-color: var(--gold); text-decoration-thickness: 2px; text-underline-offset: 3px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 0 4px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; font: inherit; font-size: .92rem;
  background: var(--card); color: var(--ink); border: 1.5px solid var(--line); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip[aria-pressed="true"] { background: var(--btn); border-color: var(--btn); } }
select.chip { padding-right: 10px; }
.status { color: var(--mute); font-size: .9rem; margin: 10px 0 8px; }

/* ---------- course groups ---------- */
.courses { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
details.course { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
details.course[open] { border-color: var(--blue); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) details.course[open] { border-color: var(--btn); } }
summary.ct-row {
  list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 12px 14px; min-height: 56px;
}
summary.ct-row::-webkit-details-marker { display: none; }
.ct { flex: 1; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.fac-tag { font-size: .75rem; color: var(--blue); background: var(--soft); border-radius: 6px; padding: 2px 7px; flex: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .fac-tag { color: var(--link); } }
.cn { color: var(--mute); font-size: .88rem; font-variant-numeric: tabular-nums; flex: none; }
.chev { width: 18px; height: 18px; color: var(--mute); flex: none; transition: transform .15s; }
details[open] > summary .chev { transform: rotate(90deg); }

.papers { border-top: 1px solid var(--line); }
.paper { padding: 12px 14px; display: grid; gap: 8px; }
.paper + .paper { border-top: 1px solid var(--line); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: .85rem; padding: 2px 9px; border-radius: 999px; background: var(--soft); color: var(--ink); }
.tag.yr { font-weight: 700; background: var(--blue); color: #fff; }
.tag.resit { background: #FFF1CC; color: #5C4200; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tag.yr { background: var(--btn); } :root:not([data-theme="light"]) .tag.resit { background: #4A3A10; color: #FFE29A; } }
.fn { color: var(--mute); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 8px; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 14px; border-radius: 10px; font: 600 .98rem var(--sans);
  text-decoration: none; border: 1.5px solid var(--btn); cursor: pointer;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.solid { background: var(--btn); color: var(--btn-ink); }
.btn.ghost { background: transparent; color: var(--link); }
.btn:active { transform: translateY(1px); }

.more { width: 100%; margin-top: 12px; }

/* ---------- empty / error ---------- */
.empty { text-align: center; padding: 36px 8px; color: var(--mute); }
.empty strong { display: block; color: var(--ink); font: 700 1.1rem var(--serif); margin-bottom: 6px; }

/* ---------- footer ---------- */
.foot { max-width: var(--max); width: 100%; margin: 0 auto; padding: 18px var(--gutter) calc(24px + env(safe-area-inset-bottom)); color: var(--mute); font-size: .85rem; border-top: 1px solid var(--line); }
.foot p { margin: 0 0 4px; }
.foot .tip { font-size: .8rem; }

@media (min-width: 640px) {
  :root { --gutter: 24px; }
  .band-in { padding-top: 22px; padding-bottom: 28px; }
  .search input { height: 56px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
