/* ============================================================
   MEDRASY · ANATOMY ATLAS — shared design system
   Branded after medrasy.com / @medrasyofficial: deep navy-teal
   surfaces, amber/gold accents, teal-green interactive highlights.
   Realistic Complete-Anatomy-referenced structure palette.
   ============================================================ */
:root {
  /* — surfaces (Medrasy navy-teal ink) — */
  --bg:            #081419;   /* deep navy-teal */
  --bg-2:          #0c1e26;
  --panel:         rgba(13, 30, 38, 0.74);
  --panel-solid:   #0e222b;
  --border:        rgba(160,210,214,0.12);
  --border-strong: rgba(160,210,214,0.22);
  --blur:          18px;

  /* — text — */
  --text:          #eef4f4;
  --text-dim:      #9fb4b7;
  --text-faint:    #5f7479;

  /* — accents (Medrasy amber + teal-green, from medrasy.com) — */
  --accent:        #ffb839;   /* Medrasy amber */
  --accent-soft:   rgba(255,184,57,0.16);
  --active:        #31988d;   /* Medrasy teal — active/selection */
  --active-soft:   rgba(49,152,141,0.20);
  --focus-ring:    #ffb839;

  /* — anatomical structure palette (realistic, synced with engine.js PALETTE) — */
  --c-muscle:      #a04338;   /* brick/terracotta muscle red */
  --c-muscle-2:    #83352c;
  --c-artery:      #b02f2a;   /* deep arterial blood red */
  --c-vein:        #3c4aaa;   /* venous indigo */
  --c-nerve:       #dcc274;   /* goldenrod nerve */
  --c-bone:        #ded2bf;   /* warm ivory */
  --c-bone-deep:   #cbbca4;
  --c-tendon:      #e2dccd;   /* pearly tendon */
  --c-fascia:      #dcd6c8;   /* translucent connective */
  --c-cartilage:   #dde5e4;   /* pale pearl cartilage */
  --c-organ:       #9d5349;   /* viscera reddish-brown */
  --c-gland:       #c39a7c;

  /* — geometry — */
  --r-sm: 7px; --r: 12px; --r-lg: 16px; --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --shadow:  0 12px 40px rgba(0,0,0,0.55);
  --shadow-lg: 0 24px 70px rgba(0,0,0,0.6);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);   /* soft-out */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

