:root {
  color-scheme: dark;
  --bg: #101316;
  --panel: #171c20;
  --panel-2: #1f262b;
  --line: #313a40;
  --text: #eef3f5;
  --muted: #9dabb2;
  --accent: #35b779;
  --accent-2: #e4b64a;
  --danger: #f05d4f;
  --blue: #4097ff;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10161a;
  color: var(--text);
  padding: 8px;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #253039;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: #54707e;
  background: #2e3b45;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(420px, 1fr) 292px;
  height: 100vh;
  overflow: hidden;
}

.left-panel,
.right-panel {
  background: var(--panel);
  border-color: var(--line);
  padding: 18px;
  min-height: 0;
  overflow-y: auto;
}

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

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

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #315e4c;
  color: #dff7ea;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
}

#buildVersion {
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.35;
}

h2 {
  font-size: 13px;
  margin-bottom: 12px;
  color: #d5dde1;
  text-transform: uppercase;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  font-size: 12px;
  color: #d5dde1;
  text-transform: uppercase;
  letter-spacing: 0;
}

p,
span {
  color: var(--muted);
}

.panel-section,
.metric-block,
.legend-block {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.context-hidden {
  display: none !important;
}

.file-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.file-card input {
  width: 100%;
}

.file-card strong {
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.full-button {
  width: 100%;
  margin-top: 8px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.control-grid label,
.range-control,
.inline-control,
.single-control {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.control-grid input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10161a;
  color: var(--text);
  padding: 8px;
}

.single-control {
  margin-top: 10px;
}

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

.size-control-grid .single-control {
  min-width: 0;
}

.single-control input {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10161a;
  color: var(--text);
  padding: 8px;
}

.design-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin: 12px 0;
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
}

.design-summary strong {
  text-align: right;
  white-space: nowrap;
}

.print-settings {
  display: grid;
  gap: 12px;
  margin: 14px 0 10px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.print-settings .single-control {
  margin-top: 0;
}

.toggle-control {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

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

.toggle-control span {
  color: var(--text);
}

.reinforcement-settings {
  display: grid;
  gap: 10px;
  padding-left: 12px;
  border-left: 2px solid #496258;
}

.reinforcement-settings.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.control-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.primary-button {
  border-color: #48c489;
  background: #2a5d48;
}

.local-segmented {
  margin-top: 10px;
  margin-bottom: 4px;
}

.local-segmented button {
  flex: 1;
}

.range-control {
  grid-template-columns: 96px minmax(0, 1fr) 62px;
  align-items: center;
  margin-bottom: 12px;
}

.range-control input {
  width: 100%;
  min-width: 0;
}

.range-control strong {
  text-align: right;
  font-size: 12px;
}

.compact-range {
  margin: 0;
}

@media (max-width: 1180px) and (min-width: 981px) {
  .app-shell {
    grid-template-columns: 300px minmax(380px, 1fr) 260px;
  }

  .left-panel,
  .right-panel {
    padding: 14px;
  }

  .range-control {
    grid-template-columns: 86px minmax(0, 1fr) 58px;
  }
}

.viewport-shell {
  position: relative;
  height: 100vh;
  min-height: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #0d1114;
  background-size: 32px 32px;
  overflow: hidden;
}

#scene {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gizmoOverlay {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.top-toolbar {
  position: absolute;
  z-index: 5;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.top-toolbar > * {
  pointer-events: auto;
}

.segmented,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 28, 32, 0.92);
  backdrop-filter: blur(12px);
}

.segmented button {
  min-width: 86px;
}

.segmented button.active {
  border-color: #48c489;
  background: #2a5d48;
}

.toolbar-actions {
  gap: 12px;
}

.pair-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 28, 32, 0.92);
  font-size: 12px;
  font-weight: 700;
}

.pair-legend.hidden {
  display: none;
}

.pair-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.pair-legend span::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: #57db9f;
}

.pair-legend .right-side::before {
  background: #40b8e0;
}

.inline-control {
  grid-template-columns: auto 90px;
  align-items: center;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  max-width: 480px;
  margin: auto;
  text-align: center;
  padding: 24px;
}

.empty-state h2 {
  font-size: 28px;
  text-transform: none;
}

.empty-state.hidden {
  display: none;
}

.progress-overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(9, 12, 14, 0.48);
  pointer-events: none;
}

.progress-overlay.hidden {
  display: none;
}

.progress-card {
  width: min(420px, calc(100% - 40px));
  border: 1px solid #46525a;
  border-radius: 8px;
  background: rgba(23, 28, 32, 0.96);
  padding: 16px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.progress-head span {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 6px;
  background: #10161a;
  border: 1px solid var(--line);
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--accent), var(--accent-2));
  transition: width 120ms linear;
}

.progress-card p {
  margin-top: 10px;
  font-size: 13px;
}

.metric {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.metric strong {
  white-space: nowrap;
}

.legend-bar {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #071f47 0%, #1a61f2 22%, #0cc0df 42%, #f2d638 60%, #ff7d1f 80%, #eb1f1f 100%);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
}

.log-box {
  min-height: 92px;
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10161a;
  color: #c9d3d8;
  padding: 10px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

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

  .left-panel,
  .right-panel {
    border: 0;
    overflow: visible;
  }

  .viewport-shell {
    height: 560px;
    min-height: 560px;
  }

  .top-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    padding: 0;
    flex-flow: row wrap;
    justify-content: flex-start;
  }

  .top-toolbar .segmented {
    flex: 0 1 auto;
  }

  .segmented button {
    min-width: 72px;
  }

  .toolbar-actions {
    margin-left: auto;
  }
}
