:root {
  --bg: #f6f1ea; --surface: #fffdf9; --surface-2: #efe7dc; --ink: #2a2420; --muted: #6f655b;
  --line: #ddd2c4; --accent: #c8651b; --accent-ink: #fff; --focus: #1d6fd1; --shadow: 0 8px 30px rgba(60, 40, 20, .12);
  --invented: #d9338a; --radius: 12px; --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #17130f; --surface: #211b16; --surface-2: #2c241d; --ink: #f3ebe0; --muted: #a79a8b;
  --line: #3a3027; --accent: #f0a04b; --accent-ink: #1b140d; --focus: #7db4ff; --shadow: 0 10px 34px rgba(0, 0, 0, .45);
  --invented: #ff6bb5; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; display: flex; flex-direction: column;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans", "Noto Sans CJK TC", "Noto Sans CJK SC", "Noto Sans CJK JP", "Noto Sans CJK KR", sans-serif;
  transition: background .3s var(--ease), color .3s var(--ease);
}
h1, h2 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1rem; letter-spacing: .02em; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand .name { font-weight: 700; font-size: 1.15rem; letter-spacing: .01em; }
.tagline { margin: 0; color: var(--muted); flex: 1; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-tools { display: flex; gap: .5rem; align-items: center; margin-left: auto; }
.select select, .field select { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; font: inherit; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; transition: transform .2s var(--ease); }
.icon-btn:hover { transform: rotate(18deg); }

.banner { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); border-bottom: 1px solid var(--line); padding: .5rem 1.25rem; font-size: .9rem; display: flex; gap: .75rem; flex-wrap: wrap; }

main { flex: 1; padding: 1.25rem; width: 100%; max-width: 1500px; margin: 0 auto; }
.landing { max-width: 820px; margin: 3vh auto 0; display: grid; gap: 1.5rem; }
.drop { border: 2px dashed var(--line); border-radius: 18px; padding: 3rem 1.5rem; text-align: center; background: var(--surface); transition: border-color .25s var(--ease), transform .25s var(--ease), background .25s; cursor: pointer; display: grid; justify-items: center; gap: .4rem; color: var(--muted); }
.drop h1 { font-size: 1.5rem; color: var(--ink); }
.drop p { margin: 0 0 .8rem; max-width: 46ch; }
.drop.over, .drop:hover { border-color: var(--accent); transform: translateY(-2px); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.drop svg { color: var(--accent); animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-5px); } }
.privacy { text-align: center; color: var(--muted); font-size: .85rem; margin: 0; }
.examples { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.example { padding: 0; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); overflow: hidden; cursor: pointer; text-align: left; color: var(--ink); font: inherit; transition: transform .25s var(--ease), box-shadow .25s; }
.example:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.example img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.example span { display: block; padding: .4rem .6rem; font-size: .85rem; }

