/* Esade Agent — strictly black, white and greys. */
:root {
  --bg: #ffffff;
  --fg: #000000;
  --fg-2: #333333;
  --muted: #6b6b6b;
  --line: #d9d9d9;
  --soft: #f2f2f2;
  --softer: #f8f8f8;
  --invert-bg: #000000;
  --invert-fg: #ffffff;
  --radius: 10px;
  --nav-h: 60px;
  --side-w: 220px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0b;
    --fg: #f5f5f5;
    --fg-2: #d0d0d0;
    --muted: #9a9a9a;
    --line: #2e2e2e;
    --soft: #1a1a1a;
    --softer: #131313;
    --invert-bg: #f5f5f5;
    --invert-fg: #0b0b0b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 var(--font);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--fg); color: var(--bg); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--invert-bg); color: var(--invert-fg);
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em;
}
.urgency {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--invert-bg); color: var(--invert-fg);
  font-size: 0.85rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.urgency.zero { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* ---------- Tabs: bottom bar on mobile ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.tabs-brand { display: none; }
.tab {
  position: relative; flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--fg); }
.tab[aria-current="page"] svg { stroke-width: 2.2; }
.tab-badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--invert-bg); color: var(--invert-fg);
  font-size: 0.7rem; line-height: 18px; text-align: center;
}

main { max-width: 980px; margin: 0 auto; padding: 16px; outline: none; }
.view > * + * { margin-top: 16px; }

/* ---------- Desktop: side nav ---------- */
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: var(--side-w); }
  .topbar { padding-left: 28px; padding-right: 28px; }
  .topbar .brand { visibility: hidden; }
  .tabs {
    top: 0; right: auto; bottom: 0; width: var(--side-w); height: auto;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 16px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .tabs-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 0 10px 18px; }
  .tab {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 10px 12px; border-radius: 8px; font-size: 0.95rem;
  }
  .tab:hover { background: var(--soft); color: var(--fg); }
  .tab[aria-current="page"] { background: var(--soft); }
  .tab-badge { position: static; margin-left: auto; }
  main { padding: 28px; }
}

