/* Inter (variable, self-hosted — no requests to third-party font servers). SIL OFL 1.1, see fonts/OFL.txt */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-vietnamese-wght-normal.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e3e6ef;
  --border-strong: #cfd4e2;
  --text: #121624;
  --muted: #667085;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-2: #9333ea;
  --accent-soft: #eef0ff;
  --on-accent: #ffffff;
  --good: #0e9f4f;
  --good-soft: #e5f6ec;
  --bad: #d92d20;
  --bad-soft: #fdecea;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 20px rgba(16, 24, 40, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f16;
    --surface: #141924;
    --surface-2: #1b2130;
    --border: #252c3c;
    --border-strong: #343d52;
    --text: #e9ecf3;
    --muted: #97a1b5;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-2: #c084fc;
    --accent-soft: rgba(129, 140, 248, .14);
    --on-accent: #0c0f16;
    --good: #3ccf7f;
    --good-soft: rgba(60, 207, 127, .13);
    --bad: #f97066;
    --bad-soft: rgba(249, 112, 102, .13);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { display: block; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); font-weight: 400; }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* ---------- Header ---------- */
.site-header { border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 80%, transparent); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 20; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.02em; color: var(--text); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; fill: var(--accent); }
.privacy-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; color: var(--good); background: var(--good-soft); padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.privacy-pill svg { width: 14px; height: 14px; }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 44px 0 30px; }
.hero h1 { margin: 0 0 10px; font-size: clamp(30px, 5vw, 46px); font-weight: 800; letter-spacing: -.035em; line-height: 1.1; }
.grad { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin: 0 auto; max-width: 560px; color: var(--muted); font-size: 17px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 24px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.settings { padding: 6px 20px; position: sticky; top: 80px; }

.field { padding: 16px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: 0; }
.field-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.sub { margin-top: 14px; display: grid; gap: 8px; }
.sub label { font-size: 14px; font-weight: 500; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
output { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.scale-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: -2px; }

/* Segmented */
.segmented { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 11px; }
.segmented button { flex: 1 1 auto; min-width: 0; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.segmented.small button { font-size: 13px; padding: 7px 8px; }

/* Inputs */
input[type="number"], input[type="text"], select {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 38px; }
.input-suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--muted); pointer-events: none; }
input[type="number"]::-webkit-inner-spin-button { opacity: .5; }
input[type="color"] { width: 40px; height: 30px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer; }

input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; margin: 4px 0; }