.btn { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: .5rem .9rem; font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; transition: transform .15s var(--ease), background .2s, opacity .2s; }
.btn:hover:not(:disabled) { transform: translateY(-1px); background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.btn.quiet { background: transparent; }
.btn.wide { width: 100%; }

.workspace { display: grid; grid-template-columns: 300px 1fr; gap: 1.25rem; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; display: grid; gap: .9rem; position: sticky; top: 76px; }
.steps { border: 0; padding: 0; margin: 0; display: grid; gap: .35rem; }
.steps label, .check { display: flex; gap: .55rem; align-items: center; cursor: pointer; }
.steps small { color: var(--muted); display: block; line-height: 1.25; }
.steps input, .check input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
.slider { display: grid; gap: .25rem; }
.slider input { accent-color: var(--accent); width: 100%; }
.slider small { color: var(--muted); line-height: 1.3; }
.field { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.status { min-height: 1.4em; margin: 0; color: var(--muted); font-size: .88rem; }
.status.error { color: #c0392b; }
.status .bar { display: block; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: .35rem; }
.status .bar::after { content: ""; display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 2px; animation: slide 1.1s var(--ease) infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.face-list { display: grid; gap: .5rem; }
.face-list label { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center; font-size: .88rem; }
.face-list input { accent-color: var(--invented); }

.stage { min-width: 0; display: grid; gap: .75rem; }
.tabs, .photo-tabs { display: flex; gap: .4rem; flex-wrap: wrap; }
.tabs button, .photo-tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: .45rem .8rem; color: var(--muted); font: inherit; cursor: pointer; }
.tabs button[aria-selected="true"], .photo-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.view { display: grid; gap: .75rem; animation: fade .35s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { background: var(--surface-2); color: var(--ink); border: 0; padding: .5rem .8rem; font: inherit; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.inline { display: inline-flex; gap: .4rem; align-items: center; font-size: .88rem; }

.canvas-box { position: relative; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; line-height: 0; touch-action: none; }
.canvas-box img { width: 100%; height: auto; display: block; user-select: none; }
.canvas-box svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.quad { fill: color-mix(in srgb, var(--accent) 16%, transparent); stroke: var(--accent); stroke-width: var(--sw); vector-effect: non-scaling-stroke; transition: fill .2s; }
.quad.sel { fill: color-mix(in srgb, var(--accent) 30%, transparent); stroke-dasharray: none; }
.quad:not(.sel) { stroke-dasharray: 6 4; }
.handle { fill: #fff; stroke: var(--accent); stroke-width: 3; cursor: grab; vector-effect: non-scaling-stroke; transition: r .15s; }
.handle:hover { r: calc(var(--hr) * 1.3); }
.qlabel { fill: var(--accent); font-weight: 700; paint-order: stroke; stroke: #000; stroke-opacity: .55; stroke-width: calc(var(--hr) * .2); pointer-events: none; }

.pipeline { list-style: none; margin: 0; padding: 0; display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; }
.pipeline li { flex: 0 0 auto; }
.chip { display: grid; gap: .1rem; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .75rem; min-width: 118px; cursor: pointer; color: var(--ink); font: inherit; transition: transform .2s var(--ease), border-color .2s, box-shadow .2s; position: relative; }
.chip:hover { transform: translateY(-2px); }
.chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.chip b { font-size: .92rem; }
.chip small { color: var(--muted); font-size: .76rem; }
.chip .tagline-badge { font-size: .7rem; font-weight: 600; border-radius: 99px; padding: .05rem .5rem; width: fit-content; }
.chip .invented { background: color-mix(in srgb, var(--invented) 20%, transparent); color: var(--invented); }
.chip .measured { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.chip.skipped { opacity: .55; border-style: dashed; }
.chip::after { content: "›"; position: absolute; right: -.55rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.pipeline li:last-child .chip::after { content: none; }
.step-note { margin: 0; min-height: 1.3em; font-size: .88rem; color: var(--muted); }

.compare { position: relative; border-radius: var(--radius); overflow: hidden; background: #000 repeating-conic-gradient(#222 0 25%, #1a1a1a 0 50%) 0 0 / 20px 20px; border: 1px solid var(--line); line-height: 0; cursor: ew-resize; touch-action: none; user-select: none; --pos: 50%; max-height: 80vh; }
.zoom { position: relative; transform-origin: 0 0; transform: translate(var(--tx, 0), var(--ty, 0)) scale(var(--z, 1)); will-change: transform; }
.zoom img { display: block; width: 100%; height: auto; max-height: 80vh; object-fit: contain; margin: 0 auto; }
#img-after { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; clip-path: inset(0 0 0 var(--pos)); }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#mask-canvas { pointer-events: auto; cursor: crosshair; opacity: .75; }
.divider { position: absolute; top: 0; bottom: 0; left: var(--pos); width: calc(2px / var(--z, 1)); background: #fff; box-shadow: 0 0 6px rgba(0, 0, 0, .6); pointer-events: none; }
.divider::after { content: "↔"; position: absolute; top: 50%; left: 50%; width: calc(36px / var(--z, 1)); height: calc(36px / var(--z, 1)); line-height: calc(36px / var(--z, 1)); font-size: calc(18px / var(--z, 1)); text-align: center; transform: translate(-50%, -50%); background: #fff; color: #222; border-radius: 50%; box-shadow: 0 2px 8px rgba(0, 0, 0, .5); }
.tag { position: absolute; top: .6rem; background: rgba(0, 0, 0, .6); color: #fff; font-size: .75rem; line-height: 1.2; padding: .25rem .55rem; border-radius: 6px; pointer-events: none; }
.tag.before { left: .6rem; } .tag.after { right: .6rem; }
.split-range { position: absolute; inset: auto 0 0 0; width: 100%; opacity: 0; height: 28px; cursor: ew-resize; }
.split-range:focus-visible { opacity: 1; }
.face-box { fill: none; stroke: var(--invented); stroke-width: 2; vector-effect: non-scaling-stroke; }
.face-num { fill: var(--invented); font-weight: 700; paint-order: stroke; stroke: #000; stroke-width: 3; }
.legend { display: flex; gap: .5rem 1.25rem; flex-wrap: wrap; align-items: center; }
.legend i { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; vertical-align: -1px; margin-right: .35rem; }

.foot { display: flex; gap: 1.25rem; flex-wrap: wrap; justify-content: center; padding: 1rem; color: var(--muted); font-size: .82rem; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .panel { position: static; order: 2; }
  .tagline { display: none; }
  main { padding: .75rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
