/* PixelShift – boxy, clean UI. Tokens use light-dark() so system + manual theme both work. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f3f3f1, #0b0b0c);
  --panel: light-dark(#ffffff, #141415);
  --sunk: light-dark(#f7f7f5, #101011);
  --ink: light-dark(#0e0e0f, #f1f1ee);
  --muted: light-dark(#6a6a68, #9a9a96);
  --line: light-dark(#d4d4d0, #2c2c2e);
  --line-strong: light-dark(#0e0e0f, #f1f1ee);
  --accent: light-dark(#1f4bff, #6b8bff);
  --accent-ink: #ffffff;
  --accent-soft: light-dark(#e8edff, #1a2142);
  --ok: light-dark(#0a7a3d, #3ddc84);
  --ok-soft: light-dark(#e3f5ea, #10281a);
  --bad: light-dark(#c8201b, #ff6b66);
  --bad-soft: light-dark(#fde9e8, #331413);
  --warn-soft: light-dark(#fff3d6, #33290f);
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px; }
.mono { font-family: var(--mono); }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 16px; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.2px; font-size: 16px; }
.logo { width: 28px; height: 28px; background: var(--ink); color: var(--bg); display: grid; place-items: center; }
.logo svg { width: 16px; height: 16px; }
.brand small { font: 600 11px var(--mono); letter-spacing: .6px; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); padding: 2px 6px; }
.tagline { font: 600 11px var(--mono); letter-spacing: .6px; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tagline::before { content: ''; width: 8px; height: 8px; background: var(--ok); display: inline-block; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--line-strong); background: var(--panel); font-size: 13px; font-weight: 600; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--ink); color: var(--bg); }
.btn:disabled { opacity: .35; cursor: not-allowed; border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.ghost { border-color: var(--line); color: var(--muted); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.field { display: grid; gap: 6px; }
.field + .field, .row + .field, .field + .row { margin-top: 14px; }
.lbl { font: 600 11px var(--mono); letter-spacing: .6px; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.lbl output, .lbl .val { color: var(--ink); }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.hint:empty { display: none; }
input[type='text'], input[type='number'], select {
  width: 100%; height: 34px; padding: 0 10px; background: var(--sunk); border: 1px solid var(--line); border-radius: 0; font-size: 13px;
}
input:focus, select:focus { border-color: var(--accent); outline: none; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
input[type='range'] { width: 100%; accent-color: var(--accent); margin: 0; height: 20px; }
input[type='color'] { width: 40px; height: 34px; padding: 2px; border: 1px solid var(--line); background: var(--sunk); border-radius: 0; }
.suffix { position: relative; }
.suffix input { padding-right: 38px; }
.suffix span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font: 11px var(--mono); color: var(--muted); pointer-events: none; }
.row { display: flex; align-items: center; gap: 8px; }
.row > * { min-width: 0; }
.row .x { color: var(--muted); font-family: var(--mono); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

/* segmented control */
.seg { display: flex; flex-wrap: wrap; border: 1px solid var(--line); background: var(--sunk); }
.seg button { flex: 1 1 auto; height: 32px; padding: 0 10px; border: 0; border-right: 1px solid var(--line); background: transparent; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--ink); background: var(--panel); }
.seg button.on { background: var(--ink); color: var(--bg); }
.seg.wrapgrid button { border-bottom: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 26px; padding: 0 9px; border: 1px solid var(--line); background: var(--panel); font: 600 11.5px var(--mono); color: var(--muted); }
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; padding: 24px 0 40px; align-items: start; }
.main { display: grid; gap: 24px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); }
.side { position: sticky; top: 80px; max-height: calc(100vh - 96px); overflow: auto; }
@media (max-width: 960px) { .shell { grid-template-columns: minmax(0, 1fr); } .side { position: static; max-height: none; } .tagline { display: none; } }

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.side-head h2 { margin: 0; font: 700 12px var(--mono); letter-spacing: .8px; text-transform: uppercase; }
.link-btn { border: 0; background: none; padding: 4px; font: 600 11px var(--mono); letter-spacing: .5px; text-transform: uppercase; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--accent); }
details.sec { border-bottom: 1px solid var(--line); }
details.sec:last-child { border-bottom: 0; }
details.sec > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; font-weight: 700; font-size: 13px; user-select: none; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary .n { font: 600 11px var(--mono); color: var(--muted); }
details.sec > summary::after { content: '+'; margin-left: auto; font: 400 18px var(--mono); color: var(--muted); }
details.sec[open] > summary::after { content: '−'; }
details.sec > summary:hover { background: var(--sunk); }
.sec-body { padding: 4px 16px 18px; }

