:root {
  color-scheme: dark;
  --bg: #070a10;
  --panel: #101722;
  --panel-strong: #151f2c;
  --line: #2a3545;
  --text: #edf3fb;
  --muted: #99a9ba;
  --accent: #58c4ff;
  --accent-strong: #1c8fd0;
  --danger: #d95c68;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  width: 100vw;
  height: 100dvh;
  min-height: 540px;
  background: #06090f;
}

.viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  touch-action: none;
}

#scene-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #03050a;
}

.hud {
  position: absolute;
  left: 16px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 32px);
  padding: 10px 12px;
  border: 1px solid rgba(105, 132, 162, 0.32);
  border-radius: var(--radius);
  background: rgba(8, 13, 22, 0.72);
  color: var(--muted);
  backdrop-filter: blur(10px);
}

.hud strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  line-height: 1.1;
}

.hud span {
  font-size: 12px;
}

.hud-top {
  top: 16px;
  justify-content: space-between;
}

.hud-bottom {
  bottom: 16px;
  min-height: 42px;
  font-size: 13px;
}

.selection-trigger {
  left: auto;
  right: 16px;
  justify-content: flex-start;
  width: min(720px, calc(100% - 32px));
  min-height: 46px;
  text-align: left;
}

.body-list {
  position: absolute;
  right: 16px;
  bottom: 72px;
  z-index: 5;
  width: min(340px, calc(100% - 32px));
  max-height: min(460px, calc(100% - 120px));
  overflow: hidden;
  border: 1px solid rgba(105, 132, 162, 0.42);
  border-radius: var(--radius);
  background: rgba(10, 16, 26, 0.94);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(12px);
}

.body-list-title {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.body-list-items {
  display: grid;
  max-height: min(390px, calc(100dvh - 190px));
  overflow-y: auto;
  padding: 6px;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.body-list-item {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 48px;
  padding: 7px 9px;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.body-list-item.is-selected {
  border-color: rgba(88, 196, 255, 0.5);
  background: rgba(88, 196, 255, 0.12);
}

.body-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.body-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.panel-toggle {
  display: none;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

.panel-section {
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.section-title,
.vector-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.transport label,
.properties label,
.storage label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.transport label {
  grid-column: 1 / -1;
}

.transport label span {
  text-transform: none;
}

button,
select,
input,
textarea {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--text);
}

button {
  padding: 0 14px;
  cursor: pointer;
  touch-action: manipulation;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

button.primary {
  border-color: #37a7e9;
  background: var(--accent-strong);
}

button.danger {
  border-color: #9b3f4a;
  background: #3a1a22;
  color: #ffd7dc;
}

select,
input {
  width: 100%;
  padding: 0 10px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

input[type="color"] {
  padding: 5px;
}

.actions,
.storage-row {
  grid-template-columns: 1fr 1fr;
}

.grid-2,
.grid-3,
.storage-row {
  display: grid;
  gap: 8px;
}

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

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.properties[aria-disabled="true"] {
  opacity: 0.55;
}

textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  padding: 10px;
  color: #cfe3f6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .control-panel {
    position: relative;
    max-height: 43dvh;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

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

  .panel-toggle {
    display: block;
    min-height: 40px;
  }

  .hud-top {
    right: 16px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    min-height: 480px;
  }

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

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

  .hud-bottom {
    bottom: 10px;
  }

  .selection-trigger {
    left: 10px;
    right: 10px;
    width: auto;
  }

  .body-list {
    right: 10px;
    bottom: 66px;
    width: calc(100% - 20px);
  }

  .control-panel {
    max-height: 48dvh;
    padding: 10px;
  }

  .transport,
  .actions,
  .storage-row {
    grid-template-columns: 1fr 1fr;
  }
}
