:root {
  color-scheme: light;
  --bg: #f7f3ea;
  --panel: rgba(255, 252, 246, .88);
  --panel-soft: rgba(247, 243, 234, .78);
  --panel-strong: #fffaf0;
  --line: rgba(157, 132, 96, .22);
  --line-strong: rgba(157, 132, 96, .34);
  --text: #151412;
  --muted: #6d685f;
  --dim: #9a9184;
  --cyan: #c96542;
  --gold: #596050;
  --red: #b84b58;
  --blue: #8f7156;
  --shadow: 0 24px 80px rgba(95, 67, 43, .16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 72% 10%, rgba(201, 101, 66, .16), transparent 30rem),
    radial-gradient(circle at 10% 42%, rgba(89, 96, 80, .12), transparent 24rem),
    linear-gradient(180deg, #fbf7ed 0%, var(--bg) 48%, #efe6d7 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(91, 78, 58, .07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(91, 78, 58, .055) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), transparent 78%);
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1720px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.app-topbar {
  height: 72px;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 14px;
  padding: 0 4px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(201, 101, 66, .96), rgba(216, 138, 104, .9)),
    #f6e5d3;
  box-shadow: 0 16px 38px rgba(201, 101, 66, .18);
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 22px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

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

.top-tabs,
.mode-switch {
  display: flex;
  align-items: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 252, 246, .72);
  backdrop-filter: blur(18px);
}

.top-tab,
.mode-btn {
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  padding: 0 15px;
  color: var(--muted);
  background: transparent;
}

.top-tab.active,
.mode-btn.active {
  color: #fff8eb;
  background: #171614;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(520px, 1fr) 320px;
  gap: 14px;
  align-items: start;
}

.sidebar,
.prompt-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 252, 246, .9), rgba(247, 243, 234, .86));
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(1.1);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  position: sticky;
  top: 14px;
}

.canvas-column {
  display: grid;
  gap: 14px;
}

.prompt-panel,
.preview-panel,
.assets-panel,
.history-panel,
.prompt-library-panel {
  padding: 16px;
}

.assets-panel,
.history-panel,
.prompt-library-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 252, 246, .9), rgba(247, 243, 234, .86));
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(1.1);
}

.work-view {
  display: none;
}

.workspace[data-view="materials"] .prompt-panel,
.workspace[data-view="materials"] .preview-panel,
.workspace[data-view="history"] .prompt-panel,
.workspace[data-view="history"] .preview-panel,
.workspace[data-view="prompts"] .prompt-panel,
.workspace[data-view="prompts"] .preview-panel {
  display: none;
}

.workspace[data-view="materials"] [data-view-panel="materials"],
.workspace[data-view="history"] [data-view-panel="history"],
.workspace[data-view="prompts"] [data-view-panel="prompts"] {
  display: block;
}

.panel-block {
  border: 1px solid rgba(157,132,96,.14);
  border-radius: 14px;
  padding: 13px;
  background: rgba(255,255,255,.32);
}

.block-head,
.panel-title-row,
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.block-head {
  margin-bottom: 12px;
}

.block-head span {
  font-weight: 700;
  font-size: 14px;
}

.block-head small,
.status-pill {
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(255,255,255,.28);
  font-size: 12px;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.field.full {
  margin-top: 14px;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(157,132,96,.26);
  border-radius: 10px;
  padding: 10px 11px;
  color: var(--text);
  background: rgba(255,252,246,.72);
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.52;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(201, 101, 66, .72);
  box-shadow: 0 0 0 3px rgba(201, 101, 66, .1);
}

.secret-row {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 8px;
}

.secret-row button,
.ghost,
.tool-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: rgba(255,255,255,.34);
}

.remember-secret {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.remember-secret input {
  width: 16px;
  height: 16px;
  margin: 0;
}

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

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

.preset-chip {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255,255,255,.32);
}

.preset-chip.active {
  color: var(--cyan);
  border-color: rgba(201, 101, 66, .45);
  background: rgba(201, 101, 66, .1);
}

.reference-strip {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
  margin-top: 14px;
}

.upload-zone {
  position: relative;
  min-height: 112px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed rgba(157,132,96,.36);
  border-radius: 14px;
  background: rgba(255,255,255,.28);
}

.upload-zone.drag {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(201, 101, 66, .1);
}

.upload-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.upload-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
}

.upload-copy strong {
  font-size: 15px;
}

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

