:root {
  --bg: #070708;
  --bg2: #131217;
  --text: #e9dfcc;
  --muted: #bcae93;
  --line: rgba(207, 158, 90, 0.28);
  --panel: rgba(16, 13, 13, 0.86);
  --accent: #cf8f48;
  --max: 1100px;
  --r: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 18px/1.62 "Palatino Linotype", Palatino, "Book Antiqua", serif;
  color: var(--text);
  overflow-x: hidden;
  background:
    radial-gradient(1200px 900px at 85% -20%, rgba(123, 21, 26, 0.32), transparent 58%),
    radial-gradient(1400px 1000px at -20% 20%, rgba(208, 145, 69, 0.18), transparent 56%),
    linear-gradient(160deg, var(--bg), var(--bg2));
}

.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding: 20px 16px 72px;
  position: relative;
  z-index: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 20px 52px rgba(0, 0, 0, 0.52);
  padding: 16px;
}

/* Отступ между соседними панелями (вставляет пространство между 2-й и 3-й и т.д.) */
.panel+.panel {
  margin-top: 20px;
}

.hero {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 12px;
  margin-bottom: 12px;
}

.hero aside {
  /* Make aside a clipping container and center its contents */
  position: relative;
  overflow: hidden;
  /* prevent image from spilling out */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  /* small inner gap */
}

h1,
h2 {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: "Copperplate", "Times New Roman", serif;
}

h1 {
  font-size: clamp(48px, 10vw, 96px);
  line-height: 0.9;
  color: var(--accent);
  text-align: center;
}

h2 {
  margin-top: 14px;
  font-size: 28px;
}

p {
  margin: 0 0 10px;
}

ul {
  margin: 8px 0 12px 20px;
}

li {
  margin: 4px 0;
}

.kicker {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  font: 12px/1.3 "Courier New", monospace;
  margin-bottom: 8px;
}

.muted {
  color: var(--muted);
}

.hero img {
  width: 100%;
  display: block;
  border-radius: 12px;
  border: 1px solid var(--line);
  object-fit: cover;
}

/* Стиль картинки Структура культа */
.cult-img {
  display: block;
  /* Center horizontally and give vertical spacing */
  margin: 18px auto;

  /* Increased size: responsive but limited to viewport/panel */
  width: min(900px, 100%);
  /* prefer larger, but not exceed 70% of container */
  max-width: calc(150% - 40px);
  /* keep small margin on very narrow screens */
  height: auto;

  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: contain;
}

.logo {
  /* Keep logo inside its parent `aside` and fully visible. */
  position: static;
  /* participate in normal flow inside aside */
  display: block;

  /* Make the image scale to fit the aside without overflowing. */
  width: 100%;
  /* scale to available width of the aside */
  max-width: 100%;
  height: auto;
  /* keep aspect ratio */
  max-height: 100%;
  /* don't exceed aside height */
  object-fit: contain;
  /* ensure whole image is visible */

  /* Прозрачность */
  opacity: 1;

  /* Keep image non-interactive and behind any interactive content */
  pointer-events: none;
  z-index: 0;
}

.members {
  max-height: 440px;
}

.quote {
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.02);
  padding: 10px 12px;
  color: #ddcaac;
}

footer {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }
}

canvas {
  position: fixed;
  left: 0;
  top: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  bottom: 0;
}

/* Modal styles */
.modal-overlay[hidden] {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  /* above content */
}

.modal {
  background: #0f0f10;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 20px 22px;
  border-radius: 10px;
  max-width: 90vw;
  width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  text-align: center;
}

/* Styles for document modal (larger, scrollable content) */
.modal.doc-modal {
  width: min(920px, 94vw);
  max-width: var(--max);
  text-align: left;
  padding: 18px;
}

.doc-content {
  max-height: 64vh;
  overflow: auto;
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
}

.doc-content > * {
  display: block;
  width: 100%;
  clear: both;
  position: relative;
}

/* Media in document content */
.doc-content img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin: 8px 0;
}
.doc-figure {
  margin: 8px 0;
  min-height: 320px;
  width: 100%;
  overflow: hidden;
  isolation: isolate;
}
.doc-caption { color: var(--muted); font-size: 13px; margin-top: 6px; }
.doc-audio { margin: 8px 0; }
.doc-figure { display:flex; flex-direction:column; align-items:stretch; min-height: 320px; }
.doc-caption { color: var(--muted); font-size: 13px; margin-top: 6px; }
.doc-audio {
  margin: 8px 0;
  width: 100%;
  position: relative;
  z-index: 2;
}
model-viewer {
  width: 100%;
  height: 100%;
  min-height: 320px;
  max-height: 70vh;
  border-radius: 8px;
  display: block;
  background: #0a0a0a;
  border: 1px solid var(--line);
  aspect-ratio: 16 / 9;
  object-fit: contain;
  position: static;
  z-index: 1;
  contain: layout paint;
}