/* ---------- Generic pieces ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; }
.subtle { color: var(--muted); font-size: 0.9rem; }
.small { font-size: 0.82rem; }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); padding: 14px 16px; }
.notice {
  border: 1px dashed var(--muted); border-radius: var(--radius);
  padding: 10px 14px; font-size: 0.88rem; color: var(--fg-2); background: var(--softer);
}
.placeholder { text-align: center; padding: 36px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.placeholder strong { display: block; color: var(--fg); font-size: 1.05rem; margin-bottom: 4px; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.select, .input {
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  padding: 8px 32px 8px 12px; min-height: 40px; max-width: 100%;
}
.select {
  background-image: linear-gradient(45deg, transparent 50%, var(--fg) 50%), linear-gradient(135deg, var(--fg) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.input { padding-right: 12px; flex: 1 1 180px; }
.segmented { display: inline-flex; border: 1px solid var(--fg); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: var(--bg); padding: 7px 14px; cursor: pointer; min-height: 38px; }
.segmented button[aria-pressed="true"] { background: var(--invert-bg); color: var(--invert-fg); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--fg); border-radius: 8px; background: var(--bg); color: var(--fg);
  padding: 6px 12px; min-height: 36px; font-size: 0.88rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--invert-bg); color: var(--invert-fg); }
.btn.primary:hover { opacity: 0.85; }
.btn.ghost { border-color: var(--line); }
.btn.icon { padding: 6px 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--fg); }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 0.74rem; font-weight: 600; color: var(--fg-2); white-space: nowrap;
}
.tag.solid { background: var(--invert-bg); color: var(--invert-fg); border-color: var(--invert-bg); }
.tag.outline { border-color: var(--fg); color: var(--fg); }
.tag.dashed { border-style: dashed; border-color: var(--muted); color: var(--muted); }
.tag.strike { text-decoration: line-through; color: var(--muted); }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cal-title { font-weight: 700; font-size: 1.05rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-dow { font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; text-align: center; padding: 6px 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--softer); }
.cal-day {
  position: relative; min-height: 64px; padding: 4px; text-align: left;
  border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: var(--bg); cursor: pointer; display: flex; flex-direction: column; gap: 2px; overflow: hidden;
}
.cal-day:hover { background: var(--softer); }
.cal-day.other { color: var(--muted); background: var(--softer); }
.cal-day.selected { box-shadow: inset 0 0 0 2px var(--fg); }
.cal-num { font-size: 0.8rem; font-weight: 600; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .cal-num { background: var(--invert-bg); color: var(--invert-fg); }
.cal-chips { display: flex; flex-wrap: wrap; gap: 2px; }
.chip { display: block; width: 7px; height: 7px; border-radius: 50%; background: var(--fg); }
.chip.hard { border-radius: 1px; transform: rotate(45deg); }
.chip.muted { background: transparent; border: 1px solid var(--muted); }
.chip.done { background: var(--line); }
.chip.exam { background: repeating-linear-gradient(45deg, var(--fg) 0 2px, transparent 2px 4px); border: 1px solid var(--fg); }
.chip-text { display: none; }
.cal-more { font-size: 0.68rem; color: var(--muted); }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 0.78rem; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
@media (min-width: 700px) {
  .cal-day { min-height: 92px; }
  .cal-chips { flex-direction: column; flex-wrap: nowrap; }
  .chip {
    width: auto; height: auto; border-radius: 4px; transform: none !important;
    padding: 0 4px; font-size: 0.68rem; line-height: 1.45; color: var(--invert-fg);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .chip.hard { font-weight: 800; }
  .chip.muted { color: var(--muted); border-color: var(--line); }
  .chip.done { color: var(--muted); background: var(--soft); text-decoration: line-through; }
  .chip.exam { color: var(--fg); background: var(--soft); border: 1px dashed var(--fg); }
  .chip-text { display: inline; }
  .cal-legend .chip { width: 9px; height: 9px; padding: 0; border-radius: 50%; }
  .cal-legend .chip.hard { border-radius: 1px; transform: rotate(45deg) !important; }
}
.btn.more { margin-top: 8px; width: 100%; }

/* ---------- Deadline lists ---------- */
.group { margin-top: 24px; }
.group-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 2px solid var(--fg); }
.group-head .count { font-size: 0.85rem; color: var(--muted); }
.group.flagged .group-head { border-bottom-style: dashed; }
.group-desc { font-size: 0.85rem; color: var(--muted); margin: -2px 0 8px; }
.list { display: grid; gap: 8px; }
.item { display: grid; gap: 6px; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: var(--bg); }
.item.urgent { border-color: var(--fg); border-width: 2px; padding: 11px 13px; }
.item.overdue { border-left: 6px solid var(--fg); }
.item.done { opacity: 0.6; }
.item.done .item-title { text-decoration: line-through; }
.item.calonly { background: var(--softer); color: var(--muted); }
.item-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.item-course { font-size: 0.74rem; font-weight: 800; letter-spacing: 0.04em; }
.item-title { font-weight: 600; }
.item-when { font-size: 0.88rem; color: var(--fg-2); }
.item-note { font-size: 0.84rem; color: var(--muted); }
.item-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
.item-actions .link { margin-left: auto; font-size: 0.85rem; font-weight: 600; }
details.group > summary { cursor: pointer; list-style: none; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary .group-head::after { content: "Show"; margin-left: auto; font-size: 0.8rem; color: var(--muted); }
details.group[open] > summary .group-head::after { content: "Hide"; }

/* ---------- Courses: grid ---------- */
.course-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 700px) { .course-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; } }
.course-card {
  display: flex; flex-direction: column; overflow: hidden; text-decoration: none;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
  transition: border-color .15s, transform .15s;
}
.course-card:hover { border-color: var(--fg); }
.course-card:active { transform: scale(.99); }
.course-banner {
  height: 84px; display: flex; align-items: flex-end; padding: 10px 12px;
  background-color: var(--invert-bg); color: var(--invert-fg);
}
.course-banner span { font-size: 1.6rem; font-weight: 800; letter-spacing: .02em; line-height: 1; }
/* Monochrome patterns so the cards are told apart without colour */
.course-banner.p0 { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.14) 0 2px, transparent 2px 12px); }
.course-banner.p1 { background-image: radial-gradient(rgba(255,255,255,.2) 1.2px, transparent 1.4px); background-size: 10px 10px; }
.course-banner.p2 { background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.12) 0 1px, transparent 1px 9px), repeating-linear-gradient(90deg, rgba(255,255,255,.12) 0 1px, transparent 1px 9px); }
.course-banner.p3 { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.12) 0 6px, transparent 6px 14px); }
@media (prefers-color-scheme: dark) {
  .course-banner.p0 { background-image: repeating-linear-gradient(135deg, rgba(0,0,0,.12) 0 2px, transparent 2px 12px); }
  .course-banner.p1 { background-image: radial-gradient(rgba(0,0,0,.18) 1.2px, transparent 1.4px); }
  .course-banner.p2 { background-image: repeating-linear-gradient(0deg, rgba(0,0,0,.1) 0 1px, transparent 1px 9px), repeating-linear-gradient(90deg, rgba(0,0,0,.1) 0 1px, transparent 1px 9px); }
  .course-banner.p3 { background-image: repeating-linear-gradient(45deg, rgba(0,0,0,.1) 0 6px, transparent 6px 14px); }
}
.course-card.empty .course-banner { background-color: var(--soft); color: var(--muted); }
.course-card.empty .course-banner.p0, .course-card.empty .course-banner.p1,
.course-card.empty .course-banner.p2, .course-card.empty .course-banner.p3 { background-image: none; }
.course-body { display: grid; gap: 2px; padding: 10px 12px 12px; }
.course-code { font-size: .74rem; font-weight: 800; letter-spacing: .06em; color: var(--muted); }
.course-name { font-weight: 700; line-height: 1.3; }
.course-meta { margin-top: 6px; font-size: .8rem; color: var(--muted); }

