: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: 304px minmax(520px, 1fr) 344px;
  height: 100vh;
  overflow: hidden;
}

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

.sidebar {
  border-right: 1px solid var(--line);
}

.inspector {
  border-left: 1px solid var(--line);
}

.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-bottom: 1px solid 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;
}

.container-grid {
  display: grid;
  gap: 8px;
}

.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-form {
  display: grid;
  gap: 9px;
}

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

.color-field {
  display: grid;
  grid-template-columns: 1fr 54px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.color-field input {
  width: 54px;
  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;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.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: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #10161b;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  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: 13px 14px;
  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: 4px 0 8px;
  font-size: 22px;
  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);
}

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

.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 {
  display: grid;
  gap: 8px;
}

.cargo-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-2);
}

.cargo-item header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cargo-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.cargo-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.cargo-item strong {
  font-size: 14px;
}

.cargo-item p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.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;
}

.cargo-editor {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.cargo-editor input {
  width: 100%;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--panel-3);
  color: var(--text);
  font-size: 12px;
}

.cargo-editor .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.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;
}

.cargo-item.dirty {
  border-color: rgba(232, 172, 66, 0.68);
  box-shadow: inset 3px 0 0 rgba(232, 172, 66, 0.8);
}

.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;
}

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

#jsonOutput {
  width: 100%;
  height: 260px;
  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(420px, 1fr);
  }

  .inspector {
    display: none;
  }
}

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

  .sidebar,
  .inspector {
    display: block;
    border: 0;
  }

  .workspace {
    min-height: 620px;
  }

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

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