/* Plumjuice Learn — shared styles.
   Brand tokens come from the Plumjuice entry page (Images/plumjuice-en.html). */

@import url("https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400&family=Source+Sans+3:ital,wght@0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;600&display=swap");

*, *::before, *::after { box-sizing: border-box; }

:root {
  --ink: #0f0f12;
  --ink-mid: #3a3650;
  --ink-light: #6f6a8f;      /* slightly darker than brand #8b87a8 for AA text contrast */
  --paper: #ede9f7;
  --surface: #f7f5fc;
  --surface-2: #e3ddf3;
  --rule: #c2bce0;
  --rule-heavy: #0f0f12;
  --accent: #6b52c8;
  --accent-soft: #ddd4f7;
  --accent-ink: #ffffff;
  --ok: #3f7d1c;
  --ok-soft: #e1efd3;
  --warn: #9a5b00;
  --warn-soft: #fbe9cc;
  --bad: #b3261e;
  --bad-soft: #f7dcda;
  --code-bg: #17151f;
  --code-ink: #e9e6f5;
  --code-dim: #8f8aa8;
  --code-str: #b5d67a;
  --code-kw: #c3a6ff;
  --code-num: #f7b955;
  --code-fn: #8fd3f0;
  --serif: "EB Garamond", Georgia, serif;
  --sans: "Source Sans 3", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ece9f7;
    --ink-mid: #c9c3e3;
    --ink-light: #9c97ba;
    --paper: #14121b;
    --surface: #1c1926;
    --surface-2: #262236;
    --rule: #3a3550;
    --rule-heavy: #ece9f7;
    --accent: #a48cf0;
    --accent-soft: #2f2750;
    --accent-ink: #14121b;
    --ok: #8fcf5f;
    --ok-soft: #1f2f16;
    --warn: #f2b45a;
    --warn-soft: #33260f;
    --bad: #ff8a80;
    --bad-soft: #3a1a19;
    --code-bg: #0e0c14;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #ece9f7;
  --ink-mid: #c9c3e3;
  --ink-light: #9c97ba;
  --paper: #14121b;
  --surface: #1c1926;
  --surface-2: #262236;
  --rule: #3a3550;
  --rule-heavy: #ece9f7;
  --accent: #a48cf0;
  --accent-soft: #2f2750;
  --accent-ink: #14121b;
  --ok: #8fcf5f;
  --ok-soft: #1f2f16;
  --warn: #f2b45a;
  --warn-soft: #33260f;
  --bad: #ff8a80;
  --bad-soft: #3a1a19;
  --code-bg: #0e0c14;
  color-scheme: dark;
}

html { scroll-behavior: smooth; scroll-padding-top: 5rem; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
img, svg { max-width: 100%; }
::selection { background: var(--accent-soft); }

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 500; line-height: 1.2; letter-spacing: 0.01em; }
h1 { font-size: clamp(2.1rem, 5vw, 2.9rem); margin: 0 0 0.4rem; }
h2 { font-size: 1.85rem; margin: 3.2rem 0 0.8rem; padding-top: 0.8rem; border-top: 1.5px solid var(--rule-heavy); }
h3 { font-size: 1.35rem; margin: 2rem 0 0.5rem; }
h4 { font-family: var(--sans); font-size: 0.95rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-light); margin: 1.6rem 0 0.4rem; }
p, ul, ol { margin: 0 0 1rem; }
li { margin-bottom: 0.25rem; }
hr { border: none; border-top: 0.5px solid var(--rule); margin: 2rem 0; }
.eyebrow { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-light); }
.muted { color: var(--ink-light); }
.serif { font-family: var(--serif); }

