/* ============================================================
   Study Notes — Shared Stylesheet
   Used by every subject and session page.
   Per-subject accent is set via --accent on <body data-accent>.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --bg:            #f7f5f0;   /* warm paper */
  --bg-soft:       #fffdf8;
  --surface:       #ffffff;
  --surface-2:     #f3f0e9;
  --ink:           #23211c;   /* near-black, warm */
  --ink-soft:      #54514a;
  --ink-faint:     #8a867c;
  --line:          #e6e1d6;
  --line-strong:   #d8d2c4;

  --accent:        #5b4bd6;   /* default = GenAI violet */
  --accent-soft:   #efeafe;
  --accent-ink:    #3a2db0;

  /* Callout palettes */
  --eli5-bg:   #fff6e6;  --eli5-line:  #f1c27a;  --eli5-ink:  #8a5a06;
  --ex-bg:     #eafaf1;  --ex-line:    #9bd9b6;  --ex-ink:    #1d7a4d;
  --key-bg:    #eef3ff;  --key-line:   #a9c2f5;  --key-ink:   #234aa0;
  --warn-bg:   #fdeeee;  --warn-line:  #f0aeae;  --warn-ink:  #9c2b2b;
  --note-bg:   #f2f0fb;  --note-line:  #c8c0ee;  --note-ink:  #4a3aa8;

  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 1px 2px rgba(40,35,20,.04), 0 8px 28px rgba(40,35,20,.06);
  --shadow-lg: 0 12px 48px rgba(40,35,20,.14);

  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;

  --maxw: 1180px;
}

/* ---------- Per-subject accent themes (light) ---------- */
[data-accent="hld"]  { --accent: #2f6fed; --accent-soft: #e7efff; --accent-ink: #1b4dc0; }
[data-accent="nn"]   { --accent: #e8590c; --accent-soft: #fff0e6; --accent-ink: #b8430a; }
[data-accent="dbms"] { --accent: #1f9d57; --accent-soft: #e4f6ec; --accent-ink: #137a41; }

/* ---------- Per-subject accent themes (dark) ---------- */
[data-theme="dark"] [data-accent="hld"]  { --accent: #74a4ff; --accent-soft: #1b2742; --accent-ink: #a9c5ff; }
[data-theme="dark"] [data-accent="nn"]   { --accent: #ff9b5c; --accent-soft: #3a2415; --accent-ink: #ffba8a; }
[data-theme="dark"] [data-accent="dbms"]{ --accent: #4fcd8a; --accent-soft: #15301f; --accent-ink: #8fe3b4; }

[data-theme="dark"] {
  --bg:            #16151a;
  --bg-soft:       #1c1b21;
  --surface:       #201f27;
  --surface-2:     #26252e;
  --ink:           #ece9e3;
  --ink-soft:      #b7b3aa;
  --ink-faint:     #87837b;
  --line:          #322f3a;
  --line-strong:   #403c4a;

  --accent:        #9b8cff;
  --accent-soft:   #2a2547;
  --accent-ink:    #c5bbff;

  --eli5-bg:   #2e2716;  --eli5-line:  #6b5524;  --eli5-ink:  #f0c474;
  --ex-bg:     #16291f;  --ex-line:    #2f5a42;  --ex-ink:    #86d7a8;
  --key-bg:    #1a2238;  --key-line:   #335089;  --key-ink:   #9cbcf5;
  --warn-bg:   #311c1c;  --warn-line:  #6e3636;  --warn-ink:  #f0a3a3;
  --note-bg:   #221f33;  --note-line:  #423a6e;  --note-ink:  #c0b6f5;

  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.55);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 90px; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: -.01em; color: var(--ink);
}
.topbar .brand:hover { text-decoration: none; }
.brand-dot {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #ff8fae));
  display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 800;
}
.crumbs { color: var(--ink-faint); font-size: .9rem; margin-left: 2px; }
.crumbs a { color: var(--ink-soft); }
.topbar .spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-soft); width: 38px; height: 38px; border-radius: 10px;
  cursor: pointer; font-size: 16px; display: grid; place-items: center;
  transition: transform .15s ease, background .2s;
}
.icon-btn:hover { transform: translateY(-1px); background: var(--surface-2); }

/* reading progress */
#progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--accent), #ff8fae);
  z-index: 60; transition: width .1s linear;
}

/* ---------- Layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px); }

.page-hero {
  padding: clamp(40px, 7vw, 80px) 0 clamp(24px, 4vw, 40px);
}
.kicker {
  display: inline-block; font-size: .78rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink);
  background: var(--accent-soft); padding: 5px 12px; border-radius: 999px;
}
.page-hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 5vw, 3.3rem); line-height: 1.08;
  letter-spacing: -.02em; margin: 18px 0 12px;
}
.page-hero p.lead { font-size: 1.12rem; color: var(--ink-soft); max-width: 65ch; margin: 0; }

/* reading-time / meta badges in hero */
.hero-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.badge-rt {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .85rem; font-weight: 600; color: var(--accent-ink);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: 6px 13px; border-radius: 999px;
}
/* reading time on cards */
.card .rt { font-size: .82rem; color: var(--ink-faint); font-weight: 600; margin: 0 0 10px; display: flex; align-items: center; gap: 5px; }

/* ---------- Subject / session cards ---------- */
.card-grid { display: grid; gap: 20px; padding-bottom: 70px; }
.card-grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.card {
  display: block; position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--line-strong); text-decoration: none; }
.card .num {
  font-family: var(--font-mono); font-size: .82rem; color: var(--accent-ink);
  font-weight: 700; letter-spacing: .04em;
}
.card h3 { font-family: var(--font-serif); font-size: 1.35rem; margin: 8px 0 8px; color: var(--ink); letter-spacing: -.01em; }
.card p { margin: 0 0 14px; color: var(--ink-soft); font-size: .96rem; }
.card .tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tag {
  font-size: .76rem; color: var(--ink-soft); background: var(--surface-2);
  border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px;
}
.card .go { margin-top: 16px; font-weight: 600; color: var(--accent-ink); font-size: .92rem; }
.card.locked { opacity: .55; pointer-events: none; }
.card.locked .go { color: var(--ink-faint); }
.card .accent-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--accent); }

