/* Anatomy Atlas — design tokens, layout and components */
:root {
  --bg: #f3f5fb; --bg2: #e7ebf6; --surface: rgba(255,255,255,.72); --surface-solid: #ffffff; --border: rgba(20,30,60,.10);
  --text: #121a2e; --muted: #5b6680; --accent: #0fb5a6; --accent2: #7c5cff; --accent-ink: #ffffff; --good: #16a36a; --bad: #e0453f; --gold: #d99a14;
  --shadow: 0 10px 30px rgba(20,30,70,.10); --radius: 18px; --glass-blur: blur(18px) saturate(140%);
  --stage: radial-gradient(120% 80% at 50% 0%, #ffffff 0%, #e6ecf8 55%, #d8e0f2 100%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070b16; --bg2: #0d1426; --surface: rgba(22,30,52,.62); --surface-solid: #121a2f; --border: rgba(160,180,255,.12);
    --text: #e8edf9; --muted: #8b97b5; --accent: #2ee6d0; --accent2: #9b82ff; --accent-ink: #04201c; --good: #34d399; --bad: #f87171; --gold: #fbbf24;
    --shadow: 0 14px 40px rgba(0,0,0,.45);
    --stage: radial-gradient(120% 80% at 50% 0%, #1a2546 0%, #0b1122 60%, #060912 100%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #070b16; --bg2: #0d1426; --surface: rgba(22,30,52,.62); --surface-solid: #121a2f; --border: rgba(160,180,255,.12);
  --text: #e8edf9; --muted: #8b97b5; --accent: #2ee6d0; --accent2: #9b82ff; --accent-ink: #04201c; --good: #34d399; --bad: #f87171; --gold: #fbbf24;
  --shadow: 0 14px 40px rgba(0,0,0,.45);
  --stage: radial-gradient(120% 80% at 50% 0%, #1a2546 0%, #0b1122 60%, #060912 100%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; overflow-x: hidden;
  background-image: radial-gradient(60vw 40vw at 85% -10%, color-mix(in srgb, var(--accent2) 18%, transparent), transparent 70%), radial-gradient(50vw 40vw at -10% 110%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%);
  background-attachment: fixed;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 3.2vw, 2.4rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.glass { background: var(--surface); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ── Shell ── */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--border); background: color-mix(in srgb, var(--surface-solid) 55%, transparent); backdrop-filter: var(--glass-blur); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; padding: 4px 10px 18px; color: var(--text); }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 19px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent2) 40%, transparent); }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; }
.nav a:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); text-decoration: none; color: var(--text); }
.nav a.active { background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 22%, transparent), transparent); color: var(--text); }
.nav a .ico { width: 22px; text-align: center; font-size: 18px; }
.sidebar .spacer { flex: 1; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: var(--glass-blur); border-bottom: 1px solid var(--border); }
.topbar .title { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud { display: flex; align-items: center; gap: 8px; }
.hud-pill { padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 700; font-size: .9rem; }
.hud-bar { width: 90px; height: 8px; border-radius: 99px; background: var(--bg2); overflow: hidden; }
.hud-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: inherit; transition: width .6s; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 17px; display: grid; place-items: center; }
.view { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; animation: fadeUp .35s ease both; }
.view.full { max-width: none; padding: 0; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tabbar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 10px 14px; }
  .view { padding: 16px 16px 96px; }
  .view.full { padding-bottom: 0; }
  .hud-bar { display: none; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface-solid) 85%, transparent); backdrop-filter: var(--glass-blur); border-top: 1px solid var(--border); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; font-size: .68rem; color: var(--muted); padding: 4px 6px; border-radius: 10px; font-weight: 600; min-width: 54px; }
  .tabbar a span { font-size: 1.3rem; line-height: 1.2; }
  .tabbar a.active { color: var(--accent); }
  .tabbar a:hover { text-decoration: none; }
}