.thumbs {
  min-height: 112px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 8px;
}

.thumb {
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.42);
}

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

.action-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px;
  margin-top: 14px;
}

.ghost,
.primary {
  min-height: 48px;
}

.primary {
  border: 0;
  border-radius: 12px;
  color: #fff8eb;
  font-weight: 800;
  background: #171614;
  box-shadow: 0 18px 44px rgba(23, 22, 20, .16);
}

.primary:disabled {
  opacity: .62;
  cursor: wait;
}

.preview-toolbar {
  margin-bottom: 14px;
}

.canvas-tools {
  display: flex;
  gap: 8px;
}

.tool-btn {
  min-height: 34px;
  padding: 8px 12px;
  text-decoration: none;
  font-size: 12px;
}

.page-label {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.28);
  font-size: 12px;
  white-space: nowrap;
}

.tool-btn.active {
  color: #fff8eb;
  border-color: #171614;
  background: #171614;
}

.tool-btn.disabled {
  pointer-events: none;
  color: var(--dim);
}

.preview-stage {
  min-height: 560px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(157,132,96,.2);
  border-radius: 16px;
  background:
    radial-gradient(circle at 50% 20%, rgba(201,101,66,.1), transparent 42%),
    linear-gradient(90deg, rgba(91,78,58,.055) 1px, transparent 1px),
    linear-gradient(0deg, rgba(91,78,58,.045) 1px, transparent 1px),
    rgba(239,231,218,.62);
  background-size: auto, 28px 28px, 28px 28px, auto;
  --result-aspect: 1 / 1;
}

.preview-panel.is-fit .preview-stage {
  min-height: calc(100vh - 150px);
}

.preview-panel.is-compare .result-card.is-ready {
  outline: 2px solid rgba(201, 101, 66, .42);
  outline-offset: 3px;
}

.preview-stage video {
  width: 100%;
  height: 100%;
  max-height: 72vh;
  object-fit: contain;
  display: block;
}

.result-grid {
  width: 100%;
  height: 100%;
  max-height: 72vh;
  min-height: 500px;
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: center;
  justify-content: center;
  overflow: auto;
}

.preview-panel.is-fit .result-grid {
  max-height: none;
}

.result-grid.landscape {
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
}

.result-grid.landscape.count-9 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-grid.portrait {
  grid-template-columns: repeat(auto-fit, minmax(180px, 260px));
}

.result-grid.portrait.count-9 {
  grid-template-columns: repeat(3, minmax(140px, 220px));
}

.result-grid.square {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.result-grid.square.count-9 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-grid.single {
  grid-template-columns: minmax(240px, min(100%, 900px));
}

.result-card {
  position: relative;
  width: 100%;
  aspect-ratio: var(--result-aspect);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.36);
}

.result-card a,
.result-card img {
  width: 100%;
  height: 100%;
  display: block;
}

.result-card img {
  max-height: none;
  object-fit: contain;
  background: rgba(255,252,246,.7);
}

.result-card.is-pending {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.result-card.is-blueprint {
  display: grid;
  place-items: center;
  color: var(--dim);
  background:
    linear-gradient(90deg, rgba(91,78,58,.055) 1px, transparent 1px),
    linear-gradient(0deg, rgba(91,78,58,.045) 1px, transparent 1px),
    rgba(255,255,255,.22);
  background-size: 18px 18px;
}

.result-card.is-blueprint::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed rgba(157,132,96,.28);
  border-radius: 8px;
}

.result-card.is-blueprint span {
  position: relative;
  z-index: 1;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,252,246,.72);
  font-size: 12px;
}

.pending-visual {
  position: absolute;
  inset: 0;
  filter: blur(10px);
  opacity: .78;
  background:
    linear-gradient(110deg, transparent 0%, rgba(255,255,255,.42) 18%, transparent 36%),
    radial-gradient(circle at 35% 35%, rgba(201,101,66,.24), transparent 35%),
    radial-gradient(circle at 70% 70%, rgba(89,96,80,.16), transparent 32%),
    rgba(255,255,255,.18);
  background-size: 220% 100%, auto, auto, auto;
  animation: pending-shimmer 1.7s linear infinite;
}

.result-card.is-pending span {
  position: relative;
  z-index: 1;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255,252,246,.72);
  backdrop-filter: blur(10px);
  font-size: 12px;
}

.result-card.is-error {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 18px;
  text-align: center;
  border-color: rgba(184, 75, 88, .42);
  color: var(--red);
}

