/* Интерактивная 3D-карта тем курса (соблюдает tokens.css). */
.knowledge-atlas {
  margin-top: var(--section-gap);
}

.atlas-header {
  display: block;
  margin-bottom: var(--space-4);
}

.atlas-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  color: var(--accent);
  font: 700 var(--type-small)/1.3 var(--font-mono);
  letter-spacing: .03em;
  text-transform: uppercase;
}

.atlas-eyebrow::before {
  content: "";
  width: 1.5rem;
  height: 1px;
  background: currentColor;
}

.atlas-heading h2 {
  margin-top: var(--space-2);
}

.atlas-lead {
  margin-top: var(--space-2);
  max-width: 56ch;
  color: var(--muted);
  font-size: var(--type-lead);
  line-height: 1.48;
  text-wrap: pretty;
}

/* 3D-сцена карты тем */
.atlas-chamber {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent-line) 55%, transparent);
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse 68% 58% at 50% 48%, color-mix(in srgb, var(--engraving-ground) 72%, var(--diagram-night)), var(--diagram-night) 76%);
  color: var(--engraving-light);
}

/* Фоновая гравюра обсерватории и небесной карты в стиле обложки и отзывов */
.atlas-chamber::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: url("../workshop/art/atlas-celestial.f2a6117dd89d.webp") center 50% / cover no-repeat;
  filter: grayscale(1) sepia(.65) hue-rotate(165deg) saturate(2) brightness(1.18);
  mix-blend-mode: screen;
  opacity: .42;
  mask-image: radial-gradient(ellipse 96% 92% at 50% 50%, black 48%, rgb(0 0 0 / 62%) 80%, transparent 100%);
  transition: opacity var(--motion) ease-out;
}

.atlas-chamber.has-hover:not(.has-selection)::before {
  opacity: .3;
}

.atlas-chamber.has-selection::before {
  opacity: .2;
}

/* Тонкая чертёжная сетка */
.atlas-grid-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgb(242 250 255 / 4.5%) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(242 250 255 / 4.5%) 1px, transparent 1px),
    radial-gradient(circle at 50% 50%, rgb(242 250 255 / 10%) 0, transparent 52%);
  background-size: 48px 48px, 48px 48px, 100% 100%;
  mask-image: radial-gradient(ellipse 90% 86% at 50% 50%, black 52%, transparent 100%);
}

.atlas-viewport {
  position: relative;
  z-index: 3;
  height: clamp(35rem, 52vw, 44rem);
  perspective: 1500px;
  perspective-origin: 50% 50%;
  overflow: hidden;
  cursor: default;
}

.atlas-scene {
  position: relative;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform-style: preserve-3d;
  transform: rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  will-change: transform;
}

.atlas-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform: translateZ(0px);
}

.atlas-links line {
  stroke: rgb(242 250 255 / 26%);
  stroke-width: .22;
  stroke-dasharray: .9 .7;
}

.atlas-links line.is-hover-link {
  stroke: rgb(255 249 232 / 48%);
  stroke-width: .28;
  stroke-dasharray: .8 .6;
}

.atlas-links line.is-active {
  stroke: rgb(255 249 232 / 75%);
  stroke-width: .36;
  stroke-dasharray: none;
}

/* Карточка темы в 3D-пространстве */
.atlas-card {
  position: absolute;
  left: var(--ax);
  top: var(--ay);
  width: clamp(8.8rem, 11.4vw, 10.8rem);
  padding: .56rem .62rem .62rem;
  border: 1px solid color-mix(in srgb, var(--accent-line) 72%, transparent);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  display: grid;
  gap: .36rem;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  backface-visibility: hidden;
  transform:
    translate(-50%, -50%)
    translate3d(var(--dx, 0px), var(--dy, 0px), calc(var(--az) + var(--dz, 0px)))
    rotateY(var(--cur-ry, var(--ary)))
    rotateX(var(--cur-rx, var(--arx)))
    scale(var(--scale, var(--base-scale, 1)));
  box-shadow: 0 14px 32px rgb(6 14 38 / 36%);
  transition:
    transform 150ms cubic-bezier(.22, 1, .36, 1),
    left 220ms cubic-bezier(.22, 1, .36, 1),
    top 220ms cubic-bezier(.22, 1, .36, 1),
    width 220ms cubic-bezier(.22, 1, .36, 1),
    opacity 150ms ease-out,
    background-color 150ms ease-out,
    border-color var(--motion) ease-out,
    box-shadow 150ms ease-out,
    filter 150ms ease-out;
}

