:root {
  --bg: #f2ede5;
  --surface: #fcfaf6;
  --surface-2: #f6f0e7;
  --surface-3: #eee7dc;
  --ink: #24211e;
  --muted: #776f66;
  --muted-strong: #5f584f;
  --line: rgba(36, 33, 30, 0.12);
  --line-strong: rgba(36, 33, 30, 0.2);
  --accent: #a75d45;
  --accent-dark: #8c4834;
  --accent-soft: #f1e2d8;
  --sage: #687563;
  --amber: #a8722f;
  --danger: #a23e35;
  --white: #fffdf9;
  --font-sans: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-serif: Georgia, "Songti SC", "SimSun", "Noto Serif SC", serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --radius: 14px;
  --radius-lg: 24px;
  --shadow-card: 0 22px 64px rgba(59, 48, 38, 0.1);
  --shadow-frame: 0 18px 48px rgba(45, 35, 27, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 540px at 8% -12%, #fbf8f2 0%, rgba(251, 248, 242, 0) 58%),
    linear-gradient(158deg, #f5f1e9 0%, #eee7dc 100%);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

.app-shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 26px 32px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 4px 2px 24px;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff8f0;
  font-family: var(--font-serif);
  font-size: 25px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(167, 93, 69, 0.25);
}

.brand-copy h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.brand-copy p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(252, 250, 246, 0.7);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b9b0a5;
  flex: 0 0 auto;
}

.status-pill.is-live .status-dot {
  background: var(--sage);
  box-shadow: 0 0 0 3px rgba(104, 117, 99, 0.14);
}

.status-pill.is-demo .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(168, 114, 47, 0.14);
}

.status-pill.is-error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(162, 62, 53, 0.14);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

#settingsBtn svg {
  fill: currentColor;
  stroke: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 470px;
  gap: 24px;
  align-items: start;
}

.stage-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  padding: 6px 16px 6px 22px;
  border-bottom: 1px solid var(--line);
}

.stage-heading {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2em;
  line-height: 1.4;
  text-transform: uppercase;
}

.stage-heading h2 {
  overflow: hidden;
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.stage-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

.meta-sep {
  opacity: 0.45;
}

.stage-body {
  position: relative;
  height: clamp(460px, calc(100vh - 330px), 900px);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0) 45%),
    #e9e2d7;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.empty-state {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 28px;
  border: 1px dashed rgba(36, 33, 30, 0.22);
  border-radius: 18px;
  background: rgba(252, 250, 246, 0.52);
  text-align: center;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.stage-body.is-dragging .empty-state {
  border-color: var(--accent);
  background: rgba(241, 226, 216, 0.68);
}

.empty-visual {
  width: 76px;
  height: 60px;
  margin-bottom: 12px;
  color: var(--muted-strong);
}

.empty-visual svg {
  width: 100%;
  height: 100%;
}

.empty-state h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
}

.empty-state p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.viewer {
  position: absolute;
  inset: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.viewer.is-ready {
  opacity: 1;
}

.image-frame {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 17px;
  background: #e5ded3;
  box-shadow: var(--shadow-frame);
  isolation: isolate;
}

.viewer-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: crosshair;
  user-select: none;
  -webkit-user-drag: none;
}

.result-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(0 0 0 50%);
  transition: opacity 0.28s ease;
  will-change: clip-path;
}

.viewer.has-result .result-layer {
  opacity: 1;
}

.viewer-top {
  position: absolute;
  top: 13px;
  left: 13px;
  right: 13px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.viewer-tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(32, 28, 24, 0.58);
  color: #fffaf4;
  font-size: 11px;
  letter-spacing: 0.04em;
  backdrop-filter: blur(10px);
}

.result-tag {
  background: rgba(167, 93, 69, 0.82);
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 4;
  width: 42px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ew-resize;
  touch-action: none;
}

.handle-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: rgba(255, 253, 249, 0.92);
  box-shadow: 0 0 0 1px rgba(24, 20, 17, 0.16);
}

.handle-grip {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(36, 33, 30, 0.12);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(35, 28, 22, 0.22);
}

.handle-grip svg {
  width: 18px;
  height: 18px;
}

.viewer-tools {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
}

.viewer-tools-right {
  left: auto;
  right: 12px;
}

