/* ============================================================
   ImgTools — design system
   Surface: Operate / Command-Inspect. Dense, calm, precise.
   ============================================================ */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-app: #fbfbfc;
  --panel: #f6f7f9;
  --panel-2: #ffffff;
  --ink: #1f2430;
  --ink-soft: #414857;
  --muted: #6b7280;
  --faint: #9aa1ad;
  --line: #e3e6eb;
  --line-strong: #d3d8e0;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #eaf1ff;
  --accent-line: #c7dafd;
  --ok: #17803d;
  --ok-soft: #e8f7ee;
  --danger: #d92d20;
  --danger-soft: #fef0ef;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 14px -2px rgba(16, 24, 40, .10), 0 2px 4px -2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, .22);
  --r-xs: 7px;
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --bar-h: 58px;
  --panel-w: 348px;
  --film-h: 104px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --dur: 160ms;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1117;
  --bg-app: #0b0e13;
  --panel: #121720;
  --panel-2: #171d27;
  --ink: #eef1f6;
  --ink-soft: #c8ceda;
  --muted: #8c95a5;
  --faint: #6c7585;
  --line: #232b38;
  --line-strong: #2f3a4a;
  --accent: #5b8cff;
  --accent-ink: #0a1020;
  --accent-soft: #17223a;
  --accent-line: #2b3d61;
  --ok: #4ade80;
  --ok-soft: #12271b;
  --danger: #ff6b60;
  --danger-soft: #2a1512;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px -4px rgba(0, 0, 0, .5);
  --shadow-lg: 0 30px 60px -18px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.i {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
kbd {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .02em;
  padding: 2px 5px; border-radius: 5px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); box-shadow: 0 1px 0 var(--line);
}

:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ======================= app bar ======================= */
.appbar {
  height: var(--bar-h);
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px 0 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--ink);
}
[data-theme="dark"] .brand-mark { background: linear-gradient(160deg, #2a3547, #1a2230); }
.brand-mark svg { width: 22px; height: 22px; fill: none; stroke: var(--bg); stroke-width: 2; }
.brand-name { font-size: 16.5px; font-weight: 650; letter-spacing: -.018em; }
.brand-name span { color: var(--accent); }

.nav { display: flex; gap: 2px; margin-left: 6px; }
.nav-link {
  padding: 7px 12px; border-radius: var(--r-sm); font-weight: 520;
  color: var(--muted); transition: color var(--dur), background var(--dur);
}
.nav-link:hover { color: var(--ink); background: var(--panel); }
.nav-link[aria-current="page"] { color: var(--ink); background: var(--panel); font-weight: 590; }

.appbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; min-width: 36px; padding: 0 9px; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-sm);
  color: var(--muted); transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.icon-btn:hover { background: var(--panel); color: var(--ink); }
.icon-btn-sm { height: 30px; min-width: 30px; padding: 0 5px; }
#btnPalette {
  border-color: var(--line); background: var(--bg); padding-right: 7px; gap: 7px;
}
#btnPalette:hover { border-color: var(--line-strong); }
#btnPalette .i { width: 15px; height: 15px; }

.i-moon { display: none; }
[data-theme="dark"] .i-sun { display: none; }
[data-theme="dark"] .i-moon { display: block; }

.account-slot { display: flex; align-items: center; gap: 8px; }
.user-chip {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 6px 0 4px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--bg);
  transition: border-color var(--dur), background var(--dur);
}
.user-chip:hover { border-color: var(--line-strong); background: var(--panel); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 650; letter-spacing: .01em;
}
.user-chip .u-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.user-menu {
  position: absolute; top: 52px; right: 14px; z-index: 60;
  min-width: 232px; padding: 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  animation: pop var(--dur) var(--ease);
}
.user-menu .um-head { padding: 9px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 5px; }
.user-menu .um-head b { display: block; font-size: 13px; }
.user-menu .um-head span { font-size: 12px; color: var(--muted); }
.menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 10px; border: 0; background: none; border-radius: var(--r-xs);
  text-align: left; font-size: 13.5px; color: var(--ink-soft);
}
.menu-item:hover { background: var(--panel); color: var(--ink); }
.menu-item.danger { color: var(--danger); }

@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.985); } }

