/* ============================================================
   Arthrocentesis Trainer — design system
   Trust-first clinical aesthetic. WCAG 2.1 AA, mobile-first.
   ============================================================ */

:root {
  /* Palette — calm clinical teal/slate */
  --c-bg:        #f6f8fa;
  --c-surface:   #ffffff;
  --c-surface-2: #eef2f6;
  --c-border:    #d6dee6;
  --c-text:      #1b2733;
  --c-text-soft: #4b5b6b;
  --c-text-mute: #6b7a8a;
  --c-primary:   #0f6b7a;   /* teal — AA on white */
  --c-primary-d: #0a4d59;
  --c-primary-l: #e1f0f2;
  --c-accent:    #b4531f;   /* warm — for "emphasis: technique" */
  --c-danger:    #b3261e;
  --c-danger-bg: #fbe9e7;
  --c-warn:      #8a5a00;
  --c-warn-bg:   #fdf3e0;
  --c-ok:        #1f6b3a;
  --c-ok-bg:     #e6f3ea;
  --c-info-bg:   #e7eff6;
  --c-info:      #1d5b9e;

  --radius:   10px;
  --radius-s: 6px;
  --shadow:   0 1px 2px rgba(27,39,51,.06), 0 4px 16px rgba(27,39,51,.06);
  --shadow-l: 0 8px 30px rgba(27,39,51,.12);
  --maxw: 820px;
  --sidebar-w: 290px;
  --header-h: 60px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark palette — shared by an explicit data-theme="dark" and (when the user
   hasn't forced light) the OS preference. */
:root[data-theme="dark"] {
  --c-bg:        #0f1419;
  --c-surface:   #161d24;
  --c-surface-2: #1d262f;
  --c-border:    #2a3540;
  --c-text:      #e6edf3;
  --c-text-soft: #b6c2cf;
  --c-text-mute: #8a98a6;
  --c-primary:   #3fb9cc;
  --c-primary-d: #6fd0df;
  --c-primary-l: #11313a;
  --c-accent:    #e08a4f;
  --c-danger:    #f0857d;
  --c-danger-bg: #2e1614;
  --c-warn:      #e0b35a;
  --c-warn-bg:   #2c2310;
  --c-ok:        #6cc488;
  --c-ok-bg:     #11261a;
  --c-info:      #6fb0ec;
  --c-info-bg:   #122230;
  --shadow:   0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --shadow-l: 0 8px 30px rgba(0,0,0,.5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-bg:        #0f1419;
    --c-surface:   #161d24;
    --c-surface-2: #1d262f;
    --c-border:    #2a3540;
    --c-text:      #e6edf3;
    --c-text-soft: #b6c2cf;
    --c-text-mute: #8a98a6;
    --c-primary:   #3fb9cc;
    --c-primary-d: #6fd0df;
    --c-primary-l: #11313a;
    --c-accent:    #e08a4f;
    --c-danger:    #f0857d;
    --c-danger-bg: #2e1614;
    --c-warn:      #e0b35a;
    --c-warn-bg:   #2c2310;
    --c-ok:        #6cc488;
    --c-ok-bg:     #11261a;
    --c-info:      #6fb0ec;
    --c-info-bg:   #122230;
    --shadow:   0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --shadow-l: 0 8px 30px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}
@media (max-width: 600px) { body { font-size: 16px; } }

a { color: var(--c-primary); text-underline-offset: 2px; }
a:hover { color: var(--c-primary-d); }

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

:focus-visible { outline: 3px solid var(--c-primary); outline-offset: 2px; border-radius: 3px; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: var(--c-text); font-weight: 700; }
.brand__mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  background: var(--c-primary-l); color: var(--c-primary); border-radius: 9px;
}
.brand__text { font-size: 1.05rem; letter-spacing: -.01em; }
.app-header__right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--c-border); background: var(--c-surface); color: var(--c-text-soft);
  border-radius: var(--radius-s); cursor: pointer;
}
.icon-btn:hover { background: var(--c-surface-2); color: var(--c-text); }
.icon-btn .icon-sun { display: none; }
.icon-btn[data-mode="dark"] .icon-sun { display: block; }
.icon-btn[data-mode="dark"] .icon-moon { display: none; }
.progress-ring {
  display: grid; place-items: center; min-width: 48px; height: 30px; padding: 0 .55rem;
  background: var(--c-surface-2); border-radius: 999px;
  font-size: .78rem; font-weight: 700; color: var(--c-primary); font-variant-numeric: tabular-nums;
}