@font-face { font-family:"Raleway"; font-style:normal; font-weight:400; font-display:swap; src:url("/atlas/fonts/Raleway-400-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:400; font-display:swap; src:url("/atlas/fonts/Raleway-400-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:600; font-display:swap; src:url("/atlas/fonts/Raleway-600-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:600; font-display:swap; src:url("/atlas/fonts/Raleway-600-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:700; font-display:swap; src:url("/atlas/fonts/Raleway-700-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:700; font-display:swap; src:url("/atlas/fonts/Raleway-700-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:800; font-display:swap; src:url("/atlas/fonts/Raleway-800-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:800; font-display:swap; src:url("/atlas/fonts/Raleway-800-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:900; font-display:swap; src:url("/atlas/fonts/Raleway-900-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Raleway"; font-style:normal; font-weight:900; font-display:swap; src:url("/atlas/fonts/Raleway-900-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Raleway", -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Medrasy brand headings use Raleway. */
.atlas-serif { font-family: "Raleway", system-ui, sans-serif; letter-spacing: -0.01em; }

a { color: inherit; text-decoration: none; }
::selection { background: var(--active-soft); }

/* — glass panel — */
.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  backdrop-filter: blur(var(--blur)) saturate(1.25);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.25);
  box-shadow: var(--shadow);
}

/* — buttons / pills — */
.btn {
  border: 1px solid var(--border); background: rgba(255,255,255,0.04);
  color: var(--text-dim); font-size: 12.5px; padding: 8px 15px; border-radius: var(--r-pill);
  cursor: pointer; transition: background .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease);
  white-space: nowrap; user-select: none;
}
.btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.btn.active { background: var(--active-soft); color: #6fd8c9; border-color: rgba(47,160,147,0.4); }

/* — scrollbars — */
.scroll::-webkit-scrollbar { width: 7px; height: 7px; }
.scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 4px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* — loading — */
.atlas-loading { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; background: var(--bg);
  transition: opacity .6s var(--ease), visibility 0s .65s; }
.atlas-loading.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.atlas-loading .ring { width: 44px; height: 44px; border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--active); border-radius: 50%; animation: atlas-spin .9s linear infinite; }
.atlas-loading .lbl { font-size: 12px; color: var(--text-dim); letter-spacing: .06em; }
.atlas-loading .sub { font-size: 10px; color: var(--text-faint); }
@keyframes atlas-spin { to { transform: rotate(360deg); } }

/* ---- floating pin labels (atlas-plate look: bare text + leader line) ---- */
.pin {
  font-family: "Raleway", system-ui, sans-serif;
  font-size: 12.5px; font-weight: 600; color: #f8fbfa; letter-spacing: .01em;
  padding: 2px 6px 2px 8px; border-radius: 4px; white-space: nowrap; pointer-events: none;
  background: rgba(6,16,20,0.78); border: none;
  border-left: 2px solid rgba(255,255,255,0.7); /* tinted per category inline */
  box-shadow: 0 1px 5px rgba(0,0,0,0.5);
  text-shadow: 0 1px 2px rgba(0,0,0,0.95);
  transition: opacity .18s var(--ease);
}
.pin.secondary { font-size: 11px; font-weight: 500; color: #dfeae9; padding: 1px 5px 1px 6px;
  background: rgba(6,16,20,0.66); border-left-color: rgba(255,255,255,0.42); box-shadow: 0 1px 3px rgba(0,0,0,0.4); }
.pin.occluded { opacity: .32 !important; }

/* ---- interaction tools (selection / isolation / cross-section) ---- */
/* Bottom-left, opposite the layer panel, and above the focus bar. Capped in height so a long
   selection list scrolls inside the panel instead of pushing the page. */
#tools{
  position:fixed; left:14px; bottom:14px; width:264px; z-index:30;
  display:flex; flex-direction:column; gap:12px; padding:12px 13px;
  max-height:min(74vh, 680px); overflow-y:auto;
}
#tools h2{ font-size:10.5px; letter-spacing:.14em; text-transform:uppercase;
  color:var(--text-faint); margin:0; font-weight:700; }
.tool-block{ display:flex; flex-direction:column; gap:7px; }
.tool-row{ display:flex; align-items:center; justify-content:space-between; gap:6px; }
.tool-row.wrap{ flex-wrap:wrap; justify-content:flex-start; }
#sel-title{ font-size:12px; color:var(--text); font-weight:600; }
#sel-count{ color:var(--accent); }
#tools .hint{ font-size:10.5px; line-height:1.4; color:var(--text-faint); }
#tools .btn.tiny{ padding:5px 9px; font-size:11px; border-radius:8px; }
#tools .btn.tiny[disabled]{ opacity:.4; cursor:default; }
#tools .btn.tiny.active,
#tools .btn.tiny[aria-pressed="true"]{ border-color:var(--accent); color:var(--accent); }
.sel-list{ display:flex; flex-direction:column; gap:4px; max-height:132px; overflow-y:auto; }
.sel-empty{ font-size:10.5px; color:var(--text-faint); font-style:italic; }
.sel-item{ display:flex; align-items:center; gap:6px; font-size:11px; }
.sel-dot{ width:7px; height:7px; border-radius:50%; background:var(--accent); flex:none; }
.sel-label{ flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sel-x{ background:none; border:none; color:var(--text-faint); cursor:pointer;
  font-size:14px; line-height:1; padding:0 2px; }
.sel-x:hover{ color:#e88; }
.detail-card{ border:1px solid var(--border); border-radius:9px; padding:7px 9px; }
.detail-name{ font-size:12px; font-weight:600; color:var(--text); }
.detail-meta{ font-size:10.5px; color:var(--text-faint); margin-top:2px; }
.iso-status{ font-size:10.5px; color:var(--accent); }
.chk{ display:flex; align-items:center; gap:5px; font-size:10.5px; color:var(--text-faint); }
#sec-pos{ width:100%; }

/* On short or narrow screens the tools would collide with the focus bar and the HUD, so they
   collapse to a compact strip rather than overlapping the model. */
@media (max-width: 900px), (max-height: 720px){
  #tools{ width:210px; max-height:40vh; padding:9px 10px; gap:8px; }
  .sel-list{ max-height:80px; }
}

/* ---- annotation (pen / eraser) — lives inside the #tools panel ---- */
.anno-swatches{ display:flex; gap:5px; align-items:center; }
.anno-swatch{ width:18px; height:18px; border-radius:50%; border:2px solid transparent; cursor:pointer; padding:0; }
.anno-swatch.active{ border-color:#fff; box-shadow:0 0 0 1px var(--accent); }
.anno-hint{ font-size:10.5px; color:var(--text-faint); line-height:1.4; }
#stage canvas.annotating{ touch-action:none; }
