:root {
  --bg: #16171a;
  --panel: #1e2024;
  --panel2: #25282d;
  --line: #33363c;
  --text: #e6e7ea;
  --muted: #9097a1;
  --accent: #4c8dff;
  --accent-text: #fff;
  --good: #3fbf7f;
  --bad: #ff5a5a;
  --checker-a: #2a2c30;
  --checker-b: #232529;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Ubuntu, Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
.muted { color: var(--muted); }
.small { font-size: 11px; }
h2 { margin: 0 0 6px; font-size: 18px; }
h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }

.top { display: flex; align-items: center; gap: 24px; padding: 0 16px; height: 46px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.brand { font-weight: 700; font-size: 15px; }
.tabs { display: flex; gap: 2px; height: 100%; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 0 14px; font: inherit; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.status { margin-left: auto; font-size: 12px; }
.coffee { font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.coffee:hover { border-color: var(--accent); color: var(--accent); }

.layout { flex: 1; display: grid; grid-template-columns: 240px 1fr 300px; min-height: 0; }
.files, .settings { background: var(--panel); overflow: auto; min-height: 0; }
.files { border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.settings { border-left: 1px solid var(--line); padding: 12px; }
.settings section { padding: 10px 0 14px; border-bottom: 1px solid var(--line); }
.settings section:last-child { border-bottom: 0; }

.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { border-color: #4a4e56; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.icon { width: 30px; padding: 4px 0; font-size: 16px; }
.btn.full, .seg.full { width: 100%; }
.file-actions { display: flex; gap: 8px; }
.file-actions .btn { flex: 1; }

.drop { border: 1.5px dashed var(--line); border-radius: 8px; padding: 18px 10px; text-align: center; color: var(--muted); }
.drop.hot { border-color: var(--accent); color: var(--text); }
.pager { display: flex; align-items: center; justify-content: space-between; }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.file-list li { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.file-list li:hover { background: var(--panel2); }
.file-list li.active { background: #2c3a55; }
.file-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .meta { font-size: 11px; color: var(--muted); }
.file-list .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 2px; }

select, input[type=number], input[type=search], input[type=text] {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; font: inherit; min-width: 0;
}
.settings select { width: 100%; }
.settings .row select { flex: 1; width: auto; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.dims .field { flex: 1; flex-direction: row; align-items: center; gap: 6px; }
.dims input { width: 100%; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; cursor: pointer; }
.range { margin: 8px 0; }
.range .lbl { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.range .lbl b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.range input { width: 100%; accent-color: var(--accent); }
.enc { margin-top: 10px; padding: 8px 10px; background: var(--panel2); border-radius: 8px; }
.enc h4 { margin: 0 0 4px; font-size: 12px; }
.hint { color: var(--muted); font-size: 11px; margin: 2px 0 4px; }
.warn { color: #ffb347; font-size: 11px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: var(--panel2); color: var(--muted); border: 0; padding: 5px 10px; font: inherit; cursor: pointer; flex: 1; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: #2c3a55; color: var(--text); }
.seg button:disabled { opacity: .4; cursor: default; }

.tab-pane { display: none; min-width: 0; min-height: 0; }
.tab-pane.active { display: flex; flex-direction: column; }
.tab-pane .pad { padding: 16px 20px; overflow: auto; }
.viewer-bar { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); flex: none; }
.busy { color: var(--accent); font-size: 12px; }
.viewer { flex: 1; position: relative; min-height: 0; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); }
.vp {
  position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none;
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 16px 16px;
}
.vp.dragging { cursor: grabbing; }
/* Dragging in the viewer must never select anything: Safari/WebKit (the Mac
   app) needs the prefixed property and otherwise tints the picture blue. */
.vp, .handle { -webkit-user-select: none; user-select: none; }
.side { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: var(--line); }
.side .vp { position: relative; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.stage img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.stage.pixelated img { image-rendering: pixelated; }
/* Split view: the compressed image sits in a window that slides with the
   divider. Moving the divider only shifts two composited layers in opposite
   directions, so the image is never repainted while dragging (Safari/WebKit
   repaints a clip-path image on every move and flashes it blank). */
.stage { will-change: transform; }
.clipper { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; will-change: transform; }
.clipper img { will-change: transform; }
.handle { position: absolute; top: 0; bottom: 0; width: 24px; margin-left: -12px; cursor: ew-resize; z-index: 2; }
.handle::before { content: ""; position: absolute; left: 11px; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 3px rgba(0,0,0,.6); }
.handle span { position: absolute; top: 50%; left: 2px; width: 20px; height: 32px; margin-top: -16px; background: #fff; border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.tag { position: absolute; top: 8px; padding: 2px 8px; background: rgba(0,0,0,.6); border-radius: 4px; font-size: 11px; pointer-events: none; z-index: 3; }
.tag.left { left: 8px; } .tag.right { right: 8px; }
.errorbar { background: #3a1f22; color: #ffb3b3; padding: 8px 12px; border-top: 1px solid #5a2a2f; white-space: pre-wrap; flex: none; }

.stats dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
#stSaved.good { color: var(--good); font-weight: 600; }
#stSaved.bad { color: var(--bad); font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; margin-bottom: 10px; }
.badge.ok { background: #1e3d2d; color: var(--good); }
.badge.warnb { background: #3d321e; color: #ffb347; }

.tbl { width: 100%; border-collapse: collapse; margin-top: 8px; }
.tbl th, .tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tbl td.val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-word; }
.tbl tr.sens td { background: rgba(255, 179, 71, .07); }
.kept { color: var(--good); } .dropped { color: var(--muted); }

.dragover { position: fixed; inset: 0; background: rgba(76,141,255,.15); border: 3px dashed var(--accent); display: grid; place-content: center; font-size: 20px; z-index: 50; pointer-events: none; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; z-index: 60; max-width: 80vw; }
.toast.err { border-color: var(--bad); }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 200px 1fr 260px; }
}

/* Edit tab */
.layout.editing { grid-template-columns: 1fr 300px; }
.layout.editing .files { display: none; }
.ed-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ed-view { flex: 1; position: relative; min-height: 0; background: #111214; }
#edImg { position: absolute; inset: 12px; width: calc(100% - 24px); height: calc(100% - 24px); object-fit: contain; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
#edBefore.active { background: #2c3a55; border-color: var(--accent); }
.strip { flex: none; height: 112px; display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; overflow-y: hidden; border-top: 1px solid var(--line); background: var(--panel); }
.thumb { flex: none; height: 94px; width: 124px; position: relative; border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--panel2); border: 2px solid transparent; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.active { border-color: var(--accent); }
.thumb .dot { position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%; background: #ffb347; box-shadow: 0 0 3px rgba(0,0,0,.8); }
.thumb .tn { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; padding: 2px 5px; background: rgba(0,0,0,.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb.add { display: grid; place-content: center; width: 72px; font: 28px/1 inherit; color: var(--muted); border: 1.5px dashed var(--line); background: none; }
.thumb.add:hover { color: var(--text); border-color: var(--accent); }
.adj .range { margin: 4px 0 10px; }
.adj .range .lbl { cursor: default; -webkit-user-select: none; user-select: none; }
.grad { height: 3px; border-radius: 2px; margin: -1px 2px 0; opacity: .8; }
.grad.temp { background: linear-gradient(90deg, #4a86ff, #c8c8c8, #ffc23d); }
.grad.tint { background: linear-gradient(90deg, #3fcf4a, #c8c8c8, #e04ae0); }
.adj input:disabled { opacity: .4; }
/* Crop (Edit tab) */
#edCrop.active { background: #2c3a55; border-color: var(--accent); }
.ratios { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.ratios .btn { padding: 4px 0; font-size: 12px; }
.crop-apply { display: block; width: 100%; margin-top: 8px; padding: 7px 0; font-weight: 600; }
.crop-apply[hidden] { display: none; }
.ratios .btn.active { background: #2c3a55; border-color: var(--accent); }
.crop-sec .curves-head .btn { min-width: 28px; }
.crop-layer { position: absolute; overflow: hidden; pointer-events: none; z-index: 1; -webkit-user-select: none; user-select: none; touch-action: none; }
.crop-box { position: absolute; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .62); outline: 1px solid rgba(255, 255, 255, .85); }
.crop-layer.editing .crop-box {
  pointer-events: auto; cursor: move;
  background-image:
    linear-gradient(to right, transparent calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% + .5px), transparent calc(33.333% + .5px), transparent calc(66.667% - .5px), rgba(255,255,255,.4) calc(66.667% - .5px), rgba(255,255,255,.4) calc(66.667% + .5px), transparent calc(66.667% + .5px)),
    linear-gradient(to bottom, transparent calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% + .5px), transparent calc(33.333% + .5px), transparent calc(66.667% - .5px), rgba(255,255,255,.4) calc(66.667% - .5px), rgba(255,255,255,.4) calc(66.667% + .5px), transparent calc(66.667% + .5px));
}
/* Handles sit just inside the box, so they stay grabbable at the image edge. */
.crop-box i { position: absolute; display: none; width: 14px; height: 14px; background: #fff; border-radius: 2px; box-shadow: 0 0 2px rgba(0,0,0,.7); pointer-events: auto; }
.crop-layer.editing .crop-box i { display: block; }
.crop-box i[data-h="n"], .crop-box i[data-h="s"] { width: 24px; height: 6px; }
.crop-box i[data-h="e"], .crop-box i[data-h="w"] { width: 6px; height: 24px; }
.crop-box i[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.crop-box i[data-h="n"] { left: calc(50% - 12px); top: 0; cursor: ns-resize; }
.crop-box i[data-h="ne"] { right: 0; top: 0; cursor: nesw-resize; }
.crop-box i[data-h="e"] { right: 0; top: calc(50% - 12px); cursor: ew-resize; }
.crop-box i[data-h="se"] { right: 0; bottom: 0; cursor: nwse-resize; }
.crop-box i[data-h="s"] { left: calc(50% - 12px); bottom: 0; cursor: ns-resize; }
.crop-box i[data-h="sw"] { left: 0; bottom: 0; cursor: nesw-resize; }
.crop-box i[data-h="w"] { left: 0; top: calc(50% - 12px); cursor: ew-resize; }

/* Curves (Edit tab) */
.curves-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.curves-head h3 { margin: 0; flex: 1; }
.curves-head select { width: auto; padding: 4px 6px; }
.curves-head .btn { padding: 4px 8px; font-size: 12px; }
#crvCanvas { display: block; width: 100%; aspect-ratio: 1; border-radius: 4px; cursor: crosshair; touch-action: none; -webkit-user-select: none; user-select: none; }
#crvCanvas.off { opacity: .4; cursor: default; }
.curves-io { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 6px 2px 2px; font-variant-numeric: tabular-nums; }
.curves-io b { color: var(--text); font-weight: 600; display: inline-block; min-width: 2.5em; }
.export-summary { font-size: 12px; padding: 6px 8px; background: var(--panel2); border-radius: 6px; margin-bottom: 4px; }
.hint a { color: var(--accent); }

/* File names (rename on export) */
.naming { display: flex; gap: 8px; align-items: center; }
.naming input[type=text] { flex: 1; min-width: 0; }
.naming-start { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.naming-start input { width: 56px; }