.viewer-tool-icon {
  width: 14px;
  height: 14px;
}

.viewer-tool {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(32, 28, 24, 0.56);
  color: #fffaf4;
  backdrop-filter: blur(10px);
}

.viewer-tool:hover {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(32, 28, 24, 0.72);
  color: #fffdf9;
}

.viewer-tool.is-active {
  border-color: rgba(255, 255, 255, 0.3);
  background: var(--accent);
  color: #fffaf4;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(247, 243, 236, 0.72);
  backdrop-filter: blur(12px);
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 28px;
  border: 1px solid rgba(36, 33, 30, 0.1);
  border-radius: 18px;
  background: rgba(252, 250, 246, 0.9);
  box-shadow: 0 18px 45px rgba(45, 35, 27, 0.12);
  text-align: center;
}

.loading-spinner {
  width: 30px;
  height: 30px;
  margin-bottom: 4px;
  border: 2px solid rgba(167, 93, 69, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-title {
  font-size: 14px;
  font-weight: 600;
}

.loading-sub {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.loading-card .btn {
  margin-top: 8px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.history-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 84px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: rgba(246, 240, 231, 0.5);
}

.history-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.history-select {
  max-width: 220px;
  height: 32px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%23776f66' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 11px;
  color: var(--muted-strong);
  font-size: 11.5px;
  text-overflow: ellipsis;
  cursor: pointer;
  appearance: none;
}

.history-select:hover {
  border-color: var(--line-strong);
}

.history-items {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 64px;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: thin;
  scrollbar-color: #c9bfb2 transparent;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
}

.history-thumb {
  position: relative;
  width: 48px;
  height: 64px;
  flex: 0 0 auto;
  overflow: hidden;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 9px;
  background: var(--surface-3);
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

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

.history-thumb:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(45, 35, 27, 0.16);
}

.history-thumb.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167, 93, 69, 0.14);
}

.history-index {
  position: absolute;
  right: 3px;
  bottom: 3px;
  padding: 1px 4px;
  border-radius: 5px;
  background: rgba(32, 28, 24, 0.62);
  color: #fffaf4;
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.4;
  backdrop-filter: blur(6px);
}

.panel {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 120px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(59, 48, 38, 0.07);
}

.panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 24px 10px;
  scrollbar-width: thin;
  scrollbar-color: #c9bfb2 transparent;
}

.panel-dock {
  flex: 0 0 auto;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(252, 250, 246, 0.92), var(--surface) 32%);
  box-shadow: 0 -12px 24px rgba(59, 48, 38, 0.04);
}

.panel-dock .btn-generate {
  margin-top: 0;
}

.panel-intro {
  padding-bottom: 18px;
}

.panel-intro h2 {
  margin: 5px 0 0;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
}

.panel-intro p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid #e2cdb5;
  border-radius: 13px;
  background: #f7eddf;
}

.demo-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  color: #6d4d33;
  font-size: 11.5px;
  line-height: 1.5;
}

.demo-banner-text strong {
  font-size: 12.5px;
  font-weight: 600;
}

.panel-section {
  padding-top: 19px;
  border-top: 1px solid var(--line);
}

.panel-section + .panel-section {
  margin-top: 19px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-bottom: 13px;
}

.section-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.section-action {
  flex: 0 0 auto;
  margin: 1px 0 0 auto;
  padding: 1px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease;
}

.section-action:hover {
  color: var(--accent);
  border-bottom-color: currentColor;
}

.section-index {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1;
}

.section-head h3 {
  margin: 1px 0 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.section-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.4;
}

.point-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.point-marker {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  padding: 0;
  border: 2px solid rgba(255, 253, 249, 0.94);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--point-color, var(--accent));
  color: #fffaf4;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 2px 10px rgba(28, 24, 20, 0.32);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.point-marker:hover {
  transform: scale(1.08);
}

.point-marker.is-active {
  transform: scale(1.06);
  box-shadow:
    0 0 0 4px rgba(255, 253, 249, 0.4),
    0 4px 14px rgba(28, 24, 20, 0.38);
}

.point-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.point-empty {
  margin: 0;
  padding: 11px 13px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.point-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.point-row:hover {
  border-color: var(--line-strong);
}

.point-row.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.point-index {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--point-color, var(--accent));
  color: #fffaf4;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
}