/* ---------- Article layout (session pages) ---------- */
.article-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 48px; padding-bottom: 100px; }
@media (max-width: 920px) { .article-layout { grid-template-columns: 1fr; gap: 0; } }

/* table of contents */
.toc { position: sticky; top: 84px; align-self: start; max-height: calc(100vh - 110px); overflow-y: auto; padding-right: 6px; }
.toc h4 { font-size: .76rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-faint); margin: 0 0 12px; }
.toc ol { list-style: none; margin: 0; padding: 0; counter-reset: toc; }
.toc li { counter-increment: toc; margin: 2px 0; }
.toc a {
  display: flex; gap: 10px; padding: 7px 10px; border-radius: 8px;
  color: var(--ink-soft); font-size: .9rem; line-height: 1.35; border-left: 2px solid transparent;
}
.toc a::before { content: counter(toc); font-family: var(--font-mono); font-size: .76rem; color: var(--ink-faint); min-width: 16px; }
.toc a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.toc a.active { color: var(--accent-ink); background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
@media (max-width: 920px) {
  .toc { position: static; max-height: none; margin-bottom: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
}

/* article body */
.article { min-width: 0; }
.article > section { scroll-margin-top: 90px; margin-bottom: 64px; }
.article h2 {
  font-family: var(--font-serif); font-size: clamp(1.6rem, 3.4vw, 2.1rem);
  letter-spacing: -.015em; margin: 0 0 6px; padding-top: 8px;
  display: flex; align-items: baseline; gap: 12px;
}
.article h2 .sec-num {
  font-family: var(--font-mono); font-size: 1rem; color: var(--accent);
  background: var(--accent-soft); border-radius: 8px; padding: 2px 9px; font-weight: 700;
}
.article h3 { font-size: 1.22rem; margin: 32px 0 8px; letter-spacing: -.01em; }
.article h4 { font-size: 1.04rem; margin: 22px 0 6px; color: var(--ink); }
.article p { margin: 12px 0; color: var(--ink); }
.article ul, .article ol { margin: 12px 0; padding-left: 24px; }
.article li { margin: 7px 0; }
.article li::marker { color: var(--accent); }
.article strong { color: var(--ink); font-weight: 700; }
.section-rule { border: 0; border-top: 1px solid var(--line); margin: 0 0 28px; }

/* term highlight */
.term { background: var(--key-bg); color: var(--key-ink); border-bottom: 1.5px solid var(--key-line); padding: 0 3px; border-radius: 3px; font-weight: 600; }

/* ---------- Callout boxes ---------- */
.callout {
  border-radius: var(--radius); padding: 18px 20px 18px 52px;
  margin: 20px 0; position: relative; border: 1px solid; line-height: 1.6;
}
.callout::before {
  position: absolute; left: 16px; top: 16px; font-size: 1.2rem; line-height: 1;
}
.callout p:first-child { margin-top: 0; }
.callout p:last-child { margin-bottom: 0; }
.callout .c-title { display: block; font-weight: 800; letter-spacing: .02em; margin-bottom: 4px; font-size: .9rem; text-transform: uppercase; }

.callout.eli5 { background: var(--eli5-bg); border-color: var(--eli5-line); color: var(--ink); }
.callout.eli5::before { content: "🧸"; }
.callout.eli5 .c-title { color: var(--eli5-ink); }

.callout.example { background: var(--ex-bg); border-color: var(--ex-line); color: var(--ink); }
.callout.example::before { content: "💡"; }
.callout.example .c-title { color: var(--ex-ink); }

.callout.key { background: var(--key-bg); border-color: var(--key-line); color: var(--ink); }
.callout.key::before { content: "🔑"; }
.callout.key .c-title { color: var(--key-ink); }

.callout.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--ink); }
.callout.warn::before { content: "⚠️"; }
.callout.warn .c-title { color: var(--warn-ink); }

