/* PPFA v3.0 — academic, high-contrast, mobile-first stylesheet (spec §21).
   No colour-only status; visible focus; semantic landmarks; readable type. */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --ink: #1c1b19;
  --ink-soft: #4a4741;
  --line: #d9d6cd;
  --brand: #2b5d5a;      /* deep teal — calm, clinical-adjacent, not alarming */
  --brand-soft: #e3efee;
  --accent: #8a5a2b;     /* warm ochre for secondary emphasis */
  --ok: #2f6b3a;
  --warn: #8a5a00;
  --stop: #9a2b2b;
  --focus: #1a73c9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --maxw: 900px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --serif: Georgia, "Times New Roman", "Noto Serif", serif;
}
:root[data-theme="dark"] {
  --bg: #16181a;
  --surface: #1e2124;
  --surface-2: #23272b;
  --ink: #eceae4;
  --ink-soft: #b6b2a8;
  --line: #34383c;
  --brand: #6fb4ae;
  --brand-soft: #21322f;
  --accent: #cf9a5e;
  --ok: #79c187;
  --warn: #e0b667;
  --stop: #e08a8a;
  --focus: #7fb2ff;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; background: var(--brand); color: #fff;
  padding: .6rem 1rem; z-index: 100; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .7rem 1rem; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand-mark { font-size: 1.6rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 1.02rem; }
.brand-sub { font-size: .72rem; color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; }
.header-controls { display: flex; align-items: center; gap: .5rem; }
.learner-chip {
  font-size: .74rem; color: var(--ink-soft); background: var(--surface-2);
  padding: .25rem .6rem; border-radius: 999px; border: 1px solid var(--line);
  max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.btn {
  font: inherit; font-size: .85rem; cursor: pointer; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: .45rem .8rem; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { filter: brightness(1.06); background: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 58px); }
.sidenav {
  width: 240px; flex: 0 0 240px; background: var(--surface); border-right: 1px solid var(--line);
  padding: .8rem .5rem; overflow-y: auto; position: sticky; top: 58px; height: calc(100vh - 58px);
}
.nav-group { margin-bottom: .8rem; }
.nav-group h3 {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft);
  margin: .5rem .6rem .3rem;
}
.nav-link {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: .9rem; margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-link .ni { width: 1.3rem; text-align: center; }

.main { flex: 1 1 auto; min-width: 0; }
.view { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1.2rem 4rem; }
.loading { color: var(--ink-soft); }

/* Typography blocks */
h1 { font-size: 1.6rem; margin: .2rem 0 .4rem; }
h2 { font-size: 1.25rem; margin: 1.6rem 0 .5rem; }
h3 { font-size: 1.02rem; }
.page-kicker { color: var(--accent); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.lead { color: var(--ink-soft); font-size: 1.02rem; }
.prose p { margin: .5rem 0 .9rem; }
.prose { font-family: var(--serif); font-size: 1.03rem; }

/* Cards & grids */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow); margin: .7rem 0;
}
.grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tile {
  display: block; text-decoration: none; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--brand); }
.tile .tile-title { font-weight: 650; margin-bottom: .2rem; }
.tile .tile-sub { font-size: .82rem; color: var(--ink-soft); }

/* Badges (never colour-only: each carries text) */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .5rem;
  border-radius: 999px; border: 1px solid var(--line); }
.badge-ok { color: var(--ok); border-color: var(--ok); }
.badge-progress { color: var(--warn); border-color: var(--warn); }
.badge-locked { color: var(--stop); border-color: var(--stop); }
.badge-none { color: var(--ink-soft); }

/* Progress bar */
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: var(--brand); }

/* Breadcrumb */
.crumb { font-size: .82rem; color: var(--ink-soft); margin-bottom: .5rem; }
.crumb a { text-decoration: none; }

/* Assessment / options */
.option { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; margin: .35rem 0; cursor: pointer; background: var(--surface); }
.option:hover { background: var(--surface-2); }
.option input { margin-top: .25rem; }
.option.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.option.incorrect { border-color: var(--stop); background: color-mix(in srgb, var(--stop) 10%, var(--surface)); }

/* Callouts */
.callout { border-left: 4px solid var(--brand); background: var(--brand-soft); padding: .7rem .9rem; border-radius: 0 8px 8px 0; margin: .8rem 0; }
.callout.stop { border-color: var(--stop); background: color-mix(in srgb, var(--stop) 12%, var(--surface)); }
.callout.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--surface)); }
.callout h4 { margin: 0 0 .3rem; }

/* Definition/detail rows */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; }
.dl dt { color: var(--ink-soft); font-size: .85rem; }
.section-block { border-top: 1px solid var(--line); padding-top: .8rem; margin-top: .8rem; }
.section-block h3 { color: var(--brand); text-transform: none; }

