/* CP311 Study Hub — shared design system */
:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efeb;
  --border: #dedcd5;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --o1: #2a78d6;   /* Objective 1 — Strategy */
  --o2: #1baf7a;   /* Objective 2 — Budgeting & Valuation */
  --o3: #6250d6;   /* Objective 3 — Decision models */
  --o4: #eb6834;   /* Objective 4 — Org behavior */
  --tip-bg: #e9f6ef;  --tip-bd: #1baf7a;
  --trap-bg: #fdecea; --trap-bd: #e34948;
  --mem-bg: #fff6df;  --mem-bd: #eda100;
  --exam-bg: #ece9fb; --exam-bd: #6250d6;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --radius: 10px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #34332f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8d8c84;
  --accent: #3987e5;
  --accent-soft: #1d2a3b;
  --o1: #3987e5; --o2: #199e70; --o3: #9085e9; --o4: #d95926;
  --tip-bg: #13281f;  --tip-bd: #199e70;
  --trap-bg: #2e1817; --trap-bd: #e66767;
  --mem-bg: #2c2412;  --mem-bd: #c98500;
  --exam-bg: #201d36; --exam-bd: #9085e9;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--sans);
}
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .92em; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; letter-spacing: .2px; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a {
  text-decoration: none; color: var(--text-2); padding: 5px 10px; border-radius: 6px; font-size: 14px;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar .spacer { flex: 1; }
.btn {
  font: inherit; font-size: 14px; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 6px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; max-width: 1380px; margin: 0 auto; padding: 24px 20px 80px; }
.layout.single { grid-template-columns: minmax(0, 1fr); max-width: 1180px; }
.toc {
  position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 80px); overflow: auto;
  font-size: 14px; padding-right: 6px;
}
.toc h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.toc a { display: flex; gap: 6px; align-items: baseline; text-decoration: none; color: var(--text-2); padding: 3px 6px; border-radius: 5px; }
.toc a:hover { background: var(--surface-2); color: var(--text); }
.toc a.done::after { content: "✓"; margin-left: auto; color: var(--o2); font-weight: 700; }
.toc .progress { margin: 12px 6px 0; font-size: 13px; color: var(--muted); }
.toc .bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.toc .bar span { display: block; height: 100%; background: var(--o2); width: 0; transition: width .3s; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } .toc { position: static; max-height: none; } }

main h1 { font-size: 30px; margin: 0 0 6px; line-height: 1.2; }
main .lede { color: var(--text-2); font-size: 17px; margin: 0 0 22px; max-width: 900px; }
.obj-tag { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 3px 9px; border-radius: 99px; color: #fff; background: var(--accent); }
.obj-tag.o1 { background: var(--o1); } .obj-tag.o2 { background: var(--o2); } .obj-tag.o3 { background: var(--o3); } .obj-tag.o4 { background: var(--o4); }

/* ---------- sections ---------- */
section.reading {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 26px; margin: 0 0 22px; scroll-margin-top: 70px;
}
section.reading > header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
section.reading > header h2 { margin: 0; font-size: 22px; line-height: 1.25; flex: 1; }
section.reading > header .src { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 3px; }
label.gotit { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); white-space: nowrap; cursor: pointer; user-select: none; padding: 4px 10px; border: 1px solid var(--border); border-radius: 99px; }
label.gotit input { accent-color: var(--o2); }
section.reading.is-done { border-left: 4px solid var(--o2); }
section.reading h3 { font-size: 17px; margin: 20px 0 8px; }
section.reading p, section.reading li { max-width: 980px; }
section.reading ul, section.reading ol { padding-left: 22px; margin: 6px 0 12px; }
section.reading li { margin: 3px 0; }

.why { font-size: 15px; background: var(--accent-soft); border-radius: 8px; padding: 10px 14px; margin: 4px 0 14px; }
.why b { color: var(--accent); }

/* ---------- callouts ---------- */
.callout { border-left: 4px solid; border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 12px 0; font-size: 15px; }
.callout > b:first-child, .callout > strong:first-child { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 3px; }
.callout p { margin: 4px 0; }
.callout ul { margin: 4px 0; }
.callout.tip  { background: var(--tip-bg);  border-color: var(--tip-bd); }
.callout.trap { background: var(--trap-bg); border-color: var(--trap-bd); }
.callout.mem  { background: var(--mem-bg);  border-color: var(--mem-bd); }
.callout.exam { background: var(--exam-bg); border-color: var(--exam-bd); }

/* ---------- grids & cards ---------- */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 10px 0 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.card h4 { margin: 0 0 6px; font-size: 15px; }
.card p, .card li { font-size: 14.5px; }
.card ul { padding-left: 18px; margin: 4px 0; }
.card .k { font-size: 26px; font-weight: 800; line-height: 1; color: var(--accent); margin-bottom: 4px; }

