:root{
  --bg:#F7F4EE;
  --surface:#FFFFFF;
  --surface-2:#F0ECE3;
  --border:#E4DFD3;
  --text:#211F1B;
  --text-muted:#736C5E;
  --accent:#C15F3C;
  --accent-hover:#A94F30;
  --accent-tint:#F3E2D9;
  --danger:#A94438;
  --shadow: 0 1px 2px rgba(33,31,27,.04), 0 8px 24px -8px rgba(33,31,27,.12);
  --radius-sm:8px;
  --radius:14px;
  --radius-lg:20px;
  --font-display:'Fraunces', Georgia, serif;
  --font-body:'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
[data-theme="dark"]{
  --bg:#1B1A17;
  --surface:#242220;
  --surface-2:#2E2B27;
  --border:#3A3631;
  --text:#EEE9DF;
  --text-muted:#A39B8B;
  --accent:#D9764F;
  --accent-hover:#E68A63;
  --accent-tint:#3A2A22;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -10px rgba(0,0,0,.55);
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:var(--font-body);
  -webkit-font-smoothing:antialiased;
  transition:background .25s ease, color .25s ease;
}
h1,h2,h3{font-family:var(--font-display); margin:0; font-weight:500;}
button{font-family:inherit;}
::selection{background:var(--accent-tint);}

/* ---------- Topbar ---------- */
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 24px;
  border-bottom:1px solid var(--border);
}
.topbar__brand{display:flex; align-items:center; gap:9px;}
.mark{
  width:26px; height:26px; border-radius:7px; background:var(--accent);
  color:#fff; display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.topbar__name{font-family:var(--font-display); font-size:18px; font-weight:600; letter-spacing:.2px;}
.topbar__tag{font-size:12.5px; color:var(--text-muted); margin-left:2px; display:none;}
@media(min-width:640px){ .topbar__tag{display:inline;} }
.topbar__actions{display:flex; align-items:center; gap:10px;}
.privacy-pill{
  display:flex; align-items:center; gap:6px;
  font-size:12px; color:var(--text-muted);
  border:1px solid var(--border); border-radius:999px;
  padding:5px 10px 5px 8px;
}
.icon-btn{
  width:34px; height:34px; border-radius:9px; border:1px solid var(--border);
  background:var(--surface); color:var(--text); cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  transition:background .15s, border-color .15s;
}
.icon-btn:hover{background:var(--surface-2);}
.icon-btn.sm{width:26px; height:26px; border-radius:7px; font-size:15px;}

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  font-size:14px; font-weight:600; padding:10px 16px;
  border-radius:10px; border:1px solid transparent; cursor:pointer;
  transition:background .15s, border-color .15s, opacity .15s, transform .1s;
  color:var(--text); background:var(--surface);
}
.btn:active{transform:scale(.98);}
.btn--primary{background:var(--accent); color:#fff;}
.btn--primary:hover{background:var(--accent-hover);}
.btn--outline{border-color:var(--border); background:transparent;}
.btn--outline:hover{background:var(--surface-2);}
.btn--ghost{background:var(--surface-2); border-color:var(--border);}
.btn--ghost:hover{background:var(--border);}
.btn--text{background:transparent; color:var(--text-muted); font-weight:500;}
.btn--text:hover{color:var(--danger);}
.btn--block{width:100%;}
.btn[disabled]{opacity:.45; cursor:not-allowed;}

/* ---------- Dropzone ---------- */
.app{padding:0;}
.dropzone{
  min-height:calc(100vh - 63px);
  display:flex; align-items:center; justify-content:center;
  padding:40px 20px;
}
.dropzone.is-drag .dropzone__inner{border-color:var(--accent); background:var(--accent-tint);}
.dropzone__inner{
  max-width:560px; width:100%; text-align:center;
  border:1.5px dashed var(--border); border-radius:var(--radius-lg);
  padding:64px 32px; background:var(--surface);
  transition:border-color .15s, background .15s;
}
.dropzone__inner h1{
  font-size:clamp(28px,4vw,38px); line-height:1.15; margin-bottom:14px; letter-spacing:-.3px;
}
.dropzone__inner h1 em{color:var(--accent); font-style:italic;}
.dropzone__sub{color:var(--text-muted); font-size:15px; line-height:1.55; max-width:420px; margin:0 auto 28px;}
.dropzone__hint{margin-top:16px; font-size:12.5px; color:var(--text-muted);}

/* ---------- Workspace layout ---------- */
.workspace{
  display:grid;
  grid-template-columns:220px 1fr 300px;
  gap:1px;
  background:var(--border);
  min-height:calc(100vh - 63px);
}
@media(max-width:980px){
  .workspace{grid-template-columns:1fr; grid-template-rows:auto auto auto;}
}
.rail,.stage,.panel{background:var(--bg);}

/* ---------- Rail ---------- */
.rail{padding:16px; display:flex; flex-direction:column; gap:10px;}
.rail__head{display:flex; align-items:center; justify-content:space-between; font-size:12.5px; font-weight:600; color:var(--text-muted); text-transform:uppercase; letter-spacing:.06em;}
.rail__add{
  width:22px; height:22px; border-radius:6px; border:1px solid var(--border);
  display:flex; align-items:center; justify-content:center; cursor:pointer; color:var(--text);
}
.rail__add:hover{background:var(--surface-2);}
.rail__list{display:flex; flex-direction:column; gap:6px; overflow-y:auto; max-height:calc(100vh - 280px); padding-right:2px;}
.rail-item{
  display:flex; align-items:center; gap:8px; padding:6px; border-radius:10px;
  border:1.5px solid transparent; cursor:pointer; position:relative;
}
.rail-item:hover{background:var(--surface-2);}
.rail-item.is-active{border-color:var(--accent); background:var(--surface);}
.rail-item__thumb{
  width:40px; height:40px; border-radius:7px; overflow:hidden; flex-shrink:0;
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%) -4px 0/8px 8px,
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%) -4px 0/8px 8px,
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%) 0/8px 8px,
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%) 0/8px 8px;
  background-color:var(--surface);
}
.rail-item__thumb img{width:100%; height:100%; object-fit:cover; display:block;}
.rail-item__meta{flex:1; min-width:0;}
.rail-item__name{font-size:12.5px; font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.rail-item__status{font-size:11px; color:var(--text-muted);}
.rail-item__status.is-done{color:#4B7A5E;}
.rail-item__remove{
  width:20px; height:20px; border-radius:6px; border:none; background:transparent; color:var(--text-muted);
  display:flex; align-items:center; justify-content:center; cursor:pointer; flex-shrink:0;
}
.rail-item__remove:hover{background:var(--danger); color:#fff;}
.rail-item__spinner{
  width:14px; height:14px; border-radius:50%; border:2px solid var(--border); border-top-color:var(--accent);
  animation:spin .7s linear infinite; flex-shrink:0;
}

/* ---------- Stage ---------- */
.stage{display:flex; flex-direction:column;}
.stage__toolbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 16px; border-bottom:1px solid var(--border); gap:12px; flex-wrap:wrap;
}
.seg{display:flex; background:var(--surface-2); border-radius:9px; padding:3px; gap:2px;}
.seg__btn{
  border:none; background:transparent; color:var(--text-muted); font-size:12.5px; font-weight:600;
  padding:6px 11px; border-radius:7px; cursor:pointer; transition:background .15s, color .15s;
}
.seg__btn.is-active{background:var(--surface); color:var(--text); box-shadow:var(--shadow);}
.stage__zoom{display:flex; align-items:center; gap:8px; font-size:12.5px; color:var(--text-muted);}

.canvas-wrap{
  flex:1; position:relative; display:flex; align-items:center; justify-content:center;
  padding:24px; overflow:auto; min-height:360px;
}
.canvas-empty{color:var(--text-muted); font-size:14px;}
#resultCanvas{
  max-width:100%; max-height:65vh; border-radius:10px; box-shadow:var(--shadow);
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%) 0 0/20px 20px,
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%) 0 0/20px 20px,
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%) 0 0/20px 20px,
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%) 0 0/20px 20px;
  background-color:var(--surface);
}
.compare{
  position:relative; max-width:100%; max-height:65vh; border-radius:10px; overflow:hidden; box-shadow:var(--shadow);
  cursor:ew-resize; user-select:none;
}
.compare__before,.compare__after{
  display:block; max-height:65vh; background-size:cover; background-position:center;
}
.compare__before img,.compare__after img{display:block; max-height:65vh; max-width:100%; pointer-events:none;}
.compare__after{
  position:absolute; inset:0; overflow:hidden; clip-path:inset(0 50% 0 0);
}
.compare__handle{
  position:absolute; top:0; bottom:0; left:50%; width:2px; background:#fff;
  box-shadow:0 0 0 1px rgba(0,0,0,.15);
}
.compare__handle span{
  position:absolute; top:50%; left:50%; width:30px; height:30px; border-radius:50%;
  background:#fff; transform:translate(-50%,-50%); box-shadow:var(--shadow);
  display:flex; align-items:center; justify-content:center;
}
.compare__handle span::before{content:"◂ ▸"; font-size:11px; color:var(--text); letter-spacing:2px;}
.compare__label{
  position:absolute; top:10px; font-size:11px; font-weight:600; color:#fff;
  background:rgba(0,0,0,.5); padding:3px 8px; border-radius:6px; letter-spacing:.03em;
}
.compare__label--l{left:10px;}
.compare__label--r{right:10px;}

