:root {
  --bg: #0a1020; --bg2: #111a2e; --card: #16213a; --card2: #1c2a48; --line: #26365a;
  --tx: #e6edf7; --tx2: #9fb0cc; --acc: #38bdf8; --sys: #38bdf8;
  --top: 56px; --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --peek: 34dvh; --side: 400px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--tx);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Samsung Sans", sans-serif; font-size: 15px; line-height: 1.45;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { position: fixed; inset: 0; }

/* top bar */
#topbar { position: absolute; left: 0; right: 0; top: 0; height: calc(var(--top) + var(--sat)); padding: var(--sat) 10px 0;
  display: flex; align-items: center; gap: 10px; z-index: 20;
  background: linear-gradient(to bottom, rgba(10,16,32,.96), rgba(10,16,32,.75)); border-bottom: 1px solid rgba(255,255,255,.06); }
.titles { flex: 1; min-width: 0; }
#titleMain { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#titleSub { font-size: 12.5px; color: var(--tx2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 22px; line-height: 1; display: grid; place-items: center; flex: none; }
.icon-btn:active { transform: scale(.94); }
body.home #backBtn { visibility: hidden; width: 0; padding: 0; border: 0; margin-right: -10px; }

/* stage */
#stage { position: absolute; left: 0; right: 0; top: calc(var(--top) + var(--sat)); bottom: var(--peek);
  background: radial-gradient(ellipse at 50% 40%, #16264a 0%, #0a1020 70%); overflow: hidden; }
#c { width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; pointer-events: auto; display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; padding: 0; border: 0; background: none; will-change: transform; }
.lbl .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px rgba(0,0,0,.35), 0 0 10px var(--c); flex: none; }
.lbl .txt { background: rgba(10,16,32,.82); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); padding: 3px 8px; border-radius: 999px; }
.lbl.l { flex-direction: row-reverse; }
.lbl.sel .txt { background: var(--c); color: #0a1020; }
.lbl.home-pin .txt { font-size: 12.5px; padding: 5px 10px; }
body.nolabels .lbl:not(.home-pin) { display: none; }
#status { position: absolute; left: 10px; right: 110px; bottom: 10px; font-size: 11.5px; color: var(--tx2); pointer-events: none; text-shadow: 0 1px 2px #000; }
#stageTools { position: absolute; right: 10px; bottom: 8px; display: flex; gap: 8px; }
.pill-btn { min-width: 44px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: rgba(22,33,58,.9); font-size: 14px; font-weight: 700; padding: 0 10px; }
.pill-btn.on { border-color: var(--sys); color: var(--sys); }
body.home #stageTools, body.home #status { display: none; }
#filters { position: absolute; left: 10px; right: 10px; top: 10px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
#filters::-webkit-scrollbar { display: none; }
#filters button { flex: none; height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(22,33,58,.9); font-size: 12.5px; font-weight: 600; }
#filters button.on { background: var(--sys); color: #0a1020; border-color: var(--sys); }

/* panel / bottom sheet */
#panel { position: absolute; left: 0; right: 0; bottom: 0; height: var(--peek); z-index: 15; display: flex; flex-direction: column;
  background: var(--bg2); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.4);
  transition: height .3s ease; padding-bottom: var(--sab); }
#panel.full { height: calc(100% - var(--top) - var(--sat) - 24px); }
#grabber { height: 26px; flex: none; display: grid; place-items: center; touch-action: none; cursor: grab; }
#grabber span { width: 44px; height: 5px; border-radius: 3px; background: #3a4b70; }
#panelBody { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px 20px; overscroll-behavior: contain; }
body.system { --peek: 46dvh; }

