:root {
  color-scheme: dark;
  --bg: oklch(18% 0.015 172);
  --panel: oklch(23% 0.014 172);
  --panel-2: oklch(27% 0.013 172);
  --line: oklch(36% 0.018 172);
  --text: oklch(91% 0.012 105);
  --muted: oklch(70% 0.014 116);
  --soft: oklch(58% 0.018 116);
  --accent: oklch(71% 0.13 151);
  --accent-2: oklch(74% 0.12 74);
  --danger: oklch(66% 0.16 29);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
}

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

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: oklch(29% 0.014 172);
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  transition: background 180ms cubic-bezier(0.22, 1, 0.36, 1), border-color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

button:hover:not(:disabled) {
  background: oklch(34% 0.016 172);
  border-color: oklch(48% 0.025 151);
}

button:disabled {
  cursor: not-allowed;
  color: oklch(52% 0.012 116);
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(520px, 1fr) 300px;
  min-height: 100vh;
}

.rail,
.inspector {
  background: var(--panel);
  border-color: var(--line);
  padding: 18px;
  overflow: auto;
}

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

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

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: oklch(17% 0.018 172);
  background: var(--accent);
  font-weight: 800;
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
}

.brand p,
.eyebrow,
label span,
.history-head,
.metrics dt {
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 18px;
}

.tab.is-active,
.tool.is-active {
  border-color: oklch(62% 0.09 151);
  background: oklch(36% 0.05 151);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.flow {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: oklch(19% 0.012 172);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px oklch(71% 0.13 151 / 0.18);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary {
  color: oklch(16% 0.018 151);
  border-color: oklch(73% 0.12 151);
  background: var(--accent);
  font-weight: 700;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: oklch(20% 0.013 172);
}

h2 {
  font-size: 20px;
  font-weight: 750;
  margin-top: 3px;
}

.actions,
.tool-row {
  display: flex;
  gap: 8px;
}

.stage {
  min-height: 0;
  padding: 18px;
}

.map-frame {
  position: relative;
  height: calc(100vh - 96px);
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: oklch(15% 0.012 172);
}

.empty-canvas,
.editor-stack {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.empty-canvas canvas {
  width: 100%;
  height: 100%;
}

.editor-stack.is-hidden,
.empty-canvas.is-hidden {
  display: none;
}

#variant-image,
#mask-canvas {
  position: absolute;
  max-width: calc(100% - 28px);
  max-height: calc(100% - 28px);
  object-fit: contain;
}

#variant-image {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

#mask-canvas {
  max-width: none;
  max-height: none;
  cursor: crosshair;
  touch-action: none;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.history-list,
.variant-list,
.opening-list,
.job-log {
  display: grid;
  gap: 8px;
}

.history-item,
.variant-item,
.opening-row,
.log-line {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: oklch(20% 0.012 172);
}

.history-item,
.variant-item {
  width: 100%;
  text-align: left;
  min-height: auto;
  padding: 10px;
}

.history-item strong,
.variant-item strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.history-item span,
.variant-item span,
.log-line {
  color: var(--muted);
  font-size: 12px;
}

.variant-item.is-active {
  border-color: var(--accent);
  background: oklch(28% 0.035 151);
}

.opening-row {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.opening-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.opening-fields label:last-child {
  grid-column: 1 / -1;
}

.opening-row label span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.opening-row b {
  color: var(--soft);
  font-weight: 650;
}

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

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

.inspector section + section {
  margin-top: 24px;
}

.inspector h3 {
  margin-bottom: 10px;
  font-size: 14px;
}

.metrics {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
}

.metrics div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.metrics dd {
  margin: 0;
  font-size: 12px;
  color: var(--text);
}

.log-line {
  padding: 8px 10px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 280px 1fr;
  }

  .inspector {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 18px;
  }

  .inspector section + section {
    margin-top: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .rail,
  .inspector {
    border: 0;
  }

  .topbar,
  .actions,
  .split,
  .inspector {
    display: grid;
    grid-template-columns: 1fr;
  }

  .map-frame {
    height: 68vh;
    min-height: 360px;
  }
}
