:root {
  --bg: #121214;
  --bg2: #19191c;
  --panel: #1f1f23;
  --panel2: #26262b;
  --line: #2f2f35;
  --text: #e6e6ea;
  --muted: #8d8d97;
  --accent: #ff6b8b;
  --accent2: #ff8fa6;
  --accent-ink: #1a0a0f;
  --danger: #ff5a5a;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
#app, .view { height: 100%; }

/* ---------- buttons / inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; white-space: nowrap; user-select: none; }
.btn:hover:not(:disabled) { background: #303037; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent2); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: rgba(255,255,255,.07); }
.btn.ghost.on { color: var(--accent); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 4px; }
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,.07); }
.input { width: 100%; height: 34px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; }
.input:focus, input[type=search]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
select { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; height: 32px; padding: 0 8px; font: inherit; }
input[type=search] { height: 32px; width: 220px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); padding: 0 10px; font: inherit; }

/* ---------- library ---------- */
#library { display: flex; }
.sidebar { width: 240px; flex: none; background: var(--bg2); border-right: 1px solid var(--line); padding: 14px 10px 0; overflow-y: auto; display: flex; flex-direction: column; }
#albumList { flex: 1; }
.user-box { position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px; margin: 12px -10px 0; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--bg2); }
.user-avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: var(--accent-ink); background: linear-gradient(135deg, #ff6b8b, #b48cff); }
.user-avatar { overflow: hidden; }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-text { min-width: 0; flex: 1; }
.user-name, .user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name { font-size: 13.5px; font-weight: 600; }
.user-email { font-size: 12px; color: var(--muted); }
.brand { font-size: 19px; font-weight: 700; padding: 4px 10px 16px; letter-spacing: .2px; }
.brand span { background: linear-gradient(90deg, #ff6b8b, #b48cff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; text-align: left; color: var(--text); }
.nav-item:hover { background: rgba(255,255,255,.05); }
.nav-item.active { background: rgba(255,107,139,.14); color: var(--accent2); }
.nav-item.drop { outline: 2px dashed var(--accent); }
.nav-item .ico { width: 18px; text-align: center; opacity: .85; }
.nav-item .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.side-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 10px 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.side-empty { color: var(--muted); font-size: 13px; padding: 4px 10px; }
.album-cover { width: 28px; height: 28px; border-radius: 4px; overflow: hidden; background: var(--panel2); display: grid; place-items: center; flex: none; color: var(--muted); }
.album-cover img { width: 100%; height: 100%; object-fit: cover; }
.album-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lib-main { flex: 1; overflow-y: auto; position: relative; padding: 0 20px 40px; }
.toolbar { display: flex; align-items: center; gap: 12px; height: 60px; position: sticky; top: 0; z-index: 5; background: rgba(18,18,20,.92); backdrop-filter: blur(8px); }
.toolbar h1 { font-size: 20px; margin: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.toolbar.dark { background: #0c0c0e; padding: 0 12px; height: 52px; border-bottom: 1px solid var(--line); position: relative; }
#sizeSlider { width: 90px; accent-color: var(--accent); }

.selection-bar { position: sticky; top: 60px; z-index: 5; display: flex; gap: 8px; align-items: center; padding: 8px 12px; margin-bottom: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); flex-wrap: wrap; }
.selection-bar #selCount { font-weight: 600; margin-right: 8px; }

.group-head { font-weight: 600; font-size: 15px; margin: 18px 2px 8px; color: #cfcfd6; }
.grid-row { display: flex; gap: 4px; margin-bottom: 4px; }
.tile { position: relative; flex: none; overflow: hidden; border-radius: 4px; background: var(--panel); cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.tile:hover img { transform: scale(1.02); }
.tile::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,.45), transparent 35%, transparent 70%, rgba(0,0,0,.4)); opacity: 0; transition: opacity .15s; pointer-events: none; }
.tile:hover::after, .selecting .tile::after { opacity: 1; }
.tile .check { position: absolute; top: 6px; left: 6px; z-index: 2; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.85); background: rgba(0,0,0,.25); color: transparent; font-size: 12px; cursor: pointer; opacity: 0; display: grid; place-items: center; padding: 0; }
.tile:hover .check, .selecting .tile .check { opacity: 1; }
.tile.selected .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); opacity: 1; }
.tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selected img { transform: scale(.94); }
.tile .fav { position: absolute; top: 4px; right: 6px; z-index: 2; border: 0; background: none; color: #fff; font-size: 18px; cursor: pointer; opacity: 0; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.tile:hover .fav, .tile .fav.on { opacity: 1; }
.tile .fav.on { color: var(--accent); }
.tile .badge { position: absolute; bottom: 6px; right: 7px; z-index: 2; font-size: 12px; background: rgba(0,0,0,.55); border-radius: 4px; padding: 0 5px; }
.tile .rating { position: absolute; bottom: 5px; left: 7px; z-index: 2; color: #ffd36b; font-size: 12px; text-shadow: 0 1px 2px rgba(0,0,0,.8); }
.rating .off, .stars .off { color: rgba(255,255,255,.25); }

.empty { text-align: center; padding: 120px 20px; }
.empty-squid { font-size: 64px; filter: drop-shadow(0 6px 20px rgba(255,107,139,.3)); }
.empty p { margin: 6px 0; font-size: 16px; }
.drop-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(255,107,139,.12); border: 3px dashed var(--accent); display: grid; place-items: center; pointer-events: none; }
.drop-overlay div { background: var(--panel); padding: 18px 28px; border-radius: 12px; font-size: 18px; font-weight: 600; }

/* ---------- viewer ---------- */
#viewer { display: flex; flex-direction: column; background: #0a0a0b; }
.viewer-title { position: absolute; left: 50%; transform: translateX(-50%); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #cfcfd6; font-size: 14px; }
#viewerTitle { cursor: text; padding: 4px 8px; border-radius: 6px; }
#viewerTitle:hover { background: rgba(255,255,255,.07); }
.viewer-body { flex: 1; display: flex; position: relative; min-height: 0; }
.viewer-stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: hidden; padding: 16px 60px; }
.viewer-stage img { max-width: 100%; max-height: 100%; min-width: 0; min-height: 0; object-fit: contain; box-shadow: 0 10px 40px rgba(0,0,0,.6); user-select: none; }
.nav-arrow { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; width: 44px; height: 64px; border: 0; border-radius: 8px; background: rgba(255,255,255,.06); color: #fff; font-size: 34px; cursor: pointer; }
.nav-arrow:hover { background: rgba(255,255,255,.14); }
.nav-arrow.left { left: 10px; }
.nav-arrow.right { right: 10px; }
.info-panel:not(.hidden) ~ .nav-arrow.right, .viewer-body:has(.info-panel:not(.hidden)) .nav-arrow.right { right: 310px; }
.info-panel { width: 300px; flex: none; background: var(--bg2); border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.info-panel h3 { margin: 0 0 12px; }
.info-panel dl { display: grid; grid-template-columns: 76px 1fr; gap: 8px 10px; font-size: 13px; margin: 16px 0; }
.info-panel dt { color: var(--muted); }
.info-panel dd { margin: 0; word-break: break-word; }
.info-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.stars { display: flex; }
.stars button { border: 0; background: none; color: rgba(255,255,255,.25); font-size: 17px; cursor: pointer; padding: 0 2px; }
.stars button.on { color: #ffd36b; }
.stars button:hover { color: #ffe29a; }
#viewerFav.on { color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; }
.field > span { color: var(--muted); }
.radio { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---------- editor ---------- */
#editor { display: flex; flex-direction: column; background: #0c0c0e; }
.editor-body { flex: 1; display: flex; min-height: 0; }
.ed-left { width: 220px; flex: none; background: var(--bg2); border-right: 1px solid var(--line); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.ed-right { width: 320px; flex: none; background: var(--bg2); border-left: 1px solid var(--line); overflow-y: auto; }
.ed-stage { flex: 1; position: relative; min-width: 0; overflow: hidden; background: #1c1c1f; }
#edCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: zoom-in; touch-action: none; }
.ed-badge { position: absolute; top: 12px; left: 12px; background: rgba(0,0,0,.7); padding: 4px 10px; border-radius: 6px; font-size: 12px; letter-spacing: .5px; text-transform: uppercase; }
.panel-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; margin-top: 6px; }
.preset-list { display: flex; flex-direction: column; gap: 1px; }
.preset-group { color: var(--muted); font-size: 11px; margin: 8px 0 2px; }
.preset { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.preset:hover { background: rgba(255,255,255,.07); }
.preset .x { border: 0; background: none; color: var(--muted); cursor: pointer; visibility: hidden; }
.preset:hover .x { visibility: visible; }
.preset .x:hover { color: var(--danger); }
.clip-btns { display: flex; gap: 6px; }
.clip-btns .btn { flex: 1; min-width: 0; justify-content: center; padding: 0 6px; font-size: 12px; }
.history-list { display: flex; flex-direction: column; gap: 1px; font-size: 12.5px; }
.hist { text-align: left; border: 0; background: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; color: #c8c8d0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist:hover { background: rgba(255,255,255,.06); }
.hist.current { background: rgba(255,107,139,.15); color: var(--accent2); }
.hist.future { color: #66666f; }

.histo-wrap { padding: 12px 14px 4px; border-bottom: 1px solid var(--line); }
#histo { width: 100%; height: 90px; display: block; background: #141416; border-radius: 4px; }
.histo-info { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 4px 2px; font-variant-numeric: tabular-nums; }
.histo-info .warn { color: #ffb36b; }
.tool-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.tool-btn { flex: 1; height: 32px; white-space: nowrap; font-size: 12.5px; padding: 0 4px; border: 1px solid var(--line); background: var(--panel2); border-radius: 6px; cursor: pointer; }
.tool-btn:hover { background: #303037; }
.tool-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.panel { border-bottom: 1px solid var(--line); }
.panel > header { display: flex; align-items: center; gap: 8px; padding: 11px 14px; cursor: pointer; user-select: none; font-weight: 600; font-size: 13.5px; }
.panel > header:hover { background: rgba(255,255,255,.03); }
.panel .caret { transition: transform .15s; color: var(--muted); font-size: 11px; }
.panel.collapsed .caret { transform: rotate(-90deg); }
.panel.collapsed .panel-body { display: none; }
.panel-body { padding: 2px 14px 14px; }
.panel-head-extra { margin-left: auto; }
.subhead { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin: 12px 0 4px; }
.hint { color: var(--muted); font-size: 11.5px; margin-top: 6px; }
.hint a { color: var(--accent2); }

.seg { display: flex; background: var(--bg); border-radius: 6px; padding: 2px; gap: 2px; margin: 4px 0 8px; }
.seg button { flex: 1; border: 0; background: none; padding: 5px 6px; border-radius: 5px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.seg .ch-r.on { color: #ff6b6b; } .seg .ch-g.on { color: #5ae27a; } .seg .ch-b.on { color: #6b9bff; }

/* sliders */
.sl { margin: 3px 0 5px; }
.sl-top { display: flex; justify-content: space-between; align-items: center; height: 20px; }
.sl-top label { font-size: 12.5px; color: #c4c4cc; cursor: default; user-select: none; }
.sl.changed .sl-top label { color: var(--text); }
.sl-num { width: 56px; text-align: right; background: none; border: 1px solid transparent; color: #c4c4cc; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 4px; border-radius: 4px; }
.sl-num:hover { border-color: var(--line); }
.sl-num:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.sl input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 16px; background: transparent; margin: 0; cursor: pointer;
  --fill-from: 50%; --fill-to: 50%; --track: linear-gradient(90deg, #3a3a42 var(--fill-from), var(--accent) var(--fill-from), var(--accent) var(--fill-to), #3a3a42 var(--fill-to)); }
.sl input[type=range]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: var(--track); }
.sl input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--track); }
.sl input[type=range].gradient::-webkit-slider-runnable-track { height: 4px; }
.sl input[type=range].gradient::-moz-range-track { height: 4px; }
.sl input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; background: #e8e8ee; margin-top: -5px; border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.6); }
.sl input[type=range].gradient::-webkit-slider-thumb { margin-top: -4.5px; }
.sl input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: #e8e8ee; border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.6); }
.sl input[type=range]:hover::-webkit-slider-thumb { background: #fff; transform: scale(1.12); }

#curveCanvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 4px; cursor: crosshair; touch-action: none; }

.wheels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 8px; }
.wheel { text-align: center; }
.wheel canvas { width: 100%; aspect-ratio: 1; cursor: crosshair; touch-action: none; }
.wheel-label { font-size: 12px; color: #c4c4cc; margin-top: 2px; }
.wheel.changed .wheel-label { color: var(--accent2); }
.wheel-val { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* crop */
.crop-panel { padding: 12px 14px; }
.aspects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 8px; }
.aspects button { border: 1px solid var(--line); background: var(--panel2); border-radius: 5px; padding: 6px 4px; cursor: pointer; font-size: 12.5px; }
.aspects button.on { border-color: var(--accent); color: var(--accent2); }
.crop-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.crop-tools .btn { justify-content: center; }
.crop-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.crop-box { position: absolute; pointer-events: auto; cursor: move; box-shadow: 0 0 0 9999px rgba(0,0,0,.6); outline: 1px solid rgba(255,255,255,.9); touch-action: none; }
.crop-box .grid-lines { position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(90deg, transparent calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% + .5px), transparent calc(33.33% + .5px), transparent calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% + .5px), transparent calc(66.66% + .5px)),
    linear-gradient(180deg, transparent calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% + .5px), transparent calc(33.33% + .5px), transparent calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% + .5px), transparent calc(66.66% + .5px)); }
.crop-box i { position: absolute; width: 18px; height: 18px; border: 0 solid #fff; }
.crop-box i[data-h=nw] { left: -3px; top: -3px; border-width: 3px 0 0 3px; cursor: nwse-resize; }
.crop-box i[data-h=ne] { right: -3px; top: -3px; border-width: 3px 3px 0 0; cursor: nesw-resize; }
.crop-box i[data-h=se] { right: -3px; bottom: -3px; border-width: 0 3px 3px 0; cursor: nwse-resize; }
.crop-box i[data-h=sw] { left: -3px; bottom: -3px; border-width: 0 0 3px 3px; cursor: nesw-resize; }
.crop-box i[data-h=n] { top: -3px; left: calc(50% - 12px); width: 24px; border-top-width: 3px; cursor: ns-resize; }
.crop-box i[data-h=s] { bottom: -3px; left: calc(50% - 12px); width: 24px; border-bottom-width: 3px; cursor: ns-resize; }
.crop-box i[data-h=w] { left: -3px; top: calc(50% - 12px); height: 24px; border-left-width: 3px; cursor: ew-resize; }
.crop-box i[data-h=e] { right: -3px; top: calc(50% - 12px); height: 24px; border-right-width: 3px; cursor: ew-resize; }
.crop-box i::after { content: ''; position: absolute; inset: -10px; }

/* ---------- overlays ---------- */
.spinner { position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); animation: spin .8s linear infinite; z-index: 4; }
@keyframes spin { to { transform: rotate(360deg); } }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2c2c33; border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.5); transition: opacity .3s, transform .3s; }
.toast.error { border-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.6); max-height: 90vh; overflow-y: auto; }
.modal-card.wide { width: min(560px, 100%); }
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.album-pick { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.album-pick .pick { display: flex; justify-content: space-between; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.album-pick .pick:hover { background: rgba(255,255,255,.07); }
.import-strip { display: flex; gap: 6px; margin-bottom: 16px; overflow: hidden; align-items: center; }
.import-strip img { width: 56px; height: 56px; object-fit: cover; border-radius: 5px; flex: none; }
.import-strip span { color: var(--muted); font-size: 13px; padding-left: 4px; white-space: nowrap; }
.import-dest { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }
.import-dest .dest { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text); }
.import-dest .dest:hover { background: rgba(255,255,255,.05); }
.import-dest .dest:has(input[type=radio]:checked) { background: rgba(255,107,139,.14); }
.import-dest input[type=radio] { accent-color: var(--accent); margin: 0; }
.import-dest .muted { margin-left: auto; font-size: 12px; }
.import-dest .input { height: 30px; }
.input.invalid { outline: 2px solid var(--danger); outline-offset: -1px; }
.menu { position: fixed; z-index: 90; min-width: 190px; background: #26262c; border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 12px 40px rgba(0,0,0,.55); }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 5px; cursor: pointer; }
.menu button:hover:not(:disabled) { background: rgba(255,255,255,.08); }
.menu button:disabled { opacity: .4; cursor: default; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.upload-progress { position: fixed; right: 20px; bottom: 20px; z-index: 70; width: 280px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: 13px; }
.upload-progress .bar { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; margin-bottom: 8px; }
.upload-progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #34343b; border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .lib-main { padding: 0 10px 40px; }
  input[type=search] { width: 130px; }
  #sizeSlider, #sortSel { display: none; }
  .ed-left { display: none; }
  .editor-body { flex-direction: column; }
  .ed-stage { flex: none; height: 50vh; }
  .ed-right { width: 100%; flex: 1; border-left: 0; }
  .info-panel { position: absolute; inset: 0 0 0 auto; width: min(300px, 90vw); z-index: 5; }
  .viewer-stage { padding: 8px; }
  .viewer-title { display: none; }
  #edReset, #edBefore { display: none; }
}

/* ---------- background removal ---------- */
a.nav-item, a.btn { text-decoration: none; }
.checker, .tile.alpha img {
  background-color: #c7c7c7;
  background-image: conic-gradient(#9e9e9e 25%, transparent 0 50%, #9e9e9e 0 75%, transparent 0);
  background-size: 20px 20px;
}
.bg-start .btn.wide { margin-top: 10px; }
.bg-color-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.bg-color-row input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.swatch:hover { border-color: var(--accent); }
.bg-redo { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.bg-redo summary { cursor: pointer; padding: 4px 0; }
.bg-redo .btn { margin-top: 6px; }
.bg-status { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 10px; background: var(--bg); border-radius: 6px; font-size: 12.5px; color: #c8c8d0; }
.spinner-inline { width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--accent); animation: spin .8s linear infinite; }

/* standalone page */
.rb-page { display: flex; flex-direction: column; height: 100%; }
.rb-top { position: relative; }
.rb-title { font-size: 16px; margin: 0 0 0 8px; font-weight: 650; }
.rb-body { flex: 1; display: flex; min-height: 0; }
.rb-side { width: 280px; flex: none; background: var(--bg2); border-right: 1px solid var(--line); padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.rb-side .panel-title { margin-top: 10px; }
.rb-add { display: flex; flex-direction: column; gap: 6px; }
.rb-add .btn { justify-content: center; }
.rb-main { flex: 1; overflow-y: auto; padding: 20px; position: relative; }
.rb-drop { border: 2px dashed var(--line); border-radius: 14px; padding: 80px 20px; text-align: center; }
.rb-drop p { margin: 6px 0; font-size: 15px; }
.rb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.rb-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.rb-preview { position: relative; aspect-ratio: 4 / 3; overflow: hidden; cursor: pointer; user-select: none; background: #0e0e10; }
.rb-preview canvas { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; display: block;
  background-color: #c7c7c7; background-image: conic-gradient(#9e9e9e 25%, transparent 0 50%, #9e9e9e 0 75%, transparent 0); background-size: 20px 20px; }
.rb-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: brightness(.6); }
.rb-overlay { position: absolute; inset: auto 8px 8px 8px; display: flex; align-items: center; gap: 8px; background: rgba(12,12,14,.85); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; }
.rb-overlay.error { color: var(--danger); }
.rb-meta { display: flex; align-items: center; gap: 8px; padding: 10px 12px 4px; font-size: 13.5px; }
.rb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; flex: none; }
.rb-actions { display: flex; align-items: center; gap: 6px; padding: 8px 12px 12px; flex-wrap: wrap; }
.rb-actions .icon-btn { margin-left: auto; }
.rb-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; max-height: 50vh; overflow-y: auto; margin-top: 12px; }
.rb-pick .pk { position: relative; aspect-ratio: 1; padding: 0; border: 3px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--panel2); }
.rb-pick .pk img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rb-pick .pk.on { border-color: var(--accent); }
.rb-pick .pk-cut { position: absolute; right: 4px; bottom: 4px; font-size: 11px; background: rgba(0,0,0,.6); border-radius: 4px; padding: 0 4px; }
.modal-actions .muted { margin-right: auto; align-self: center; font-size: 13px; }
@media (max-width: 900px) {
  .rb-body { flex-direction: column; overflow-y: auto; }
  .rb-side { width: 100%; border-right: 0; border-bottom: 1px solid var(--line); }
  .rb-main { overflow: visible; }
  .rb-top .toolbar-actions .btn { padding: 0 8px; }
  .rb-title { display: none; }
}

/* ---------- masks & copy/paste ---------- */
.ed-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: hidden; }
.ed-overlay .h { pointer-events: all; fill: #fff; stroke: rgba(0,0,0,.65); stroke-width: 2; cursor: grab; }
.ed-overlay .h:hover { fill: var(--accent2); }
.ed-overlay .h.center { fill: var(--accent); }
.ed-overlay .h.rot { fill: #9fd3ff; cursor: alias; }
.ed-overlay .h.sq { cursor: nwse-resize; }
.ed-overlay .h.pin { fill: rgba(255,255,255,.55); r: 5; }
.ed-overlay .g-line { fill: none; stroke: #fff; stroke-width: 1.5; filter: drop-shadow(0 0 1px rgba(0,0,0,.9)); }
.ed-overlay .dashed { stroke-dasharray: 6 5; }
.ed-overlay .brush { fill: none; stroke: #fff; stroke-width: 1.5; filter: drop-shadow(0 0 1px #000); }
.ed-overlay .brush.inner { stroke-dasharray: 3 4; stroke-width: 1; }
.ed-overlay .brush-label { fill: #fff; font: bold 18px sans-serif; text-anchor: middle; filter: drop-shadow(0 0 1px #000); }
.ed-overlay .marquee { fill: rgba(255,107,139,.08); stroke: #000; stroke-width: 1.5; }
.ed-overlay .marquee.ants { fill: none; stroke: #fff; stroke-dasharray: 6 6; animation: ants .6s linear infinite; }
@keyframes ants { to { stroke-dashoffset: -12; } }
.ed-overlay .piece { fill: none; stroke: rgba(255,255,255,.55); stroke-width: 1; stroke-dasharray: 4 4; }
.ed-overlay .piece.on { stroke: var(--accent); stroke-width: 2; stroke-dasharray: none; }
.ed-overlay .piece-box { fill: none; stroke: rgba(255,255,255,.8); stroke-width: 1; }
#edCanvas.tool-cursor { cursor: crosshair; }
#edCanvas.panning { cursor: grab; }
.tool-panel { padding: 12px 14px 16px; }
.tool-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.tool-head .panel-title { margin: 0; }
.mask-list { display: flex; flex-direction: column; gap: 2px; margin: 6px 0; }
.mask-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; border: 1px solid transparent; }
.mask-row:hover { background: rgba(255,255,255,.05); }
.mask-row.on { background: rgba(255,107,139,.12); border-color: rgba(255,107,139,.35); }
.mask-ico { width: 20px; text-align: center; }
.mask-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mask-name i { color: var(--muted); font-style: normal; font-size: 11.5px; }
.mask-title { margin: 10px 0 4px; }
.input.small { height: 30px; font-size: 13px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #c4c4cc; margin: 6px 0; cursor: pointer; }
.chk input { accent-color: var(--accent); margin: 0; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.row-btns .btn { flex: 1; justify-content: center; }
.link-btn { border: 0; background: none; color: var(--accent2); font-size: 12px; cursor: pointer; padding: 4px 0; }
.color-pick { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.swatch.big { width: 30px; height: 30px; border-radius: 6px; cursor: default; }
#maskDone, #pcDone { margin-top: 14px; justify-content: center; }