/* ---------- hero + drop ---------- */
.hero { padding: 28px 0 4px; display: flex; align-items: end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.hero h1 { margin: 0; font-size: clamp(26px, 3.4vw, 40px); line-height: 1.05; letter-spacing: -1.2px; font-weight: 800; }
.hero p { margin: 8px 0 0; color: var(--muted); max-width: 560px; }
.drop {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px; padding: 28px; cursor: pointer;
  border: 1px dashed var(--muted); background: var(--panel);
}
.drop:hover, .drop:focus-visible, .drop.over { border-color: var(--accent); border-style: solid; background: var(--accent-soft); outline: none; }
.drop-icon { width: 56px; height: 56px; display: grid; place-items: center; background: var(--ink); color: var(--bg); }
.drop-icon svg { width: 26px; height: 26px; }
.drop-title { margin: 0; font-size: 18px; font-weight: 700; }
.drop-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.drop .fmts { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; max-width: 260px; }
.drop .fmts span { font: 600 10.5px var(--mono); border: 1px solid var(--line); padding: 2px 6px; color: var(--muted); }
@media (max-width: 640px) { .drop { grid-template-columns: auto 1fr; } .drop .fmts { display: none; } }
.banner { padding: 10px 14px; border: 1px solid var(--line-strong); background: var(--warn-soft); font-size: 13px; }

/* ---------- stats + toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: stretch; justify-content: space-between; }
.stats { display: flex; border: 1px solid var(--line); background: var(--panel); }
.stat { padding: 7px 16px; border-right: 1px solid var(--line); min-width: 96px; }
.stat:last-child { border-right: 0; }
.stat small { display: block; font: 600 10px var(--mono); letter-spacing: .7px; text-transform: uppercase; color: var(--muted); }
.stat b { font: 700 16px var(--mono); }
.stat.good b { color: var(--ok); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.meter { height: 3px; background: var(--line); }
.meter > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- queue ---------- */
.queue { list-style: none; margin: 0; padding: 0; }
.item { border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item-top { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 14px; }
.thumb { width: 64px; height: 64px; object-fit: cover; display: block; border: 1px solid var(--line); background: repeating-conic-gradient(var(--sunk) 0% 25%, var(--line) 0% 50%) 50% / 12px 12px; }
.thumb-ph { display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { flex: none; font: 700 10px var(--mono); letter-spacing: .6px; text-transform: uppercase; padding: 2px 6px; border: 1px solid var(--line); color: var(--muted); }
.tag.working { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tag.done { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.tag.error { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.sub { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 2px 14px; font: 12px var(--mono); color: var(--muted); }
.sub .bad { color: var(--bad); }
.sub .chipnote { color: var(--ink); background: var(--warn-soft); padding: 0 6px; }
.sub .good { color: var(--ok); font-weight: 700; }
.btns { display: flex; gap: 6px; align-items: center; }
.item-bar { height: 3px; background: var(--line); }
.item-bar > div { height: 100%; width: 0; background: var(--accent); }
@media (max-width: 640px) { .item-top { grid-template-columns: 56px minmax(0, 1fr); } .btns { grid-column: 1 / -1; justify-content: flex-end; } .thumb { width: 56px; height: 56px; } }

.pair { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.fig { display: block; padding: 0; text-align: left; background: none; border: 0; border-right: 1px solid var(--line); cursor: zoom-in; min-width: 0; }
.fig:last-child { border-right: 0; }
.fig-img { height: 200px; background: repeating-conic-gradient(var(--sunk) 0% 25%, var(--line) 0% 50%) 50% / 14px 14px; }
.fig-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.fig-cap { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); font: 12px var(--mono); color: var(--muted); }
.fig-cap b { color: var(--ink); text-transform: uppercase; letter-spacing: .6px; }
.fig-cap .save { font-weight: 700; padding: 0 6px; }
.fig-cap .save.ok { background: var(--ok-soft); color: var(--ok); }
.fig-cap .save.bad { background: var(--bad-soft); color: var(--bad); }
.vresult { border-top: 1px solid var(--line); background: #000; }
.vresult video { width: 100%; max-height: 320px; display: block; }
@media (max-width: 640px) { .pair { grid-template-columns: 1fr; } .fig { border-right: 0; border-bottom: 1px solid var(--line); } }

.empty { padding: 36px 20px; text-align: center; color: var(--muted); font: 12px var(--mono); letter-spacing: .4px; text-transform: uppercase; }
.foot { padding: 0 0 40px; color: var(--muted); font: 11px var(--mono); letter-spacing: .4px; text-transform: uppercase; }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line-strong); padding: 0; background: var(--panel); color: var(--ink); box-shadow: 8px 8px 0 rgb(0 0 0 / .25); max-width: 96vw; }
dialog::backdrop { background: rgb(8 8 10 / .72); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.dlg-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.dlg-foot { display: flex; gap: 8px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); }

.cmp { width: min(96vw, 1000px); }
.cmp-body { padding: 14px; }
.cmp-stage { position: relative; margin: 0 auto; overflow: hidden; user-select: none; touch-action: none; cursor: ew-resize; width: 100%; max-height: 68vh; border: 1px solid var(--line); background: repeating-conic-gradient(var(--sunk) 0% 25%, var(--line) 0% 50%) 50% / 16px 16px; }
.cmp-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.cmp-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .5); pointer-events: none; }
.cmp-handle span { position: absolute; top: 50%; left: 50%; width: 30px; height: 30px; transform: translate(-50%, -50%); background: #fff; border: 1px solid #000; display: grid; place-items: center; font: 700 9px var(--mono); color: #000; }
.cmp-handle span::before { content: '◀▶'; letter-spacing: 1px; }
.cmp-tag { position: absolute; top: 10px; font: 700 10px var(--mono); letter-spacing: .6px; text-transform: uppercase; color: #fff; background: #000; padding: 3px 7px; pointer-events: none; }
.cmp-tag.l { left: 10px; } .cmp-tag.r { right: 10px; }
#cmpRange { margin-top: 12px; }
.cmp-foot { margin: 8px 0 0; text-align: center; color: var(--muted); font: 12px var(--mono); }

/* editor (crop / trim) */
.editor { width: min(960px, 96vw); }
.editor-stage { position: relative; display: flex; justify-content: center; padding: 14px; background: #060607; touch-action: none; user-select: none; }
.editor-stage video, .editor-stage img { display: block; max-width: 100%; max-height: 54vh; pointer-events: none; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgb(0 0 0 / .62); cursor: move; touch-action: none; }
.crop-grid { position: absolute; inset: 0; pointer-events: none; background:
  linear-gradient(#fff5, #fff5) 33.33% 0 / 1px 100% no-repeat, linear-gradient(#fff5, #fff5) 66.66% 0 / 1px 100% no-repeat,
  linear-gradient(#fff5, #fff5) 0 33.33% / 100% 1px no-repeat, linear-gradient(#fff5, #fff5) 0 66.66% / 100% 1px no-repeat; }
.crop-label { position: absolute; left: 0; top: 0; font: 700 11px var(--mono); color: #000; background: #fff; padding: 1px 6px; pointer-events: none; }
.crop-h { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; background: #fff; border: 2px solid #000; }
.crop-h.nw { left: 0; top: 0; cursor: nwse-resize; } .crop-h.n { left: 50%; top: 0; cursor: ns-resize; }
.crop-h.ne { left: 100%; top: 0; cursor: nesw-resize; } .crop-h.e { left: 100%; top: 50%; cursor: ew-resize; }
.crop-h.se { left: 100%; top: 100%; cursor: nwse-resize; } .crop-h.s { left: 50%; top: 100%; cursor: ns-resize; }
.crop-h.sw { left: 0; top: 100%; cursor: nesw-resize; } .crop-h.w { left: 0; top: 50%; cursor: ew-resize; }
.editor[data-locked='1'] .crop-h.n, .editor[data-locked='1'] .crop-h.s, .editor[data-locked='1'] .crop-h.e, .editor[data-locked='1'] .crop-h.w { display: none; }
.editor-tools { display: grid; gap: 12px; padding: 12px 14px; }
.editor-tools .t-row { display: grid; grid-template-columns: 78px 1fr auto; gap: 10px; align-items: center; font: 12px var(--mono); color: var(--muted); }
.editor-tools .t-row b { color: var(--ink); font-weight: 700; min-width: 54px; text-align: right; }

/* ---------- toasts / overlay ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: grid; gap: 8px; max-width: min(92vw, 380px); }
.toast { padding: 10px 14px; font-size: 13px; font-weight: 600; background: var(--ink); color: var(--bg); border: 1px solid var(--ink); box-shadow: 4px 4px 0 rgb(0 0 0 / .25); animation: in .18s ease-out; }
.toast.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.toast.error { background: var(--bad); border-color: var(--bad); color: #fff; }
.toast.out { opacity: 0; transition: opacity .25s; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }
.overlay { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; pointer-events: none; background: rgb(8 8 10 / .78); }
.overlay div { font: 800 22px Inter, sans-serif; color: #fff; padding: 28px 44px; border: 2px dashed #fff; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
