:root {
  --bg: #070b10;
  --panel: rgba(13, 19, 26, 0.72);
  --panel-solid: #0d131a;
  --stroke: rgba(255, 255, 255, 0.09);
  --stroke-strong: rgba(255, 255, 255, 0.16);
  --text: #eef4fa;
  --muted: rgba(206, 220, 234, 0.6);
  --accent: #3fe0a4;
  --accent-dim: rgba(63, 224, 164, 0.14);
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#scene.is-dragging {
  cursor: grabbing;
}

/* ---------- общие панели ---------- */

.hud {
  position: fixed;
  z-index: 10;
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
}

/* ---------- шапка ---------- */

.hud-top-left {
  top: 22px;
  left: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, rgba(63, 224, 164, 0.24), rgba(63, 224, 164, 0.04));
  border: 1px solid rgba(63, 224, 164, 0.32);
  box-shadow: 0 0 30px rgba(63, 224, 164, 0.16);
}

.brand__mark svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.brand h1 span {
  color: var(--accent);
}

.brand__ver {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(110, 240, 170, 0.28);
  background: rgba(110, 240, 170, 0.1);
  color: var(--accent);
  font-size: 10px;
  font-style: normal;
  font-weight: 600;
  letter-spacing: 0.4px;
  vertical-align: 2px;
}

.brand p {
  margin: 2px 0 0;
  font-size: 11.5px;
  letter-spacing: 0.3px;
  color: var(--muted);
  text-transform: uppercase;
}

/* ---------- панель управления ---------- */

