:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #111821;
  --panel-soft: #182230;
  --line: #2a3948;
  --text: #eef5fb;
  --muted: #9cabba;
  --accent: #52c7a6;
  --amber: #f0b85c;
  --red: #ef6f68;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(82, 199, 166, 0.14), transparent 28rem),
    linear-gradient(135deg, #07090d 0%, #101722 52%, #17141b 100%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input {
  font: inherit;
}

.gravity-3d {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.scene-panel,
.control-panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(11, 16, 23, 0.86);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

.scene-panel {
  position: relative;
  overflow: hidden;
  min-height: 640px;
}

.scene-mount,
.scene-mount canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 640px;
  touch-action: none;
}

.scene-header {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  pointer-events: none;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  color: var(--accent);
  font-size: clamp(1.2rem, 2.1vw, 2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
}

h2 {
  color: #dce8f3;
  font-size: 1rem;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(7, 9, 13, 0.86);
  color: var(--muted);
  font-weight: 800;
}

.loading.is-hidden {
  display: none;
}

.impact-meter {
  position: absolute;
  z-index: 3;
  left: 20px;
  right: 20px;
  bottom: 20px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 92px;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  padding: 12px;
  background: rgba(7, 9, 13, 0.72);
}

.impact-meter span,
.readouts span,
.range-control span,
.world-button span {
  color: var(--muted);
  font-size: 0.82rem;
}

.impact-meter strong {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.impact-bar {
  overflow: hidden;
  height: 12px;
  border-radius: 999px;
  background: #263241;
}

.impact-bar i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--amber), var(--red));
  transition: width 120ms linear;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow: auto;
  max-height: calc(100vh - 36px);
  padding: 20px;
}

.world-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.world-button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.world-button::before {
  content: "";
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: var(--world-color);
  box-shadow: 0 0 18px var(--world-glow);
}

.world-button strong,
.world-button span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.world-button.is-active {
  border-color: var(--accent);
  background: #18332f;
}

.controls {
  display: grid;
  gap: 15px;
}

.object-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.object-toggle label {
  position: relative;
}

.object-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.object-toggle span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: #dce8f3;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
}

.object-toggle input:checked + span {
  border-color: var(--accent);
  background: #18332f;
  color: var(--text);
}

.range-control {
  display: grid;
  gap: 8px;
}

.range-control span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

output {
  color: #dce8f3;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #dce8f3;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.readouts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.readouts div {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 10px;
  background: rgba(24, 34, 48, 0.8);
}

.readouts strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: auto;
}

.button-row button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: #263443;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.button-row button:first-child {
  background: var(--accent);
  color: #05120f;
}

.button-row button:hover,
.world-button:hover {
  filter: brightness(1.08);
}

@media (max-width: 1000px) {
  .gravity-3d {
    grid-template-columns: 1fr;
  }

  .control-panel {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .gravity-3d {
    padding: 10px;
  }

  .scene-header {
    flex-direction: column;
    padding: 14px 12px;
  }

  .impact-meter {
    left: 12px;
    right: 12px;
    grid-template-columns: 1fr;
  }

  .impact-meter strong {
    text-align: left;
  }

  .readouts,
  .object-toggle,
  .button-row {
    grid-template-columns: 1fr;
  }

  .scene-panel,
  .scene-mount,
  .scene-mount canvas {
    min-height: 660px;
  }
}