.callout.note { background: var(--note-bg); border-color: var(--note-line); color: var(--ink); }
.callout.note::before { content: "📝"; }
.callout.note .c-title { color: var(--note-ink); }

/* analogy / big idea band */
.bigidea {
  background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 40%, var(--surface)));
  border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 22px 24px; margin: 22px 0; box-shadow: var(--shadow);
}
.bigidea .c-title { color: var(--accent-ink); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; font-size: .82rem; }
.bigidea p { margin: 6px 0 0; font-size: 1.05rem; }

/* code / mono */
code.inl { font-family: var(--font-mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; color: var(--accent-ink); }
pre {
  background: #1c1b22; color: #e8e6f0; border-radius: var(--radius-sm);
  padding: 16px 18px; overflow-x: auto; font-family: var(--font-mono);
  font-size: .86rem; line-height: 1.55; margin: 16px 0; border: 1px solid #2a2935;
}
pre .cm { color: #8a86a0; }   /* comment */
pre .kw { color: #ff9eb6; }   /* keyword */
pre .st { color: #9be59b; }   /* string */
pre .nm { color: #ffd479; }   /* number */

/* figures — embedded diagrams from class handouts */
.figure { margin: 22px 0; text-align: center; }
.figure img {
  max-width: 100%; height: auto; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fff; box-shadow: var(--shadow);
}
.figure figcaption {
  margin-top: 8px; font-size: .86rem; color: var(--ink-faint); font-style: italic;
  max-width: 60ch; margin-left: auto; margin-right: auto;
}

/* multi-language tabbed code blocks */
.codetabs { margin: 18px 0; border: 1px solid #2a2935; border-radius: var(--radius-sm); overflow: hidden; background: #1c1b22; }
.codetab-bar { display: flex; flex-wrap: wrap; gap: 2px; background: #14131a; border-bottom: 1px solid #2a2935; padding: 6px 6px 0; }
.codetab {
  background: transparent; border: 0; color: #9a96a8; cursor: pointer;
  font-family: var(--font-mono); font-size: .8rem; font-weight: 600;
  padding: 7px 15px; border-radius: 8px 8px 0 0; transition: background .15s, color .15s;
}
.codetab:hover { color: #e8e6f0; }
.codetab.active { background: #1c1b22; color: #fff; box-shadow: inset 0 -2px 0 var(--accent); }
.codetabs pre.codepane { display: none; margin: 0; border: 0; border-radius: 0; }
.codetabs pre.codepane.active { display: block; }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 18px 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: .94rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; color: var(--ink); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td:first-child { font-weight: 600; }

/* step flow diagram */
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0; margin: 22px 0; }
.flow .step {
  flex: 1 1 130px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px; text-align: center; box-shadow: var(--shadow);
  position: relative; min-width: 120px;
}
.flow .step .s-ico { font-size: 1.5rem; }
.flow .step .s-t { font-weight: 700; font-size: .9rem; margin-top: 4px; }
.flow .step .s-d { font-size: .8rem; color: var(--ink-soft); margin-top: 2px; }
.flow .arrow { display: grid; place-items: center; color: var(--accent); font-size: 1.4rem; padding: 0 4px; }
@media (max-width: 640px) { .flow { flex-direction: column; } .flow .arrow { transform: rotate(90deg); } }

/* recap / quiz at end of each section */
.recap { background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 18px 22px; margin-top: 24px; }
.recap .c-title { color: var(--accent-ink); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; font-size: .8rem; display: block; margin-bottom: 8px; }

details.quiz { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 16px; margin: 10px 0; box-shadow: var(--shadow); }
details.quiz summary { cursor: pointer; font-weight: 600; color: var(--ink); }
details.quiz summary::marker { color: var(--accent); }
details.quiz[open] summary { margin-bottom: 8px; }
details.quiz .ans { color: var(--ink-soft); }

/* prev / next nav */
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 40px; border-top: 1px solid var(--line); padding-top: 24px; }
.pager a { flex: 1; padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.pager a:hover { text-decoration: none; border-color: var(--accent); }
.pager .dir { font-size: .78rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .08em; }
.pager .ttl { font-weight: 700; color: var(--ink); margin-top: 2px; }
.pager a.next { text-align: right; }
.pager a.disabled { opacity: .4; pointer-events: none; }

/* footer */
.foot { border-top: 1px solid var(--line); padding: 28px 0 60px; color: var(--ink-faint); font-size: .88rem; text-align: center; }

/* small helpers */
.muted { color: var(--ink-soft); }
.center { text-align: center; }

/* ---------- 1-page cheat sheet (dense multi-column) ---------- */
.sheet-grid { columns: 310px; column-gap: 18px; margin: 12px 0 70px; }
.sheet-card {
  break-inside: avoid; -webkit-column-break-inside: avoid;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px 16px; margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.sheet-card h3 {
  margin: 0 0 8px; font-size: 1.02rem; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--line); padding-bottom: 7px;
}
.sheet-card h3 .n { font-family: var(--font-mono); font-size: .72rem; color: var(--accent-ink); background: var(--accent-soft); border-radius: 6px; padding: 2px 7px; }
.sheet-card ul { margin: 0; padding-left: 18px; }
.sheet-card li { margin: 5px 0; font-size: .9rem; line-height: 1.45; }
.sheet-card li::marker { color: var(--accent); }
.sheet-card p { margin: 6px 0; font-size: .9rem; }
.sheet-card .k { font-weight: 700; color: var(--ink); }
.sheet-card code { font-family: var(--font-mono); font-size: .82em; background: var(--surface-2); border: 1px solid var(--line); padding: 0 4px; border-radius: 5px; }
@media print {
  .topbar, .tts-player, .tts-launch { display: none; }
  .sheet-grid { columns: 3; }
  .sheet-card { box-shadow: none; }
}

/* ---------- Listen / read-aloud player ---------- */
.tts-player {
  position: fixed; right: 18px; bottom: 18px; z-index: 80;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 7px 9px; box-shadow: var(--shadow-lg);
  font-family: var(--font-sans);
}
.tts-player.collapsed { display: none; }
.tts-btn {
  border: 0; cursor: pointer; border-radius: 999px;
  width: 40px; height: 40px; display: grid; place-items: center;
  font-size: 1rem; background: var(--surface-2); color: var(--ink); transition: transform .15s, background .2s;
}
.tts-btn:hover { transform: translateY(-1px); }
.tts-btn.primary { background: var(--accent); color: #fff; width: 46px; height: 46px; font-size: 1.15rem; }
.tts-btn.primary:hover { filter: brightness(1.05); }
.tts-speed {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
  border-radius: 999px; font-size: .8rem; font-weight: 600; padding: 6px 8px; cursor: pointer;
}
.tts-voice {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
  border-radius: 999px; font-size: .8rem; font-weight: 600; padding: 6px 8px; cursor: pointer;
  max-width: 150px; text-overflow: ellipsis;
}
.tts-status { font-size: .78rem; color: var(--ink-faint); min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; }
.tts-launch {
  position: fixed; right: 18px; bottom: 18px; z-index: 80;
  width: 52px; height: 52px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 1.4rem; box-shadow: var(--shadow-lg);
  display: grid; place-items: center; transition: transform .15s;
}
@media (max-width: 640px) { .tts-launch { right: 10px; bottom: 10px; } }
.tts-launch:hover { transform: translateY(-2px) scale(1.04); }

/* the block currently being read aloud */
.tts-reading {
  scroll-margin-top: 100px;
  background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
  border-radius: 6px; transition: background .4s ease;
}
/* the word currently being spoken — a smooth color change, no highlight box */
.tts-w { transition: color .2s ease; }
.tts-w-active { color: #e11d6b; font-weight: 500; }
[data-theme="dark"] .tts-w-active { color: #ff8ab6; }
@media (max-width: 640px) { .tts-player { right: 10px; bottom: 10px; } }
@media print { .tts-player, .tts-launch { display: none; } }
