/* ==========================================================================
   Anatomy Viewer Engine — Stylesheet
   Visual direction: a specimen light-table / engraved atlas-plate aesthetic.
   Bone-ivory ink on deep charcoal, brass-tone pin markers for hotspots,
   a serif for identity (echoes classic anatomical plate lettering) paired
   with a humanist sans for controls and a mono face for technical readouts.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,600&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg:          #14171a;
  --panel:       #1b1f23;
  --panel-alt:   #20252a;
  --border:      #2b3136;
  --border-soft: #23282d;
  --ink:         #e9e2d0;
  --ink-dim:     #8f9aa3;
  --ink-faint:   #a5afb6;
  --accent:      #80c6bb;
  --accent-soft: rgba(79, 158, 147, 0.16);
  --brass:       #c9a227;
  --landmark:    #c9a227;
  --origin:      #ff8585;
  --insertion:   #63a9dc;
  --note:        #a98bd4;
  --select:      #c0392b;
  --select-soft: rgba(192, 57, 43, 0.15);
  --brass-soft:  rgba(201, 162, 39, 0.18);
  --danger:      #c9634a;
  --focus-ring:  #7fd1c4;

  --font-display: 'Source Serif 4', Georgia, serif;
  --font-ui:      'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  --radius: 3px;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
}

body {
  overflow: hidden;
}

/* Visible keyboard focus everywhere — non-negotiable for a teaching tool */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---------------------------------------------------------------- Sidebar */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar__header {
  padding: 24px 20px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar__eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 6px;
}

.sidebar__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  line-height: 1.25;
  margin: 0;
  color: var(--ink);
}

.specimen-picker {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 14px;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.specimen-picker select {
  width: 100%;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-alt);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12.5px;
}

.sidebar__section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar__section h2 {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0 0 10px;
  font-weight: 500;
}

.sidebar__section--grow {
  flex: 1 0 auto;
}

/* Preset (camera view) list */

.preset-list, .hotspot-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preset-btn, .hotspot-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13.5px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 120ms ease, border-color 120ms ease;
}

.preset-btn:hover, .hotspot-btn:hover {
  background: var(--panel-alt);
  border-color: var(--border);
}

.preset-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}

.preset-btn__index {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  width: 16px;
  flex-shrink: 0;
}

.hotspot-btn__marker {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brass);
  flex-shrink: 0;
}

.hotspot-btn--landmark { --annotation-color: var(--landmark); }
.hotspot-btn--origin { --annotation-color: var(--origin); }
.hotspot-btn--insertion { --annotation-color: var(--insertion); }
.hotspot-btn--note { --annotation-color: var(--note); }

.hotspot-btn__marker { background: var(--annotation-color, var(--landmark)); }

.hotspot-btn__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.hotspot-btn__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hotspot-btn__detail {
  font-family: var(--font-mono);
  color: var(--annotation-color, var(--ink-faint));
  font-size: 9.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.annotation-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 9px;
}

.annotation-filter {
  --annotation-color: var(--ink-faint);
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  border-left: 3px solid var(--annotation-color);
  border-radius: var(--radius);
  color: var(--ink-faint);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 10.5px;
  padding: 6px 7px;
  text-align: left;
}