.nav-toggle {
  display: none; width: 40px; height: 40px; border: 1px solid var(--c-border);
  background: var(--c-surface); border-radius: var(--radius-s); cursor: pointer; position: relative;
}
.nav-toggle__bar, .nav-toggle__bar::before, .nav-toggle__bar::after {
  content: ""; position: absolute; left: 9px; width: 20px; height: 2px; background: var(--c-text); transition: .2s;
}
.nav-toggle__bar { top: 19px; }
.nav-toggle__bar::before { top: -6px; } .nav-toggle__bar::after { top: 6px; }

/* ---------- Layout ---------- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: var(--header-h);
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: 1rem .75rem;
  display: flex; flex-direction: column;
}
.module-nav { list-style: none; margin: 0; padding: 0; counter-reset: mod; flex: 1; }
.module-nav a {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .65rem; margin-bottom: 2px;
  border-radius: var(--radius-s); text-decoration: none; color: var(--c-text-soft);
  font-size: .92rem; line-height: 1.25;
}
.module-nav a:hover { background: var(--c-surface-2); color: var(--c-text); }
.module-nav a.active { background: var(--c-primary-l); color: var(--c-primary-d); font-weight: 650; }
.module-nav .num {
  flex: 0 0 26px; height: 26px; display: grid; place-items: center;
  background: var(--c-surface-2); border-radius: 7px; font-size: .8rem; font-weight: 700; color: var(--c-text-mute);
}
.module-nav a.active .num { background: var(--c-primary); color: #fff; }
.module-nav a.done .num { background: var(--c-ok-bg); color: var(--c-ok); }
.module-nav a.done .num::after { content: "✓"; }
.module-nav a.done .num .n { display: none; }
.module-nav .star { color: var(--c-accent); font-size: .7rem; }
.sidebar__footer { padding-top: .75rem; border-top: 1px solid var(--c-border); margin-top: .75rem; }

.btn-text { background: none; border: none; color: var(--c-text-mute); cursor: pointer; font-size: .85rem; padding: .35rem; text-decoration: underline; }
.btn-text:hover { color: var(--c-danger); }

.sidebar-backdrop { position: fixed; inset: var(--header-h) 0 0 0; background: rgba(0,0,0,.4); z-index: 30; }

.content { flex: 1; min-width: 0; padding: 1.75rem 1.5rem 5rem; }
.view { max-width: var(--maxw); margin: 0 auto; }

@media (max-width: 880px) {
  .nav-toggle { display: block; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; z-index: 35;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-l);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 1.25rem 1.1rem 4rem; }
}

/* ---------- Typography & content blocks ---------- */
.view h1 { font-size: 1.85rem; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 .35rem; }
.view h2 { font-size: 1.3rem; margin: 2.2rem 0 .6rem; padding-top: .2rem; letter-spacing: -.01em; scroll-margin-top: 76px; }
.view h3 { font-size: 1.06rem; margin: 1.4rem 0 .4rem; }
.view p { margin: .7rem 0; color: var(--c-text-soft); }
.view ul, .view ol { color: var(--c-text-soft); padding-left: 1.3rem; }
.view li { margin: .3rem 0; }
.view strong { color: var(--c-text); }
.lede { font-size: 1.1rem; color: var(--c-text-soft); margin: .5rem 0 1.5rem; }

.eyebrow { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--c-primary); margin-bottom: .5rem; }
.eyebrow--accent { color: var(--c-accent); }

/* Callouts */
.callout { border: 1px solid var(--c-border); border-left-width: 4px; border-radius: var(--radius-s); padding: .85rem 1rem; margin: 1.1rem 0; background: var(--c-surface); }
.callout p:first-child { margin-top: 0; } .callout p:last-child { margin-bottom: 0; }
.callout__title { font-weight: 700; color: var(--c-text); display: block; margin-bottom: .25rem; }
.callout--key   { border-left-color: var(--c-primary); background: var(--c-primary-l); }
.callout--warn  { border-left-color: var(--c-warn); background: var(--c-warn-bg); }
.callout--danger{ border-left-color: var(--c-danger); background: var(--c-danger-bg); }
.callout--ok    { border-left-color: var(--c-ok); background: var(--c-ok-bg); }
.callout--info  { border-left-color: var(--c-info); background: var(--c-info-bg); }
.callout--pearl { border-left-color: var(--c-accent); background: var(--c-surface); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 1.1rem 0; border: 1px solid var(--c-border); border-radius: var(--radius-s); }
table.data { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.data th, table.data td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--c-border); vertical-align: top; }
table.data thead th { background: var(--c-surface-2); color: var(--c-text); font-weight: 700; position: sticky; top: 0; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:nth-child(even) { background: var(--c-bg); }

/* Citation references — discreet */
sup.cite { font-size: .68em; line-height: 0; vertical-align: super; }
sup.cite a { color: var(--c-text-mute); text-decoration: none; padding: 0 1px; font-weight: 600; }
sup.cite a:hover { color: var(--c-primary); text-decoration: underline; }
.references {
  margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--c-border);
  font-size: .82rem; color: var(--c-text-mute);
}
.references h2 { font-size: .82rem !important; text-transform: uppercase; letter-spacing: .05em; color: var(--c-text-mute); margin: 0 0 .5rem !important; }
.references ol { padding-left: 1.4rem; margin: 0; }
.references li { margin: .25rem 0; }
.references a { color: var(--c-text-soft); }
.references .src { color: var(--c-text-mute); font-style: italic; }