textarea, input[type=text] {
  width: 100%; font: inherit; padding: .6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); resize: vertical;
}
.hint { font-size: .8rem; color: var(--ink-soft); }
.muted { color: var(--ink-soft); }
.pill-row { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0; }
.pill { font-size: .78rem; padding: .2rem .55rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }

.footer, .app-footer { border-top: 1px solid var(--line); background: var(--surface); }
.app-footer p { max-width: var(--maxw); margin: 0 auto; padding: .9rem 1.2rem; font-size: .78rem; color: var(--ink-soft); }
.app-footer .build { float: right; }

/* Mobile */
.nav-toggle { display: none; }
@media (max-width: 820px) {
  .layout { display: block; }
  .sidenav {
    position: static; width: auto; height: auto; flex: none; border-right: 0;
    border-bottom: 1px solid var(--line); display: none;
  }
  .sidenav.open { display: block; }
  .nav-toggle { display: inline-flex; }
  .app-header { flex-wrap: wrap; gap: .4rem; }
  .header-controls { flex-wrap: wrap; justify-content: flex-end; }
  .learner-chip { display: none; }
  .header-controls .btn { padding: .4rem .55rem; font-size: .8rem; }
  .app-footer .build { float: none; display: block; margin-top: .3rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ============================ PPFA v3.1 additions ============================ */
.stat-num { font-size: 1.7rem; font-weight: 700; }
.card.stat { text-align: left; }
.card.mini { padding: .7rem .8rem; }
.subhead { color: var(--accent); margin: .8rem 0 .3rem; font-size: .98rem; }

/* figures & tables in chapter reader */
.figure { border: 1px dashed var(--line); border-radius: var(--radius); padding: .8rem; background: var(--surface-2); margin: .8rem 0; }
.figure figcaption { margin-bottom: .3rem; }
.table-wrap { overflow-x: auto; margin: .8rem 0; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.table-wrap th, .table-wrap td { border: 1px solid var(--line); padding: .45rem .6rem; text-align: left; vertical-align: top; }
.table-wrap thead th { background: var(--surface-2); }

/* encounter (RAPID/SAFER/case) */
.encounter-step { border-left: 4px solid var(--brand); }
.encounter-prompt { font-size: 1.05rem; margin: .3rem 0 .6rem; }
.encounter-step .opts { display: flex; flex-direction: column; gap: .4rem; }
.option.chosen { border-color: var(--brand); background: var(--brand-soft); }
.response { font-style: italic; color: var(--ink-soft); border-left: 3px solid var(--line); padding: .3rem .7rem; margin: .6rem 0; }
.step-actions { margin-top: .7rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.evidence-grid { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.encounter-debrief textarea, .activity-item textarea { margin-bottom: .5rem; }
.stepper-track, .phase-track { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; padding: 0; list-style: none; }
.track-step { font-size: .78rem; padding: .2rem .55rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }

/* ranking widget */
.rank-list { list-style: none; padding: 0; margin: .5rem 0; }
.rank-item { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; margin: .3rem 0; background: var(--surface); }
.rank-num { font-weight: 700; color: var(--brand); width: 1.4rem; text-align: center; }
.rank-label { flex: 1; }
.rank-btns { display: flex; gap: .25rem; }

/* match widget */
.match-grid { display: flex; flex-direction: column; gap: .4rem; margin: .5rem 0; }
.match-row { display: flex; align-items: center; gap: .6rem; }
.match-left { flex: 0 0 45%; }
.match-row select { flex: 1; padding: .4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }

/* simulation facilitation */
.phase-track { flex-direction: column; }
.phase-track li, .observer li { list-style: none; }
.observer { padding: 0; }
.role-pick.chosen { background: var(--brand); color: #fff; border-color: var(--brand); }
.rec-field { margin: .6rem 0; }

/* Learning Guide panel */
.guide-panel { position: fixed; right: 1rem; bottom: 1rem; width: min(360px, 92vw); max-height: 70vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem; z-index: 50; }
.guide-head { display: flex; align-items: center; gap: .5rem; }
.guide-head strong { flex: 1; }
.guide-log { flex: 1; overflow-y: auto; margin: .5rem 0; display: flex; flex-direction: column; gap: .5rem; }
.guide-q { align-self: flex-end; background: var(--brand-soft); color: var(--brand); padding: .35rem .6rem; border-radius: 10px 10px 2px 10px; font-size: .88rem; }
.guide-a { background: var(--surface-2); padding: .4rem .6rem; border-radius: 10px 10px 10px 2px; font-size: .88rem; }
.guide-a.stop { background: color-mix(in srgb, var(--stop) 12%, var(--surface)); border: 1px solid var(--stop); }
.guide-panel form { display: flex; gap: .4rem; }
.guide-panel input { flex: 1; }

@media print {
  .app-header, .sidenav, .guide-panel, .step-actions, #guide-btn, .skip-link { display: none !important; }
  .layout { display: block; }
  .view { max-width: none; }
}