.stage__overlay{
  position:absolute; inset:0; background:color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter:blur(3px);
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px;
}
.spinner{
  width:30px; height:30px; border-radius:50%; border:3px solid var(--border);
  border-top-color:var(--accent); animation:spin .8s linear infinite;
}
@keyframes spin{to{transform:rotate(360deg);}}
.stage__overlay p{font-size:13.5px; color:var(--text-muted);}
.progress{width:200px; height:5px; border-radius:99px; background:var(--surface-2); overflow:hidden;}
.progress__bar{height:100%; width:0%; background:var(--accent); transition:width .2s ease;}

/* ---------- Panel ---------- */
.panel{padding:16px; display:flex; flex-direction:column; gap:22px; overflow-y:auto;}
.panel__group h3{
  font-size:12px; text-transform:uppercase; letter-spacing:.07em; color:var(--text-muted);
  margin-bottom:12px; font-family:var(--font-body); font-weight:600;
}
.swatches{display:flex; flex-wrap:wrap; gap:9px;}
.swatch{
  width:32px; height:32px; border-radius:9px; border:1.5px solid var(--border); cursor:pointer;
  position:relative; padding:0; overflow:hidden;
}
.swatch.is-active{outline:2px solid var(--accent); outline-offset:2px;}
.swatch--transparent{
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%) 0 0/10px 10px,
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%) 0 0/10px 10px,
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%) 0 0/10px 10px,
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%) 0 0/10px 10px;
  background-color:var(--surface);
}
.swatch--custom, .swatch--image{display:flex; align-items:center; justify-content:center; background:var(--surface); color:var(--text-muted);}
.swatch--custom input{opacity:0; position:absolute; inset:0; cursor:pointer;}
.swatch--custom{background:conic-gradient(red,yellow,lime,cyan,blue,magenta,red);}
.row{display:flex; gap:8px; margin-top:10px; align-items:center; flex-wrap:wrap;}
.row input[type=color]{width:30px; height:30px; border-radius:8px; border:1.5px solid var(--border); padding:0; cursor:pointer; background:none;}
.row select{
  flex:1; padding:7px 8px; border-radius:8px; border:1.5px solid var(--border); background:var(--surface);
  color:var(--text); font-size:12.5px;
}
.field{display:flex; flex-direction:column; gap:5px; font-size:11.5px; color:var(--text-muted); flex:1;}
.field select{padding:7px 8px; border-radius:8px; border:1.5px solid var(--border); background:var(--surface); color:var(--text); font-size:12.5px;}
.field input[type=range]{accent-color:var(--accent);}

.kbd-list{list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:8px;}
.kbd-list li{display:flex; align-items:center; justify-content:space-between; font-size:12.5px; color:var(--text-muted);}
kbd{
  font-family:var(--font-body); font-size:11px; border:1px solid var(--border); background:var(--surface);
  padding:2px 6px; border-radius:5px; margin-left:4px; color:var(--text);
}

/* ---------- Toast ---------- */
.toast{
  position:fixed; bottom:20px; left:50%; transform:translate(-50%,20px);
  background:var(--text); color:var(--bg); padding:10px 16px; border-radius:10px;
  font-size:13px; opacity:0; pointer-events:none; transition:opacity .2s, transform .2s;
  box-shadow:var(--shadow); z-index:50;
}
.toast.is-visible{opacity:1; transform:translate(-50%,0);}

@media (prefers-reduced-motion: reduce){
  *{animation-duration:.001ms !important; transition-duration:.001ms !important;}
}
