/* Photo to Painting */
:root {
  --bg: #f7f3ec; --surface: #ffffff; --surface-2: #f1ebe1; --ink: #2a2420; --muted: #6d6258; --line: #e2d8ca;
  --accent: #b4532a; --accent-ink: #ffffff; --accent-soft: #f6e3d8; --focus: #2f6fd6; --stage: #ebe4d8; --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 24px rgba(60, 40, 20, .07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181513; --surface: #221e1b; --surface-2: #2b2622; --ink: #f0e9e1; --muted: #a99d91; --line: #3a332d;
    --accent: #e0814f; --accent-ink: #1b1209; --accent-soft: #3b2619; --focus: #7aa7ff; --stage: #12100e; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #181513; --surface: #221e1b; --surface-2: #2b2622; --ink: #f0e9e1; --muted: #a99d91; --line: #3a332d;
  --accent: #e0814f; --accent-ink: #1b1209; --accent-soft: #3b2619; --focus: #7aa7ff; --stage: #12100e; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 17px; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.top-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.top-link:hover { color: var(--ink); }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; padding: 20px; max-width: 1400px; margin: 0 auto; align-items: start; }
.stage-col { position: sticky; top: 12px; min-width: 0; }
.stage { background: var(--stage); border-radius: 16px; min-height: 420px; display: grid; place-items: center; overflow: hidden; position: relative; border: 1px solid var(--line); }
.stage.drag { outline: 3px dashed var(--accent); outline-offset: -10px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-icon { color: var(--accent); opacity: .85; }
.empty-title { font-size: 20px; font-weight: 700; color: var(--ink); margin: 8px 0 2px; }
.empty-sub { margin: 0 0 12px; }
.empty-note { font-size: 13px; margin: 12px 0 0; }
.samples { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.samples-label { font-size: 14px; font-weight: 600; color: var(--ink); width: 100%; }
.sample { padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer; background: none; line-height: 0; }
.sample:hover { border-color: var(--accent); }
.sample img { width: 96px; height: 64px; object-fit: cover; display: block; }

.viewer { width: 100%; height: 100%; display: grid; place-items: center; padding: 12px; position: relative; }
.frame { position: relative; line-height: 0; max-width: 100%; box-shadow: var(--shadow); touch-action: pan-y; }
.frame canvas { display: block; max-width: 100%; max-height: calc(100vh - 190px); width: auto; height: auto; }
.before-clip { position: absolute; inset: 0; clip-path: inset(0 50% 0 0); }
.before-clip canvas { width: 100%; height: 100%; max-height: none; }
.divider { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none; }
.knob { position: absolute; top: 50%; left: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.35); }
.knob::before, .knob::after { content: ""; position: absolute; top: 10px; border: 5px solid transparent; }
.knob::before { left: 3px; border-right-color: #555; }
.knob::after { right: 3px; border-left-color: #555; }
.compare-range { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.tag { position: absolute; top: 10px; font-size: 12px; line-height: 1; padding: 5px 8px; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff; pointer-events: none; }
.tag-left { left: 10px; } .tag-right { right: 10px; }
.busy { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); min-width: 240px; }
.busy-text { font-size: 13px; white-space: nowrap; }
.bar { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 2px 0; flex-wrap: wrap; }
.photo-info { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.stage-actions { display: flex; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-quiet { min-height: 34px; padding: 6px 12px; font-weight: 500; font-size: 14px; }

.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.group { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 16px; }
.group h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; }
.sub-h { font-size: 13px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; text-transform: none; }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.status { font-size: 13px; color: var(--muted); margin: 8px 0 0; min-height: 1em; }
.status.error { color: #c0392b; }

.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.style-card { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 0 0 7px; border: 2px solid var(--line); border-radius: 11px; background: var(--surface-2); cursor: pointer; overflow: hidden; text-align: left; }
.style-card img, .style-card .swatch { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; display: block; background: var(--line); }
.style-card .name { font-size: 12.5px; font-weight: 600; padding: 0 7px; line-height: 1.25; }
.style-card[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.style-card:disabled { cursor: not-allowed; opacity: .55; }
.style-card .badge { position: absolute; top: 5px; left: 5px; font-size: 10.5px; padding: 2px 6px; border-radius: 5px; background: rgba(0,0,0,.6); color: #fff; }

.slider { display: block; margin: 10px 0 0; }
.slider-head { display: flex; justify-content: space-between; font-size: 14px; }
.slider-head output { color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input[type="range"] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
.seg-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.seg-label { font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-btn { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; font-size: 13.5px; min-height: 36px; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.palette-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
.pal { display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 0 0 4px; border: 2px solid var(--line); border-radius: 9px; background: var(--surface-2); cursor: pointer; overflow: hidden; }
.pal img, .pal-none { width: 100%; aspect-ratio: 1; object-fit: cover; display: grid; place-items: center; font-size: 12px; color: var(--muted); background: var(--surface); }
.pal-name { font-size: 10.5px; line-height: 1.2; padding: 0 3px; text-align: center; }
.pal[aria-pressed="true"] { border-color: var(--accent); }
.dl-row { display: flex; gap: 8px; margin-top: 10px; }
.dl-row .btn-primary { flex: 1; }

.info { max-width: 1400px; margin: 10px auto 0; padding: 0 20px; }
.info-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.info h2 { font-size: 16px; margin: 10px 0 6px; }
.info p { color: var(--muted); margin: 0 0 8px; font-size: 14px; }
.credits { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.credits summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.footer { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; padding: 26px 20px 34px; color: var(--muted); font-size: 13px; }
.footer a { color: var(--muted); }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; gap: 14px; }
  .stage-col { position: static; }
  .stage { min-height: 0; }
  .viewer { padding: 8px; }
  .frame canvas { max-height: 62vh; }
  .info-grid { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .info { padding: 0 16px; }
  .topbar { padding: 10px 16px; }
}
@media (max-width: 480px) {
  .pill { display: none; }
  .brand-name { font-size: 16px; }
  .style-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .busy { min-width: 0; width: calc(100% - 32px); }
}