.result-card.is-error span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

@keyframes pending-shimmer {
  from {
    background-position: 160% 0, center, center, center;
  }
  to {
    background-position: -80% 0, center, center, center;
  }
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 22px;
}

.empty-state p {
  max-width: 360px;
  line-height: 1.5;
}

.spark {
  width: 84px;
  height: 84px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(201,101,66,.92), rgba(89,96,80,.82));
  box-shadow: 0 22px 58px rgba(201,101,66,.18);
}

.result-meta {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  color: var(--muted);
}

.result-meta code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cost-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  border-color: rgba(201, 101, 66, .24);
}

.cost-panel div {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.cost-panel strong {
  font-size: 24px;
}

.cost-panel small {
  max-width: 100%;
  color: var(--cyan);
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.queue-list {
  display: grid;
  gap: 8px;
}

.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px;
  border: 1px solid rgba(157,132,96,.14);
  border-radius: 10px;
  background: rgba(255,255,255,.24);
}

.queue-item b {
  font-size: 13px;
}

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

.queue-item.active {
  border-color: rgba(201, 101, 66, .28);
}

.log-box {
  min-height: 190px;
  max-height: 260px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #5d554c;
  background: rgba(255,255,255,.26);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.asset-groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.prompt-library-block {
  grid-column: 1 / -1;
}

.asset-block {
  border: 1px solid rgba(157,132,96,.14);
  border-radius: 14px;
  padding: 13px;
  background: rgba(255,255,255,.32);
}

.prompt-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px 180px;
  gap: 10px;
  margin-bottom: 12px;
}

.prompt-template-list {
  min-height: 260px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.prompt-template-card {
  min-width: 0;
  display: grid;
  gap: 10px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255,255,255,.3);
}

.prompt-template-image {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: rgba(255,252,246,.68);
}

.prompt-template-image img {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  object-fit: cover;
  transition: transform .18s ease;
}

.prompt-template-image:hover img {
  transform: scale(1.03);
}

.prompt-template-head,
.prompt-template-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.prompt-template-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.prompt-template-head span,
.prompt-template-foot small {
  flex: 0 0 auto;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  background: rgba(255,255,255,.24);
  font-size: 11px;
}

.prompt-template-card pre {
  min-height: 150px;
  max-height: 260px;
  margin: 0;
  overflow: hidden;
  overflow-y: auto;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid rgba(157,132,96,.14);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255,252,246,.44);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.prompt-template-foot .asset-actions {
  margin-top: 0;
}

.image-preview {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(21,20,18,.72);
  backdrop-filter: blur(12px);
}

.image-preview-panel {
  width: min(980px, 100%);
  max-height: calc(100vh - 48px);
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(255,252,246,.2);
  border-radius: 14px;
  background: rgba(255,252,246,.94);
  box-shadow: 0 28px 88px rgba(0,0,0,.3);
}

.image-preview-panel .tool-btn {
  justify-self: end;
}

.image-preview-panel img,
.image-preview-panel video {
  width: 100%;
  max-height: calc(100vh - 170px);
  display: block;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(239,231,218,.62);
}

.image-preview-panel strong {
  color: var(--text);
  font-size: 14px;
}

.asset-list {
  min-height: 240px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.asset-card,
.history-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.3);
  overflow: hidden;
}

.asset-card img,
.asset-card video {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
  background: rgba(255,252,246,.7);
}

.asset-card-body,
.history-card {
  padding: 10px;
}

.asset-card strong,
.history-card strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.asset-card span,
.history-card span,
.history-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.asset-actions,
.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}

.mini-btn {
  min-height: 30px;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255,255,255,.34);
  font-size: 12px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.history-card p {
  margin: 6px 0 0;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.history-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  background: rgba(255,255,255,.24);
}

.empty-list {
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .right-rail {
    position: static;
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 260px 1fr 1fr;
  }
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100vw - 18px, 1720px);
    padding-top: 10px;
  }

  .app-topbar {
    height: auto;
    grid-template-columns: 1fr;
  }

  .top-tabs,
  .mode-switch {
    width: 100%;
  }

  .top-tab,
  .mode-btn {
    flex: 1;
  }

  .workspace,
  .right-rail {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .reference-strip,
  .field-grid,
  .action-row,
  .result-meta,
  .asset-groups,
  .prompt-tools,
  .history-card {
    grid-template-columns: 1fr;
  }
}