.annotation-filter--landmark { --annotation-color: var(--landmark); }
.annotation-filter--origin { --annotation-color: var(--origin); }
.annotation-filter--insertion { --annotation-color: var(--insertion); }
.annotation-filter--note { --annotation-color: var(--note); }
.annotation-filter--muscles { --annotation-color: #ca6c65; }
.annotation-filter--skeleton { --annotation-color: #ddd8c8; }
.annotation-filter--fascia { --annotation-color: #d9c99a; }
.annotation-filter--tendons { --annotation-color: #e9e3cb; }
.annotation-filter--sheaths { --annotation-color: #62b4b8; }
.annotation-filter--bursae { --annotation-color: #879cd5; }

.annotation-filter.is-active {
  background: color-mix(in srgb, var(--annotation-color) 12%, transparent);
  color: var(--ink);
}

.annotation-filter:not(.is-active) {
  border-left-color: var(--border);
  opacity: 0.58;
}

.empty-note {
  font-size: 12.5px;
  color: var(--ink-faint);
  font-style: italic;
  padding: 4px 10px;
}

/* Footer controls */

.sidebar__footer {
  margin-top: auto;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.btn--link {
  display: block;
  text-align: center;
  text-decoration: none;
}

.btn:hover { border-color: var(--ink-faint); }

.btn--accent {
  border-color: var(--accent);
  color: var(--accent);
}
.btn--accent:hover { background: var(--accent-soft); }

.btn--active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.btn--student {
  border-color: #4fa9b8;
  color: #83cfda;
}

.btn--student:hover { background: rgba(79, 169, 184, 0.12); }
.btn--student.btn--active {
  background: #4fa9b8;
  border-color: #4fa9b8;
  color: #0d1517;
}

/* -------------------------------------------------------------------- Stage */

.stage {
  position: relative;
  flex: 1;
  background: radial-gradient(ellipse at 50% 40%, #1a1e22 0%, var(--bg) 70%);
}

.stage__fullscreen-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid rgba(233, 226, 208, 0.35);
  border-radius: var(--radius);
  background: rgba(27, 31, 35, 0.9);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.24);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.stage__fullscreen-btn:hover {
  border-color: var(--focus-ring);
  background: rgba(32, 37, 42, 0.97);
}

.stage__fullscreen-btn[aria-pressed="true"] {
  border-color: var(--focus-ring);
  color: #a7e6ee;
}

.stage__fullscreen-icon {
  font-size: 18px;
  line-height: 1;
}

.stage__markup-btn {
  position: absolute;
  top: 16px;
  right: 156px;
  z-index: 40;
  display: none;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid rgba(79, 169, 184, 0.72);
  border-radius: var(--radius);
  background: rgba(27, 31, 35, 0.9);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.24);
  color: #a7e6ee;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.stage__markup-btn:hover {
  border-color: #83cfda;
  background: rgba(32, 37, 42, 0.97);
}

.stage__markup-btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.stage:fullscreen .stage__markup-btn,
.stage:-webkit-full-screen .stage__markup-btn {
  display: inline-flex;
  align-items: center;
}

.stage.is-markup .stage__fullscreen-btn {
  top: auto;
  bottom: 16px;
}

.stage.is-markup .stage__markup-btn {
  display: none;
}

.stage:fullscreen {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 40%, #1a1e22 0%, var(--bg) 70%);
}

.stage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 40%, #1a1e22 0%, var(--bg) 70%);
}

model-viewer {
  width: 100%;
  height: 100%;
  --poster-color: transparent;
}

.app.is-markup .sidebar__section,
.app.is-markup #resetBtn,
.app.is-markup #downloadViewBtn,
.app.is-markup #authorModeBtn {
  opacity: 0.42;
  pointer-events: none;
}

.stage.is-markup model-viewer {
  pointer-events: none;
  user-select: none;
}

/* --------------------------------------------------------- Student markup */

.markup-workspace {
  position: absolute;
  inset: 0;
  z-index: 20;
}

.markup-workspace[hidden] { display: none; }

.markup-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.markup-workspace.is-text-mode .markup-canvas { cursor: text; }

.markup-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(960px, calc(100% - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(131, 207, 218, 0.55);
  border-radius: var(--radius);
  background: rgba(20, 23, 26, 0.96);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
  color: var(--ink);
  pointer-events: auto;
}

.markup-toolbar__heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.markup-toolbar__heading strong {
  color: #83cfda;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.markup-toolbar__heading span {
  color: var(--ink-faint);
  font-size: 11px;
}

.markup-toolbar__tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: end;
}

.markup-tool {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-alt);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

.markup-tool:hover { border-color: #83cfda; }
.markup-tool:disabled { opacity: 0.38; cursor: not-allowed; }
.markup-tool.is-active {
  background: #4fa9b8;
  border-color: #4fa9b8;
  color: #0d1517;
}

.markup-tool--download {
  border-color: #83cfda;
  color: #a7e6ee;
}

.markup-tool--resume {
  border-color: var(--brass);
  color: var(--brass);
}

.markup-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.markup-field input {
  height: 34px;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-alt);
  color: var(--ink);
}

.markup-field--color input {
  width: 42px;
  padding: 3px;
  cursor: pointer;
}

.markup-field--size input { width: 100%; }
.markup-field--size { flex: 0 1 110px; }

.markup-field--text input {
  width: 100%;
  padding: 7px 9px;
  font-family: var(--font-ui);
  font-size: 12px;
  text-transform: none;
}

.markup-field--text {
  flex: 1 1 190px;
  min-width: 150px;
}

.markup-status {
  min-height: 15px;
  margin-top: 7px;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
}

#loadingOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  transition: opacity 300ms ease;
  pointer-events: none;
}

#loadingOverlay.is-hidden { opacity: 0; }

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ Hotspots
   Signature element: a brass pin + thin leader line to a label chip,
   echoing hand-annotated anatomical plate callouts.                       */

.hotspot {
  --annotation-color: var(--landmark);
  position: relative;
  cursor: pointer;
}

.hotspot--landmark { --annotation-color: var(--landmark); }
.hotspot--origin { --annotation-color: var(--origin); }
.hotspot--insertion { --annotation-color: var(--insertion); }
.hotspot--note { --annotation-color: var(--note); }
.hotspot.is-filtered { display: none; }

.hotspot__pin {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--annotation-color);
  border: 2px solid #0f1113;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--annotation-color) 20%, transparent);
  transition: transform 150ms ease;
}

.hotspot:hover .hotspot__pin,
.hotspot.is-focused .hotspot__pin {
  transform: scale(1.35);
}

.hotspot__label {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(20, 23, 26, 0.92);
  border: 1px solid var(--border);
  border-left: 2px solid var(--annotation-color);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12.5px;
  white-space: nowrap;
  padding: 4px 9px;
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 260px;
  white-space: normal;
}

.hotspot__type {
  color: var(--annotation-color);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.hotspot__title {
  font-weight: 600;
  white-space: nowrap;
}

.hotspot__detail {
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.25;
}

.hotspot:hover .hotspot__label,
.hotspot.is-focused .hotspot__label {
  opacity: 1;
}

/* ------------------------------------------------------------- Author Mode */

.author-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brass-soft);
  border: 1px solid var(--brass);
  color: var(--brass);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 7px 14px;
  border-radius: var(--radius);
  display: none;
}

.author-banner.is-active { display: block; }

.author-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 320px;
  max-height: 60%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: none;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.author-panel.is-active { display: flex; }

.author-panel h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0;
}