.hud-top-right {
  top: 22px;
  right: 24px;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.segmented button {
  flex: 1;
  padding: 8px 14px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.is-active {
  color: #04231a;
  background: linear-gradient(180deg, #4ceab1, #2ecb95);
  box-shadow: 0 4px 14px rgba(46, 203, 149, 0.3);
}

.toolbar__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* строка с подписью сверху — выбор культуры поля */
.toolbar__row--stack {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.toolbar__row--stack[hidden] {
  display: none;
}

/* четыре кнопки культуры теснее обычного сегмента */
.segmented--sm button {
  padding: 6px 8px;
  font-size: 11.5px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--stroke-strong);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn .i-play {
  display: none;
}

.icon-btn.is-paused .i-pause {
  display: none;
}

.icon-btn.is-paused .i-play {
  display: block;
  fill: currentColor;
  stroke: none;
}

.icon-btn#play-btn svg rect,
.icon-btn#play-btn svg path {
  fill: currentColor;
  stroke: none;
}

.speed {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  flex: 1;
  min-width: 168px;
}

/* кнопка смены дня и ночи */
.icon-btn--daynight svg {
  transition: transform 0.4s ease, color 0.3s ease;
}

.icon-btn--daynight.is-active {
  color: #ffd27d;
  border-color: rgba(255, 210, 125, 0.4);
  background: rgba(255, 210, 125, 0.12);
}

.icon-btn--daynight.is-active svg {
  animation: sunspin 18s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .icon-btn--daynight.is-active svg {
    animation: none;
  }
}

.speed__label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.speed__value {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 34px;
  text-align: right;
}

/* метка «ночью почти стоит» рядом со шкалой скорости */
.speed__pill {
  flex: 0 0 auto;
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  white-space: nowrap;
  padding: 0 6px;
  border-radius: 999px;
  color: #ffd27d;
  background: rgba(255, 210, 125, 0.14);
  border: 1px solid rgba(255, 210, 125, 0.3);
  font-variant-numeric: tabular-nums;
}

.speed__pill[hidden] {
  display: none;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
  cursor: pointer;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0b1116;
  box-shadow: 0 0 12px rgba(63, 224, 164, 0.6);
}

input[type='range']::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0b1116;
}

/* ---------- карточка оборудования ---------- */

.details {
  right: 24px;
  top: 50%;
  width: 300px;
  padding: 20px;
  transform: translateY(-50%);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: auto;
}

.details.is-hidden {
  opacity: 0;
  transform: translateY(-50%) translateX(18px);
  pointer-events: none;
}

.details__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.details__close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.details__tag {
  display: inline-block;
  padding: 4px 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(63, 224, 164, 0.3);
  border-radius: 999px;
}

.details h2 {
  margin: 12px 0 14px;
  font-size: 19px;
  font-weight: 620;
  line-height: 1.25;
}

.details__specs {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.details__specs li {
  padding: 5px 9px;
  font-size: 11px;
  color: rgba(226, 237, 247, 0.82);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--stroke);
  border-radius: 7px;
}

.details__desc {
  margin: 0 0 18px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}

.btn {
  width: 100%;
  padding: 11px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s, transform 0.12s, box-shadow 0.18s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.11);
}

.btn:active {
  transform: scale(0.985);
}

.btn--primary {
  color: #052117;
  background: linear-gradient(180deg, #4ceab1, #2ecb95);
  border-color: transparent;
  box-shadow: 0 8px 22px rgba(46, 203, 149, 0.28);
}

.btn--primary:hover {
  filter: brightness(1.06);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn--danger {
  color: #ffd9d9;
  background: rgba(255, 92, 92, 0.14);
  border-color: rgba(255, 92, 92, 0.35);
}

/* ---------- нижняя панель ---------- */

.hud-bottom {
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border-radius: 999px;
}

.chip {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

.chip b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.chip--total b {
  color: var(--accent);
}

/* базовый модуль платформы: питание и связь */
.chip--power {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  background: rgba(110, 240, 170, 0.09);
  border: 1px solid rgba(110, 240, 170, 0.18);
}

.chip--power svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  opacity: 0.9;
}

.chip--power b {
  color: var(--accent);
}

.statusbar__sep {
  width: 1px;
  height: 18px;
  background: var(--stroke);
  margin: 0 4px;
}

.link {
  font: inherit;
  font-size: 11.5px;
  font-weight: 550;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(63, 224, 164, 0.22);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.18s;
}

.link:hover {
  background: rgba(63, 224, 164, 0.24);
}

.hint {
  display: flex;
  gap: 7px;
  margin: 0;
  padding: 7px 16px;
  font-size: 11.5px;
  color: rgba(214, 226, 238, 0.72);
  background: rgba(8, 12, 17, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.hint__dot {
  opacity: 0.4;
}

/* ---------- призрак перетаскивания ---------- */

#drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  width: 152px;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -104%) rotate(-2.5deg) scale(0.92);
  transition: opacity 0.14s ease, transform 0.14s ease;
  filter: drop-shadow(0 24px 40px rgba(0, 0, 0, 0.6));
}

#drag-ghost.is-visible {
  opacity: 1;
  transform: translate(-50%, -104%) rotate(-2.5deg) scale(1);
}

#drag-ghost.is-invalid img {
  filter: grayscale(0.65) brightness(0.75);
}

#drag-ghost img {
  display: block;
  width: 100%;
  border-radius: 14px;
}

/* ---------- тост ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 50;
  padding: 10px 18px;
  font-size: 12.5px;
  font-weight: 550;
  color: #eafff6;
  background: rgba(12, 40, 30, 0.9);
  border: 1px solid rgba(63, 224, 164, 0.35);
  border-radius: 999px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  max-width: min(560px, 86vw);
  text-align: center;
}

#toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast.is-error {
  background: rgba(60, 16, 16, 0.92);
  border-color: rgba(255, 92, 92, 0.45);
  color: #ffe9e9;
  white-space: normal;
  max-width: 70vw;
}

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

@media (max-width: 900px) {
  .hud-top-left {
    top: 12px;
    left: 12px;
  }

  .brand p {
    display: none;
  }

  .hud-top-right {
    top: 62px;
    right: 12px;
  }

  .toolbar {
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    width: 244px;
    max-width: calc(100vw - 24px);
  }

  .segmented,
  .segmented button {
    min-width: 0;
  }

  .segmented button {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .segmented button {
    padding: 7px 6px;
    font-size: 11px;
  }

  .speed {
    min-width: 0;
    padding: 0 4px;
  }

  .speed__label {
    display: none;
  }

  .details {
    right: 14px;
    left: 14px;
    top: auto;
    bottom: 140px;
    width: auto;
    max-height: 46vh;
    overflow-y: auto;
    transform: none;
  }

  .details.is-hidden {
    transform: translateY(14px);
  }

  .hud-bottom {
    bottom: 12px;
    width: calc(100% - 24px);
    align-items: stretch;
  }

  .statusbar {
    max-width: 100%;
  }

  .statusbar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 16px;
  }

  .statusbar__sep {
    display: none;
  }

  .chip {
    font-size: 10.5px;
  }

  .hint {
    display: none;
  }
}

/* ---------- Интеграция с сайтом «Проксима» ---------- */
.brand-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
  padding: 5px 11px 5px 9px;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-decoration: none;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.brand-back:hover {
  color: var(--text);
  border-color: var(--accent);
}

.filewarn {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 28px;
  background: #070b10;
}

.filewarn[hidden] {
  display: none;
}

.filewarn__inner {
  max-width: 720px;
  text-align: center;
}

.filewarn img {
  width: 100%;
  max-height: 46vh;
  object-fit: cover;
  border: 1px solid var(--stroke);
  border-radius: 14px;
}

.filewarn h2 {
  margin: 22px 0 8px;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.filewarn p {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.filewarn code {
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 12.5px;
}

.filewarn a {
  color: var(--accent);
}

@media (max-width: 640px) {
  .brand-back {
    margin-bottom: 10px;
  }
}

/* На узких экранах панель управления уходит под бренд-блок,
   иначе ссылка «← Проксима» и заголовок перекрываются тулбаром */
@media (max-width: 640px) {
  .hud-top-left {
    top: 10px;
    left: 10px;
  }

  .hud-top-right {
    top: 100px;
    right: 10px;
    left: 10px;
  }

  .hud-top-right .toolbar {
    width: auto;
    max-width: none;
  }

  .hud-bottom {
    bottom: 10px;
    width: calc(100% - 20px);
  }
}