/* ======================= layout ======================= */
.app { height: calc(100dvh - var(--bar-h)); display: flex; overflow: hidden; }
.view { flex: 1; min-width: 0; display: flex; overflow: hidden; }
.view[hidden] { display: none; }

/* ======================= left panel ======================= */
.panel {
  width: var(--panel-w); flex: none;
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.panel-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 24px; }
.panel-scroll::-webkit-scrollbar { width: 10px; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 3px solid var(--bg); }
.panel-scroll::-webkit-scrollbar-thumb:hover { background: var(--faint); }

.sec { border-bottom: 1px solid var(--line); }
.sec-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 15px 18px; background: none; border: 0; text-align: left;
}
.sec-head h2 {
  font-size: 12px; font-weight: 640; letter-spacing: .055em; text-transform: uppercase;
  color: var(--muted);
}
.sec-head .chev { margin-left: auto; width: 15px; height: 15px; color: var(--faint); transition: transform var(--dur) var(--ease); }
.sec[data-open="false"] .chev { transform: rotate(-90deg); }
.sec[data-open="false"] .sec-body { display: none; }
.sec-badge {
  font-size: 11.5px; color: var(--muted); padding: 1px 7px; border-radius: 99px;
  background: var(--panel); border: 1px solid var(--line); white-space: nowrap;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis;
}
.sec-body { padding: 0 18px 16px; display: flex; flex-direction: column; gap: 13px; }

