:root {
  color-scheme: dark;
  --bg: #0b0f12;
  --panel: #12181d;
  --panel-2: #172027;
  --panel-3: #0f1519;
  --line: #26333c;
  --text: #e5edf2;
  --muted: #91a0aa;
  --soft: #5f707b;
  --cyan: #27c4d9;
  --amber: #e8ac42;
  --green: #45c47f;
  --red: #ef5b5b;
  --blue: #6da8ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
  overflow: hidden;
}

.sidebar,
.inspector {
  min-width: 0;
  overflow: auto;
  background: var(--panel);
  border-color: var(--line);
}

.sidebar {
  display: block;
  grid-row: 1 / 3;
  border-right: 1px solid var(--line);
  border-bottom: 0;
}

.inspector {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) minmax(300px, 0.42fr) minmax(220px, 0.28fr);
  max-height: 270px;
  border-top: 1px solid var(--line);
  border-left: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(39, 196, 217, 0.55);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(39, 196, 217, 0.18), rgba(232, 172, 66, 0.14));
  color: var(--cyan);
  font-size: 13px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.panel-section {
  padding: 16px;
  border-right: 0;
  border-bottom: 1px solid var(--line);
}

.step-section {
  position: relative;
}

.step-section + .step-section::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 28px;
  width: 1px;
  height: 16px;
  background: var(--line);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-head b {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  border-radius: 50%;
  background: rgba(39, 196, 217, 0.13);
  color: var(--cyan);
  font-size: 10px;
}

summary.section-head {
  cursor: pointer;
  list-style: none;
}

summary.section-head::-webkit-details-marker {
  display: none;
}

.summary-hint {
  color: var(--soft);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.container-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  max-height: 232px;
  overflow: auto;
}

.container-card {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
}

.container-card.active {
  border-color: var(--cyan);
  background: rgba(39, 196, 217, 0.1);
}

.container-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
}

.container-card span {
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 13px;
}

.input-unit {
  display: grid;
  grid-template-columns: 70px 38px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-3);
}

.input-unit input,
.cargo-form input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: var(--panel-3);
  color: var(--text);
}

.input-unit input {
  width: 100%;
  padding: 8px 9px;
  text-align: right;
}

.input-unit small {
  color: var(--soft);
  font-size: 11px;
}

.cargo-drawer[open] .cargo-form,
.custom-space-section details[open] .custom-space-grid {
  animation: slideDown 0.18s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cargo-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 8px;
}

.cargo-form .primary-button,
.cargo-form .check-row {
  grid-column: 1 / -1;
}

.cargo-form > input,
.form-grid input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.color-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.color-field input {
  width: 100%;
  height: 36px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-3);
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-2);
}

.primary-button {
  padding: 10px 12px;
  border-color: rgba(39, 196, 217, 0.56);
  background: #1a6570;
  color: white;
  font-weight: 800;
}

.ghost-button {
  min-width: 44px;
  height: 36px;
  padding: 0 12px;
}

.danger-action {
  border-color: rgba(239, 91, 91, 0.58);
  color: #ffb3b3;
}

.danger-action.active,
.ghost-button.active,
.icon-button.active {
  border-color: rgba(69, 196, 127, 0.7);
  background: rgba(69, 196, 127, 0.14);
  color: #b7ffd7;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
  background: #0b1014;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #10161b;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.metrics-strip article {
  min-width: 0;
  padding: 10px 12px;
  background: var(--panel);
}

.metrics-strip article.cog-danger {
  background: linear-gradient(180deg, rgba(239, 91, 91, 0.18), var(--panel));
}

.metrics-strip span,
.metrics-strip small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metrics-strip strong {
  display: block;
  margin: 3px 0 7px;
  font-size: 18px;
  letter-spacing: 0;
}

.meter {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #26313a;
}

.meter i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  transition: width 0.25s ease;
}

.viewer-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.three-mount {
  position: absolute;
  inset: 0;
  display: none;
  cursor: grab;
}

.three-mount:active {
  cursor: grabbing;
}