/* letter "acronym" tiles */
.acro { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.acro div { flex: 1 1 150px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.acro div b { display: block; font-size: 24px; line-height: 1; color: var(--accent); margin-bottom: 4px; }
.acro div i { display: block; font-style: normal; font-weight: 700; margin-bottom: 2px; }

/* tables */
table.t { width: 100%; border-collapse: collapse; font-size: 14.5px; margin: 10px 0 16px; }
table.t th, table.t td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
table.t th { background: var(--surface-2); font-weight: 600; }
table.t td.c, table.t th.c { text-align: center; }
.tablewrap { overflow-x: auto; }

/* formulas */
.formula {
  font-family: "Cambria Math", Cambria, "Times New Roman", serif; font-size: 19px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 16px; margin: 10px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
}
.formula .lbl { font-family: var(--sans); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); flex-basis: 100%; }
.frac { display: inline-flex; flex-direction: column; text-align: center; vertical-align: middle; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 4px 2px; }
.frac > span:last-child { padding: 2px 4px 0; }

/* flow / steps */
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0; margin: 12px 0; }
.flow > div { flex: 1 1 140px; background: var(--surface-2); border: 1px solid var(--border); padding: 10px 12px; font-size: 14px; position: relative; border-radius: 8px; margin-right: 22px; }
.flow > div:last-child { margin-right: 0; }
.flow > div:not(:last-child)::after { content: "➜"; position: absolute; right: -19px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.flow > div b { display: block; margin-bottom: 2px; }

/* stack (bottom-up diagrams e.g. strategy map) */
.stack { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.stack > div { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 9px 12px; font-size: 14px; }
.stack > div b { display: inline-block; min-width: 170px; }

/* reveal / self-test */
details.reveal { border: 1px dashed var(--border); border-radius: 8px; padding: 8px 12px; margin: 8px 0; background: var(--surface); }
details.reveal > summary { cursor: pointer; font-weight: 600; font-size: 14.5px; color: var(--text-2); }
details.reveal > summary::marker { color: var(--accent); }
details.reveal[open] > summary { color: var(--text); margin-bottom: 6px; }

/* calculators */
.calc { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 14px 16px; margin: 14px 0; }
.calc h4 { margin: 0 0 10px; font-size: 15px; }
.calc .row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; }
.calc label { display: flex; flex-direction: column; font-size: 12.5px; color: var(--text-2); gap: 3px; }
.calc input, .calc select { font: inherit; font-size: 14px; width: 120px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.calc .out { margin-top: 12px; font-size: 15px; padding: 8px 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.calc .out b { font-size: 18px; }

/* pills */
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); margin: 0 3px 3px 0; }
.pill.hot { background: var(--trap-bg); border-color: var(--trap-bd); color: var(--text); font-weight: 600; }

/* flashcards (drill page) */
.fc-wrap { max-width: 820px; margin: 0 auto; }
.fc { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; min-height: 280px; padding: 28px 32px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; }
.fc .meta { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.fc .q { font-size: 21px; font-weight: 600; line-height: 1.35; }
.fc .a { font-size: 16.5px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); display: none; }
.fc.flipped .a { display: block; }
.fc .a ul { padding-left: 20px; margin: 4px 0; }
.fc-controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 16px 0; }
.fc-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: center; margin-bottom: 14px; }
.fc-stats { text-align: center; color: var(--muted); font-size: 14px; }

footer.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 10px; }

@media print {
  .topbar, .toc, label.gotit, .fc-controls, .btn { display: none !important; }
  .layout { display: block; padding: 0; }
  body { background: #fff; color: #000; font-size: 12px; }
  section.reading { break-inside: avoid-page; border: 1px solid #bbb; }
  details.reveal { display: block; } details.reveal > *:not(summary) { display: block; }
}
.btn.primary .kbd { color: var(--text); }

/* ---------- mobile ---------- */
.topbar .menu { display: none; }
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .menu { display: inline-block; order: 2; }
  .topbar .spacer { display: none; }
  .topbar nav { display: none; order: 9; width: 100%; flex-direction: column; gap: 2px; padding-top: 6px; }
  .topbar nav.open { display: flex; }
  .topbar nav a { padding: 10px 12px; font-size: 16px; }
  .topbar #revealAll { display: none; }
  .topbar .brand { flex: 1; }
  .layout { padding: 14px 12px 60px; gap: 14px; }
  section.reading { padding: 16px 14px; }
  main h1 { font-size: 24px; }
  table.t { font-size: 13px; }
  .formula { font-size: 16px; }
}
@media (max-width: 760px) {
  table.t, .stem table, .sol table, .solbox table { display: block; overflow-x: auto; max-width: 100%; }
  main img, main svg, section.reading svg { max-width: 100%; height: auto; }
  .flow > div { flex-basis: 100%; margin-right: 0; margin-bottom: 18px; }
  .flow > div:not(:last-child)::after { content: "⬇"; right: 50%; top: auto; bottom: -19px; transform: translateX(50%); }
  .grid, .grid.two { grid-template-columns: minmax(0, 1fr); }
  pre, code { white-space: pre-wrap; word-break: break-word; }
}
@media (max-width: 760px) { .card, .acro div, .grid > *, .callout, section.reading p, section.reading li { min-width: 0; overflow-wrap: anywhere; } }