/* ── Components ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; transition: transform .12s, box-shadow .2s, background .2s; text-decoration: none !important; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 50%, var(--accent2))); color: var(--accent-ink); border: none; box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 55%, #000), 0 10px 24px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn.primary:active { box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 55%, #000); transform: translateY(4px); }
.btn.small { padding: 6px 12px; font-size: .88rem; border-radius: 11px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); color: var(--text); font-size: .85rem; font-weight: 600; cursor: pointer; margin: 2px; font-family: inherit; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip:hover { text-decoration: none; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; background: color-mix(in srgb, var(--accent2) 16%, transparent); color: var(--text); vertical-align: middle; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.card { padding: 18px; }
.card.link { cursor: pointer; transition: transform .18s, box-shadow .2s; color: var(--text); display: block; }
.card.link:hover { transform: translateY(-3px); text-decoration: none; box-shadow: 0 18px 40px rgba(0,0,0,.18); }
.sys-card { position: relative; overflow: hidden; }
.sys-card .emoji { font-size: 2rem; }
.sys-card::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: var(--c); opacity: .18; filter: blur(4px); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
input[type=text], input[type=search], input[type=url], textarea, select {
  width: 100%; padding: 11px 14px; border-radius: 13px; border: 1px solid var(--border); background: var(--surface-solid); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input[type=range] { accent-color: var(--accent); width: 100%; }
label.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.seg { display: inline-flex; padding: 4px; border-radius: 14px; background: var(--bg2); gap: 4px; flex-wrap: wrap; }
.seg button { border: none; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--surface-solid); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.progress { height: 10px; border-radius: 99px; background: var(--bg2); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .5s; }
.ring-bg { fill: none; stroke: var(--bg2); stroke-width: 7; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset 1s; }
.ring text { fill: var(--text); font-weight: 800; font-size: 13px; }
.stat { font-size: 1.8rem; font-weight: 800; }
.kpi { padding: 16px; }
.kpi .label { color: var(--muted); font-size: .85rem; font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.hero { padding: 28px; position: relative; overflow: hidden; }
.hero h1 { background: linear-gradient(120deg, var(--text), var(--accent) 60%, var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.empty { text-align: center; padding: 40px; color: var(--muted); }

/* ── Body explorer ── */
.explorer { position: relative; height: calc(100vh - 63px); display: grid; grid-template-columns: 290px 1fr 340px; background: var(--stage); }
.explorer canvas { width: 100%; height: 100%; display: block; cursor: grab; }
.explorer canvas:active { cursor: grabbing; }
.stage { position: relative; min-width: 0; overflow: hidden; }
.stage.camera { background: #000; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.stage canvas { position: absolute; inset: 0; }
.panel { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.panel-left { border-right: 1px solid var(--border); background: color-mix(in srgb, var(--surface-solid) 40%, transparent); backdrop-filter: var(--glass-blur); }
.panel-right { border-left: 1px solid var(--border); background: color-mix(in srgb, var(--surface-solid) 40%, transparent); backdrop-filter: var(--glass-blur); }
.layer { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; cursor: pointer; user-select: none; font-weight: 600; }
.layer:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.layer .dot { width: 14px; height: 14px; border-radius: 5px; background: var(--c); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent); }
.layer.off { opacity: .45; }
.layer.off .dot { background: transparent; border: 2px solid var(--c); }
.layer .eye { margin-left: auto; font-size: .85rem; color: var(--muted); }
.panel h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 0 2px; }
.stage-toolbar { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); width: max-content; display: flex; gap: 6px; padding: 6px; z-index: 5; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 24px); }
.stage-toolbar .icon-btn.on { background: var(--accent); color: var(--accent-ink); }
.stage-hint { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); font-size: .82rem; padding: 6px 14px; border-radius: 99px; pointer-events: none; white-space: nowrap; z-index: 4; }
.tip3d { position: absolute; pointer-events: none; z-index: 6; padding: 4px 10px; border-radius: 9px; font-size: .82rem; font-weight: 700; background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow); transform: translate(12px, -50%); white-space: nowrap; }
.label3d { position: absolute; z-index: 5; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer; font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: color-mix(in srgb, var(--surface-solid) 88%, transparent); border: 1px solid var(--border); white-space: nowrap; transition: transform .15s; }
.label3d::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--accent)); margin-right: 6px; }
.label3d:hover, .label3d.on { transform: translate(-50%, -50%) scale(1.08); background: var(--accent); color: var(--accent-ink); }
.info-empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.info h2 { margin-bottom: .2em; }
.info .latin { font-style: italic; color: var(--muted); margin-bottom: 10px; }
.info section { margin-bottom: 12px; }
.info ul { margin: 4px 0; padding-left: 18px; }
.fact { padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--gold) 14%, transparent); border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent); font-size: .92rem; }
.search-results { max-height: 220px; overflow: auto; display: flex; flex-direction: column; }
.search-results button { text-align: left; border: none; background: none; color: var(--text); padding: 7px 10px; border-radius: 9px; cursor: pointer; font: inherit; }
.search-results button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.drawer-btn { display: none; }
.drawer-btn[hidden] { display: none !important; }
@media (max-width: 1100px) { .explorer { grid-template-columns: 250px 1fr; } .panel-right { position: absolute; right: 12px; top: 12px; bottom: 80px; width: min(340px, calc(100% - 24px)); border-radius: var(--radius); border: 1px solid var(--border); z-index: 8; transform: translateX(110%); transition: transform .3s; box-shadow: var(--shadow); background: var(--surface-solid); } .panel-right.open { transform: none; } }
@media (max-width: 860px) {
  .explorer { grid-template-columns: 1fr; height: calc(100vh - 59px - 64px); height: calc(100dvh - 59px - 64px); }
  .panel-left { position: absolute; left: 12px; top: 12px; bottom: 80px; width: min(300px, calc(100% - 24px)); z-index: 8; border-radius: var(--radius); border: 1px solid var(--border); transform: translateX(-115%); transition: transform .3s; background: var(--surface-solid); box-shadow: var(--shadow); }
  .panel-left.open { transform: none; }
  .panel-right { top: auto; bottom: 74px; max-height: 55%; }
  .drawer-btn { display: grid; }
}