/* ---------- site header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 0.5px solid var(--rule);
}
.site-header .inner {
  max-width: 1180px; margin: 0 auto; padding: 0.6rem 16px;
  display: flex; align-items: center; gap: 0.9rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--ink); }
.brand .logo-chip { width: 38px; height: 38px; border-radius: 50%; background: #f3effc; display: grid; place-items: center; overflow: hidden; flex: none; }
.brand .logo-chip img { width: 34px; height: 34px; }
.brand .name { font-family: var(--serif); font-size: 1.3rem; font-weight: 500; white-space: nowrap; }
.brand .name em { color: var(--accent); font-style: italic; }
.site-header nav { margin-left: auto; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.site-header nav a { color: var(--ink-mid); text-decoration: none; font-weight: 500; font-size: 0.95rem; padding: 0.3rem 0.6rem; border-radius: 6px; }
.site-header nav a:hover, .site-header nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); }
.whoami { font-size: 0.82rem; color: var(--ink-light); max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-toggle { border: 0.5px solid var(--rule); background: var(--surface); color: var(--ink-mid); border-radius: 6px; width: 34px; height: 34px; cursor: pointer; display: grid; place-items: center; }
.theme-toggle svg { width: 18px; height: 18px; }

/* ---------- generic layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.site-footer { margin-top: 5rem; padding: 2rem 16px 3rem; border-top: 0.5px solid var(--rule); text-align: center; color: var(--ink-light); font-size: 0.85rem; }

.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font: 600 0.95rem var(--sans);
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 0.55rem 1rem; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }

.pill { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.78rem; font-weight: 600; padding: 0.12rem 0.55rem; border-radius: 999px; background: var(--surface-2); color: var(--ink-mid); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.notice { font-size: 0.9rem; padding: 0.6rem 0.9rem; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin: 1rem 0; }
.notice[hidden] { display: none; }

/* ---------- unit page ---------- */
.unit-hero { padding: 3rem 0 1.5rem; }
.unit-hero .lede { font-family: var(--serif); font-size: 1.3rem; color: var(--ink-mid); max-width: 44rem; line-height: 1.5; }
.unit-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; align-items: center; }
.prereq-list a { text-decoration: none; }