/* Три плана глубины (всегда с Z > 0 и непрозрачным фоном, чтобы текст не просвечивал) */
.atlas-layer-0 {
  z-index: 30;
  --base-scale: 1;
  background: var(--surface);
}

.atlas-layer-1 {
  z-index: 20;
  --base-scale: .93;
  background: color-mix(in srgb, var(--surface) 84%, #b9c9de);
}

.atlas-layer-2 {
  z-index: 10;
  --base-scale: .86;
  background: color-mix(in srgb, var(--surface) 68%, #9cb2cf);
}

/* Подсветка при наведении: любая карточка (включая дальний слой) выходит вперёд без рывка */
.atlas-chamber.has-hover:not(.has-selection) .atlas-card:not(.is-hovered) {
  opacity: .46;
}

.atlas-chamber.has-hover:not(.has-selection) .atlas-card.is-hover-related:not(.is-hovered) {
  opacity: .88;
  border-color: rgb(255 249 232 / 72%);
}

.atlas-card.is-hovered:not(.is-selected),
.atlas-card:focus-visible:not(.is-selected) {
  z-index: 65;
  opacity: 1;
  background: var(--surface);
  border-color: var(--on-accent);
  --cur-ry: 0deg;
  --cur-rx: 0deg;
  --scale: 1.05;
  box-shadow:
    0 24px 48px rgb(4 10 28 / 58%),
    0 0 0 2px var(--on-accent),
    0 0 0 5px rgb(23 60 156 / 32%);
}

.atlas-card:focus-visible {
  outline: 2px solid var(--on-accent);
  outline-offset: 3px;
}

/* Когда выбрана карточка: остальные мягко отступают, оставаясь кликабельными с Z > 0 */
.atlas-chamber.has-selection .atlas-card:not(.is-selected) {
  opacity: .3;
  filter: saturate(.55);
  --dz: -12px;
}

.atlas-chamber.has-selection .atlas-card.is-related:not(.is-selected) {
  opacity: .62;
  filter: none;
  --dz: 0px;
}

.atlas-chamber.has-selection .atlas-card.is-hovered:not(.is-selected) {
  opacity: 1;
  filter: none;
  z-index: 65;
  background: var(--surface);
  border-color: var(--on-accent);
  --cur-ry: 0deg;
  --cur-rx: 0deg;
  --scale: 1.03;
  box-shadow: 0 20px 42px rgb(4 10 28 / 54%), 0 0 0 2px var(--on-accent);
}

/* Выбранная карточка раскрывается прямо внутри визуализации */
.atlas-card.is-selected {
  left: 50%;
  top: 50%;
  z-index: 90;
  opacity: 1;
  filter: none;
  cursor: default;
  user-select: text;
  width: clamp(19rem, 29vw, 23.5rem);
  padding: 1rem 1.1rem 1.05rem;
  gap: .58rem;
  background: var(--surface);
  border: 2px solid var(--accent);
  transform:
    translate(-50%, -50%)
    translate3d(0, 0, 300px)
    rotateY(0deg)
    rotateX(0deg)
    scale(1);
  box-shadow:
    0 34px 72px rgb(4 10 28 / 68%),
    0 0 0 1px rgb(255 249 232 / 90%),
    0 0 0 6px rgb(23 60 156 / 28%);
}

.atlas-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .45rem;
}

.atlas-folio {
  font: 700 .72rem/1 var(--font-mono);
  color: var(--accent);
  letter-spacing: .04em;
}

.atlas-badge-full {
  display: none;
  font: 700 .74rem/1.2 var(--font-mono);
  color: var(--accent);
  letter-spacing: .02em;
}

.atlas-card.is-selected .atlas-folio {
  display: none;
}

.atlas-card.is-selected .atlas-badge-full {
  display: inline-block;
  margin-right: auto;
}

.atlas-pill {
  padding: .15rem .44rem;
  border-radius: 2px;
  background: var(--accent-wash);
  color: var(--accent-deep);
  font: 700 .66rem/1.15 var(--font-body);
  white-space: nowrap;
}

.atlas-pill.is-free {
  background: var(--accent);
  color: var(--on-accent);
}

.atlas-card-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-left: .15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--motion) ease-out, color var(--motion) ease-out, background-color var(--motion) ease-out;
}

