:root {
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --text: #1B2430;
  --muted: #536072;
  --line: #E4E9F0;
  --accent: #2F6FED;
  --accent-soft: #EEF3FE;
  --muscle: #E2725B;
  --bone: #DED5C3;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(27, 36, 48, .04), 0 8px 28px rgba(27, 36, 48, .06);
  --t: 180ms cubic-bezier(.2, .7, .3, 1);
  --figure-h: clamp(500px, 78vh, 820px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Шапка ---------- */

.app-header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  flex-wrap: wrap;
}

.brand-title { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
.brand-sub { margin: 2px 0 0; font-size: 14px; color: var(--muted); }

.segmented {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: #E8ECF2;
  border-radius: var(--radius-sm);
}

.seg-btn {
  height: 40px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  border-radius: 9px;
  font: inherit;
  font-size: 15px;
  font-weight: 550;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t), color var(--t), box-shadow var(--t);
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-selected="true"] {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(27, 36, 48, .08), 0 2px 8px rgba(27, 36, 48, .06);
}
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 14px; color: var(--muted); }
.user-logout {
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  transition: background var(--t);
}
.user-logout:hover { background: var(--bg); }
.user-logout:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Сетка ---------- */

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px 56px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 24px;
  align-items: start;
}

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.model-card { grid-column: span 7; padding: 20px; }

.side {
  grid-column: span 5;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ---------- Модель ---------- */

.model-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 12px;
  flex-wrap: wrap;
  min-height: 32px;
  margin-bottom: 14px;
}

.switchers { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.switchers[hidden] { display: none; }

/* Группа из одного варианта ничего не переключает, поэтому её не показываем.
   Сейчас ATLAS_SCOPE отдаёт одну фигуру и один ракурс, и обе группы скрыты.
   Если в данных появится больше вариантов, чипы вернутся без правок шаблона и JS. */
.chips:not(:has(> .chip ~ .chip)) { display: none; }
.switchers:not(:has(.chips > .chip ~ .chip)) { display: none; }

.chips { display: flex; gap: 4px; padding: 3px; background: var(--bg); border-radius: 10px; }
.chips[hidden] { display: none; }
.chip-div { width: 1px; height: 20px; background: var(--line); }
.switchers:not(:has(.chips > .chip ~ .chip)) + .chip-div,
.chip-div:has(+ .chips:not(:has(> .chip ~ .chip))) { display: none; }

.chip {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t), color var(--t);
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(27,36,48,.08); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mode-badge {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.stage {
  position: relative;
  border-radius: var(--radius-sm);
  background-color: #FAFBFD;
  background-image: radial-gradient(#E3E8EF 1px, transparent 1.2px);
  background-size: 22px 22px;
  overflow: hidden;
}

/* Рамка строго повторяет пропорции изображения (1100×1650), иначе
   проценты маркеров считались бы от letterbox-полей и уплывали в сторону.
   Размеры заданы явно через одну переменную — без aspect-ratio и margin:auto,
   чтобы вёрстка была одинаковой во всех движках. */
.frame {
  display: flex;
  justify-content: center;
}
.frame[hidden] { display: none; }

.frame-inner {
  position: relative;
  flex: 0 0 auto;
  height: var(--figure-h);
  width: calc(var(--figure-h) * 1100 / 1650);
  line-height: 0;
}

.frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
  mix-blend-mode: multiply;
  /* Картинка никогда не перехватывает клики, они уходят маркерам */
  pointer-events: none;
}
/* Маркеры */
.pins { position: absolute; inset: 0; z-index: 1; }

.pin {
  position: absolute;
  width: 30px; height: 30px;
  margin: -15px 0 0 -15px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 160ms cubic-bezier(.2,.7,.3,1);
}
.pin::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 26%, #fff);
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}
.pin-dot {
  position: relative;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 2.5px #fff, 0 2px 6px rgba(27, 36, 48, .3);
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.pin:hover { transform: scale(1.15); }
.pin:hover::before, .pin:focus-visible::before { opacity: 1; }
.pin:hover .pin-dot { transform: scale(1.15); }
.pin:focus-visible { outline: none; }
.pin:focus-visible .pin-dot {
  box-shadow: 0 0 0 2.5px #fff, 0 0 0 5px var(--accent);
}
.pin.is-active .pin-dot {
  transform: scale(1.3);
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent);
}
.pin.is-active::before { opacity: 1; }

/* Схема (для костей и органов) */
.scheme {
  display: block;
  width: 100%;
  height: clamp(500px, 78vh, 820px);
  padding: 16px 0;
  user-select: none;
}
.scheme[hidden] { display: none; }

.body-outline { fill: #CDD5E0; stroke: #CDD5E0; stroke-width: 4; stroke-linejoin: round; }
.body-fill { fill: #ECEFF4; }
.floor { fill: #E3E8EF; }

.layer {
  opacity: 0; visibility: hidden;
  transform-origin: 200px 400px;
  transform: scale(.985);
  transition: opacity 200ms ease, transform 200ms ease, visibility 0s linear 200ms;
}
.layer.is-active {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity 200ms ease, transform 200ms ease, visibility 0s;
}

.zone { cursor: pointer; outline: none; transition: opacity var(--t); }
.shape {
  fill: var(--c);
  fill-opacity: .94;
  stroke-width: 1.25;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: fill-opacity var(--t), stroke var(--t), stroke-width var(--t);
}
.layer--muscle .shape { stroke: #FFFFFF; }
.layer--bone .shape { stroke: #B6A98E; }
.layer--organ .shape { stroke: rgba(27, 36, 48, .22); }
.deco { pointer-events: none; }

.layer:hover .zone, .layer.is-peeking .zone { opacity: .5; }
.layer:hover .zone:hover, .layer.is-peeking .zone.is-peek { opacity: 1; }
.zone:hover .shape, .zone.is-peek .shape { fill-opacity: 1; }
.zone:focus-visible .shape { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 5 3; }

.sel-overlay { pointer-events: none; }
.sel-overlay path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  animation: sel-in 200ms ease both;
}
.sel-overlay .sel-halo { stroke: rgba(47, 111, 237, .22); stroke-width: 9; }
@keyframes sel-in { from { opacity: 0; } to { opacity: 1; } }

/* Подсказка */
.tooltip {
  position: absolute;
  top: 0; left: 0;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--text);
  color: #fff;
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(27, 36, 48, .2);
  pointer-events: none;
  opacity: 0;
  transform: translate(var(--x, 0), var(--y, 0)) translate(-50%, calc(-100% - 12px));
  transition: opacity 150ms ease;
}
.tooltip.is-visible { opacity: 1; }
.tooltip-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--c, var(--accent));
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .25);
}

.model-hint { margin: 14px 4px 0; font-size: 13px; color: var(--muted); text-wrap: pretty; }
kbd {
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 1px 6px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
}

/* ---------- Поиск ---------- */

.search { position: relative; }
.search-icon {
  position: absolute; left: 14px; top: 50%;
  width: 18px; height: 18px;
  transform: translateY(-50%);
  fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round;
  pointer-events: none;
}
.search-input {
  width: 100%; height: 48px;
  padding: 0 14px 0 42px;
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(27, 36, 48, .03);
  transition: border-color var(--t), box-shadow var(--t);
}
.search-input::placeholder { color: #6B7787; }
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .18);
}