/* ── Quiz ── */
.quiz-wrap { max-width: 760px; margin: 0 auto; }
.q-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.q-top .progress { flex: 1; height: 14px; }
.q-card { padding: 26px; }
.q-text { font-size: 1.25rem; font-weight: 700; margin-bottom: 18px; }
.choices { display: grid; gap: 10px; }
.choice { text-align: left; padding: 15px 18px; border-radius: 16px; border: 2px solid var(--border); background: var(--surface-solid); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; transition: transform .1s, border-color .2s, background .2s; box-shadow: 0 3px 0 var(--border); display: flex; gap: 12px; align-items: center; }
.choice:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.choice .k { width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--border); display: grid; place-items: center; font-size: .8rem; flex: none; }
.choice.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--surface-solid)); }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface-solid)); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 14px; font-weight: 600; }
.feedback.good { background: color-mix(in srgb, var(--good) 14%, transparent); }
.feedback.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.1rem; }
.label-stage { height: 340px; border-radius: 16px; overflow: hidden; position: relative; background: var(--stage); margin-bottom: 16px; }
.label-stage canvas { width: 100%; height: 100%; display: block; }
.mode-card { padding: 20px; cursor: pointer; text-align: left; border: 1px solid var(--border); font: inherit; color: var(--text); transition: transform .18s; }
.mode-card:hover { transform: translateY(-3px); }
.mode-card .emoji { font-size: 1.9rem; }

/* ── Tutor ── */
.chat { display: flex; flex-direction: column; height: calc(100vh - 63px - 48px); max-width: 860px; margin: 0 auto; }
.msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 4px 12px; }
.msg { max-width: 85%; padding: 12px 16px; border-radius: 18px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 50%, var(--accent2))); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.bot .src { font-size: .72rem; color: var(--muted); margin-top: 6px; }
.typing span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin: 0 2px; animation: blink 1s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .2; } }
.composer { display: flex; gap: 8px; padding-top: 10px; }
.mini-q { margin-top: 10px; padding: 10px; border-radius: 12px; background: var(--bg2); white-space: normal; }
.mini-q .choice { padding: 9px 12px; font-size: .9rem; }
@media (max-width: 860px) { .chat { height: calc(100dvh - 59px - 64px - 32px); } }

/* ── Feedback layers ── */
#toasts { position: fixed; top: 74px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: 14px; background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow); transform: translateX(120%); transition: transform .3s; max-width: 320px; }
.toast.in { transform: none; }
.toast.gold { border-color: var(--gold); }
.xp-float { position: fixed; left: 50%; top: 40%; z-index: 99; font-size: 1.6rem; font-weight: 900; color: var(--gold); transform: translateX(-50%); animation: xpUp 1.2s ease forwards; pointer-events: none; text-shadow: 0 2px 10px rgba(0,0,0,.25); }
@keyframes xpUp { from { opacity: 0; transform: translate(-50%, 20px) scale(.8); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); } to { opacity: 0; transform: translate(-50%, -60px); } }
.celebrate { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; background: rgba(0,0,0,.45); animation: fadeUp .25s; }
.celebrate-card { padding: 32px 40px; text-align: center; background: var(--surface-solid); }
.celebrate .burst { font-size: 3.4rem; animation: pop .6s; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
.confetti { position: fixed; top: -12px; width: 9px; height: 14px; z-index: 130; border-radius: 2px; animation: fall linear forwards; pointer-events: none; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .8; } }
.badge { padding: 14px; text-align: center; }
.badge .b-ico { font-size: 2rem; filter: grayscale(1); opacity: .35; }
.badge.got .b-ico { filter: none; opacity: 1; }
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.flow .step { padding: 8px 12px; border-radius: 12px; background: var(--surface-solid); border: 1px solid var(--border); font-weight: 600; font-size: .9rem; animation: fadeUp .4s both; }
.flow .arrow { color: var(--accent); font-weight: 900; }
.sys-viewer { height: 460px; border-radius: var(--radius); overflow: hidden; position: relative; background: var(--stage); }
.sys-viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.chart { width: 100%; height: 220px; }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; }
.lb-row.me { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.lb-rank { width: 28px; font-weight: 900; text-align: center; }
.term { padding: 12px 14px; }
.term b { display: block; }
.loading { display: grid; place-items: center; height: 100%; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