.row { display: flex; gap: 8px; align-items: center; }
.row-end { justify-content: flex-end; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: var(--panel); color: var(--ink);
  font-weight: 550; font-size: 13.5px; white-space: nowrap;
  transition: background var(--dur), border-color var(--dur), color var(--dur), transform 60ms, box-shadow var(--dur);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn .i { width: 16px; height: 16px; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { border-color: var(--line-strong); background: var(--panel); color: var(--ink); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-block { width: 100%; height: 42px; }
.btn-compare[data-active="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 11px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink-soft);
  font-size: 12.5px; font-weight: 520;
  transition: all var(--dur);
}
.chip:hover { border-color: var(--line-strong); background: var(--panel); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }

/* fields */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field {
  display: flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.field > span { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.field input {
  width: 100%; min-width: 0; border: 0; background: none; outline: none;
  font-variant-numeric: tabular-nums; font-weight: 560; font-size: 13.5px;
  appearance: textfield; -moz-appearance: textfield;
}
.field input::-webkit-outer-spin-button, .field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field small { font-size: 11px; color: var(--faint); }
.field.invalid { border-color: var(--danger); }

.size-row { display: flex; align-items: flex-end; gap: 8px; }
.size-row .field { flex: 1; }
.lock-btn {
  width: 34px; height: 36px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); color: var(--muted);
  transition: all var(--dur);
}
.lock-btn:hover { background: var(--panel); color: var(--ink); }
.lock-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.lock-btn .i-unlock { display: none; }
.lock-btn[aria-pressed="false"] .i-lock { display: none; }
.lock-btn[aria-pressed="false"] .i-unlock { display: block; }

/* sliders */
.sliders { display: flex; flex-direction: column; gap: 2px; }
.slider-row {
  display: grid; grid-template-columns: 84px 1fr 42px; align-items: center; gap: 8px;
  min-height: 32px;
}
.sl-name { font-size: 12.5px; color: var(--muted); }
.slider-row output {
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-soft);
  text-align: right; font-family: var(--mono);
}
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 20px;
  background: none; cursor: grab; --p: 50%;
}
input[type="range"]:active { cursor: grabbing; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--line) var(--p));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; margin-top: -5.5px;
  border-radius: 50%; background: #fff; border: 1.5px solid var(--accent);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .22);
  transition: transform 100ms var(--ease);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 99px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 99px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: #fff;
  border: 1.5px solid var(--accent); box-shadow: 0 1px 3px rgba(16, 24, 40, .22);
}
[data-theme="dark"] input[type="range"]::-webkit-slider-thumb,
[data-theme="dark"] input[type="range"]::-moz-range-thumb { background: #0f1420; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-ui {
  width: 34px; height: 20px; border-radius: 99px; background: var(--line-strong);
  position: relative; transition: background var(--dur); flex: none;
}
.switch-ui::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 2px; }
.switch-label { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.switch:hover .switch-label { color: var(--ink); }

/* segmented */
.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.seg-block { display: flex; width: 100%; }
.seg-item {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 10px; border: 0; border-radius: 6px; background: none;
  font-size: 12.5px; font-weight: 520; color: var(--muted); white-space: nowrap;
  transition: background var(--dur), color var(--dur), box-shadow var(--dur);
}
.seg-item .i { width: 15px; height: 15px; }
.seg-item:hover { color: var(--ink); }
.seg-item.active { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg-item.active { background: var(--panel-2); }
.seg-tabs { margin: 4px 0 14px; }

/* presets */
.preset-groups { display: flex; flex-direction: column; gap: 12px; }
.pgroup-label {
  font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--faint); font-weight: 600; margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.pgroup-items { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset-item {
  display: flex; flex-direction: column; gap: 1px; text-align: left;
  padding: 7px 9px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--bg); transition: all var(--dur);
}
.preset-item:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.preset-item b { font-size: 12.5px; font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset-item span { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.preset-item.is-mine { border-style: dashed; }

/* filters */
.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.filter-tile {
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  padding: 4px 4px 5px; border-radius: var(--r-sm); border: 1px solid transparent;
  background: none; transition: background var(--dur), border-color var(--dur);
}
.filter-tile canvas {
  width: 100%; aspect-ratio: 1; height: auto; border-radius: 6px;
  background: var(--panel); display: block; object-fit: cover;
  box-shadow: 0 0 0 1px var(--line) inset;
}
.filter-tile span {
  font-size: 10.5px; color: var(--muted); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.filter-tile:hover { background: var(--panel); }
.filter-tile[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent-line); }
.filter-tile[aria-checked="true"] span { color: var(--accent); font-weight: 600; }
.filter-tile[aria-checked="true"] canvas { box-shadow: 0 0 0 2px var(--accent) inset; }
.filter-tile:disabled { opacity: .4; }

/* palette */
.palette { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .12);
  padding: 0; position: relative; transition: transform 100ms var(--ease);
}
.swatch:hover { transform: scale(1.12); }
.swatch[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--accent);
}
.swatch-custom {
  width: 26px; height: 26px; border-radius: 50%; overflow: hidden; position: relative;
  border: 1px dashed var(--line-strong); display: grid; place-items: center; color: var(--muted);
}
.swatch-custom input { position: absolute; inset: -6px; opacity: 0; cursor: pointer; }
.swatch-custom::before { content: "+"; font-size: 15px; line-height: 1; }

/* ======================= workspace ======================= */
.workspace {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--bg-app); position: relative;
}
.ws-bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--bg);
  border-bottom: 1px solid var(--line); min-height: 56px;
}
.file-meta { min-width: 0; display: flex; flex-direction: column; }
.file-meta strong {
  font-size: 13.5px; font-weight: 600; letter-spacing: -.01em;
  max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-meta span { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ws-controls { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.zoom { display: flex; align-items: center; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 2px; }
.zoom-val {
  min-width: 52px; height: 26px; border: 0; background: none; border-radius: 6px;
  font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--muted); font-family: var(--mono);
}
.zoom-val:hover { background: var(--bg); color: var(--ink); }

.stage {
  flex: 1; min-height: 0; position: relative; overflow: auto;
  overscroll-behavior: contain; scrollbar-gutter: stable; display: block;
  background-image: radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0);
  background-size: 22px 22px;
}
.stage::-webkit-scrollbar { width: 11px; height: 11px; }
.stage::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 99px;
  border: 3px solid var(--bg-app); background-clip: padding-box;
}
.stage::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: padding-box; }
.stage-inner {
  min-width: 100%; min-height: 100%; width: max-content;
  box-sizing: border-box; padding: 22px;
  display: flex; align-items: center; justify-content: center;
}
[data-theme="dark"] .stage { background-image: radial-gradient(circle at 1px 1px, #1b222d 1px, transparent 0); }
.stage.is-drawing { cursor: crosshair; }
.stage.panning { cursor: grabbing; }

.dropzone {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 44px)); border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-xl); background: color-mix(in srgb, var(--bg) 70%, transparent);
  padding: 42px 28px; text-align: center;
  transition: border-color var(--dur), background var(--dur), transform var(--dur) var(--ease);
}
.dropzone:hover { border-color: var(--faint); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.005); }
.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.dz-art svg { width: 118px; height: 88px; fill: none; stroke: var(--line-strong); stroke-width: 2.4; }
.dz-art svg rect:last-of-type { stroke: var(--accent); opacity: .55; }
.dz-inner h3 { font-size: 17px; font-weight: 620; letter-spacing: -.015em; margin-top: 4px; }
.dz-inner p { font-size: 12.5px; color: var(--muted); }
.dz-actions { margin-top: 8px; }
.dz-note { font-size: 11.5px; color: var(--faint); margin-top: 4px; }