.three-mount canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#loadCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    #0a0f13;
  background-size: 38px 38px;
}

.viewer-tools,
.legend {
  position: absolute;
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(38, 51, 60, 0.9);
  border-radius: 8px;
  background: rgba(18, 24, 29, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.viewer-tools {
  top: 12px;
  left: 12px;
  align-items: center;
}

.legend {
  right: 12px;
  bottom: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.dimension-note {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: min(520px, calc(100% - 24px));
  padding: 8px 10px;
  border: 1px solid rgba(38, 51, 60, 0.9);
  border-radius: 8px;
  background: rgba(18, 24, 29, 0.86);
  color: var(--muted);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 2px;
  vertical-align: -1px;
}

.dot.box {
  background: var(--cyan);
}

.dot.dead {
  background: rgba(239, 91, 91, 0.72);
}

.dot.cog {
  border-radius: 50%;
  background: var(--amber);
}

.dot.cog-before {
  border-radius: 50%;
  background: rgba(239, 91, 91, 0.46);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.cargo-list {
  overflow: auto;
  max-height: 198px;
}

.cargo-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

.cargo-table th,
.cargo-table td {
  padding: 6px;
  border-bottom: 1px solid rgba(38, 51, 60, 0.7);
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  vertical-align: middle;
}

.cargo-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  color: var(--soft);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cargo-table input[type="text"],
.cargo-table input[type="number"] {
  width: 100%;
  min-width: 0;
  padding: 6px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  outline: 0;
  background: rgba(15, 21, 25, 0.82);
  color: var(--text);
  font-size: 11px;
}

.cargo-table input[type="color"] {
  width: 28px;
  height: 24px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-3);
}

.cargo-table input[type="checkbox"] {
  width: 15px;
  height: 15px;
}

.cargo-row.dirty td {
  background: rgba(232, 172, 66, 0.08);
}

.cargo-row .mini-button {
  width: 24px;
  height: 24px;
}

.swatch {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 3px;
  flex: 0 0 auto;
}

.mini-button {
  border: 0;
  border-radius: 6px;
  background: #26333c;
  color: var(--muted);
  width: 26px;
  height: 26px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.edit-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.edit-field span {
  line-height: 1;
}

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--muted);
  font-size: 11px;
}

.tag.warn {
  border-color: rgba(239, 91, 91, 0.55);
  color: #ff9a9a;
}

.recommendation {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  max-height: 194px;
  overflow: auto;
}

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

.mini-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}

.viewer-toggle {
  padding-left: 4px;
  white-space: nowrap;
}

.import-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.file-button {
  display: inline-grid;
  place-items: center;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.file-button input {
  display: none;
}

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

.custom-space-grid .primary-button {
  grid-column: 1 / -1;
}

.recommendation strong {
  color: var(--text);
}

.result-card,
.result-alert {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-2);
}

.result-card span {
  display: block;
  margin-bottom: 4px;
  color: var(--soft);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 15px;
}

.result-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.result-card.ok {
  border-color: rgba(69, 196, 127, 0.45);
  background: rgba(69, 196, 127, 0.08);
}

.result-card.warn {
  border-color: rgba(232, 172, 66, 0.45);
  background: rgba(232, 172, 66, 0.08);
}

.result-card.danger,
.result-alert {
  border-color: rgba(239, 91, 91, 0.5);
  background: rgba(239, 91, 91, 0.09);
  color: #ffb3b3;
}

#jsonOutput {
  width: 100%;
  height: 190px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--panel-3);
  color: #bed7e4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(14px);
  padding: 10px 14px;
  border: 1px solid rgba(39, 196, 217, 0.45);
  border-radius: 8px;
  background: rgba(18, 24, 29, 0.94);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: 0.22s ease;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

  .inspector {
    grid-template-columns: 1fr;
    max-height: 360px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(560px, 1fr) auto;
    overflow: visible;
  }

  .sidebar {
    display: block;
    grid-row: auto;
    border: 0;
  }

  .inspector {
    display: block;
    max-height: none;
    border: 0;
  }

  .workspace {
    min-height: 620px;
  }

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