/* ---------- Courses: course page ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: .85rem; color: var(--muted); }
.crumbs a { color: var(--fg-2); text-decoration: none; border-bottom: 1px solid var(--line); }
.crumbs a:hover { border-color: var(--fg); }
.crumbs .sep { color: var(--line); }
.kicker { font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.source-list { font-size: 0.85rem; color: var(--muted); padding-left: 18px; margin: 6px 0 0; }
.part { margin-top: 26px; }
.part-title { font-size: 1rem; padding-bottom: 6px; border-bottom: 2px solid var(--fg); margin-bottom: 4px; }
.topic-list { list-style: none; margin: 0; padding: 0; }
.topic-row {
  display: grid; grid-template-columns: 30px 1fr 14px; gap: 10px; align-items: start;
  padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none;
}
.topic-row:hover { background: var(--softer); }
.topic-num {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--fg);
  display: grid; place-items: center; font-size: .78rem; font-weight: 700; margin-top: 1px;
}
.topic-main { display: grid; gap: 2px; min-width: 0; }
.topic-name { font-weight: 700; line-height: 1.3; }
.topic-from { font-size: .76rem; color: var(--muted); }
.topic-sum { font-size: .86rem; color: var(--fg-2); }
.chev { color: var(--muted); font-size: 1.3rem; line-height: 1.2; }

/* ---------- Courses: topic page ---------- */
.topic-head { padding-bottom: 14px; border-bottom: 2px solid var(--fg); }
.topic-title { font-size: clamp(1.6rem, 6vw, 2.3rem); line-height: 1.15; letter-spacing: -.02em; margin: 4px 0 8px; }
.topic-sessions { font-size: .8rem; color: var(--muted); }
.jump { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.summary-box { background: var(--softer); border: 1px solid var(--line); border-left: 4px solid var(--fg); border-radius: var(--radius); padding: 14px 16px; }
.summary-box h2 { font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.summary-box ul { margin: 8px 0 0; padding-left: 20px; }
.summary-box li { margin: 4px 0; line-height: 1.5; }
.section-title { font-size: 1.35rem; letter-spacing: -.01em; margin-top: 8px; }

.notes { max-width: 70ch; font-size: 1.04rem; line-height: 1.68; }
.notes h3 { font-size: 1.15rem; margin: 30px 0 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.notes h2 + h3 { border-top: 0; padding-top: 0; margin-top: 16px; }
.notes p { margin: 10px 0; }
.notes ul, .notes ol { margin: 10px 0; padding-left: 22px; }
.notes li { margin: 6px 0; }
.notes strong { font-weight: 700; }
.source { font-size: .76rem; line-height: 1.4; color: var(--muted); margin: 8px 0 0; padding-left: 10px; border-left: 2px solid var(--line); }
.example { margin: 16px 0; padding: 12px 14px; border: 1px dashed var(--fg); border-radius: var(--radius); background: var(--bg); }
.example-title { font-size: .76rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.example p { margin: 6px 0 0; }
.example ul { margin: 6px 0 0; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 12px 0 4px; border: 1px solid var(--line); border-radius: 8px; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: .88rem; line-height: 1.45; }
.table-wrap th, .table-wrap td { text-align: left; vertical-align: top; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.table-wrap thead th { background: var(--soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.table-wrap tbody th { font-weight: 600; }
.table-wrap tbody tr:last-child > * { border-bottom: 0; }
.table-caption { font-size: .78rem; color: var(--muted); margin: 4px 0 0 !important; line-height: 1.4; }

/* Diagrams: the only place colour is used. Always on a white panel so colours read in dark mode too. */
.figure { margin: 16px 0; }
.figure-art { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.figure.svg .figure-art { max-width: 520px; }
.figure-art svg { display: block; width: 100%; height: auto; font-family: var(--font); }
.figure-art img { display: block; width: 100%; height: auto; border-radius: 4px; }
.figure figcaption { font-size: .8rem; color: var(--fg-2); line-height: 1.4; margin-top: 6px; }

.related-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.related-list .tag { text-decoration: none; white-space: normal; padding: 4px 10px; font-size: .8rem; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 16px; border-top: 2px solid var(--fg); }
.pager-link { display: grid; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; font-weight: 600; line-height: 1.3; }
.pager-link:hover { border-color: var(--fg); }
.pager-link.next { text-align: right; }

/* ---------- Topic quiz ---------- */
.practice-label {
  display: inline-block; margin-top: 6px; border: 2px solid var(--fg); border-radius: 6px;
  padding: 3px 10px; font-weight: 700; font-size: .85rem; letter-spacing: .01em;
}
.quiz > * + * { margin-top: 10px; }
.quiz-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.q .source { margin-top: 10px; }
.quiz-score {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px;
  background: var(--bg); border: 2px solid var(--fg); border-radius: var(--radius); padding: 10px 14px;
  box-shadow: 0 4px 18px rgba(0,0,0,.12);
}
.quiz-score .progress { flex: 1 1 120px; }
@media (min-width: 900px) { .quiz-score { bottom: 12px; } }
.progress { height: 4px; background: var(--soft); border-radius: 2px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--fg); }
.question { font-size: 1.05rem; font-weight: 600; margin: 6px 0 12px; line-height: 1.45; }
.options { display: grid; gap: 8px; }
.option {
  display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
  padding: 12px 14px; cursor: pointer; width: 100%; line-height: 1.4;
}
.option:hover:not(:disabled) { border-color: var(--fg); }
.option:disabled { cursor: default; color: var(--fg); }
.option .key { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--fg); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.option.correct { border: 2px solid var(--fg); padding: 11px 13px; }
.option.correct .key { background: var(--invert-bg); color: var(--invert-fg); }
.option.wrong { border-style: dashed; border-color: var(--fg); background: var(--softer); }
.option .why { display: block; margin-top: 6px; font-size: .88rem; color: var(--fg-2); }
.option .verdict { font-weight: 700; }
.feedback { margin-top: 12px; font-weight: 700; }
.score { font-size: 1.8rem; font-weight: 800; letter-spacing: -.02em; }

/* ---------- Settings & deep links ---------- */
.settings > * + * { margin-top: 10px; }
.settings h2 { font-size: 1.05rem; margin: 0; }
.settings p { margin-bottom: 0; }
.push-state { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.item.focus { outline: 3px solid var(--fg); outline-offset: 2px; }
