:root {
  --bg: #ede6dc;
  --surface: #fffaf3;
  --surface-2: #f8efe4;
  --ink: #201a16;
  --muted: #6f6257;
  --line: #d8cab9;
  --line-strong: #bca994;
  --clay: #b65b38;
  --clay-dark: #81371f;
  --teal: #1f766f;
  --teal-dark: #104f4b;
  --gold: #a17a18;
  --danger: #973516;
  --ok-bg: #eaf7f4;
  --warn-bg: #fff0e6;
  --shadow: 0 18px 45px rgba(42, 29, 16, 0.12);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 34px;
  padding: 7px 10px;
  background: #fffdf9;
  color: var(--ink);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

button:hover {
  border-color: var(--line-strong);
}

button.primary {
  border-color: var(--teal-dark);
  background: var(--teal);
  color: #fff;
  font-weight: 700;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: 66px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 243, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--clay), var(--gold));
  color: #fff;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.05;
}

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

.top-actions {
  flex-shrink: 0;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(320px, 1fr) 340px;
  gap: 10px;
  padding: 10px;
}

.pane {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 243, 0.92);
  box-shadow: var(--shadow);
}

.panel {
  overflow-y: auto;
  padding: 10px;
}

/* Collapsible parameter groups (left panel) */

details.group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf9;
  margin-bottom: 8px;
}

details.group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .05em;
  user-select: none;
  list-style: none;
}

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

details.group summary::after {
  content: "▸";
  color: var(--muted);
  transition: transform 140ms ease;
}

details.group[open] summary::after {
  transform: rotate(90deg);
}

details.group summary .badge {
  margin-left: auto;
  border-radius: 999px;
  background: var(--clay);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 2px 8px;
}

.group-body {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid #eadfd3;
}

.group-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.recipe-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.recipe-grid button {
  min-height: 38px;
  font-size: 13px;
}

/* Center stage */

.stage {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 10px;
}

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

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf9;
  padding: 8px 10px;
}

.metric span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewport-wrap {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #efe8dc;
}

#viewport {
  position: absolute;
  inset: 0;
}

#viewport canvas {
  display: block;
  cursor: grab;
  touch-action: none;
}

#viewport canvas:active {
  cursor: grabbing;
}

.viewport-msg {
  margin: 0;
  padding: 24px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.view-buttons {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
}

.view-buttons button {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
  background: rgba(255, 253, 249, 0.9);
}

.status-line,
.export-status {
  min-height: 26px;
  color: var(--muted);
  font-size: 13px;
}

.export-status a {
  color: var(--teal-dark);
  font-weight: 800;
}

.pill {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 3px 9px;
  margin: 1px 6px 1px 0;
  color: var(--muted);
  font-size: 12px;
}

.pill.warn {
  color: var(--danger);
  border-color: #dfa985;
  background: var(--warn-bg);
}

.pill.ok {
  color: var(--teal-dark);
  border-color: #9bc8c1;
  background: var(--ok-bg);
}

/* Right panel: cross-sections */

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

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

#outlineCanvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fffdf9;
}

.sections-panel {
  display: grid;
  gap: 8px;
  align-content: start;
}

.section-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 8px;
}

.section-tools span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.section-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf9;
  padding: 8px;
}

.section-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #eadfd3;
}

.section-card-head strong {
  font-size: 14px;
}

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

.section-card-head button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

/* Controls */

.control {
  display: grid;
  grid-template-columns: minmax(88px, 118px) minmax(0, 1fr) minmax(52px, auto);
  gap: 8px;
  align-items: center;
}

.control.no-value {
  grid-template-columns: minmax(88px, 118px) minmax(0, 1fr);
}

.control label {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
}

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

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 6px 8px;
}

.number-override {
  width: 74px;
  min-width: 64px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Responsive */

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app {
    min-height: 100dvh;
    height: auto;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "stage stage"
      "left right";
  }

  #leftPanel {
    grid-area: left;
  }

  .stage {
    grid-area: stage;
    min-height: 70vh;
  }

  .right-panel {
    grid-area: right;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .app {
    display: block;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    width: 100%;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stage"
      "left"
      "right";
    padding: 8px;
  }

  .stage {
    min-height: 75vh;
  }

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