/* App shell for the brachial plexus teaching app. Module styles live in their own files. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --border: #d6dde8;
  --primary: #3156e8;
  --primary-hover: #2443c4;
  --primary-soft: #e8edff;
  --on-primary: #ffffff;
  --focus: #3156e8;
  --st-target: #db2777;
  --st-covers: #16a34a;
  --st-variable: #d97706;
  --st-spares: #94a3b8;
  --warn-bg: #fff7ed;
  --warn-border: #fdba74;
  --adv-bg: #ede9fe; --adv-text: #5b21b6; --adv-soft: #f5f3ff; --adv-border: #c4b5fd;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1017; --surface: #121a24; --surface-2: #17212d; --text: #e6ebf2; --muted: #a3b0c2;
    --border: #2a3646; --primary: #8aa4ff; --primary-hover: #a9bcff; --primary-soft: #1d2a4a; --on-primary: #0b1017;
    --focus: #9db4ff; --st-spares: #7b8798; --warn-bg: #2a1d0e; --warn-border: #9a5b14; --adv-bg: #2e1f5e; --adv-text: #d4c8ff; --adv-soft: #1a1530; --adv-border: #4c3a8a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1017; --surface: #121a24; --surface-2: #17212d; --text: #e6ebf2; --muted: #a3b0c2;
  --border: #2a3646; --primary: #8aa4ff; --primary-hover: #a9bcff; --primary-soft: #1d2a4a; --on-primary: #0b1017;
  --focus: #9db4ff; --st-spares: #7b8798; --warn-bg: #2a1d0e; --warn-border: #9a5b14; --adv-bg: #2e1f5e; --adv-text: #d4c8ff; --adv-soft: #1a1530; --adv-border: #4c3a8a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 130px; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button { font: inherit; color: inherit; }
.sr-only, .sr-status { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--primary); color: var(--on-primary); padding: 8px 14px; border-radius: 6px; text-decoration: none; }
.skip:focus { top: 12px; color: var(--on-primary); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.noscript { padding: 16px; }

/* ------------------------------------------------------------ header */
.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner, .blockbar-inner, main, .foot-inner { max-width: 1600px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.top-inner { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding-top: 16px; padding-bottom: 10px; }
.org { margin: 0 0 2px; font-size: 14px; font-weight: 600; color: var(--muted); }
.org a { color: inherit; text-decoration: none; }
.org a:hover { text-decoration: underline; }
h1 { margin: 0; font-size: clamp(22px, 2.6vw, 30px); line-height: 1.2; letter-spacing: -.01em; }
.top-tools { display: flex; gap: 8px; flex-shrink: 0; }
.tool-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px; }
.tool-btn:hover { border-color: var(--primary); }
.tool-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool-btn svg .fill { fill: currentColor; stroke: none; }

.blockbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.blockbar-inner { display: flex; align-items: center; gap: 12px; padding-top: 8px; padding-bottom: 8px; }
.blockbar-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: thin; padding: 2px; margin: -2px; }
.chip { display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center; min-height: 44px; padding: 4px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; white-space: nowrap; line-height: 1.15; transition: background-color .15s, border-color .15s; }
.chip:hover { border-color: var(--primary); }
.chip-main { font-weight: 600; font-size: 15px; }
.chip-sub { font-size: 12px; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chip[aria-pressed="true"] .chip-sub { color: inherit; opacity: .85; }

/* ------------------------------------------------------------ layout */
main { padding-top: 14px; padding-bottom: 32px; }
.intro { margin: 0 0 14px; color: var(--muted); max-width: 900px; }
.stage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }
@media (min-width: 1100px) {
  /* The diagram gets the wider column so its small print stays legible. */
  .stage { grid-template-columns: minmax(0, 1fr) minmax(0, 1.55fr); align-items: start; }
  .panel-3d { position: sticky; top: 72px; }
  .mount-3d { height: clamp(420px, calc(100vh - 190px), 760px); }
}
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--border); }
.panel.is-collapsed .panel-head { border-bottom: 0; }
.panel-head h2 { margin: 0; font-size: 17px; }
.collapse-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted); }
.collapse-btn:hover { border-color: var(--border); color: var(--text); }
.collapse-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.collapse-btn[aria-expanded="false"] svg { transform: rotate(-90deg); }
.panel-body { padding: 10px; min-width: 0; }
.mount { min-width: 0; }
.mount-3d { height: clamp(380px, 68vh, 760px); display: flex; flex-direction: column; }
.mount-3d > * { flex: 1; min-height: 0; }
.mount-error { padding: 16px; border: 1px dashed var(--border); border-radius: 8px; color: var(--muted); }

