:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #efece6;
  --ink: #14161b;
  --ink-2: #555a66;
  --ink-3: #8a8f9a;
  --line: #e2ded6;
  --accent: #ff5b3a;
  --accent-ink: #ffffff;
  --accent-soft: #ffe7e0;
  --checker-a: #ffffff;
  --checker-b: #e4e1db;
  --shadow: 0 1px 2px rgba(20, 22, 27, .06), 0 8px 24px rgba(20, 22, 27, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #23272f;
    --ink: #f1efe9;
    --ink-2: #b4b7bf;
    --ink-3: #7d828d;
    --line: #2d313a;
    --accent: #ff6a4b;
    --accent-soft: #3a211b;
    --checker-a: #2a2e36;
    --checker-b: #21242b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
kbd {
  font: 600 .78em ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 .35em;
  background: var(--surface);
}
[hidden] { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  font: inherit; font-weight: 600;
  border: 1px solid transparent; border-radius: 999px;
  padding: .6em 1.2em;
  cursor: pointer; user-select: none;
  transition: transform .08s, background .15s, box-shadow .15s;
  color: var(--ink); background: var(--surface-2);
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .seg-btn:focus-visible, .tab:focus-visible, .swatch:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover, .btn-ghost.is-on { background: var(--surface-2); }
.btn-ghost.is-on { border-color: var(--accent); }
.btn-small { padding: .4em .9em; font-size: .9rem; }
.btn-large { padding: .85em 2em; font-size: 1.15rem; }
.btn-block { width: 100%; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 40px);
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-size: 1.25rem; letter-spacing: -.01em; }
.brand svg { width: 32px; height: 32px; }
.topnav { display: flex; align-items: center; gap: clamp(10px, 2.5vw, 24px); font-size: .95rem; }
.topnav a { text-decoration: none; color: var(--ink-2); }
.topnav a:hover { color: var(--ink); }
body.is-editing .topnav a { display: none; }

/* Landing */
.landing { flex: 1; padding: 0 clamp(16px, 4vw, 40px) 40px; max-width: 1180px; width: 100%; margin: 0 auto; }
.hero {
  display: grid; grid-template-columns: 1.05fr 1fr; gap: clamp(24px, 5vw, 64px);
  align-items: center; padding: clamp(24px, 6vw, 72px) 0 clamp(40px, 6vw, 80px);
}
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.6rem); line-height: 1.05; letter-spacing: -.03em; margin: 0 0 .5em; }
.accent { color: var(--accent); }
.lede { font-size: clamp(1.02rem, 1.5vw, 1.15rem); color: var(--ink-2); max-width: 34em; margin: 0 0 1.4em; }
.ticks { list-style: none; padding: 0; margin: 0; display: grid; gap: .45em; }
.ticks li { padding-left: 1.7em; position: relative; font-weight: 500; }
.ticks li::before {
  content: ""; position: absolute; left: 0; top: .3em; width: 1.05em; height: 1.05em; border-radius: 50%;
  background: var(--accent-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4.5 8.2 2.3 2.3 4.7-5' fill='none' stroke='%23ff5b3a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/80% no-repeat;
}
.drop-card {
  background: var(--surface); border-radius: 28px; box-shadow: var(--shadow);
  padding: 14px; transition: transform .15s;
}
.drop-card.is-over { transform: scale(1.015); }
.drop-inner {
  border: 2px dashed var(--line); border-radius: 20px;
  padding: clamp(36px, 7vw, 72px) 20px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
}
.drop-card.is-over .drop-inner { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 52px; height: 52px; color: var(--accent); }
.drop-hint { margin: 0; color: var(--ink-2); }
.drop-fine { margin: 0; color: var(--ink-3); font-size: .85rem; }
@media (hover: none) { .desk-only { display: none; } }

.how, .faq { padding: 32px 0; border-top: 1px solid var(--line); }
.how h2, .faq h2 { font-size: 1.6rem; letter-spacing: -.02em; margin: 0 0 20px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.steps li { background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.steps h3 { margin: 12px 0 6px; font-size: 1.08rem; }
.steps p { margin: 0; color: var(--ink-2); font-size: .95rem; }
.num { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.faq details { background: var(--surface); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 10px; box-shadow: var(--shadow); }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { color: var(--ink-2); margin: .6em 0 0; }

/* Editor */
.editor {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px;
  padding: 0 clamp(16px, 3vw, 32px) 20px; min-height: 0;
  height: calc(100vh - 64px - 52px); min-height: 520px;
}
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 12px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg-btn {
  font: inherit; font-size: .9rem; font-weight: 600; color: var(--ink-2);
  background: none; border: 0; border-radius: 999px; padding: .38em 1em; cursor: pointer;
}
.seg-btn.is-on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-wide { display: flex; }
.seg-wide .seg-btn { flex: 1; }
.tool-group { display: flex; align-items: center; gap: 4px; }
.divider { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 10px; background: none; color: var(--ink); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg, .tray-add svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.zoom-label { font: 600 .85rem ui-monospace, Menlo, monospace; min-width: 56px; height: 36px; border: 0; background: none; color: var(--ink-2); cursor: pointer; border-radius: 10px; }
.zoom-label:hover { background: var(--surface-2); }

.stage {
  position: relative; flex: 1; min-height: 0;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: auto; overscroll-behavior: contain;
}
.stage.is-panning, .stage.is-panning * { cursor: grab !important; }
.stage-inner { min-width: 100%; min-height: 100%; display: grid; place-items: center; padding: 20px; width: max-content; height: max-content; }
.canvas-wrap { position: relative; line-height: 0; box-shadow: 0 0 0 1px var(--line); touch-action: none; }
.checker {
  background-color: var(--checker-a);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%, transparent 75%, var(--checker-b) 75%),
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%, transparent 75%, var(--checker-b) 75%);
  background-size: 20px 20px; background-position: 0 0, 10px 10px;
}
#view { display: block; }
.canvas-wrap.is-brush { cursor: none; }
.brush-cursor {
  position: absolute; pointer-events: none; border-radius: 50%;
  border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.35);
  transform: translate(-50%, -50%);
}
.compare-handle { position: absolute; top: 0; bottom: 0; width: 0; cursor: ew-resize; }
.compare-handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: #fff; box-shadow: 0 0 4px rgba(0,0,0,.5); }
.compare-handle span {
  position: absolute; top: 50%; left: 0; width: 36px; height: 36px; transform: translate(-50%, -50%);
  border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m9 7-5 5 5 5M15 7l5 5-5 5' fill='none' stroke='%2314161b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 22px; background-position: center; background-repeat: no-repeat;
}
.compare-handle::after { content: ""; position: absolute; top: 0; bottom: 0; left: -16px; width: 32px; }

.stage-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(2px);
}
.status-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 26px; width: min(360px, 90%); text-align: center;
}
.status-text { margin: 10px 0 4px; font-weight: 600; }
.status-sub { margin: 6px 0 0; color: var(--ink-3); font-size: .85rem; min-height: 1.2em; }
.spinner {
  width: 30px; height: 30px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.tray { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 4px; flex: none; }
.tray-item, .tray-add {
  flex: none; width: 64px; height: 64px; border-radius: 12px; position: relative;
  cursor: pointer; overflow: hidden; border: 2px solid transparent; background-color: var(--surface);
  box-shadow: var(--shadow);
}
.tray-add { display: grid; place-items: center; color: var(--ink-2); border: 2px dashed var(--line); box-shadow: none; background: none; }
.tray-add:hover { color: var(--accent); border-color: var(--accent); }
.tray-item.is-on { border-color: var(--accent); }
.tray-item canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.tray-item.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.6); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.tray-item.is-busy canvas { opacity: .45; }
.tray-item.is-error { border-color: #d33; }
.tray-x {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: rgba(20,22,27,.7); color: #fff; font: 700 13px/20px system-ui; padding: 0;
  cursor: pointer; opacity: 0; transition: opacity .15s;
}
.tray-item:hover .tray-x, .tray-item:focus-within .tray-x { opacity: 1; }
@media (hover: none) { .tray-x { opacity: 1; } }

.panel {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: auto;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab {
  flex: 1; font: inherit; font-weight: 600; font-size: .92rem; color: var(--ink-2);
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 14px 8px; cursor: pointer; margin-bottom: -1px;
}
.tab.is-on { color: var(--ink); border-bottom-color: var(--accent); }
.tab-body { padding: 16px 18px; flex: 1; }
.tab-body h4 { margin: 4px 0 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.tab-body h4 ~ h4 { margin-top: 18px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.swatch {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; padding: 0; position: relative;
}
.swatch.is-on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch-none { background: conic-gradient(var(--checker-b) 25%, var(--checker-a) 0 50%, var(--checker-b) 0 75%, var(--checker-a) 0) 0 0/12px 12px; }
.swatch-custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); overflow: hidden; }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.photo-row { display: flex; gap: 8px; flex-wrap: wrap; }
.slider-row { display: grid; grid-template-columns: 72px 1fr 44px; align-items: center; gap: 10px; margin: 14px 0; font-size: .9rem; }
.slider-row output { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
#blur-row { grid-template-columns: 72px 1fr; }
input[type=range] { accent-color: var(--accent); width: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; margin-top: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.hint { color: var(--ink-3); font-size: .85rem; margin: 10px 0 14px; }

.download { border-top: 1px solid var(--line); padding: 16px 18px; flex: none; }
.dl-opts { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; margin-bottom: 14px; font-size: .9rem; }
.dl-opts .check { grid-column: 1 / -1; margin-top: 2px; }
select {
  font: inherit; font-size: .9rem; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: .45em .6em;
}
.dl-meta { margin: 8px 0 0; text-align: center; color: var(--ink-3); font-size: .8rem; min-height: 1.2em; }

.footer { padding: 16px clamp(16px, 4vw, 40px) 20px; color: var(--ink-3); font-size: .8rem; text-align: center; }
.footer p { margin: 0; }
body.is-editing .footer { padding-top: 0; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 22%, rgba(0,0,0,.35)); backdrop-filter: blur(3px);
  pointer-events: none;
}
.drop-overlay div {
  background: var(--surface); padding: 22px 34px; border-radius: 18px; font-weight: 700; font-size: 1.2rem;
  border: 2px dashed var(--accent); box-shadow: var(--shadow);
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: .92rem;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; }
  .editor { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .stage { height: 62vh; min-height: 320px; flex: none; }
  .panel { overflow: visible; }
}
@media (max-width: 520px) {
  .topnav a { display: none; }
  .toolbar { gap: 8px; }
  .seg-btn { padding: .38em .75em; }
  .divider { display: none; }
}