/* ---------- Панель ---------- */

.panel { padding: 24px; min-height: 248px; }

.empty {
  min-height: 200px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 6px;
}
.empty-mark { width: 44px; height: 44px; border-radius: 50%; border: 2px dashed #C3CCD8; margin-bottom: 8px; }
.empty-title { margin: 0; font-size: 18px; font-weight: 600; }
.empty-text { margin: 0; font-size: 14px; color: var(--muted); max-width: 30ch; text-wrap: pretty; }

.detail { animation: detail-in 200ms ease both; }
@keyframes detail-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.detail-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.chip-tag {
  display: inline-flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 12px 0 10px;
  font-size: 13px; font-weight: 600; color: var(--text);
  background: color-mix(in srgb, var(--c) 16%, #fff);
  border-radius: 999px;
}
.chip-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(27, 36, 48, .12);
}

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer;
  transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.detail-name {
  margin: 16px 0 2px;
  font-size: 26px; font-weight: 650; line-height: 1.2;
  letter-spacing: -.01em; text-wrap: balance;
}
.detail-latin { margin: 0; font-size: 15px; font-style: italic; color: var(--muted); }
.detail-desc { margin: 16px 0 0; font-size: 16px; line-height: 1.6; text-wrap: pretty; }

.trauma-grid {
  margin: 20px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.trauma-grid > div { display: grid; gap: 2px; }
.trauma-grid dt {
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.trauma-grid dd { margin: 0; font-size: 15px; line-height: 1.55; text-wrap: pretty; }

.fact {
  margin-top: 20px; padding: 14px 16px;
  background: var(--accent-soft); border-radius: var(--radius-sm);
}
.fact-label {
  display: block; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: #1F56C7; margin-bottom: 4px;
}
.fact p { margin: 0; font-size: 15px; text-wrap: pretty; }

/* ---------- Список ---------- */

.list-card { padding: 8px; }
.list-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 12px 12px 8px;
}
.list-title { margin: 0; font-size: 15px; font-weight: 650; }
.list-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.parts-list { list-style: none; margin: 0; padding: 0; }

.list-item {
  width: 100%; min-height: 48px;
  display: grid; grid-template-columns: 12px 1fr auto;
  align-items: center; gap: 12px;
  padding: 8px 12px;
  border: 0; border-radius: 10px;
  background: transparent;
  font: inherit; text-align: left; color: var(--text);
  cursor: pointer;
  transition: background var(--t), box-shadow var(--t);
}
.list-item:hover { background: var(--bg); }
.list-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list-item[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }

.list-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(27, 36, 48, .12);
}
.list-text { display: flex; flex-direction: column; min-width: 0; }
.list-name { font-size: 15px; font-weight: 550; }
.list-latin {
  font-size: 13px; font-style: italic; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-tag {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--bg); padding: 2px 8px; border-radius: 999px;
}
.list-empty { padding: 20px 12px 24px; font-size: 14px; color: var(--muted); }

/* ---------- Адаптив ---------- */

@media (max-width: 880px) {
  :root { --figure-h: clamp(420px, 62vh, 620px); }
  .app-header { padding: 20px 16px 8px; }
  .segmented { width: 100%; }
  .seg-btn { flex: 1; padding: 0 8px; font-size: 14px; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 8px 16px 40px; gap: 16px; }
  .model-card, .side { grid-column: auto; }
  .model-card { padding: 16px; }
  .frame-inner { height: var(--figure-h); }
  .scheme { height: clamp(420px, 62vh, 620px); }
  .panel { padding: 20px; min-height: 0; }
  .detail-name { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