.canvas-wrap {
  position: relative; line-height: 0; flex: none;
  box-shadow: 0 10px 40px -12px rgba(16, 24, 40, .28), 0 0 0 1px var(--line);
  background:
    repeating-conic-gradient(#f0f2f5 0% 25%, #ffffff 0% 50%) 50% / 16px 16px;
  touch-action: none;
}
[data-theme="dark"] .canvas-wrap { box-shadow: 0 10px 40px -8px rgba(0,0,0,.7), 0 0 0 1px var(--line-strong); }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.canvas-wrap.is-draw { cursor: crosshair; }

.crop-box {
  position: absolute; box-shadow: 0 0 0 9999px rgba(14, 18, 27, .52);
  outline: 1.5px solid rgba(255, 255, 255, .95); cursor: move;
  touch-action: none;
}
.crop-box::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 70%, transparent);
}
.crop-grid { position: absolute; inset: 0; pointer-events: none; opacity: .5; }
.crop-grid i { position: absolute; background: rgba(255, 255, 255, .65); }
.crop-grid i:nth-child(1) { left: 33.33%; top: 0; bottom: 0; width: 1px; }
.crop-grid i:nth-child(2) { left: 66.66%; top: 0; bottom: 0; width: 1px; }
.crop-grid i:nth-child(3) { top: 33.33%; left: 0; right: 0; height: 1px; }
.crop-grid i:nth-child(4) { top: 66.66%; left: 0; right: 0; height: 1px; }
.crop-size {
  position: absolute; left: 50%; bottom: -30px; transform: translateX(-50%);
  padding: 3px 8px; border-radius: 6px; background: rgba(14, 18, 27, .82);
  color: #fff; font-size: 11px; font-family: var(--mono); white-space: nowrap;
  letter-spacing: .01em;
}
.crop-box.narrow .crop-size { display: none; }
.h {
  position: absolute; background: transparent; z-index: 2;
}
.h::before {
  content: ""; position: absolute; inset: 0; border-radius: 2px;
  background: #fff; box-shadow: 0 0 0 1px rgba(37, 99, 235, .35);
}
.h[data-h="nw"], .h[data-h="ne"], .h[data-h="sw"], .h[data-h="se"] { width: 16px; height: 16px; }
.h[data-h="n"], .h[data-h="s"] { left: 50%; margin-left: -14px; width: 28px; height: 8px; }
.h[data-h="w"], .h[data-h="e"] { top: 50%; margin-top: -14px; width: 8px; height: 28px; }
.h[data-h="nw"] { left: -8px; top: -8px; cursor: nwse-resize; }
.h[data-h="ne"] { right: -8px; top: -8px; cursor: nesw-resize; }
.h[data-h="sw"] { left: -8px; bottom: -8px; cursor: nesw-resize; }
.h[data-h="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.h[data-h="n"] { top: -5px; cursor: ns-resize; }
.h[data-h="s"] { bottom: -5px; cursor: ns-resize; }
.h[data-h="w"] { left: -5px; cursor: ew-resize; }
.h[data-h="e"] { right: -5px; cursor: ew-resize; }
.h::before { opacity: 0; transition: opacity var(--dur); }
.crop-box:hover .h::before, .crop-box:focus-within .h::before { opacity: 1; }

.stage-hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  padding: 6px 12px; border-radius: 99px; font-size: 11.5px;
  background: color-mix(in srgb, var(--ink) 88%, transparent); color: var(--bg);
  pointer-events: none; white-space: nowrap;
}
.compare-badge {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 5px 12px; border-radius: 99px; font-size: 11.5px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  background: var(--ink); color: var(--bg); pointer-events: none;
}