/* side layout for tablets / landscape */
@media (min-width: 900px), (orientation: landscape) and (min-width: 640px) {
  :root { --side: clamp(340px, 36vw, 480px); }
  #stage { bottom: 0 !important; right: var(--side); }
  #panel, #panel.full { top: calc(var(--top) + var(--sat)); left: auto; width: var(--side); height: auto; border-radius: 0; border-top: 0; border-left: 1px solid var(--line); }
  #grabber { display: none; }
  #panelBody { padding-top: 14px; }
}
@media (orientation: landscape) and (max-height: 500px) { :root { --top: 48px; } #titleSub { display: none; } }
@media (min-width: 700px) { html, body { font-size: 16px; } .lbl { font-size: 12.5px; } }

/* home content */
.intro { color: var(--tx2); font-size: 13.5px; margin: 2px 0 12px; }
.sys-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) and (orientation: portrait) { .sys-grid { grid-template-columns: repeat(4, 1fr); } }
.sys-card { text-align: left; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.sys-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.sys-card .ic { font-size: 22px; }
.sys-card b { font-size: 14.5px; }
.sys-card small { color: var(--tx2); font-size: 12px; line-height: 1.3; }
.sys-card:active { transform: scale(.97); }
.disclaimer { margin-top: 16px; font-size: 12px; color: var(--tx2); border-top: 1px solid var(--line); padding-top: 10px; }

/* system panel */
.sys-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sys-head .ic { font-size: 26px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: color-mix(in srgb, var(--sys) 18%, transparent); }
.sys-head h2 { margin: 0; font-size: 19px; }
.sys-head p { margin: 0; font-size: 12.5px; color: var(--tx2); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; position: sticky; top: 0; background: var(--bg2); z-index: 2; scrollbar-width: none; margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; height: 34px; padding: 0 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; font-weight: 600; color: var(--tx2); }
.tab.on { background: var(--sys); border-color: var(--sys); color: #0a1020; }
.sec h3 { font-size: 15px; margin: 14px 0 6px; color: var(--sys); }
.sec p { margin: 6px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 8px 0; }
ul.list { margin: 4px 0; padding-left: 18px; } ul.list li { margin: 4px 0; }
.facts li::marker { content: "✦  "; color: var(--sys); }
.flags li::marker { content: "⚠  "; color: #f87171; }
.care li::marker { content: "✔  "; color: #4ade80; }
table.vals { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.vals td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.vals td:first-child { color: var(--tx2); width: 34%; }
table.vals td:nth-child(2) { font-weight: 700; }
table.vals td:nth-child(3) { color: var(--tx2); font-size: 12.5px; }
.part-card { cursor: pointer; }
.part-card .pt { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; }
.part-card .pt::after { content: "›"; color: var(--tx2); font-size: 20px; }
.part-card .pd { display: none; margin-top: 6px; font-size: 14px; }
.part-card.sel { border-color: var(--sys); box-shadow: 0 0 0 1px var(--sys) inset; }
.part-card.sel .pd { display: block; }
.part-card.sel .pt::after { content: "◉"; color: var(--sys); font-size: 14px; }
.nurse { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--sys) 12%, transparent); border-left: 3px solid var(--sys); font-size: 13.5px; }
.nurse b { color: var(--sys); }
.cond { display: grid; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cond b { font-size: 14px; } .cond span { color: var(--tx2); font-size: 13px; }

/* tools */
.tool label { display: block; font-size: 12.5px; color: var(--tx2); margin: 8px 0 4px; }
.tool input[type=number], .tool select { width: 100%; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--tx); font-size: 16px; padding: 0 10px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.result { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; }
.result .big { font-size: 28px; font-weight: 800; }
.ok { color: #4ade80; } .warn { color: #fbbf24; } .bad { color: #f87171; }
.btn { height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--sys); background: color-mix(in srgb, var(--sys) 20%, transparent); font-weight: 700; }
.btn.solid { background: var(--sys); color: #0a1020; }
.btn.block { width: 100%; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-height: 40px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 13px; text-align: left; }
.seg button.on { border-color: var(--sys); background: color-mix(in srgb, var(--sys) 22%, transparent); }
.seg.v { flex-direction: column; }
.seg .sc { display: inline-block; min-width: 22px; font-weight: 800; color: var(--sys); }
.tapper { width: 100%; height: 120px; border-radius: 18px; border: 2px dashed var(--sys); background: color-mix(in srgb, var(--sys) 10%, transparent); font-size: 20px; font-weight: 800; }
.tapper:active { background: color-mix(in srgb, var(--sys) 30%, transparent); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--sys); margin-top: 1px; }
.bristol { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.bristol button { height: 52px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 800; font-size: 17px; }
.bristol button.on { background: var(--sys); color: #0a1020; }

/* quiz */
.q { margin: 10px 0 16px; }
.q .qt { font-weight: 700; margin-bottom: 6px; }
.q .opts { display: grid; gap: 6px; }
.q .opts button { text-align: left; min-height: 42px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }
.q .opts button.right { border-color: #22c55e; background: rgba(34,197,94,.18); }
.q .opts button.wrong { border-color: #ef4444; background: rgba(239,68,68,.18); }
.q .why { display: none; margin-top: 6px; font-size: 13px; color: var(--tx2); }
.q.done .why { display: block; }
.score { position: sticky; bottom: 0; background: var(--bg2); padding: 8px 0; font-weight: 700; text-align: center; border-top: 1px solid var(--line); }

/* loading */
#loading { position: absolute; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--bg); color: var(--tx2); transition: opacity .4s; }
#loading.hide { opacity: 0; pointer-events: none; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--acc); animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
#err { position: absolute; left: 10px; right: 10px; top: 70px; z-index: 60; background: #7f1d1d; padding: 10px; border-radius: 10px; font-size: 12px; white-space: pre-wrap; }

/* optional labels (individual muscles) only show when that one structure is selected */
.lbl.opt { display: none; }
.lbl.opt.sel.one { display: flex; }

/* search */
#search { position: absolute; inset: 0; z-index: 40; background: rgba(6,10,22,.82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: calc(var(--sat) + 8px) 10px calc(var(--sab) + 10px); display: flex; flex-direction: column; gap: 8px; }
#search[hidden] { display: none; }
.sbar { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 6px 0 14px; border-radius: 14px; border: 1px solid var(--acc);
  background: var(--bg2); color: var(--tx2); width: 100%; max-width: 640px; margin: 0 auto; flex: none; }
#sInput { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--tx); font: inherit; font-size: 16px;
  -webkit-user-select: text; user-select: text; }
#sInput::-webkit-search-cancel-button { display: none; }
#sClose { width: 38px; height: 38px; border: 0; border-radius: 10px; background: var(--card); font-size: 16px; flex: none; }
#sResults { flex: 1; overflow-y: auto; width: 100%; max-width: 640px; margin: 0 auto; border-radius: 14px; overscroll-behavior: contain; }
.sres { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 6px;
  border-radius: 12px; border: 1px solid var(--line); border-left: 4px solid var(--c); background: var(--card); }
.sres:active, .sres.kb { background: var(--card2); }
.sres .ic { font-size: 22px; flex: none; }
.sres .tx { min-width: 0; flex: 1; }
.sres b { display: block; font-size: 15px; }
.sres b mark { background: none; color: var(--c); }
.sres small { display: block; color: var(--tx2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shint { color: var(--tx2); text-align: center; padding: 18px 10px; font-size: 14px; }
.shint .chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.shint .chips button { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; }
.sall { width: 100%; height: 40px; margin-bottom: 8px; border-radius: 12px; border: 1px dashed var(--acc); background: none; color: var(--acc); font-weight: 700; font-size: 13.5px; }

/* vertebral column */
.lbl.mini { font-size: 10.5px; gap: 3px; }
.lbl.mini .dot { width: 7px; height: 7px; box-shadow: 0 0 0 2px rgba(0,0,0,.35), 0 0 6px var(--c); }
.lbl.mini .txt { padding: 1px 6px; font-weight: 700; }
@media (min-width: 700px) { .lbl.mini { font-size: 11.5px; } }
.nurse.sup { border-left-color: #facc15; }
.lvl-h { font-size: 12px; font-weight: 700; color: var(--tx2); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.lvls { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.lvls button { height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; font-size: 13.5px; }
.lvls button.on { background: var(--sys); border-color: var(--sys); color: #0a1020; }
table.vals.lv td:first-child { white-space: nowrap; color: var(--tx2); width: 1%; }
table.vals.lv td:nth-child(2) { font-weight: 400; }
