* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font-family: -apple-system, Segoe UI, Roboto, sans-serif; background: #060a10; color: #e8ecf4; }

/* ---------- полноэкранная карта (нижний слой) ---------- */
#viewport { position: fixed; inset: 0; z-index: 1; background: #060a10; }
#three-canvas { width: 100%; height: 100%; display: block; }
#timeline {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 18px; width: min(640px, calc(100% - 36px));
  background: rgba(11,15,23,0.85); border: 1px solid #222a38; border-radius: 10px;
  padding: 8px 12px; display: flex; align-items: center; gap: 10px; backdrop-filter: blur(6px); z-index: 5;
}
#timeline.hidden { display: none; }
#timeline button { width: auto; padding: 4px 10px; margin: 0; background: #1d2531; color: #e8ecf4; border: none; border-radius: 6px; cursor: pointer; }
#timeline input[type=range] { flex: 1; accent-color: #ff9a3c; }
#scrub-label { font-size: 0.8em; color: #93a0b4; min-width: 5em; text-align: right; }
#current-chart {
  position: absolute; bottom: 18px; right: 18px; background: rgba(11,15,23,0.85);
  border: 1px solid #222a38; border-radius: 10px; padding: 8px; z-index: 5;
}

/* ---------- оверлей-панели (поверх карты) ---------- */
:root { --topbar-h: 64px; }  /* переопределяется из JS по реальной высоте топбара */

.overlay-panel {
  position: fixed; z-index: 10; background: rgba(17,22,31,0.88); backdrop-filter: blur(8px);
  border: 1px solid #222a38; transition: transform 0.22s ease, top 0.22s ease;
}
.overlay-panel--top { top: 0; left: 0; right: 0; border-left: none; border-right: none; border-top: none; }
/* левая/правая панели всегда начинаются СРАЗУ под топбаром - top считается
   динамически в JS (высота топбара не фиксирована: фильтры могут переноситься
   на вторую строку на узких экранах), чтобы панели никогда не перекрывались.
   Когда топбар свёрнут, top уезжает в 0 - боковые панели занимают всю высоту. */
.overlay-panel--left { top: var(--topbar-h); left: 0; bottom: 0; width: 300px; border-top: none; border-bottom: none; border-left: none; }
.overlay-panel--right { top: var(--topbar-h); right: 0; bottom: 0; width: 300px; border-top: none; border-bottom: none; border-right: none; }

.overlay-panel--top.collapsed { transform: translateY(-100%); }
.overlay-panel--left.collapsed { transform: translateX(-100%); }
.overlay-panel--right.collapsed { transform: translateX(100%); }