.check { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 400 !important; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.dims { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.dims label { display: block; margin-bottom: 6px; }
.lock { width: 34px; height: 40px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.lock svg { width: 17px; height: 17px; }
.lock[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

.chips { display: flex; gap: 6px; }
.chips button { flex: 1; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 5px 0; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.chips button:hover, .chips button.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.advanced summary { cursor: pointer; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); list-style: none; display: flex; align-items: center; justify-content: space-between; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::after { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .2s; margin-right: 4px; }
.advanced[open] summary::after { transform: rotate(-135deg); }
.link-btn { justify-self: start; border: 0; background: none; padding: 4px 0; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }

/* ---------- Dropzone ---------- */
.workspace { display: grid; gap: 16px; min-width: 0; }
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center;
  min-height: 260px; padding: 32px 20px; border: 2px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s, min-height .25s;
}
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dz-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 35%, transparent); }
.dz-icon svg { width: 26px; height: 26px; }
.dz-text { display: grid; gap: 4px; }
.dz-text strong { font-size: 17px; }
.dz-text span { font-size: 13px; color: var(--muted); }
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.dropzone.compact { min-height: 0; flex-direction: row; padding: 16px 20px; gap: 14px; text-align: left; }
.dropzone.compact .dz-icon { width: 40px; height: 40px; border-radius: 12px; flex: none; }
.dropzone.compact .dz-icon svg { width: 20px; height: 20px; }
.dropzone.compact .dz-text strong { font-size: 15px; }

/* ---------- Summary ---------- */
.summary { padding: 16px 20px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; position: relative; overflow: hidden; }
.summary-stats { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.summary-stats div { display: grid; }
.summary-stats .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.summary-stats strong { font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.summary-actions { display: flex; gap: 8px; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: transparent; }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s, opacity .4s; }
.progress.done .bar { opacity: 0; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px; font-size: 14px; font-weight: 600; border: 1px solid transparent; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, opacity .15s; white-space: nowrap; }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 9px; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn[disabled] { opacity: .35; pointer-events: none; }

/* ---------- File list ---------- */
.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.file {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto auto auto; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
  animation: rise .25s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.thumb { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 12px 12px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.info { min-width: 0; }
.name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .note { color: var(--accent); }
.meta .err { color: var(--bad); }
.sizes { display: flex; align-items: center; gap: 8px; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sizes .from { color: var(--muted); }
.sizes .to { font-weight: 700; }
.sizes svg { width: 14px; height: 14px; color: var(--muted); }
.badge { min-width: 58px; text-align: center; font-size: 13px; font-weight: 700; padding: 4px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.actions { display: flex; align-items: center; gap: 4px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Features ---------- */
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; padding: 56px 0 24px; }
.features h3 { margin: 0 0 6px; font-size: 16px; letter-spacing: -.01em; }
.features p { margin: 0; color: var(--muted); font-size: 14px; }
.site-footer { border-top: 1px solid var(--border); padding: 22px 0 30px; color: var(--muted); font-size: 13px; margin-top: 24px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 10, 18, .6); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: min(1000px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: 18px; border: 1px solid var(--border); overflow: hidden; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.modal-head p { margin: 2px 0 0; font-size: 13px; }
.compare { --pos: 50%; position: relative; flex: 0 1 auto; min-height: 240px; height: min(70vh, 640px); background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 18px 18px; user-select: none; }
.compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
#compareAfter { clip-path: inset(0 0 0 var(--pos)); }
.compare-handle { position: absolute; top: 0; bottom: 0; left: var(--pos); width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .2); pointer-events: none; }
.compare-handle span { position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .3); }
.compare-handle span::before, .compare-handle span::after { content: ""; position: absolute; top: 50%; width: 0; height: 0; border: 5px solid transparent; margin-top: -5px; }
.compare-handle span::before { left: 6px; border-right-color: #4b5563; }
.compare-handle span::after { right: 6px; border-left-color: #4b5563; }
.compare input[type="range"] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.tag { position: absolute; top: 12px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: rgba(10, 12, 20, .7); color: #fff; pointer-events: none; }
.tag.left { left: 12px; }
.tag.right { right: 12px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .settings { position: static; order: 2; }
  .workspace { order: 1; }
}
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .hero { padding: 28px 0 20px; }
  .hero p { font-size: 15px; }
  .privacy-pill { font-size: 0; gap: 0; padding: 7px; }
  .privacy-pill svg { width: 16px; height: 16px; }
  .file { grid-template-columns: 48px minmax(0, 1fr) auto; grid-template-areas: "t i b" "t s a"; row-gap: 6px; }
  .thumb { grid-area: t; width: 48px; height: 48px; align-self: start; }
  .info { grid-area: i; }
  .badge { grid-area: b; justify-self: end; }
  .sizes { grid-area: s; font-size: 13px; }
  .actions { grid-area: a; justify-self: end; }
  .file { column-gap: 12px; }
  .meta { white-space: normal; }
  .js-download { width: 34px; padding: 0; }
  .js-download span { display: none; }
  .summary-actions { width: 100%; }
  .summary-actions .btn { flex: 1; }
  .features { grid-template-columns: 1fr; gap: 18px; padding-top: 40px; }
  .dropzone { min-height: 200px; }
}

/* =====================================================================
   Watermark settings
   ===================================================================== */
.sub-label { font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.wm-place { display: flex; align-items: flex-end; gap: 16px; margin-top: 4px; }
.wm-place .check { flex: 1; padding-bottom: 2px; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 30px); gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; width: max-content; transition: opacity .15s; }
.pos-grid button { width: 30px; height: 24px; border: 0; border-radius: 6px; background: var(--surface); cursor: pointer; display: grid; place-items: center; padding: 0; }
.pos-grid button::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.pos-grid button:hover::after { background: var(--muted); }
.pos-grid button.active { background: var(--accent); }
.pos-grid button.active::after { background: var(--on-accent); }
.pos-grid.disabled { opacity: .4; pointer-events: none; }

.logo-pick { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; transition: border-color .15s, background .15s; }
.logo-pick:hover { border-color: var(--accent); background: var(--accent-soft); }
.logo-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.logo-thumb { width: 44px; height: 44px; flex: none; border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 10px 10px; }
.logo-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-text { display: grid; min-width: 0; font-size: 13px; }
.logo-text strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* =====================================================================
   Editor modal (crop / rotate / flip)
   ===================================================================== */
.editor-card { width: min(980px, 100%); }
.editor-stage { display: flex; align-items: center; justify-content: center; padding: 20px; min-height: 240px; overflow: hidden; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 18px 18px; }
.crop-wrap { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; line-height: 0; flex: none; }
.crop-wrap canvas { display: block; }
.crop-mask { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.crop-shade { position: absolute; box-shadow: 0 0 0 9999px rgba(8, 10, 18, .58); }
.crop-box { position: absolute; cursor: move; outline: 2px solid #fff; }
.crop-box::before, .crop-box::after { content: ""; position: absolute; pointer-events: none; opacity: 0; transition: opacity .15s; }
.crop-box::before { left: 33.333%; width: 33.333%; top: 0; bottom: 0; border-left: 1px solid rgba(255, 255, 255, .6); border-right: 1px solid rgba(255, 255, 255, .6); }
.crop-box::after { top: 33.333%; height: 33.333%; left: 0; right: 0; border-top: 1px solid rgba(255, 255, 255, .6); border-bottom: 1px solid rgba(255, 255, 255, .6); }
.crop-wrap.dragging .crop-box::before, .crop-wrap.dragging .crop-box::after, .crop-box:hover::before, .crop-box:hover::after { opacity: 1; }
.crop-box .h { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; background: #fff; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25), 0 1px 4px rgba(0, 0, 0, .3); }
.crop-box .h::after { content: ""; position: absolute; inset: -10px; } /* bigger hit area */
.h[data-dir="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.h[data-dir="n"] { left: 50%; top: 0; cursor: ns-resize; }
.h[data-dir="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.h[data-dir="e"] { left: 100%; top: 50%; cursor: ew-resize; }
.h[data-dir="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.h[data-dir="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.h[data-dir="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.h[data-dir="w"] { left: 0; top: 50%; cursor: ew-resize; }
.h[data-dir="n"], .h[data-dir="s"] { width: 22px; height: 8px; margin: -4px 0 0 -11px; }
.h[data-dir="e"], .h[data-dir="w"] { width: 8px; height: 22px; margin: -11px 0 0 -4px; }
.crop-box.locked .h[data-dir="n"], .crop-box.locked .h[data-dir="s"], .crop-box.locked .h[data-dir="e"], .crop-box.locked .h[data-dir="w"] { display: none; }

.editor-tools { display: grid; gap: 12px; padding: 14px 18px; border-top: 1px solid var(--border); }
.ratio-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ratio-chips button { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); font-variant-numeric: tabular-nums; }
.ratio-chips button:hover { color: var(--text); }
.ratio-chips button.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tool-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tool-group { display: flex; align-items: center; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 11px; }
.tool-btn { width: 36px; height: 32px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 8px; color: var(--text); cursor: pointer; }
.tool-btn svg { width: 18px; height: 18px; }
.tool-btn:hover { background: var(--surface); }
.tool-btn.on { background: var(--accent); color: var(--on-accent); }
.tool-sep { width: 1px; height: 20px; background: var(--border-strong); margin: 0 4px; }
.crop-size { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-left: auto; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }

/* Row badge for edited images */
.edited-tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent); vertical-align: 1px; }
.icon-btn.has-edit { color: var(--accent); }

@media (pointer: coarse) {
  .crop-box .h { width: 18px; height: 18px; margin: -9px 0 0 -9px; }
}
@media (max-width: 640px) {
  .editor-stage { padding: 12px; }
  .modal { padding: 8px; }
  .modal-foot .spacer { display: none; }
  .modal-foot .btn { flex: 1; }
  #editorApplyAll { flex-basis: 100%; order: 3; }
  .crop-size { margin-left: 0; }
}

/* =====================================================================
   Presets
   ===================================================================== */
.preset-row { display: flex; align-items: center; gap: 4px; }
.preset-row select { flex: 1; min-width: 0; font-weight: 600; }
.preset-row .icon-btn { width: 38px; height: 40px; }
.preset-field .hint { margin-top: 8px; }
.preset-save { display: grid; gap: 8px; margin-top: 10px; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.preset-save-actions { display: flex; justify-content: flex-end; gap: 6px; }
.field-label.no-margin { margin-bottom: 0; }
.crop-ratio { margin-top: 16px; }

/* Switch */
.switch { position: relative; display: inline-flex; width: 40px; height: 24px; flex: none; cursor: pointer; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span[aria-hidden] { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .2s; }
.switch span[aria-hidden]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch input:checked + span[aria-hidden] { background: var(--accent); }
.switch input:checked + span[aria-hidden]::after { transform: translateX(16px); }
.switch input:focus-visible + span[aria-hidden] { box-shadow: 0 0 0 3px var(--accent-soft); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Responsive settings */
#rIntro { margin-top: 8px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.hint code, label code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.chips.wrap { flex-wrap: wrap; }
.chips.wrap button { flex: 0 0 auto; padding: 5px 10px; font-variant-numeric: tabular-nums; }
.add-width { display: flex; gap: 6px; }
.add-width .input-suffix { flex: 1; }
.add-width .btn { height: 40px; }
.locked-section { opacity: .45; pointer-events: none; }

/* =====================================================================
   Rows: responsive info + code button
   ===================================================================== */
.r-tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--good-soft); color: var(--good); vertical-align: 1px; }
.js-code[hidden] { display: none; }

/* =====================================================================
   Compare modal — many images
   ===================================================================== */
.compare-card { width: min(1100px, 100%); }
.modal-head .head-text { min-width: 0; }
.modal-head h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.counter { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; padding: 4px 10px; background: var(--surface-2); border-radius: 999px; }
.counter:empty { display: none; }
.compare-card .compare { height: min(62vh, 600px); }
.nav-btn { position: absolute; top: 50%; z-index: 3; width: 44px; height: 44px; margin-top: -22px; border: 0; border-radius: 50%; background: rgba(12, 15, 22, .62); color: #fff; display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px); transition: background .15s, opacity .15s, transform .15s; }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { background: rgba(12, 15, 22, .85); transform: scale(1.05); }
.nav-btn.prev { left: 12px; }
.nav-btn.next { right: 12px; }
.nav-btn:disabled { opacity: 0; pointer-events: none; }
.compare .tag { z-index: 2; }
.compare input[type="range"] { z-index: 1; }

.filmstrip { display: flex; gap: 8px; padding: 10px 14px; overflow-x: auto; border-top: 1px solid var(--border); scroll-behavior: smooth; scrollbar-width: thin; }
.filmstrip:empty { display: none; }
.film { position: relative; flex: none; width: 72px; height: 56px; padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 10px 10px; transition: border-color .15s, opacity .15s; }
.film img { width: 100%; height: 100%; object-fit: cover; display: block; }
.film:hover { border-color: var(--border-strong); }
.film.active { border-color: var(--accent); }
.film .film-badge { position: absolute; left: 3px; bottom: 3px; padding: 0 5px; border-radius: 6px; font-size: 10px; font-weight: 700; line-height: 16px; background: rgba(12, 15, 22, .72); color: #fff; font-variant-numeric: tabular-nums; }
.film .film-badge.good { color: #6ee7a8; }
.film .film-badge.bad { color: #fca5a5; }
.film:disabled { opacity: .4; cursor: default; }
.film .spinner { position: absolute; top: 50%; left: 50%; margin: -8px 0 0 -8px; }
.compare-tip { margin: 0; padding: 0 14px 12px; font-size: 12px; text-align: center; }
kbd { display: inline-block; min-width: 20px; padding: 0 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; font: 600 11px/18px var(--font); color: var(--text); background: var(--surface); text-align: center; }

/* =====================================================================
   Code modal
   ===================================================================== */
.code-card { width: min(820px, 100%); }
.code-body { padding: 16px 18px; display: grid; gap: 14px; overflow: auto; }
.code-wrap { position: relative; }
.code-wrap pre { margin: 0; padding: 16px; padding-right: 110px; border-radius: 12px; background: #0f1320; color: #d7def0; font-size: 13px; line-height: 1.55; overflow: auto; max-height: 300px; white-space: pre; }
.code-wrap code { font-size: inherit; }
.copy-btn { position: absolute; top: 10px; right: 10px; }
.variant-table-wrap { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.variant-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.variant-table th, .variant-table td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.variant-table th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 12px; }
.variant-table tr:last-child td { border-bottom: 0; }
.variant-table td:first-child { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

@media (max-width: 640px) {
  .head-actions .counter { display: none; }
  .head-actions .btn span { display: none; }
  .head-actions .btn { width: 34px; padding: 0; }
  .compare-card .compare { height: 56vh; }
  .nav-btn { width: 38px; height: 38px; margin-top: -19px; }
  .nav-btn.prev { left: 6px; }
  .nav-btn.next { right: 6px; }
  .film { width: 60px; height: 48px; }
  .compare-tip { display: none; }
  .code-wrap pre { padding-right: 16px; padding-top: 52px; }
}
.spinner.center { margin: 0 auto; }
.modal-card:focus { outline: none; }
