:root {
  color-scheme: dark;
  font-family:
    Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-synthesis: none;
  --ink: #f5f5f0;
  --muted: rgba(231, 235, 235, 0.62);
  --muted-strong: rgba(241, 243, 240, 0.78);
  --line: rgba(255, 255, 255, 0.13);
  --line-strong: rgba(255, 255, 255, 0.21);
  --panel: rgba(8, 16, 22, 0.76);
  --panel-solid: #0b141b;
  --accent: #c8a66a;
  --accent-soft: rgba(200, 166, 106, 0.17);
  --success: #89bc9b;
  --danger: #e49b8f;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #071018;
}

body {
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

button,
select,
input {
  font: inherit;
}

button,
select,
a,
label {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
a:focus-visible,
input:focus-visible + .switch {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

button {
  color: inherit;
}

svg {
  display: block;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 440px;
  isolation: isolate;
  background:
    radial-gradient(circle at 72% 42%, rgba(159, 176, 174, 0.17), transparent 36%),
    linear-gradient(136deg, #071017 0%, #101d24 50%, #071018 100%);
  transition: background 500ms ease;
}

.app[data-atmosphere="natural"] {
  background:
    radial-gradient(circle at 74% 34%, rgba(229, 226, 206, 0.27), transparent 40%),
    linear-gradient(136deg, #182128 0%, #354044 50%, #111b22 100%);
}

.app[data-atmosphere="noturno"] {
  background:
    radial-gradient(circle at 73% 48%, rgba(74, 94, 126, 0.2), transparent 35%),
    radial-gradient(circle at 82% 74%, rgba(188, 143, 75, 0.12), transparent 24%),
    linear-gradient(136deg, #03070d 0%, #091221 50%, #03070d 100%);
}

.stage,
#scene-canvas,
.stage-glow,
.stage-vignette,
.labels-layer {
  position: absolute;
  inset: 0;
}

.stage {
  overflow: hidden;
}

#scene-canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#scene-canvas:active {
  cursor: grabbing;
}

.stage-glow {
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(2, 7, 11, 0.38), transparent 29%, transparent 82%, rgba(2, 7, 11, 0.2)),
    linear-gradient(0deg, rgba(2, 6, 10, 0.28), transparent 23%);
  mix-blend-mode: multiply;
}

.stage-vignette {
  pointer-events: none;
  box-shadow: inset 0 0 180px rgba(0, 0, 0, 0.28);
}

.topbar {
  position: absolute;
  z-index: 30;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 16px clamp(18px, 3.2vw, 48px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(5, 12, 17, 0.72), rgba(5, 12, 17, 0.13));
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(200, 166, 106, 0.42);
  border-radius: 50%;
  background: rgba(200, 166, 106, 0.08);
}

.brand-mark svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.45;
}

.brand-copy {
  display: grid;
  gap: 3px;
}

.brand-copy strong {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.brand-copy small {
  color: var(--muted);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.27em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.model-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 7px;
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(200, 166, 106, 0.12);
  animation: status-pulse 1.6s ease-in-out infinite;
}

.model-status.is-ready .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(137, 188, 155, 0.12);
  animation: none;
}

.model-status.is-error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(228, 155, 143, 0.13);
  animation: none;
}

@keyframes status-pulse {
  50% {
    opacity: 0.44;
    transform: scale(0.85);
  }
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(8, 16, 22, 0.48);
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background 180ms ease,
    transform 180ms ease;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

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

.icon-contract {
  display: none;
}

:fullscreen .icon-expand {
  display: none;
}

:fullscreen .icon-contract {
  display: block;
}

.control-panel {
  position: absolute;
  z-index: 25;
  top: 101px;
  left: clamp(18px, 3.2vw, 48px);
  width: min(296px, calc(100vw - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(120%);
}

.panel-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 15px 17px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.17em;
}

.panel-toggle svg,
.select-wrap > svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
  transition: transform 200ms ease;
}

.panel-content {
  padding: 5px 20px 19px;
}

.control-section {
  padding: 18px 0 20px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 16px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.section-value {
  color: var(--accent);
  font-size: 8px;
  letter-spacing: 0.13em;
}

.view-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.view-button {
  display: grid;
  min-width: 0;
  gap: 7px;
  justify-items: center;
  padding: 10px 3px 8px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  cursor: pointer;
  transition:
    color 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.view-button:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.view-button.is-active {
  border-color: rgba(200, 166, 106, 0.39);
  background: var(--accent-soft);
  color: var(--ink);
}

.view-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.25;
}

.view-button span {
  overflow: hidden;
  width: 100%;
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.select-wrap select {
  width: 100%;
  height: 43px;
  padding: 0 39px 0 34px;
  border: 1px solid var(--line);
  border-radius: 2px;
  appearance: none;
  background: rgba(255, 255, 255, 0.035);
  color: var(--ink);
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.025em;
}

.select-wrap select option {
  background: var(--panel-solid);
  color: var(--ink);
}

.select-wrap > svg {
  position: absolute;
  right: 13px;
  pointer-events: none;
  color: var(--muted);
}

.atmosphere-swatch {
  position: absolute;
  z-index: 1;
  left: 13px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #c8a66a;
  box-shadow: 0 0 0 3px rgba(200, 166, 106, 0.11);
  pointer-events: none;
}

.app[data-atmosphere="natural"] .atmosphere-swatch {
  background: #d9dbc8;
  box-shadow: 0 0 0 3px rgba(217, 219, 200, 0.11);
}

.app[data-atmosphere="noturno"] .atmosphere-swatch {
  background: #788bae;
  box-shadow: 0 0 0 3px rgba(120, 139, 174, 0.12);
}

.control-section-options {
  padding: 8px 0;
}

.switch-row {
  position: relative;
  display: flex;
  min-height: 57px;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  cursor: pointer;
}

.switch-row + .switch-row {
  border-top: 1px solid rgba(255, 255, 255, 0.055);
}

.switch-copy {
  display: grid;
  gap: 3px;
}

.switch-copy > span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.switch-copy small {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.015em;
}

.switch-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 31px;
  height: 17px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  transition:
    border-color 200ms ease,
    background 200ms ease;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted-strong);
  content: "";
  transition:
    transform 200ms ease,
    background 200ms ease;
}

.switch-row input:checked + .switch {
  border-color: rgba(200, 166, 106, 0.55);
  background: rgba(200, 166, 106, 0.17);
}

.switch-row input:checked + .switch::after {
  background: var(--accent);
  transform: translateX(14px);
}

.interaction-hint {
  display: flex;
  align-items: center;
  gap: 11px;
  padding-top: 17px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.interaction-hint svg {
  flex: 0 0 auto;
  width: 25px;
  height: 25px;
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.1;
}

.interaction-hint strong {
  color: var(--muted-strong);
  font-weight: 500;
}

.presentation-caption {
  position: absolute;
  z-index: 20;
  right: clamp(18px, 3.2vw, 48px);
  bottom: 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, 0.42);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.18em;
}

.caption-line {
  width: 42px;
  height: 1px;
  background: rgba(255, 255, 255, 0.23);
}

.labels-layer {
  z-index: 10;
  pointer-events: none;
}

.scene-label {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 7px;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 180ms ease;
  will-change: transform;
}

.scene-label.is-visible {
  opacity: 1;
}

.scene-label-dot {
  width: 7px;
  height: 7px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(200, 166, 106, 0.19);
}

.scene-label-text {
  max-width: 155px;
  overflow: hidden;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 2px;
  background: rgba(5, 12, 17, 0.82);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
  color: rgba(255, 255, 255, 0.89);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.loading-overlay {
  position: absolute;
  z-index: 100;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background:
    radial-gradient(circle at 50% 42%, rgba(46, 63, 70, 0.46), transparent 36%),
    #071018;
  transition:
    opacity 650ms ease,
    visibility 650ms ease;
}

.loading-overlay::before {
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  content: "";
  pointer-events: none;
}

.loading-overlay.is-ready {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loading-brand {
  display: grid;
  width: 70px;
  height: 70px;
  margin-bottom: 23px;
  place-items: center;
  border: 1px solid rgba(200, 166, 106, 0.38);
  border-radius: 50%;
  background: rgba(200, 166, 106, 0.06);
}

.loading-brand svg {
  width: 48px;
  height: 48px;
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.3;
  animation: logo-breathe 2s ease-in-out infinite;
}

@keyframes logo-breathe {
  50% {
    opacity: 0.5;
    transform: scale(0.95);
  }
}

.loading-kicker,
.dialog-kicker {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.26em;
}

.loading-overlay h1 {
  margin: 0 0 32px;
  font-size: clamp(20px, 3vw, 31px);
  font-weight: 300;
  letter-spacing: -0.025em;
  text-align: center;
}

.progress-track {
  width: min(360px, 72vw);
  height: 1px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.13);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(200, 166, 106, 0.42);
  transition: width 220ms ease;
}

.loading-meta {
  display: flex;
  width: min(360px, 72vw);
  justify-content: space-between;
  margin-top: 11px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.07em;
}

.load-error {
  width: min(520px, 86vw);
  margin-top: 22px;
  text-align: center;
}

.load-error p {
  margin: 0 0 14px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.55;
}

.load-error button,
.dialog-primary {
  min-height: 42px;
  padding: 0 21px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--accent);
  color: #111314;
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.15em;
}

.load-error button:hover,
.dialog-primary:hover {
  filter: brightness(1.07);
}

.load-error code {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 16px;
  color: rgba(255, 255, 255, 0.48);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 9px;
}

.toast {
  position: absolute;
  z-index: 60;
  left: 50%;
  bottom: 30px;
  max-width: min(420px, calc(100vw - 34px));
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: rgba(8, 16, 22, 0.88);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  color: var(--muted-strong);
  font-size: 10px;
  letter-spacing: 0.035em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition:
    opacity 200ms ease,
    transform 200ms ease;
  backdrop-filter: blur(10px);
}

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

.help-dialog {
  width: min(650px, calc(100vw - 34px));
  max-height: calc(100vh - 34px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: rgba(9, 17, 23, 0.97);
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.52);
  color: var(--ink);
  backdrop-filter: blur(24px);
}

.help-dialog::backdrop {
  background: rgba(1, 5, 8, 0.72);
  backdrop-filter: blur(5px);
}

.help-dialog form {
  padding: clamp(23px, 5vw, 43px);
}

.help-dialog header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 31px;
}

.help-dialog h2 {
  margin: 0;
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 300;
  letter-spacing: -0.03em;
}

.dialog-close {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.dialog-close svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.5;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.help-grid > div {
  display: grid;
  min-height: 130px;
  align-content: start;
  gap: 8px;
  padding: 18px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.help-index {
  color: var(--accent);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.15em;
}

.help-grid strong {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.help-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.dialog-note {
  margin: 20px 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

kbd {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  margin: 0 2px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  font-family: inherit;
  font-size: 9px;
}

.dialog-primary {
  width: 100%;
}

noscript {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  padding: 30px;
  place-items: center;
  background: #071018;
  color: #fff;
  text-align: center;
}

@media (max-width: 760px) {
  .topbar {
    min-height: 67px;
    padding: 12px 15px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-copy strong {
    font-size: 10px;
  }

  .brand-copy small,
  .model-status {
    display: none;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .control-panel {
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: calc(100% - 90px);
    overflow: auto;
  }

  .panel-toggle {
    display: flex;
  }

  .control-panel.is-collapsed .panel-toggle svg {
    transform: rotate(180deg);
  }

  .control-panel.is-collapsed .panel-content {
    display: none;
  }

  .panel-content {
    padding: 0 17px 16px;
  }

  .control-section {
    padding: 14px 0;
  }

  .control-section-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 13px;
    padding: 8px 0;
  }

  .switch-row {
    min-height: 50px;
  }

  .switch-row + .switch-row {
    border-top: 0;
  }

  .switch-copy small,
  .interaction-hint,
  .presentation-caption {
    display: none;
  }

  .help-grid {
    grid-template-columns: 1fr;
  }

  .help-grid > div {
    min-height: 0;
  }

  .toast {
    bottom: 83px;
  }
}

@media (max-width: 430px) {
  .brand-copy small {
    display: none;
  }

  .view-grid {
    gap: 4px;
  }

  .view-button {
    padding-inline: 1px;
  }

  .loading-overlay::before {
    inset: 10px;
  }
}

@media (max-height: 650px) and (min-width: 761px) {
  .control-panel {
    top: 86px;
    max-height: calc(100vh - 104px);
    overflow: auto;
  }

  .control-section {
    padding-top: 13px;
    padding-bottom: 14px;
  }

  .interaction-hint {
    display: none;
  }
}

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