/* ------------------------------------------------------------ tabs */
.tabbar { border-bottom: 1px solid var(--border); padding: 0 8px; position: relative; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs [role="tab"] { appearance: none; border: 0; background: transparent; padding: 12px 16px 10px; min-height: 48px; font-weight: 600; font-size: 16px; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs [role="tab"]:hover { color: var(--text); }
.tabs [role="tab"][aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tabpanel { padding: 14px; min-width: 0; }
.tabpanel:focus-visible { outline-offset: -3px; }

/* ------------------------------------------------------------ block guide */
/* Narrow screens: once something is selected, its card sits as a sheet at the
   bottom of the screen, so a tapped chip gives visible feedback right away. */
@media (max-width: 999px) {
  .guide-side.has-selection { position: sticky; bottom: 0; z-index: 3; max-height: 45vh; overflow: auto; margin: 0 -4px; padding: 10px 12px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px 14px 0 0; box-shadow: 0 -6px 18px rgba(15, 23, 42, .14); }
  .guide-side.has-selection .guide-title { font-size: 15px; margin-bottom: 6px; }
}
.guide { max-width: 1400px; }
.guide-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
@media (min-width: 1000px) {
  .guide-grid { grid-template-columns: minmax(0, 1fr) 360px; }
  .guide-side { position: sticky; top: 76px; align-self: start; }
}
.guide h3, .guide h4 { line-height: 1.25; }
.guide-title { margin: 0 0 10px; font-size: 18px; }
.guide-main h4 { margin: 22px 0 8px; font-size: 16px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.guide-main > .guide-title:not(:first-child) { margin-top: 26px; }
.guide p { margin: 0 0 8px; }
.guide ul { margin: 0 0 8px; padding-left: 20px; }
.guide li { margin-bottom: 4px; }
.eyebrow { margin: 0 0 2px !important; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.block-head h3 { margin: 0 0 8px; font-size: 24px; }
.facts-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.fact { display: inline-block; padding: 6px 10px; border-radius: 8px; background: var(--primary-soft); font-size: 15px; }
.fact .muted { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; margin-right: 4px; }
.jump-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-ghost { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 12px; border: 1px solid var(--primary); border-radius: 8px; background: transparent; color: var(--primary); font-weight: 600; font-size: 15px; cursor: pointer; }
.btn-ghost:hover { background: var(--primary-soft); }
.link-btn { appearance: none; border: 0; background: none; padding: 4px 0; color: var(--primary); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; text-align: left; }

.kv { margin: 0; display: grid; gap: 10px; }
.kv > div { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.kv dt { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kv dd { margin: 0; }
.kv-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.kv-grid > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }

.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps > li { counter-increment: step; position: relative; padding: 10px 12px 10px 52px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.steps > li::before { content: counter(step); position: absolute; left: 12px; top: 10px; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.step-title { font-weight: 700; margin: 2px 0 4px !important; }
.steps ul { margin: 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.id-chip { min-height: 32px; padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 600; }
.id-chip:hover { border-color: var(--primary); }
.id-chip.is-selected { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.id-chip.st-target { box-shadow: inset 4px 0 0 var(--st-target); }
.id-chip.st-covers { box-shadow: inset 4px 0 0 var(--st-covers); }
.id-chip.st-variable { box-shadow: inset 4px 0 0 var(--st-variable); }
.id-chip.st-spares { box-shadow: inset 4px 0 0 var(--st-spares); color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--st-spares); flex-shrink: 0; }
.dot.st-target { background: var(--st-target); }
.dot.st-covers { background: var(--st-covers); }
.dot.st-variable { background: var(--st-variable); }
.dot.st-spares { background: var(--st-spares); }
.cover-lists { margin-top: 10px; }
.note { padding: 8px 12px; border-left: 4px solid var(--primary); background: var(--primary-soft); border-radius: 0 8px 8px 0; margin-top: 10px !important; }
.note-warn { border-left-color: var(--warn-border); background: var(--warn-bg); }

.qa { display: grid; gap: 8px; }
.qa details { border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.qa summary { cursor: pointer; padding: 10px 12px; font-weight: 600; list-style-position: outside; margin-left: 18px; }
.qa summary .q-num { display: inline-block; min-width: 30px; color: var(--primary); }
.qa details[open] summary { border-bottom: 1px solid var(--border); }
.qa details p { padding: 10px 14px; margin: 0; }

.el-card .el-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.el-card h3 { margin: 0; font-size: 19px; }
.spinal { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.spinal-chip { padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); font-weight: 700; font-size: 13px; }
.el-status { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); }
.el-status[data-status="target"] .dot { background: var(--st-target); }
.el-status[data-status="covers"] .dot { background: var(--st-covers); }
.el-status[data-status="variable"] .dot { background: var(--st-variable); }
.el-card .kv { margin-bottom: 8px; }

.mnemonic { padding: 10px 14px; background: var(--primary-soft); border-radius: 8px; }
.levels { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.level-card { border-top: 4px solid var(--level-colour); }
.level-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.level-head h4 { margin: 0; font-size: 18px; }
.level-head .count { color: var(--muted); font-weight: 600; }
.level-num { width: 26px; height: 26px; border-radius: 50%; background: var(--level-colour); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.level-card .facts { font-size: 15px; }
.level-card .chip-row { margin: 8px 0; }
.level-blocks { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.summary { border-collapse: collapse; width: 100%; min-width: 760px; font-size: 15px; }
.summary th, .summary td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.summary thead th { background: var(--surface-2); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.summary tbody tr:last-child > * { border-bottom: 0; }

/* ------------------------------------------------------------ footer */
.foot { border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 14px; }
.foot-inner { padding-top: 20px; padding-bottom: 32px; }
.foot p { margin: 0 0 8px; max-width: 1000px; }
.foot .disclaimer { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------ phones */
@media (max-width: 899px) {
  html { scroll-padding-top: 76px; }
  .top-inner { padding-top: 12px; align-items: flex-start; }
  .tool-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tool-btn { width: 44px; height: 44px; justify-content: center; padding: 0; }
  .blockbar-label { display: none; }
  .org { font-size: 13px; }
  .intro { font-size: 15px; }
  .chip { padding: 4px 12px; }
  .panel-head h2 { cursor: pointer; flex: 1; }
  .panel-body { padding: 6px; }
  .mount-3d { height: clamp(360px, 62vh, 560px); }
  .tabpanel { padding: 10px; }
  .tabs [role="tab"] { padding: 12px 12px 10px; flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ------------------------------------------------------------ advanced blocks */
/* Group label between the core four and the advanced chips: part of the same
   scrollable row, with a divider line on its left. */
.chip-group-label { display: inline-flex; align-items: center; flex-shrink: 0; align-self: center; gap: 8px; margin-left: 4px; padding-left: 12px; border-left: 2px solid var(--border); min-height: 36px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); white-space: nowrap; }
.chip--advanced { border-style: dashed; }
.chip--advanced[aria-pressed="true"] { border-style: solid; }
.adv-tag { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--adv-bg); color: var(--adv-text); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; vertical-align: 1px; }
.btn-ghost .adv-tag { margin-left: 4px; }
.variant-note { margin: 8px 0 10px !important; }
.variants-row { align-items: center; margin-top: 8px; }
.variant-note .adv-tag { margin-right: 6px; }
.variant-note .link-btn { font-weight: 700; padding: 0; font-size: inherit; }
.why-box { margin: 0 0 12px; padding: 10px 14px; border: 1px solid var(--adv-border); border-radius: 8px; background: var(--adv-soft); }
.why-box .why-title { font-weight: 700; margin-bottom: 4px; }
.why-box p:last-child { margin-bottom: 0; }
.sources { font-size: 15px; padding-left: 20px; }
.sources li { margin-bottom: 6px; overflow-wrap: anywhere; }
.sources a { color: var(--primary); }
.summary .group-row th { background: var(--adv-soft); font-size: 14px; font-weight: 700; color: var(--text); text-transform: none; letter-spacing: 0; }
.summary .group-row .muted { font-weight: 400; }
.summary .row-variant { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 2px; }
/* Desktop: with the advanced group the row is a little wider than the site
   column, so tighten the chips and let them wrap rather than hide behind a
   scroll. Phones keep the single scrollable row (rules above). */
@media (min-width: 900px) {
  #block-chips { flex-wrap: wrap; gap: 6px; overflow-x: visible; }
  #block-chips .chip { padding-left: 11px; padding-right: 11px; }
}