.collapse-tab {
  position: absolute; z-index: 11; background: rgba(17,22,31,0.92); border: 1px solid #222a38; color: #93a0b4;
  cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 0.9em;
}
.collapse-tab:hover { color: #ff9a3c; }
.collapse-tab--top { bottom: -22px; left: 50%; transform: translateX(-50%); width: 44px; height: 22px; border-top: none; border-radius: 0 0 8px 8px; }
.collapse-tab--left { top: 50%; right: -22px; transform: translateY(-50%); width: 22px; height: 44px; border-left: none; border-radius: 0 8px 8px 0; }
.collapse-tab--right { top: 50%; left: -22px; transform: translateY(-50%); width: 22px; height: 44px; border-right: none; border-radius: 8px 0 0 8px; }

/* ---------- верхняя панель ---------- */
.topbar-inner { display: flex; align-items: center; gap: 22px; padding: 14px 20px; flex-wrap: wrap; }
.topbar-brand { display: flex; align-items: center; gap: 10px; flex: none; }
.topbar-filters { display: flex; align-items: flex-end; gap: 14px; flex: 1; flex-wrap: wrap; }
.topbar-filters .filter-group { min-width: 130px; }
.topbar-action { display: flex; align-items: center; gap: 10px; flex: none; flex-wrap: wrap; }
.switch-inline { display: flex; align-items: center; gap: 6px; font-size: 0.78em; color: #93a0b4; }

.app-header-icon {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, #ff9a3c, #ff5f6d);
  display: flex; align-items: center; justify-content: center; font-size: 1.1em;
}
.app-header-text h1 { font-size: 1.05em; margin: 0; white-space: nowrap; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid #2a3344; background: #0b0f17;
  color: #93a0b4; font-size: 0.85em; cursor: pointer; flex: none;
}
.icon-btn:hover { color: #ff9a3c; border-color: #ff9a3c; }

/* ---------- боковые панели ---------- */
.panel-inner { height: 100%; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.panel-heading { font-size: 0.78em; text-transform: uppercase; letter-spacing: .06em; color: #6f8099; }

/* ---------- карточки ---------- */
.card { background: #0b0f17; border: 1px solid #222a38; border-radius: 12px; padding: 14px 16px; }
.card-title { font-size: 0.76em; text-transform: uppercase; letter-spacing: .05em; color: #6f8099; margin: 0 0 10px; }
.hint { font-size: 0.76em; color: #6f8099; margin: 8px 0 0; line-height: 1.4; }

/* ---------- кнопки / спиннер ---------- */
.btn {
  border: none; border-radius: 8px; padding: 9px 14px; font-size: 0.88em; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg, #ff9a3c, #ff5f6d); color: #141414; }
.btn-primary:disabled { opacity: 0.55; cursor: wait; }
.btn-outline { background: #1d2531; color: #c3cde0; }
.btn-outline:hover { background: #242e3d; }
.btn-lg { padding: 10px 18px; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(0,0,0,0.25);
  border-top-color: #141414; animation: spin 0.8s linear infinite; display: inline-block;
}
.spinner[hidden] { display: none; }  /* [hidden] и .spinner - одинаковая специфичность,
                                        без этого правила display:inline-block перебивает атрибут */
@keyframes spin { to { transform: rotate(360deg); } }
.sim-status { font-size: 0.76em; color: #93a0b4; max-width: 160px; }

.report {
  font-size: 0.82em; background: #060a10; border: 1px solid #222a38; border-radius: 8px;
  padding: 10px 12px; line-height: 1.5;
}
.report:empty { display: none; }
.report b { color: #ff9a3c; }
.report.good { border-color: #2e7d4f; }
.report.bad { border-color: #a33636; }

/* ---------- фильтры-комбобоксы ---------- */
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label { font-size: 0.72em; color: #6f8099; text-transform: uppercase; letter-spacing: .03em; }
.filter.has-arrow { position: relative; }
.filter.has-arrow::after {
  content: "▾"; position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  color: #6f8099; pointer-events: none; font-size: 0.8em;
}
.filter select {
  width: 100%; appearance: none; background: #0b0f17; color: #e8ecf4; border: 1px solid #2a3344;
  border-radius: 8px; padding: 8px 28px 8px 9px; font-size: 0.85em; cursor: pointer;
}
.filter select:focus { border-color: #ff9a3c; outline: none; }

/* ---------- числовые поля: ввод + слайдер ---------- */
.fields-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.fields-grid--1col { grid-template-columns: 1fr; }
.field-numeric label { display: block; font-size: 0.78em; color: #c3cde0; margin-bottom: 4px; }
.numeric-row { display: flex; align-items: center; gap: 8px; }
.numeric-row input[type=number] {
  width: 64px; flex: none; background: #060a10; color: #ff9a3c; border: 1px solid #2a3344;
  border-radius: 6px; padding: 4px 5px; font-size: 0.82em; font-weight: 600; text-align: right;
}
.numeric-row input[type=range] { flex: 1; accent-color: #ff9a3c; min-width: 0; }
.field-seed { width: 92px; }
.field-seed span { display: block; font-size: 0.72em; color: #93a0b4; margin-bottom: 3px; }
#seed { width: 100%; background: #0b0f17; color: #e8ecf4; border: 1px solid #2a3344; border-radius: 8px; padding: 8px 9px; font-size: 0.85em; }

/* ---------- свитчи ---------- */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; font-size: 0.84em; color: #c3cde0; }
.switch { position: relative; display: inline-block; width: 38px; height: 21px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: #2a3344; border-radius: 22px; cursor: pointer; transition: 0.15s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; background: #e8ecf4;
  border-radius: 50%; transition: 0.15s;
}
.switch input:checked + .slider { background: #ff9a3c; }
.switch input:checked + .slider::before { transform: translateX(17px); background: #141414; }

/* ---------- легенда поля ---------- */
#field-legend canvas { width: 100%; height: 14px; border-radius: 3px; display: block; }
#field-legend .legend-labels { display: flex; justify-content: space-between; font-size: 0.72em; color: #93a0b4; margin-top: 2px; }

/* ---------- модалки ---------- */
.modal-backdrop-custom {
  position: fixed; inset: 0; background: rgba(5,7,11,0.72); display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 20px;
}
.modal-backdrop-custom[hidden] { display: none; }
.modal-box {
  background: #11161f; border: 1px solid #222a38; border-radius: 14px; max-width: 520px; width: 100%;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-box.modal-xl { max-width: 860px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid #222a38; position: sticky; top: 0; background: #11161f;
}
.modal-head-left { display: flex; align-items: center; gap: 10px; }
.modal-head-icon {
  width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #ff9a3c, #ff5f6d);
  display: flex; align-items: center; justify-content: center; font-size: 1.1em; flex: none;
}
.modal-head-title { font-size: 1em; font-weight: 600; }
.modal-head-subtitle { font-size: 0.78em; color: #93a0b4; margin-top: 2px; }
.modal-close { background: none; border: none; color: #93a0b4; font-size: 1.4em; cursor: pointer; line-height: 1; }
.modal-close:hover { color: #e8ecf4; }
.modal-body-custom { padding: 16px 18px; font-size: 0.87em; line-height: 1.6; color: #c3cde0; }
.modal-body-custom h3 { font-size: 0.92em; color: #ff9a3c; margin: 18px 0 8px; }
.modal-body-custom h3:first-child { margin-top: 0; }
.modal-body-custom p { margin: 0 0 10px; }
.modal-body-custom .formula { text-align: center; font-size: 1em; color: #e8ecf4; background: #0b0f17; border-radius: 6px; padding: 8px; margin: 6px 0 12px; }
.modal-body-custom ul { margin: 0; padding-left: 20px; }
.modal-body-custom li { margin-bottom: 8px; }
.modal-note { color: #6f8099; font-size: 0.85em; }
.modal-footer { padding: 14px 18px; border-top: 1px solid #222a38; display: flex; justify-content: flex-end; position: sticky; bottom: 0; background: #11161f; }

/* ---------- мобильная адаптация ---------- */
@media (max-width: 860px) {
  .overlay-panel--left, .overlay-panel--right { width: min(300px, 85vw); }
  .topbar-filters { gap: 10px; }
  .topbar-filters .filter-group { min-width: 100px; }
}

/* формулы KaTeX и таблицы констант в окне описания */
.modal-body-custom .formula { overflow-x: auto; overflow-y: hidden; }
.modal-body-custom .formula .katex-display { margin: 0; }
.modal-body-custom .katex { color: #e8ecf4; font-size: 1.02em; }
.modal-body-custom table.const { width: 100%; border-collapse: collapse; margin: 6px 0 14px; font-size: 0.92em; }
.modal-body-custom table.const th { text-align: left; color: #93a0b4; font-weight: 600; border-bottom: 1px solid #2a3547; padding: 4px 8px; }
.modal-body-custom table.const td { border-bottom: 1px solid #1c2433; padding: 4px 8px; vertical-align: top; }
.modal-body-custom table.const td:first-child { white-space: nowrap; }
.modal-body-custom code { background: #0b0f17; padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
