:root {
  color-scheme: light;
  --bg: #f4f7f4;
  --surface: #ffffff;
  --surface-strong: #edf5ef;
  --ink: #1d2b28;
  --muted: #66736f;
  --line: #d9e4dc;
  --solar: #f0b429;
  --solar-dark: #b7791f;
  --green: #2f855a;
  --green-dark: #236746;
  --blue: #2b6cb0;
  --panel: #20364a;
  --shadow: 0 16px 40px rgba(26, 43, 38, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 24px;
  background: #fdfefd;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.pane-heading h2,
.section-title h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.control-rail {
  overflow-y: auto;
  padding: 18px;
  background: #fbfcfb;
  border-right: 1px solid var(--line);
}

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

.control-section:first-child {
  padding-top: 0;
}

.control-section:last-child {
  border-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.section-title h2 {
  font-size: 16px;
}

.step-badge {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 26px;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--green-dark);
  font-weight: 700;
}

.upload-box {
  min-height: 92px;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 16px;
  border: 1px dashed #9fb9a7;
  border-radius: 8px;
  background: #f8fbf9;
  color: var(--ink);
  text-align: center;
}

.upload-box input {
  display: none;
}

.upload-box span {
  font-weight: 700;
}

.upload-box small {
  color: var(--muted);
}

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

.thumb {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-strong);
  padding: 0;
}

.thumb.active {
  border-color: var(--green);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

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

.tool-button,
.ghost-button,
.primary-button,
.segment {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.tool-button:hover,
.ghost-button:hover,
.segment:hover {
  border-color: #9fb9a7;
  background: #f6faf7;
}

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

.primary-button:hover {
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.wide {
  width: 100%;
}

.compact-note {
  min-height: 38px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.input-grid {
  display: grid;
  gap: 10px;
}

.two-col {
  grid-template-columns: 1fr 1fr;
}

label,
.stacked-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

input:focus,
select:focus {
  border-color: var(--green);
  outline: 2px solid rgba(47, 133, 90, 0.16);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.segment.active {
  border-color: var(--blue);
  background: #edf5ff;
  color: #184a7d;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 12px;
}

.metrics div {
  min-height: 78px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metrics dt {
  color: var(--muted);
  font-size: 12px;
}

.metrics dd {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: minmax(390px, 1.05fr) minmax(320px, 0.95fr);
  gap: 18px;
  padding: 18px;
}

.plan-pane,
.preview-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.preview-pane {
  grid-template-rows: auto 1fr auto;
}

.pane-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.pane-heading h2 {
  font-size: 18px;
}

.state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #edf5ff;
  color: #184a7d;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.canvas-wrap {
  position: relative;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.plan-wrap {
  min-height: 420px;
}

.render-wrap {
  min-height: 300px;
  background: linear-gradient(180deg, #e9f4ff 0%, #f8fbf9 58%, #dfe9df 100%);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.orbit-bar {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
}

.orbit-bar label {
  grid-template-columns: auto 1fr;
  align-items: center;
}

input[type="range"] {
  padding: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  transform: translate(-50%, 16px);
  max-width: min(460px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(29, 43, 40, 0.94);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

@media (min-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(0, 1.08fr) minmax(430px, 0.92fr);
    grid-template-rows: 1fr;
  }

  .plan-pane,
  .preview-pane {
    min-height: calc(100vh - 112px);
  }
}

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

  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .top-actions .state-pill {
    grid-column: 1 / -1;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

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

  .workspace {
    grid-template-rows: minmax(360px, 1fr) minmax(300px, 1fr);
  }
}

@media (max-width: 540px) {
  .topbar,
  .control-rail,
  .workspace {
    padding: 14px;
  }

  .two-col,
  .metrics,
  .tool-grid,
  .orbit-bar {
    grid-template-columns: 1fr;
  }

  .plan-wrap {
    min-height: 340px;
  }
}