/* Buttons & cards */
.btn {
  display: inline-flex; align-items: center; gap: .5rem; justify-content: center;
  padding: .6rem 1.1rem; border-radius: var(--radius-s); border: 1px solid transparent;
  font: inherit; font-weight: 650; font-size: .95rem; cursor: pointer; text-decoration: none;
}
.btn--primary { background: var(--c-primary); color: #fff; }
.btn--primary:hover { background: var(--c-primary-d); color: #fff; }
.btn--ghost { background: var(--c-surface); border-color: var(--c-border); color: var(--c-text); }
.btn--ghost:hover { background: var(--c-surface-2); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.5rem; }
.pager .btn { flex: 1; max-width: 48%; }
.pager .spacer { flex: 1; }

/* Home / cards */
.hero { text-align: center; padding: 1.5rem 0 1rem; }
.hero h1 { font-size: 2.1rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; margin: 1.5rem 0; }
.card {
  display: block; text-decoration: none; color: inherit; background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-l); }
.card__num { font-size: .75rem; font-weight: 700; color: var(--c-text-mute); letter-spacing: .04em; }
.card__title { font-weight: 700; font-size: 1.05rem; margin: .25rem 0; display: flex; align-items: center; gap: .4rem; }
.card__desc { font-size: .88rem; color: var(--c-text-mute); margin: 0; }
.card__bar { height: 4px; background: var(--c-surface-2); border-radius: 2px; margin-top: .8rem; overflow: hidden; }
.card__bar span { display: block; height: 100%; background: var(--c-ok); width: 0; }

/* Video */
.video-embed { margin: 1.2rem 0; }
.video-embed__frame { position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius-s); overflow: hidden; border: 1px solid var(--c-border); }
.video-embed__frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-embed__poster { position: absolute; inset: 0; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .6rem; background: var(--c-primary-d); color: #fff; cursor: pointer; border: 0; font: inherit; }
.video-embed__poster:hover { background: var(--c-primary); }
.video-embed__play { width: 56px; height: 56px; display: grid; place-items: center; background: rgba(255,255,255,.15); border-radius: 999px; }
.video-embed__play svg { width: 26px; height: 26px; margin-left: 3px; }
.video-embed__label { font-weight: 650; font-size: .95rem; padding: 0 1rem; text-align: center; }
.video-embed__attrib { font-size: .78rem; color: var(--c-text-mute); margin-top: .45rem; display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.video-embed__attrib a { color: var(--c-text-soft); }

/* SVG figure */
.figure { margin: 1.3rem 0; text-align: center; }
.figure svg { max-width: 100%; height: auto; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-s); }
.figure figcaption { font-size: .82rem; color: var(--c-text-mute); margin-top: .5rem; }

/* Quiz */
.quiz { margin: 1.5rem 0; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.quiz__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.quiz__head h2 { margin: 0 !important; font-size: 1.2rem !important; }
.quiz__count { font-size: .82rem; color: var(--c-text-mute); }
.q { margin-bottom: 1.4rem; }
.q__stem { font-weight: 650; color: var(--c-text); margin-bottom: .6rem; }
.q__opts { display: flex; flex-direction: column; gap: .5rem; }
.opt {
  display: flex; align-items: flex-start; gap: .6rem; padding: .65rem .8rem;
  border: 1px solid var(--c-border); border-radius: var(--radius-s); cursor: pointer; background: var(--c-surface); text-align: left; font: inherit; color: var(--c-text-soft); width: 100%;
}
.opt:hover:not([disabled]) { border-color: var(--c-primary); background: var(--c-primary-l); }
.opt__key { flex: 0 0 22px; height: 22px; display: grid; place-items: center; border: 1.5px solid var(--c-border); border-radius: 50%; font-size: .78rem; font-weight: 700; }
.opt.correct { border-color: var(--c-ok); background: var(--c-ok-bg); }
.opt.correct .opt__key { background: var(--c-ok); color: #fff; border-color: var(--c-ok); }
.opt.wrong { border-color: var(--c-danger); background: var(--c-danger-bg); }
.opt.wrong .opt__key { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.opt[disabled] { cursor: default; }
.q__feedback { margin-top: .6rem; padding: .65rem .8rem; border-radius: var(--radius-s); font-size: .9rem; background: var(--c-surface-2); border-left: 3px solid var(--c-primary); }
.q__feedback.correct { border-left-color: var(--c-ok); }
.q__feedback.wrong { border-left-color: var(--c-danger); }
.quiz__result { text-align: center; padding: 1rem; border-radius: var(--radius-s); background: var(--c-primary-l); font-weight: 650; }

/* Interactive walkthrough */
.walk { margin: 1.5rem 0; border: 1px solid var(--c-border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.walk__bar { height: 5px; background: var(--c-surface-2); }
.walk__bar span { display: block; height: 100%; background: var(--c-primary); transition: width .3s; }
.walk__body { padding: 1.25rem; }
.walk__step-n { font-size: .78rem; font-weight: 700; color: var(--c-text-mute); letter-spacing: .04em; }
.walk__prompt { font-weight: 650; font-size: 1.08rem; margin: .3rem 0 1rem; }
.walk__opts { display: flex; flex-direction: column; gap: .5rem; }
.walk__teach { margin-top: 1rem; padding: .8rem 1rem; background: var(--c-info-bg); border-left: 3px solid var(--c-info); border-radius: var(--radius-s); font-size: .92rem; }

/* Fluid interpreter */
.interp { margin: 1.5rem 0; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.interp__grid { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) { .interp__grid { grid-template-columns: 1fr; } }
.field label { display: block; font-weight: 650; font-size: .88rem; margin-bottom: .3rem; }
.field input, .field select { width: 100%; padding: .55rem .7rem; border: 1px solid var(--c-border); border-radius: var(--radius-s); font: inherit; background: var(--c-surface); color: var(--c-text); }
.field .unit { font-size: .78rem; color: var(--c-text-mute); }
.interp__out { margin-top: 1.25rem; padding: 1rem; border-radius: var(--radius-s); border: 1px solid var(--c-border); background: var(--c-bg); }
.interp__verdict { font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.tag { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.tag--noninf { background: var(--c-ok-bg); color: var(--c-ok); }
.tag--inf { background: var(--c-warn-bg); color: var(--c-warn); }
.tag--septic { background: var(--c-danger-bg); color: var(--c-danger); }
.tag--haem { background: var(--c-info-bg); color: var(--c-info); }
.tag--normal { background: var(--c-surface-2); color: var(--c-text-mute); }

/* Draft banner */
.draft-banner { background: var(--c-warn-bg); color: var(--c-warn); text-align: center; padding: .5rem 1rem; font-size: .85rem; border-bottom: 1px solid var(--c-warn); }

/* Quicklinks — jump to joint sections */
.quicklinks { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.25rem 0 .5rem; padding: 0; }
.qlink {
  font: inherit; font-size: .88rem; font-weight: 600;
  padding: .4rem .8rem; border-radius: 999px; cursor: pointer;
  background: var(--c-primary-l); color: var(--c-primary-d); border: 1px solid transparent;
}
.qlink:hover { background: var(--c-primary); color: #fff; }

/* Back-to-top floating button */
.to-top {
  position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 45;
  width: 46px; height: 46px; display: grid; place-items: center;
  background: var(--c-primary); color: #fff; border: none; border-radius: 50%;
  box-shadow: var(--shadow-l); cursor: pointer;
}
.to-top:hover { background: var(--c-primary-d); }
.to-top[hidden] { display: none; }
@media (max-width: 600px) { .to-top { right: .9rem; bottom: .9rem; } }

/* Site footer — disclaimer on every page */
.site-footer {
  max-width: var(--maxw); margin: 3rem auto 0; padding: 1.25rem 0 .5rem;
  border-top: 1px solid var(--c-border);
  font-size: .8rem; color: var(--c-text-mute); line-height: 1.5;
}
.site-footer__disclaimer { margin: 0 0 .6rem; }
.site-footer__disclaimer strong { color: var(--c-text-soft); }
.site-footer__links { margin: 0; }
.site-footer__links a { color: var(--c-text-soft); font-weight: 600; }

/* Misc */
.muted { color: var(--c-text-mute); }
.pill-row { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.pill { font-size: .8rem; padding: .25rem .6rem; background: var(--c-surface-2); border-radius: 999px; color: var(--c-text-soft); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 1rem 0; font-size: .92rem; }
.kv dt { font-weight: 700; color: var(--c-text); }
.kv dd { margin: 0; color: var(--c-text-soft); }

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