/* filmstrip */
.filmstrip {
  height: var(--film-h); flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: var(--bg); border-top: 1px solid var(--line);
  overflow: hidden;
}
.thumbs {
  display: flex; gap: 8px; align-items: center; flex: 1; min-width: 0;
  overflow-x: auto; overflow-y: hidden; height: 100%; padding: 10px 0;
  scrollbar-width: thin;
}
.thumbs::-webkit-scrollbar { height: 6px; }
.thumbs::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }
.thumb {
  position: relative; flex: none; width: 74px; height: 74px; border-radius: 10px;
  background: var(--panel); padding: 0; border: 2px solid transparent;
  overflow: hidden; transition: border-color var(--dur), transform var(--dur) var(--ease);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { transform: translateY(-1px); }
.thumb[aria-selected="true"] { border-color: var(--accent); }
.thumb.excluded img { opacity: .42; }
.thumb .t-badges {
  position: absolute; top: 3px; left: 3px; display: flex; gap: 2px;
}
.t-badge {
  width: 15px; height: 15px; border-radius: 4px; display: grid; place-items: center;
  background: rgba(14, 18, 27, .72); color: #fff;
}
.t-badge .i { width: 9px; height: 9px; stroke-width: 2.2; }
.t-check {
  position: absolute; right: 3px; top: 3px; width: 17px; height: 17px; border-radius: 5px;
  border: 1.5px solid rgba(255, 255, 255, .95); background: rgba(14, 18, 27, .3);
  display: grid; place-items: center; color: #fff;
  backdrop-filter: blur(2px);
}
.t-check .i { width: 10px; height: 10px; stroke-width: 3; opacity: 0; }
.thumb:not(.excluded) .t-check { background: var(--accent); border-color: var(--accent); }
.thumb:not(.excluded) .t-check .i { opacity: 1; }
.thumb .t-del {
  position: absolute; right: 3px; bottom: 3px; width: 18px; height: 18px; border-radius: 5px;
  border: 0; background: rgba(14, 18, 27, .7); color: #fff; display: grid; place-items: center;
  opacity: 0; transition: opacity var(--dur);
}
.thumb .t-del .i { width: 10px; height: 10px; stroke-width: 2.6; }
.thumb:hover .t-del { opacity: 1; }
.thumb .t-num {
  position: absolute; left: 3px; bottom: 3px; font-size: 9.5px; font-family: var(--mono);
  color: #fff; background: rgba(14, 18, 27, .6); padding: 0 4px; border-radius: 4px;
}
.thumb-add {
  flex: none; width: 74px; height: 74px; border-radius: 10px;
  border: 1.5px dashed var(--line-strong); background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; transition: all var(--dur);
}
.thumb-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.thumb-add .i { width: 18px; height: 18px; }
.film-actions { display: flex; align-items: center; gap: 8px; flex: none; padding-left: 10px; border-left: 1px solid var(--line); }
.film-info { font-size: 11.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ======================= presets page ======================= */
.view-presets { background: var(--bg-app); overflow-y: auto; display: block; }
.page { max-width: 1040px; margin: 0 auto; padding: 42px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-head h1 { font-size: 27px; font-weight: 650; letter-spacing: -.028em; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.preset-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.preset-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.preset-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); }
.preset-card h3 { font-size: 15px; font-weight: 620; letter-spacing: -.012em; }
.pc-specs { display: flex; flex-wrap: wrap; gap: 5px; }
.spec {
  font-size: 11px; color: var(--ink-soft); background: var(--panel);
  border: 1px solid var(--line); padding: 2px 7px; border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.pc-actions { display: flex; gap: 6px; margin-top: auto; }
.pc-actions .btn { flex: 1; }
.empty-state {
  border: 1.5px dashed var(--line-strong); border-radius: var(--r-lg);
  padding: 54px 28px; text-align: center; background: var(--bg);
  grid-column: 1 / -1;
}
.empty-state h2 { font-size: 17px; font-weight: 620; letter-spacing: -.015em; }
.empty-state p { color: var(--muted); margin: 6px auto 16px; max-width: 46ch; font-size: 13px; }

/* ======================= modal ======================= */
.modal {
  border: 0; padding: 0; background: transparent; max-width: none; max-height: none;
  color: var(--ink);
}
.modal::backdrop { background: rgba(14, 18, 27, .42); backdrop-filter: blur(2px); }
.modal[open] { animation: fade var(--dur) var(--ease); }
@keyframes fade { from { opacity: 0; } }
.modal-card {
  width: min(420px, calc(100vw - 32px)); margin: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-xl);
  padding: 24px; box-shadow: var(--shadow-lg); position: relative;
  animation: rise 220ms var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal-card h2 { font-size: 19px; font-weight: 640; letter-spacing: -.02em; }
.modal-sub { font-size: 12.5px; color: var(--muted); margin: 6px 0 16px; line-height: 1.5; }
.modal-x {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px;
  display: grid; place-items: center; border: 0; border-radius: 8px;
  background: none; color: var(--muted);
}
.modal-x:hover { background: var(--panel); color: var(--ink); }
.input-field { display: block; margin-bottom: 12px; position: relative; }
.input-field > span { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.input-field input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--bg); outline: none;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.input-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.input-field small { position: absolute; right: 10px; bottom: 12px; font-size: 10.5px; color: var(--faint); }
.form-error {
  font-size: 12px; color: var(--danger); background: var(--danger-soft);
  padding: 8px 10px; border-radius: var(--r-xs); margin-bottom: 12px;
}
.modal-note { font-size: 11px; color: var(--faint); line-height: 1.5; margin-top: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.preset-summary {
  display: flex; flex-wrap: wrap; gap: 5px; padding: 10px;
  background: var(--panel); border-radius: var(--r-sm); border: 1px solid var(--line);
  margin-bottom: 4px;
}

/* command palette */
.modal-wide .modal-card { width: min(560px, calc(100vw - 32px)); padding: 0; overflow: hidden; }
.cmd-card { margin-top: min(14vh, 120px) !important; }
.cmd-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.cmd-input .i { color: var(--muted); }
.cmd-input input { flex: 1; border: 0; outline: none; background: none; font-size: 15px; }
.cmd-list { list-style: none; margin: 0; padding: 6px; max-height: min(56vh, 420px); overflow-y: auto; }
.cmd-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: var(--r-xs); cursor: pointer; font-size: 13.5px;
}
.cmd-list li .cmd-kind { margin-left: auto; font-size: 11px; color: var(--faint); }
.cmd-list li[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.cmd-empty { padding: 18px 10px; color: var(--muted); font-size: 13px; text-align: center; }

/* toasts + progress */
.toasts {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px; border-radius: var(--r-sm); font-size: 13px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg);
  animation: toast-in 220ms var(--ease);
  max-width: 340px;
}
.toast .i { width: 15px; height: 15px; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.progress {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100;
  width: min(340px, calc(100vw - 40px)); padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 8px;
}
.progress-bar { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 120ms linear; }
#progressLabel { font-size: 12px; color: var(--muted); }

/* ======================= responsive ======================= */
.panel-toggle { display: none; }

@media (max-width: 1080px) {
  :root { --panel-w: 312px; }
  .user-chip .u-name { display: none; }
}

@media (max-width: 860px) {
  :root { --film-h: 92px; }
  .nav { display: none; }
  .only-desktop { display: none; }
  .app { position: relative; }
  .view-editor { flex-direction: column-reverse; }
  .panel {
    width: 100%; border-right: 0; border-top: 1px solid var(--line);
    max-height: 46vh; flex: none;
  }
  .workspace { flex: 1; min-height: 0; }
  .stage { padding: 12px; }
  .ws-bar { padding: 8px 12px; gap: 8px; }
  .file-meta strong { max-width: 20ch; }
  .switch-label { display: none; }
  .film-info { display: none; }
  .filmstrip { height: var(--film-h); padding: 0 10px; gap: 6px; }
  .thumb .t-del { opacity: 1; width: 22px; height: 22px; }
  .thumb .t-check { width: 22px; height: 22px; }
  .thumb .t-check .i { width: 12px; height: 12px; }
  .thumb, .thumb-add { width: 64px; height: 64px; }
  .film-actions { padding-left: 6px; gap: 6px; }
  .seg-item span { display: none; }
}

@media (max-width: 520px) {
  .brand-name { font-size: 15px; }
  .page { padding: 26px 16px 70px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .modal-card { padding: 20px; }
  .crop-size { display: none; }
}

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

/* numeric side-input next to a slider */
.slider-row { grid-template-columns: 84px 1fr 48px; }
.sl-num {
  width: 100%; height: 24px; padding: 0 5px;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
  text-align: right; font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; outline: none;
  appearance: textfield; -moz-appearance: textfield;
}
.sl-num::-webkit-outer-spin-button, .sl-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.sl-num:hover { border-color: var(--line); }
.sl-num:focus { border-color: var(--accent); background: var(--bg); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 12%, transparent); }

[hidden] { display: none !important; }
.rename-input {
  width: 100%; height: 32px; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--bg); font-size: 14px; font-weight: 600;
}

/* toast above the filmstrip */
.toasts { bottom: calc(var(--film-h) + 22px); }

/* mobile bottom sheet */
.sheet-btn { display: none; }
.sheet-backdrop { display: none; }

@media (max-width: 860px) {
  .sheet-btn { display: inline-flex; }
  .view-editor { flex-direction: column; }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; max-height: none; height: min(72dvh, 600px);
    z-index: 45; border: 1px solid var(--line); border-bottom: 0;
    border-radius: 18px 18px 0 0; padding-top: 10px;
    box-shadow: 0 -20px 50px -16px rgba(16, 24, 40, .35);
    transform: translateY(102%);
    transition: transform 260ms var(--ease);
  }
  .panel::before {
    content: ""; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 99px; background: var(--line-strong);
  }
  .panel.sheet-open { transform: translateY(0); }
  .panel-scroll { padding-top: 10px; }
  .sheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 44;
    background: rgba(12, 16, 24, .45);
    animation: fade 200ms var(--ease);
  }
  .ws-bar { padding: 8px 12px; gap: 8px; min-height: 0; }
  .file-meta { flex: 1 1 100%; }
  .ws-controls { margin-left: 0; width: 100%; justify-content: space-between; gap: 8px; }
  .stage { padding: 10px; }
}

/* presets: compact cards, odd last item spans the row so no empty hole */
.pgroup-items { grid-auto-rows: 1fr; }
.preset-item { padding: 6px 9px; }
.preset-item span { font-size: 10.5px; }
.pgroup-items > .preset-item:last-child:nth-child(odd) { grid-column: 1 / -1; }
.pgroup-items > .hint:last-child { margin: 0; }

/* header reset menu + real-size zoom */
.menu-wrap { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 55;
  min-width: 208px; padding: 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); animation: pop 140ms var(--ease);
}
.zoom-11 {
  min-width: 34px; padding: 0 5px;
  border-left: 1px solid var(--line); border-radius: 0 6px 6px 0;
}
.switch-sm .switch-label { font-size: 12px; }
.stage.panning { cursor: grabbing; }
.stage { cursor: default; }
.stage.scrollable { cursor: grab; }

.auth-alt { margin-top: 10px; text-align: right; font-size: 12.5px; }
.auth-alt a { color: var(--accent); }
.auth-alt a:hover { text-decoration: underline; }

/* temperature slider shows the cold → warm scale */
.slider-temp input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(to right, #3b82f6 0%, #93c5fd 25%, var(--line) 50%, #fbbf24 75%, #f59e0b 100%);
}
.slider-temp input[type="range"]::-moz-range-track {
  background: linear-gradient(to right, #3b82f6 0%, #93c5fd 25%, var(--line) 50%, #fbbf24 75%, #f59e0b 100%);
}

/* panel footer: copyright of the tools panel */
.panel-foot {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 10px 18px 11px; border-top: 1px solid var(--line); background: var(--bg);
  font-size: 11.5px; letter-spacing: .01em; color: var(--faint);
}
.panel-foot-mark {
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: .6; flex: none;
}
@media (max-width: 860px) {
  .panel-foot { padding-bottom: calc(11px + env(safe-area-inset-bottom, 0px)); }
}