.unit-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3rem; }
@media (min-width: 1020px) {
  .unit-layout { grid-template-columns: 230px minmax(0, 1fr); }
}
.toc { display: none; }
@media (min-width: 1020px) {
  .toc { display: block; position: sticky; top: 5rem; align-self: start; max-height: calc(100vh - 6rem); overflow: auto; font-size: 0.9rem; }
}
.toc ol { list-style: none; padding: 0; margin: 0; counter-reset: toc; }
.toc li { margin: 0; }
.toc a { display: block; padding: 0.28rem 0.6rem; border-left: 2px solid var(--rule); color: var(--ink-mid); text-decoration: none; }
.toc a:hover { color: var(--ink); border-left-color: var(--ink-light); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.toc .toc-status { margin-top: 1rem; padding: 0.6rem; border-radius: 8px; background: var(--surface); border: 0.5px solid var(--rule); }

.prose { max-width: 46rem; min-width: 0; }
.prose > section > h2:first-child { margin-top: 2.2rem; }
.prose code:not(pre code) {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px;
  overflow-wrap: anywhere;
}
.prose kbd { font-family: var(--mono); font-size: 0.82em; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; padding: 0.05em 0.35em; background: var(--surface); }

.objectives { background: var(--surface); border: 0.5px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.3rem 0.4rem; }
.objectives ul { padding-left: 1.2rem; }

/* callouts */
.callout { border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; padding: 0.85rem 1.1rem; margin: 1.4rem 0; }
.callout > :last-child { margin-bottom: 0; }
.callout .callout-title { font-weight: 700; font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; display: block; margin-bottom: 0.3rem; color: var(--accent); }
.callout.hpc { border-left-color: #84a418; }
.callout.hpc .callout-title { color: var(--ok); }
.callout.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout.warn .callout-title { color: var(--warn); }
.callout.try { border-left-color: var(--ink-light); }
.callout.try .callout-title { color: var(--ink-mid); }

details.deep { border: 0.5px solid var(--rule); border-radius: var(--radius); background: var(--surface); margin: 1.4rem 0; }
details.deep > summary { cursor: pointer; padding: 0.7rem 1rem; font-weight: 600; color: var(--ink-mid); list-style: none; }
details.deep > summary::-webkit-details-marker { display: none; }
details.deep > summary::before { content: "▸ "; color: var(--accent); }
details.deep[open] > summary::before { content: "▾ "; }
details.deep > .deep-body { padding: 0 1rem 0.6rem; }

/* code */
figure.code { margin: 1.3rem 0; border-radius: var(--radius); overflow: hidden; background: var(--code-bg); border: 0.5px solid #2c2840; }
figure.code figcaption { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.4rem 0.6rem 0.4rem 0.9rem; font: 600 0.78rem var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--code-dim); border-bottom: 0.5px solid #2c2840; }
figure.code pre { margin: 0; padding: 0.9rem 1rem; overflow-x: auto; font: 0.86rem/1.6 var(--mono); color: var(--code-ink); tab-size: 4; }
figure.code pre code { font: inherit; background: none; padding: 0; white-space: pre; }
.copy-btn { font: 600 0.72rem var(--sans); color: var(--code-dim); background: transparent; border: 1px solid #39344f; border-radius: 5px; padding: 0.15rem 0.5rem; cursor: pointer; text-transform: uppercase; letter-spacing: 0.05em; }
.copy-btn:hover { color: var(--code-ink); border-color: var(--code-dim); }
.copy-btn.done { color: var(--code-str); border-color: var(--code-str); }

/* terminal session blocks: lines beginning with "$ " are commands */
figure.term pre .prompt { color: var(--code-kw); user-select: none; }
figure.term pre .out { color: var(--code-dim); }
figure.term pre .cmt { color: #6f6a8f; font-style: italic; }

/* prism tokens */
.token.comment, .token.prolog { color: #7d7899; font-style: italic; }
.token.string, .token.char, .token.attr-value { color: var(--code-str); }
.token.keyword, .token.builtin, .token.important { color: var(--code-kw); }
.token.number, .token.boolean, .token.constant { color: var(--code-num); }
.token.function, .token.class-name { color: var(--code-fn); }
.token.variable, .token.parameter { color: #f0a0c8; }
.token.operator, .token.punctuation { color: #b9b4d1; }

/* figures */
figure.diagram { margin: 1.8rem 0; }
figure.diagram svg { display: block; width: 100%; height: auto; background: var(--surface); border: 0.5px solid var(--rule); border-radius: var(--radius); }
figure.diagram figcaption { font-size: 0.88rem; color: var(--ink-light); margin-top: 0.5rem; }
/* SVG classes so diagrams follow the theme */
.d-box { fill: var(--paper); stroke: var(--ink-mid); stroke-width: 1.4; }
.d-box-accent { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.6; }
.d-box-ok { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 1.4; }
.d-box-warn { fill: var(--warn-soft); stroke: var(--warn); stroke-width: 1.4; }
.d-line { stroke: var(--ink-mid); stroke-width: 1.5; fill: none; }
.d-line-accent { stroke: var(--accent); stroke-width: 2; fill: none; }
.d-dash { stroke: var(--ink-light); stroke-width: 1.2; stroke-dasharray: 5 4; fill: none; }
.d-text { fill: var(--ink); font: 500 15px var(--sans); }
.d-text-s { fill: var(--ink-mid); font: 400 12.5px var(--sans); }
.d-mono { fill: var(--ink); font: 500 13px var(--mono); }
.d-mono-s { fill: var(--ink-mid); font: 400 11.5px var(--mono); }
.d-title { fill: var(--accent); font: 700 11px var(--sans); letter-spacing: 0.1em; text-transform: uppercase; }
.d-arrowhead { fill: var(--ink-mid); }
.d-arrowhead-accent { fill: var(--accent); }

/* tables */
.table-wrap { overflow-x: auto; margin: 1.2rem 0; }
table.t { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
table.t th, table.t td { text-align: left; padding: 0.45rem 0.7rem; border-bottom: 0.5px solid var(--rule); vertical-align: top; }
table.t th { font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-light); border-bottom: 1.5px solid var(--rule-heavy); }
table.t td code { white-space: nowrap; }

/* ---------- quiz ---------- */
.quiz { margin-top: 1rem; }
.q { background: var(--surface); border: 0.5px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1rem; }
.q .q-head { display: flex; gap: 0.6rem; font-weight: 600; margin-bottom: 0.6rem; }
.q .q-num { color: var(--accent); font-family: var(--serif); font-size: 1.2rem; line-height: 1.3; }
.q .q-text code { font-family: var(--mono); font-size: 0.86em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
.q label.opt { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.4rem 0.6rem; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.q label.opt:hover { background: var(--surface-2); }
.q label.opt input { margin-top: 0.35rem; accent-color: var(--accent); }
.q label.opt code { font-family: var(--mono); font-size: 0.86em; }
.q input[type="text"] { font: 0.95rem var(--mono); width: 100%; max-width: 26rem; padding: 0.45rem 0.6rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: var(--ink); }
.q.correct { border-color: var(--ok); }
.q.wrong { border-color: var(--bad); }
.q label.opt.is-answer { border-color: var(--ok); background: var(--ok-soft); }
.q label.opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.q .explain { display: none; margin-top: 0.6rem; font-size: 0.93rem; color: var(--ink-mid); border-top: 0.5px dashed var(--rule); padding-top: 0.5rem; }
.q.graded .explain { display: block; }
.quiz-result { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 0.5rem; }
.score { font-family: var(--serif); font-size: 1.5rem; }

/* ---------- exercise ---------- */
.tasks { counter-reset: task; list-style: none; padding: 0; }
.tasks > li { counter-increment: task; position: relative; padding: 0.8rem 1rem 0.8rem 3.2rem; border: 0.5px solid var(--rule); border-radius: var(--radius); background: var(--surface); margin-bottom: 0.7rem; }
.tasks > li::before { content: counter(task); position: absolute; left: 1rem; top: 0.75rem; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 0.85rem; }
.tasks .key { font-family: var(--mono); font-size: 0.82rem; color: var(--accent); }

.env-tabs { margin: 1.2rem 0; }
.env-tabs [role="tablist"] { display: flex; gap: 0.3rem; flex-wrap: wrap; border-bottom: 0.5px solid var(--rule); }
.env-tabs [role="tab"] { font: 600 0.9rem var(--sans); background: none; border: none; border-bottom: 2px solid transparent; padding: 0.5rem 0.8rem; color: var(--ink-mid); cursor: pointer; }
.env-tabs [role="tab"][aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.env-tabs [role="tabpanel"] { padding-top: 0.6rem; }

.submit-box { border: 1.5px dashed var(--rule); border-radius: var(--radius); padding: 1.2rem; background: var(--surface); }
.submit-box textarea { width: 100%; min-height: 7rem; font: 0.82rem var(--mono); padding: 0.6rem; border-radius: 6px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); resize: vertical; }
.submit-row { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; margin-top: 0.7rem; }
.submit-msg { font-size: 0.92rem; }
.submit-msg.ok { color: var(--ok); }
.submit-msg.bad { color: var(--bad); }
.report-preview { font-size: 0.9rem; margin-top: 0.8rem; }
.report-preview li.pass::marker { content: "✓  "; color: var(--ok); }
.report-preview li.fail::marker { content: "✗  "; color: var(--bad); }

/* ---------- catalogue ---------- */
.home-hero { padding: 3.5rem 0 2rem; display: grid; gap: 2rem; align-items: center; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) { .home-hero { grid-template-columns: minmax(0, 1fr) 220px; } }
.home-hero img { width: 200px; justify-self: center; }
.home-hero .lede { font-family: var(--serif); font-size: 1.3rem; color: var(--ink-mid); max-width: 38rem; line-height: 1.5; }
.progress-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; max-width: 28rem; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.4s; }
.unit-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); margin-top: 1rem; }
.unit-card { display: flex; flex-direction: column; gap: 0.5rem; padding: 1.1rem 1.2rem; border-radius: var(--radius); background: var(--surface); border: 0.5px solid var(--rule); text-decoration: none; color: var(--ink); transition: border-color 0.15s, transform 0.15s; }
.unit-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.unit-card .num { font-family: var(--serif); font-size: 2rem; color: var(--accent); line-height: 1; }
.unit-card h3 { margin: 0; font-size: 1.3rem; }
.unit-card p { margin: 0; font-size: 0.93rem; color: var(--ink-mid); }
.unit-card .row { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin-top: auto; padding-top: 0.4rem; }
.unit-card.locked { opacity: 0.72; }

/* ---------- dashboard ---------- */
table.grid td.cell { text-align: center; }
table.grid td.cell button { border: none; background: none; cursor: pointer; font-size: 1rem; color: inherit; padding: 0.1rem 0.4rem; border-radius: 4px; }
table.grid td.cell button:hover { background: var(--surface-2); }
dialog.report { max-width: min(760px, calc(100vw - 32px)); width: 100%; border: 0.5px solid var(--rule); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 1.2rem; }
dialog.report::backdrop { background: rgb(0 0 0 / 0.45); }
dialog.report pre { font: 0.8rem var(--mono); background: var(--code-bg); color: var(--code-ink); padding: 0.8rem; border-radius: 8px; overflow: auto; max-height: 60vh; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  h2 { font-size: 1.6rem; }
  .brand .name { font-size: 1.1rem; }
  .whoami { display: none; }
  .site-header .inner { gap: 0.5rem; }
  .site-header nav { gap: 0.1rem; flex-wrap: nowrap; }
  .site-header nav a { padding: 0.3rem 0.4rem; }
  .brand .logo-chip { width: 32px; height: 32px; }
  .brand .logo-chip img { width: 28px; height: 28px; }
  /* keep diagram text legible: scroll the figure sideways instead of shrinking it */
  figure.diagram { overflow-x: auto; }
  figure.diagram svg { min-width: 600px; }
  .tasks > li { padding-left: 2.8rem; }
}