/* Prevent text selection / dragging when interacting with 3D viewer */
model-viewer,
.doc-figure {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.model-error {
  margin-top: 8px;
  color: #f5c6c6;
  background: rgba(201, 40, 40, 0.06);
  border: 1px solid rgba(201, 40, 40, 0.12);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
}

/* Stabilize audio controls and prevent layout shift on hover/focus */
.doc-audio audio {
  display: block;
  width: 100%;
  box-sizing: border-box;
  height: 44px; /* fixed control height to avoid jump */
  position: relative;
  z-index: 2;
}
.doc-audio audio:focus,
.doc-audio audio:focus-visible {
  outline: 0; /* remove default focus outline that can shift layout */
}

/* Ensure model-viewer uses consistent box model and doesn't cause reflow on interaction */
.doc-figure model-viewer {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 320px;
  max-height: 72vh;
  border-radius: 8px;
  background: #0a0a0a;
  border: 1px solid var(--line);
}
.doc-figure {
  width: 100%;
  min-width: 0;
}
.modal.doc-modal {
  overflow: hidden;
}


/* Avoid any transforms on interactive elements that could cause neighboring text to move */
.doc-item button,
.doc-item .doc-open {
  transform: none;
}

.modal h3 {
  margin: 0 0 14px;
  font-size: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.btn.primary {
  background: var(--accent);
  color: #0b0b0b;
  border-color: rgba(0, 0, 0, 0.2);
}

/* Search bar styles - improved UI */
#search-panel .search-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 12px 0 18px;
}

#doc-search {
  flex: 1;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.6);
  font-size: 16px;
  outline: none;
  transition: box-shadow 120ms ease, transform 80ms ease, border-color 120ms;
}

#doc-search:focus {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  transform: translateY(-1px);
  border-color: rgba(207, 158, 90, 0.6);
}

#doc-search::placeholder {
  color: rgba(233, 223, 204, 0.5);
  font-style: italic;
}

#doc-filter {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 32px;
  /* space for caret */
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) calc(50% + 2px), calc(100% - 6px) calc(50% + 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

#search-clear {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 120ms, color 120ms, transform 80ms;
}

#search-clear:hover {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  transform: translateY(-1px);
}

/* Improved document cards */
.results {
  padding: 12px 16px 28px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.doc-item {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.012), rgba(0, 0, 0, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  /* prevent inner content from sticking out */
}

.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 8px;
}

.doc-title {
  font-size: 18px;
  margin: 0;
  line-height: 1.2;
}

.doc-meta {
  font-size: 12px;
  color: var(--muted);
}

.doc-excerpt {
  color: var(--text);
  opacity: 0.95;
  margin: 0;
  /* truncate preview to 3 lines with ellipsis */
  display: -webkit-box;
  line-clamp: 3;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-badge {
  display: inline-block;
  font-size: 12px;
  color: var(--muted);
  margin-right: 10px;
  font-weight: 600;
}

.doc-open {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
}

.doc-open:hover {
  transform: translateY(-1px);
}

.doc-full {
  margin-top: 0;
  /* collapsed: no gap */
  padding: 0;
  /* collapsed: no padding so nothing shows */
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform-origin: top;
  transition: max-height 260ms ease, opacity 200ms ease, transform 200ms ease, padding 180ms ease, margin-top 180ms ease;
}

/* When the parent .doc-item has .open, expand the .doc-full area */
.doc-item.open .doc-full {
  margin-top: 8px;
  /* restore gap when opened */
  padding: 12px;
  /* restore padding when opened */
  max-height: 360px;
  /* limit expanded height and allow internal scroll */
  opacity: 1;
  overflow: auto;
}

/* style for open state button */
.doc-open.open {
  background: var(--accent);
  color: #0b0b0b;
  border-color: rgba(0, 0, 0, 0.12);
}

@media (max-width: 700px) {
  .results {
    grid-template-columns: 1fr;
  }

  .doc-item {
    padding: 12px;
  }
}
#doc-modal model-viewer {
  height: 420px !important;
}

@media (max-width: 900px) {
  .modal.doc-modal {
    width: 96vw;
    padding: 14px;
  }
}

@media (max-width: 700px) {
  body {
    font-size: 16px;
  }

  .wrap {
    padding: 12px 10px 52px;
  }

  .panel {
    padding: 12px;
  }

  h1 {
    font-size: clamp(34px, 10vw, 62px);
  }

  h2 {
    font-size: 22px;
  }

  #search-panel .search-bar {
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
  }

  #doc-search,
  #doc-filter,
  #search-clear {
    width: 100%;
    min-width: 0;
  }

  .modal {
    width: 94vw;
    padding: 14px;
  }

  .modal-actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .doc-content {
    max-height: 58vh;
    white-space: normal;
  }

  .doc-content p,
  .doc-caption,
  .doc-audio {
    margin-top: 10px;
  }

  .doc-figure,
  model-viewer,
  .doc-figure model-viewer,
  #doc-modal model-viewer {
    min-height: 220px;
    max-height: 46vh;
    height: 220px !important;
  }
}