.point-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted-strong);
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.point-remove {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.14s ease, border-color 0.14s ease;
}

.point-remove:hover {
  border-color: var(--line-strong);
  color: var(--danger);
}

.point-remove svg {
  width: 13px;
  height: 13px;
}

.color-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.color-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  transition: opacity 0.16s ease;
}

.color-card.is-disabled {
  opacity: 0.5;
}

.color-card.is-disabled .swatch {
  cursor: not-allowed;
}

.color-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.color-card-title {
  font-size: 12.5px;
  font-weight: 600;
}

.color-value {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-chip {
  position: relative;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: #fff;
  box-shadow:
    0 0 0 1px var(--line),
    0 5px 12px rgba(55, 44, 35, 0.11);
  cursor: pointer;
}

.color-chip-fill {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: 50%;
}

.native-color {
  position: absolute;
  inset: -4px;
  z-index: 2;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  border: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.color-chip:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hex-input {
  width: 88px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
}

.hex-input:focus {
  border-color: var(--accent);
}

.hex-input.invalid {
  border-color: var(--danger);
  background: #fff5f3;
}

.swatch-groups {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 13px;
}

.swatch-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch-group-label {
  width: 28px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.swatch {
  position: relative;
  width: 23px;
  height: 23px;
  padding: 0;
  border: 1px solid rgba(36, 33, 30, 0.14);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch.selected {
  box-shadow:
    0 0 0 2px var(--surface-2),
    0 0 0 3.5px var(--accent);
  transform: scale(1.05);
}

.size-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}

.segmented button {
  min-width: 48px;
  padding: 7px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.segmented button.active {
  background: var(--ink);
  color: var(--white);
  box-shadow: 0 4px 10px rgba(36, 33, 30, 0.16);
}

.advanced {
  margin: 13px 0;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
}

.advanced summary {
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  list-style: none;
}

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

.advanced summary::before {
  content: "+";
  display: inline-block;
  width: 14px;
  color: var(--accent);
  font-weight: 600;
}

.advanced[open] summary::before {
  content: "−";
}

.advanced textarea {
  width: 100%;
  min-height: 70px;
  margin-top: 9px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.55;
  resize: vertical;
}

.advanced textarea:focus {
  border-color: var(--accent);
}

.hint {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease,
    box-shadow 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-sm {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 11.5px;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffaf5;
  box-shadow: 0 8px 20px rgba(167, 93, 69, 0.18);
}

.btn-primary:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.btn-dark {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--white);
}

.btn-dark:hover {
  background: #3a342e;
}

.btn-ghost {
  border-color: var(--line);
  background: rgba(252, 250, 246, 0.72);
  color: var(--muted-strong);
}

.btn-ghost:hover {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.btn-ghost.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-generate {
  width: 100%;
  min-height: 52px;
  margin-top: 4px;
  border-radius: 12px;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.btn-generate.is-busy {
  background: var(--accent-dark);
}

.btn-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
}

.btn-icon svg {
  width: 100%;
  height: 100%;
}

.generate-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 19px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.privacy-note svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  margin-top: 2px;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 3px 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.03em;
}

.settings-dialog {
  width: min(520px, calc(100vw - 32px));
  max-width: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.settings-dialog::backdrop {
  background: rgba(35, 30, 25, 0.46);
  backdrop-filter: blur(6px);
}

.settings-dialog[open] {
  animation: dialog-in 0.18s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.settings-dialog form {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 32px 80px rgba(35, 28, 22, 0.26);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.dialog-head h2 {
  margin: 5px 0 0;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
}

.dialog-copy {
  margin: 0 0 16px;
  padding: 11px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.65;
}

.dialog-copy code {
  padding: 1px 4px;
  border-radius: 4px;
  background: #ece3d7;
  color: var(--muted-strong);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.inline-link {
  color: var(--accent-dark);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.inline-link:hover {
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 13px;
}

.field > span {
  font-size: 12px;
  font-weight: 500;
}

.field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
}

.field input:focus {
  border-color: var(--accent);
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 17px;
}

.sample-dialog {
  width: min(780px, calc(100vw - 32px));
}

.sample-panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 32px 80px rgba(35, 28, 22, 0.26);
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  max-height: min(58vh, 560px);
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
  scrollbar-color: #c9bfb2 transparent;
}

.sample-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.sample-card img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: var(--surface-3);
}

.sample-card-name {
  padding: 7px 9px 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sample-card:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 10px 24px rgba(45, 35, 27, 0.16);
}

.sample-card.is-loading {
  opacity: 0.55;
  pointer-events: none;
}

.sample-empty {
  margin: 0;
  padding: 22px 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 640px) {
  .sample-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.big-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #14110e;
  color: #fffaf4;
}

.big-dialog::backdrop {
  background: rgba(20, 17, 14, 0.86);
}

.big-dialog[open] {
  animation: big-dialog-in 0.2s ease-out;
}

@keyframes big-dialog-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.big-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.big-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px 14px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.big-bar .eyebrow {
  color: rgba(255, 250, 244, 0.55);
}

.big-labels {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.big-label {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 250, 244, 0.8);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.big-label.is-result {
  border-color: rgba(167, 93, 69, 0.5);
  background: rgba(167, 93, 69, 0.28);
  color: #fff4ec;
}

.big-close {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: #fffaf4;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.big-close:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.14);
}

.big-close svg {
  width: 18px;
  height: 18px;
}

.big-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vh, 40px) clamp(16px, 3vw, 48px);
}

.big-frame {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 10px;
  background: #1d1915;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.5);
  isolation: isolate;
}

.big-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.big-result-layer {
  position: absolute;
  inset: 0;
  clip-path: inset(0 0 0 50%);
  will-change: clip-path;
}

.big-handle {
  width: 56px;
}

.big-handle .handle-grip {
  width: 46px;
  height: 46px;
}

.big-handle .handle-grip svg {
  width: 20px;
  height: 20px;
}

.spacer {
  flex: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 120;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 999px;
  background: #29241f;
  color: #fff9f2;
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 14px 34px rgba(28, 22, 18, 0.26);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.toast[data-tone="error"] {
  background: #7f2f27;
}

@media (max-width: 1100px) {
  .app-shell {
    padding: 20px 20px 30px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: 18px;
  }

  .stage-body {
    height: clamp(440px, calc(100vh - 320px), 760px);
  }

  .stage-meta {
    display: none;
  }
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .panel {
    position: static;
    max-height: none;
  }

  .panel-scroll {
    overflow: visible;
  }

  .stage-body {
    height: clamp(400px, 56vh, 640px);
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    padding-bottom: 16px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }

  .brand-copy h1 {
    font-size: 23px;
  }

  .brand-copy p {
    font-size: 10px;
  }

  .status-pill {
    padding: 0 10px;
    font-size: 11px;
  }

  .stage-bar {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
  }

  .stage-heading h2 {
    font-size: 17px;
  }

  .stage-tools {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  .stage-body {
    height: 46vh;
    min-height: 320px;
    padding: 9px;
  }

  .viewer {
    inset: 9px;
  }

  .empty-state {
    padding: 20px 16px;
  }

  .empty-state h3 {
    font-size: 16px;
  }

  .history-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }

  .history-select {
    flex: 1 1 auto;
    max-width: none;
  }

  .panel-scroll {
    padding: 18px 18px 8px;
  }

  .panel-dock {
    padding: 12px 18px 16px;
  }

  .swatch-group {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .swatch-group-label {
    width: auto;
  }

  .footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Account: balance pill + login dialog ---------- */
.balance-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--white);
  color: var(--muted-strong);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.balance-pill:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.balance-pill.is-authed {
  color: var(--accent-dark);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.balance-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.balance-pill.is-authed .balance-dot {
  background: var(--accent);
}

.auth-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: none;
}

.auth-dialog::backdrop {
  background: rgba(36, 33, 30, 0.44);
  backdrop-filter: blur(3px);
}

.auth-card {
  position: relative;
  width: min(92vw, 400px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 30px 26px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.auth-card h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  color: var(--ink);
}

.auth-hint {
  margin: 0 0 4px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-strong);
}

.auth-field input {
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167, 93, 69, 0.12);
}

.auth-code-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.auth-note {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.auth-error {
  margin: 0;
  font-size: 12px;
  color: var(--danger);
}

.auth-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.auth-close:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.auth-logout {
  align-self: flex-start;
  border: none;
  background: none;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}
