:root,
[data-theme='dark'] {
  color-scheme: dark;
  --bg: #161513;
  --bg-elev: #211f1c;
  --bg-elev-2: #2b2824;
  --line: #3c3833;
  --text: #f4f0e8;
  --muted: #a39c92;
  --accent: #7f9e8c;
  --accent-ink: #10211a;
  --stage: #d9d3c8;
  --danger: #b55248;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

[data-theme='light'] {
  color-scheme: light;
  --bg: #f3efe8;
  --bg-elev: #fffcf8;
  --bg-elev-2: #f6f1e8;
  --line: #e3dcd2;
  --text: #1c1a17;
  --muted: #6f6a63;
  --accent: #2f6f56;
  --accent-ink: #f4f0e8;
  --stage: #d5cfc3;
  --danger: #9d3b34;
  --shadow: 0 12px 30px rgba(40, 30, 20, 0.08);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 'Segoe UI', 'Helvetica Neue', system-ui, sans-serif;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.workspace { flex: 1; min-height: 0; }

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

button {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

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

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

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}

button.wide { width: 100%; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
}

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

.mark { width: 36px; height: 36px; flex: none; }

.wordmark {
  margin: 0;
  font-family: Palatino, 'Palatino Linotype', 'Iowan Old Style', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

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

.top-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

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

.panel {
  min-height: 0;
  overflow: auto;
  background: var(--bg-elev);
  padding: 8px 14px 18px;
}

.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }

.panel .fold + .fold { border-top: 1px solid var(--line); margin-top: 8px; }

h2 {
  margin: 14px 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.fold > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  min-height: 44px;
}

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

.fold > summary h2 { margin: 0; }

.fold > summary::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  flex: none;
}

.fold[open] > summary::after { transform: rotate(45deg); margin-top: -4px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.install-chrome {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
}

.install-chrome a {
  color: var(--accent-ink);
  background: var(--accent);
  text-decoration: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  white-space: nowrap;
}

.install-chrome p { margin: 0; color: var(--muted); font-size: 12px; flex: 1 1 280px; }

.install-chrome .url { font-family: ui-monospace, 'Segoe UI Mono', monospace; }

.hint, .privacy, .subhead {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0;
}

.subhead { margin: 10px 0 4px; }

.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.starter, .sample {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: var(--stage);
  color: #1c1a17;
  border-color: transparent;
}

.starter img, .sample img {
  width: 100%;
  height: 72px;
  object-fit: contain;
}

.starter span, .sample span { font-size: 12px; }

.starter.is-active { outline: 2px solid var(--accent); outline-offset: 1px; }

.sample { width: 100%; margin-bottom: 8px; }
.sample img { height: 64px; width: 64px; }

.lookbook { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.look {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.look-open {
  display: flex;
  gap: 8px;
  align-items: center;
  text-align: left;
  min-width: 0;
  background: transparent;
}

.look-open img, .look-fallback {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background: var(--stage);
  object-fit: contain;
  flex: none;
}

.look-copy { min-width: 0; }
.look-copy strong, .look-copy small { display: block; }
.look-copy strong {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.look-copy small { color: var(--muted); }

.look-actions { display: flex; flex-direction: column; gap: 4px; }
.look-actions button, .layer-actions button { padding: 4px 6px; font-size: 11px; }

.confirm-delete {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

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

.stage-toolbar { display: flex; gap: 8px; align-items: end; }

.name-field { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

input[type='text'], input[type='number'], textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
}

textarea { resize: vertical; }

.stage-wrap {
  position: relative;
  min-height: 0;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 28%),
    var(--stage);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.stage-wrap.is-dropping { outline: 2px dashed var(--accent); outline-offset: -8px; }

#stage {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
  padding: 28px;
  color: #3c3833;
}

.empty[hidden] { display: none; }
.empty-title { margin: 0 0 6px; font-size: 20px; font-family: Palatino, Georgia, serif; }
.empty p { margin: 0; max-width: 360px; }

.layer-list { display: flex; flex-direction: column; gap: 6px; }

.layer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.layer.is-selected { border-color: var(--accent); }

.layer-select {
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  min-width: 0;
}

.layer-select strong, .layer-select small { display: block; }
.layer-select small { color: var(--muted); font-size: 11px; }

.layer-actions { display: flex; gap: 4px; flex: none; }

.preset-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.preset-grid button { padding: 8px 4px; font-size: 12px; }

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

.swatch {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--bg);
}

.swatch i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  display: block;
}

.swatch span { font-variant-numeric: tabular-nums; font-size: 12px; }

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

fieldset:disabled { opacity: 0.45; }

.slider-field, .select-field, .stack, .check-field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.slider-field span, .select-field span { font-size: 12px; color: var(--muted); }
.grow { flex: 1; }

.flip-row, .tint-row, .quick-tints { display: flex; gap: 8px; flex-wrap: wrap; }

.tint-row { align-items: end; }

input[type='color'] {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 8px;
}

.quick-tint {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

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

.num-grid label, .check-field {
  font-size: 12px;
  color: var(--muted);
}

.check-field { flex-direction: row; align-items: center; }

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: 12px;
  color: var(--muted);
}

.statusbar p { margin: 0; }
#status.is-error { color: var(--danger); }
#status.is-ok { color: var(--text); }

@media (max-width: 1040px) {
  body { height: auto; min-height: 100%; overflow: auto; }
  .workspace { flex: none; }
  .workspace { grid-template-columns: 1fr; }
  .stage-column { order: -1; }
  .stage-wrap { height: 62vh; min-height: 320px; }
  .panel { overflow: visible; }
  .panel-left, .panel-right { border: 0; }
  .topbar { align-items: flex-start; }
  .top-actions button,
  .stage-toolbar button,
  .wide { min-height: 44px; }
}

@media (max-width: 760px) {
  .topbar { padding: 10px 12px; }
  .wordmark { font-size: 20px; }
  .tagline { max-width: 34ch; }
  .stage-column { padding: 10px; }
  .stage-wrap { height: 52vh; min-height: 280px; border-radius: 14px; }
  .stage-toolbar { flex-wrap: wrap; }
  .name-field { min-width: 100%; }
  .install-chrome { padding: 8px 12px; }
  .install-chrome a { min-height: 44px; display: inline-flex; align-items: center; }
  .statusbar {
    flex-wrap: wrap;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .preset-grid button,
  .flip-row button,
  .layer-actions button { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
