:root {
  color-scheme: light;
  --bg: oklch(97.7% 0.005 238);
  --surface: oklch(99.4% 0.002 238);
  --surface-soft: oklch(96.4% 0.006 238);
  --ink: oklch(22% 0.018 238);
  --muted: oklch(51% 0.022 238);
  --line: oklch(88% 0.012 238);
  --blue: oklch(54% 0.15 252);
  --blue-dark: oklch(45% 0.14 252);
  --green: oklch(46% 0.12 164);
  --green-dark: oklch(37% 0.11 164);
  --red: oklch(49% 0.15 30);
  --shadow: 0 1px 2px rgba(31, 45, 50, 0.04);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

.floating-controls {
  position: fixed;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.floating-status,
.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.top-actions select {
  width: 150px;
  min-height: 34px;
}

.floating-status p {
  max-width: min(520px, 42vw);
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  color: oklch(98% 0.004 238);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 720;
  text-decoration: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-weight: 740;
  text-decoration: none;
  white-space: nowrap;
}

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

.primary-button {
  color: oklch(98% 0.004 238);
  background: var(--blue);
  border-color: var(--blue);
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button:hover {
  background: var(--surface-soft);
  border-color: oklch(79% 0.014 238);
}

.workflow-shell {
  width: 100vw;
  height: 100vh;
  min-height: 0;
}

.canvas-viewport {
  width: 100%;
  height: 100%;
  overflow: auto;
  background:
    linear-gradient(rgba(62, 72, 79, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(62, 72, 79, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 40px 40px;
}

.workflow-canvas {
  position: relative;
  width: 2600px;
  height: 1500px;
  min-width: 100vw;
  min-height: 100vh;
}

.connector-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.connector-layer path {
  fill: none;
  stroke: #e14444;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workflow-node {
  position: absolute;
  z-index: 2;
  width: 320px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workflow-node.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(39, 110, 241, 0.14), var(--shadow);
}

.input-node {
  left: 64px;
  top: 104px;
  width: 390px;
}

.plan-node {
  left: 64px;
  top: 840px;
  width: 390px;
}

.node-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  cursor: grab;
  user-select: none;
}

.dragging-node .node-head {
  cursor: grabbing;
}

.selection-box {
  position: absolute;
  z-index: 10;
  background: rgba(39, 110, 241, 0.12);
  border: 1px solid rgba(39, 110, 241, 0.72);
  border-radius: 4px;
  pointer-events: none;
}

.node-head h2 {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}

label {
  display: grid;
  gap: 5px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: oklch(98% 0.003 238);
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
}

input,
select {
  height: 32px;
  padding: 0 8px;
}

textarea {
  min-height: 52px;
  padding: 7px 8px;
  overflow: hidden;
  resize: none;
  field-sizing: content;
}

input:focus,
select:focus,
textarea:focus {
  background: var(--surface);
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(39, 110, 241, 0.12);
}

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

.dimension-readout {
  margin: -2px 0 8px;
  padding: 6px 8px;
  color: var(--green);
  background: oklch(96% 0.028 164);
  border: 1px solid oklch(86% 0.038 164);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 760;
}

.drop-zone {
  display: grid;
  gap: 5px;
  margin-bottom: 8px;
  padding: 9px;
  cursor: pointer;
  background: var(--surface);
  border: 1px dashed #9eb0b8;
  border-radius: 8px;
}

.drop-zone:hover,
.drop-zone:focus,
.drop-zone.drag-over {
  background: oklch(96.5% 0.018 252);
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(39, 110, 241, 0.1);
}

.drop-title {
  color: var(--ink);
  font-weight: 780;
}

.drop-copy,
.drop-note {
  color: var(--muted);
  font-size: 12px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.material-list {
  display: grid;
  gap: 6px;
}

.project-pick-button {
  width: 100%;
  margin: 8px 0;
}

.material-empty {
  padding: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: 7px;
  font-size: 12px;
}

.material-chip {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 6px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.material-chip img {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.material-chip span {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-history-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 8px;
  color: var(--green-dark);
  background: oklch(96% 0.028 164);
  border: 1px solid oklch(86% 0.038 164);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 760;
}

.material-remove {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.plan-output {
  display: grid;
  gap: 6px;
  min-height: 130px;
  color: var(--muted);
}

.plan-title {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 780;
}

.plan-copy {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.screen-node {
  width: 340px;
}

.image-node {
  width: 320px;
}

.image-preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 156px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.image-preview img {
  display: block;
  width: 100%;
  max-height: 210px;
  object-fit: contain;
}

.image-preview.has-image {
  cursor: zoom-in;
}

.image-variant-controls {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.image-variant-button,
.image-variant-counter {
  min-height: 30px;
  color: oklch(96% 0.006 238);
  background: oklch(18% 0.018 238 / 0.78);
  border: 1px solid oklch(82% 0.012 238 / 0.28);
  border-radius: 7px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.image-variant-button {
  padding: 0;
  font-size: 24px;
  line-height: 1;
  pointer-events: auto;
}

.image-variant-button:disabled {
  opacity: 0.36;
}

.image-variant-counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 780;
}

.screen-purpose-preview {
  display: -webkit-box;
  min-height: 38px;
  margin: 0 0 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.screen-copy-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 26px;
  margin-bottom: 9px;
}

.copy-chip {
  max-width: 100%;
  overflow: hidden;
  padding: 3px 6px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-chip.muted {
  color: var(--muted);
  font-weight: 650;
}

.node-editor {
  margin-top: 8px;
  border-top: 1px solid var(--line);
}

.node-editor summary {
  padding: 8px 0 2px;
  color: var(--blue-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 760;
  user-select: none;
}

.node-editor[open] summary {
  margin-bottom: 8px;
}

.compact-editor {
  display: grid;
  gap: 6px;
}

.compact-editor label {
  margin: 0;
}

.editor-title {
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
}

.editor-section {
  display: grid;
  gap: 6px;
  padding: 7px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.editor-section label {
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
}

.editor-title > span,
.editor-section label > span {
  padding-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.section-label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 820;
}

.compact-editor textarea {
  min-height: 42px;
  max-height: none;
  line-height: 1.45;
}

.node-message {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.node-message.error {
  color: var(--red);
}

.node-message.ok {
  color: var(--green);
}

.history-panel {
  position: fixed;
  top: 58px;
  right: 12px;
  z-index: 32;
  display: grid;
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100vh - 72px);
  padding: 10px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

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

.history-head h2 {
  margin: 2px 0 0;
  font-size: 15px;
}

.history-save {
  width: 100%;
  margin-bottom: 8px;
}

.history-list {
  display: grid;
  gap: 6px;
  min-height: 0;
  overflow: auto;
}

.history-empty {
  margin: 0;
  padding: 14px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.history-item {
  display: grid;
  gap: 6px;
  padding: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-item.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(39, 110, 241, 0.1);
}

.history-item h3 {
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

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

.history-actions button {
  min-height: 30px;
  font-size: 12px;
}

.image-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: rgba(12, 16, 18, 0.68);
  outline: none;
}

.image-preview-blur {
  position: absolute;
  inset: -36px;
  background-position: center;
  background-size: cover;
  filter: blur(28px);
  opacity: 0.55;
  transform: scale(1.06);
}

.image-preview-stage {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  padding: 28px;
}

.image-preview-stage img {
  display: block;
  max-width: calc(100vw - 56px);
  max-height: calc(100vh - 56px);
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
}

.project-image-modal {
  position: fixed;
  inset: 0;
  z-index: 52;
  display: grid;
  place-items: center;
  padding: 4vh 4vw;
  background: rgba(12, 16, 18, 0.48);
}

.project-image-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1280px, 92vw);
  height: 92vh;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(31, 45, 50, 0.18);
}

.project-image-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.project-image-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.project-image-head h2 {
  margin: 2px 0 0;
  font-size: 19px;
}

.project-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  align-content: start;
  gap: 14px;
  min-height: 180px;
  padding: 16px;
  overflow: auto;
}

.project-image-option {
  display: grid;
  grid-template-rows: auto minmax(34px, auto);
  align-content: start;
  align-items: stretch;
  gap: 8px;
  min-height: 238px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  white-space: normal;
}

.project-image-option:hover {
  background: var(--surface-soft);
}

.project-image-option img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 7px;
}

.project-image-option span {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-close {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 2;
  color: var(--ink);
  background: var(--surface);
}

.image-preview-confirm {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 2;
  min-width: 104px;
  color: oklch(98% 0.004 238);
  background: var(--green);
  border-color: var(--green-dark);
}

.image-preview-nav {
  position: fixed;
  top: 50%;
  z-index: 2;
  width: 48px;
  height: 72px;
  padding: 0;
  color: oklch(94% 0.006 238);
  background: oklch(18% 0.018 238 / 0.76);
  border: 1px solid oklch(72% 0.018 238 / 0.28);
  border-radius: 8px;
  font-size: 44px;
  font-weight: 520;
  line-height: 1;
  transform: translateY(-50%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.image-preview-nav:hover {
  background: oklch(24% 0.022 238 / 0.9);
}

.image-preview-nav:disabled {
  opacity: 0.32;
}

.image-preview-prev {
  left: 18px;
}

.image-preview-next {
  right: 18px;
}

.series-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: oklch(13% 0.018 238 / 0.92);
  outline: none;
}

.series-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  color: oklch(96% 0.006 238);
  background: oklch(18% 0.018 238 / 0.96);
  border-bottom: 1px solid oklch(34% 0.02 238);
}

.series-preview-head span {
  color: oklch(74% 0.014 238);
  font-size: 12px;
  font-weight: 760;
}

.series-preview-head h2 {
  margin: 2px 0 0;
  max-width: min(620px, 58vw);
  overflow: hidden;
  font-size: 18px;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.series-preview-head p {
  margin: 4px 0 0;
  color: oklch(78% 0.012 238);
  font-size: 12px;
  font-weight: 680;
}

.series-preview-head .secondary-button {
  color: var(--ink);
  background: oklch(96% 0.006 238);
  border-color: oklch(86% 0.012 238);
}

.series-preview-scroll {
  min-height: 0;
  overflow: auto;
  padding: 28px 18px 44px;
}

.series-preview-stack {
  display: grid;
  width: min(100%, 760px);
  margin: 0 auto;
  gap: 0;
  background: transparent;
  box-shadow: none;
}

.series-preview-screen {
  position: relative;
  display: block;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  line-height: 0;
  background: transparent;
}

.series-preview-screen + .series-preview-screen {
  margin-top: 0;
}

.series-preview-screen img {
  display: block;
  width: 100%;
  height: auto;
}

@media (max-width: 760px) {
  .floating-controls {
    align-items: flex-start;
    flex-direction: column;
    right: auto;
  }

  .floating-status,
  .top-actions {
    max-width: calc(100vw - 28px);
  }

  .top-actions {
    flex-wrap: nowrap;
    gap: 4px;
    padding: 5px;
  }

  .top-actions button {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0 8px;
  }

  .project-image-modal {
    padding: 2vh 2vw;
  }

  .project-image-panel {
    width: 96vw;
    height: 96vh;
  }

  .project-image-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
    padding: 10px;
  }

  .image-preview-nav {
    width: 40px;
    height: 58px;
    font-size: 36px;
  }

  .image-preview-prev {
    left: 10px;
  }

  .image-preview-next {
    right: 10px;
  }

  .series-preview-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .series-preview-head h2 {
    max-width: calc(100vw - 36px);
  }

  .series-preview-scroll {
    padding: 16px 10px 32px;
  }
}