.author-snippet {
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--panel-alt);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.author-panel__hint {
  font-size: 11.5px;
  color: var(--ink-faint);
  line-height: 1.4;
}

.author-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.author-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.author-field:nth-child(4) { grid-column: 1 / -1; }

.author-field small {
  color: var(--ink-faint);
  font-size: 8.5px;
  text-transform: none;
}

.author-field input,
.author-field select,
.author-field textarea {
  width: 100%;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 7px 8px;
  text-transform: none;
}

.author-field textarea {
  min-height: 54px;
  resize: vertical;
}

.author-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}


/* ------------------------------------------------------- Selection panel */

.selection__name {
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.3;
  color: var(--ink);
  padding: 8px 10px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-left: 2px solid var(--select);
  border-radius: var(--radius);
  margin-bottom: 8px;
  word-break: break-word;
}

.selection__name--empty {
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-style: italic;
  color: var(--ink-faint);
  border-left-color: var(--border);
}

.selection__actions {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.selection__actions .btn { flex: 1; }

.btn--sm {
  font-size: 12px;
  padding: 7px 8px;
}

.btn--wide { width: 100%; }
#structureLayers.is-hidden,
#attachmentViewBtn.is-hidden { display: none; }

.btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.btn:disabled:hover { border-color: var(--border); }

/* ----------------------------------------------------------- Bone index */

.count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  letter-spacing: 0;
}

.search {
  width: 100%;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 7px 9px;
  margin-bottom: 8px;
}

.search::placeholder { color: var(--ink-faint); }

.bone-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}

.bone-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-dim);
  font-family: var(--font-ui);
  font-size: 12.5px;
  padding: 6px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.bone-btn:hover {
  background: var(--panel-alt);
  color: var(--ink);
}

.bone-btn.is-active {
  background: var(--select-soft);
  border-color: var(--select);
  color: var(--ink);
}

/* -------------------------------------------------------------- Stage hint */

.stage__hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: rgba(20, 23, 26, 0.75);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 6px 12px;
  transition: opacity 400ms ease;
  pointer-events: none;
}

.stage__hint.is-hidden { opacity: 0; }

.loading__detail {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  text-transform: none;
  letter-spacing: 0;
  max-width: 80%;
  text-align: center;
}

/* ------------------------------------------------------------------ Mobile */

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .stage { flex: 1; min-height: 40vh; }
  .author-panel { width: calc(100% - 32px); }
  .markup-toolbar {
    top: 8px;
    max-height: calc(100% - 16px);
    overflow-y: auto;
  }
}

@media (max-width: 480px) {
  .stage__fullscreen-btn { top: 8px; right: 8px; }
  .stage__markup-btn { top: 8px; left: 8px; right: auto; }
  .markup-toolbar__heading span { display: none; }
  .markup-tool--download,
  .markup-tool--resume { flex: 1 1 45%; }
}

/* -------------------------------------------------------- Reduced motion */

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