.atlas-card-close:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-wash);
}

.atlas-card.is-selected .atlas-card-close {
  display: inline-flex;
}

.atlas-card-thumb {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--paper);
}

.atlas-card-thumb img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  mix-blend-mode: multiply;
}

.atlas-card.is-selected .atlas-card-thumb img {
  aspect-ratio: 16 / 9;
  max-height: 10.5rem;
}

.atlas-card-title {
  display: block;
  font: 520 clamp(.88rem, 1.04vw, 1.02rem)/1.18 var(--font-display);
  letter-spacing: -.022em;
  color: var(--ink);
  text-wrap: balance;
}

.atlas-card-full-title {
  display: none;
  font: 520 clamp(1.16rem, 1.45vw, 1.38rem)/1.18 var(--font-display);
  letter-spacing: -.024em;
  color: var(--accent-deep);
  text-wrap: balance;
}

.atlas-card-summary {
  display: none;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.46;
  text-wrap: pretty;
}

.atlas-card-actions {
  display: none;
  padding-top: .35rem;
}

.atlas-card-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 100%;
  min-height: 40px;
  padding: .5rem .95rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-size: .88rem;
  font-weight: 700;
  text-decoration: none;
  transition: background-color var(--motion) ease-out;
}

.atlas-card-cta:hover {
  background: var(--accent-deep);
  text-decoration: underline;
}

.atlas-card.is-selected .atlas-card-title,
.atlas-card.is-selected .atlas-card-foot {
  display: none;
}

.atlas-card.is-selected .atlas-card-full-title,
.atlas-card.is-selected .atlas-card-summary,
.atlas-card.is-selected .atlas-card-actions {
  display: block;
}

.atlas-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  padding-top: .32rem;
  border-top: 1px solid var(--line);
  font-size: .72rem;
  color: var(--muted);
}

.atlas-card-depth {
  color: var(--accent);
  font-weight: 700;
}

/* Мобильный режим: горизонтальная колода с раскрытием карточки на месте */
@media (max-width: 760px) {
  .atlas-chamber::before {
    background-position: center 44%;
    opacity: .34;
  }
  .atlas-links {
    display: none;
  }
  .atlas-viewport {
    height: auto;
    perspective: none;
    overflow: visible;
    padding: 1.15rem .9rem 1.25rem;
  }
  .atlas-scene {
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    overflow-x: auto;
    pointer-events: auto;
    scroll-snap-type: x proximity;
    padding: .5rem .25rem .95rem;
    transform: none !important;
    -webkit-overflow-scrolling: touch;
  }
  .atlas-card {
    position: relative;
    left: auto !important;
    top: auto !important;
    flex: 0 0 13.5rem;
    width: 13.5rem;
    scroll-snap-align: center;
    transform: translateY(var(--mobile-y, 0px)) scale(var(--mobile-scale, .97)) !important;
    opacity: .94;
    filter: none !important;
  }
  .atlas-layer-1 { --mobile-y: 8px; }
  .atlas-layer-2 { --mobile-y: 14px; }
  .atlas-chamber.has-selection .atlas-card:not(.is-selected) {
    opacity: .56;
    --mobile-scale: .93;
  }
  .atlas-card.is-selected {
    width: 17.5rem;
    flex-basis: 17.5rem;
    --mobile-y: -6px;
    --mobile-scale: 1;
    opacity: 1;
    box-shadow: 0 18px 36px rgb(4 10 28 / 58%), 0 0 0 2px var(--on-accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .atlas-scene {
    transform: none !important;
  }
  .atlas-card {
    transition: opacity 0ms, border-color 0ms;
  }
}
