/* Self-hosted fonts (no external requests) */
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:400;font-display:swap;src:url(fonts/kantumruy-pro-khmer-400-normal.woff2) format("woff2");unicode-range:U+1780-17FF,U+19E0-19FF,U+200C-200D,U+25CC}
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:400;font-display:swap;src:url(fonts/kantumruy-pro-latin-400-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}
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:500;font-display:swap;src:url(fonts/kantumruy-pro-khmer-500-normal.woff2) format("woff2");unicode-range:U+1780-17FF,U+19E0-19FF,U+200C-200D,U+25CC}
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:500;font-display:swap;src:url(fonts/kantumruy-pro-latin-500-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}
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:600;font-display:swap;src:url(fonts/kantumruy-pro-khmer-600-normal.woff2) format("woff2");unicode-range:U+1780-17FF,U+19E0-19FF,U+200C-200D,U+25CC}
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:600;font-display:swap;src:url(fonts/kantumruy-pro-latin-600-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}
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:700;font-display:swap;src:url(fonts/kantumruy-pro-khmer-700-normal.woff2) format("woff2");unicode-range:U+1780-17FF,U+19E0-19FF,U+200C-200D,U+25CC}
@font-face{font-family:"Kantumruy Pro";font-style:normal;font-weight:700;font-display:swap;src:url(fonts/kantumruy-pro-latin-700-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}
@font-face{font-family:"IBM Plex Mono";font-style:normal;font-weight:400;font-display:swap;src:url(fonts/ibm-plex-mono-latin-400-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}
@font-face{font-family:"IBM Plex Mono";font-style:normal;font-weight:500;font-display:swap;src:url(fonts/ibm-plex-mono-latin-500-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}

/* Layout: file queue on the left, sticky settings panel on the right; stacks on phones */
:root {
  --paper: #eef2f1;
  --surface: #ffffff;
  --ink: #15201d;
  --muted: #5b6a65;
  --line: #d3dcd9;
  --accent: #1d6b59;
  --accent-ink: #ffffff;
  --accent-soft: #dcece7;
  --warn: #b4530f;
  --good: #1b7a3e;
  --font-ui: "Kantumruy Pro", "Noto Sans Khmer", "Khmer OS", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1513; --surface: #16201d; --ink: #e4ece9; --muted: #95a59f;
    --line: #29352f; --accent: #4cbc9c; --accent-ink: #08130f; --accent-soft: #1b2f29;
    --warn: #f0954e; --good: #5fcf85; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1513; --surface: #16201d; --ink: #e4ece9; --muted: #95a59f;
  --line: #29352f; --accent: #4cbc9c; --accent-ink: #08130f; --accent-soft: #1b2f29;
  --warn: #f0954e; --good: #5fcf85; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
}
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
h1, h2 { text-wrap: balance; margin: 0; }

.shell { max-width: 1120px; margin: 0 auto; padding: 28px 16px 40px; display: flex; flex-direction: column; gap: 24px; }

.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 24px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 46px; height: 46px; border-radius: 12px; overflow: hidden; flex: none; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); }
.logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.mark { width: 32px; height: 32px; color: var(--accent); }
h1 { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.tag { margin: 0; color: var(--muted); font-size: .9rem; }
.privacy { margin-top: 8px; display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--good);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px 3px 9px; }
.privacy svg { width: 15px; height: 15px; flex: none; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.work { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-align: center; padding: 36px 20px; border: 2px dashed var(--line); border-radius: var(--r);
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-ic { width: 44px; height: 44px; color: var(--accent); }
.drop-title { font-weight: 600; font-size: 1.05rem; }
.drop-sub { color: var(--muted); font-size: .82rem; letter-spacing: .02em; }

.queue-head { display: flex; justify-content: space-between; align-items: baseline; }
.queue-head h2 { font-size: 1.05rem; }
.count { color: var(--muted); font-weight: 500; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; padding: 4px; }
.link-btn:hover { color: var(--warn); }

.bulk { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--r); padding: 12px 16px; }
.bulk-info { display: flex; flex-direction: column; min-width: 0; }
.bulk-info b { font-weight: 600; }
.bulk-info span { font-size: .8rem; color: var(--muted); }
.bulk-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.bulk-actions .primary { flex: none; }
.bulk-actions button:disabled { opacity: .5; cursor: wait; }
.bulk-note { flex-basis: 100%; margin: 0; font-size: .78rem; color: var(--muted); }
.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.item.active { border-color: var(--accent); }
.item-top { display: flex; gap: 8px; align-items: start; justify-content: space-between; }
.item-name { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.x { background: none; border: 0; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.x:hover { color: var(--warn); }
.x:disabled { visibility: hidden; }
.meta { color: var(--muted); font-size: .78rem; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.status { font-size: .88rem; color: var(--muted); }
.status.err { color: var(--warn); }
.status.ok { color: var(--good); }

.bar { height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.result { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.sizes { display: flex; flex-direction: column; gap: 4px; }
.size-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: .82rem; }
.lbl { color: var(--muted); min-width: 2.2em; }
.track { height: 10px; background: var(--paper); border-radius: 2px; overflow: hidden; }
.fill { height: 100%; border-radius: 2px; }
.fill.orig { background: var(--muted); opacity: .45; width: 100%; }
.fill.new { background: var(--accent); }
.num { min-width: 7.5em; text-align: right; }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.saved { margin-right: auto; font-weight: 600; color: var(--good); }
.saved.bad { color: var(--warn); font-weight: 500; font-size: .85rem; }
.preview { width: 100%; max-width: 100%; border-radius: 6px; background: #000; max-height: 360px; }

.empty { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; counter-reset: step; }
.empty li { counter-increment: step; border-left: 2px solid var(--line); padding-left: 10px; display: flex; flex-direction: column; }
.empty li::before { content: counter(step); font-family: var(--font-mono); font-size: .78rem; color: var(--accent); }
.empty b { font-size: .92rem; }
.empty span { color: var(--muted); font-size: .82rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 16px; position: sticky; top: calc(16px + env(safe-area-inset-top, 0px)); }
@media (max-width: 860px) { .panel { position: static; } }
.panel-title { font-size: 1.05rem; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .field label, .field-row label { font-size: .82rem; color: var(--muted); font-weight: 500; padding: 0; margin-bottom: 6px; display: block; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: flex; flex-direction: column; align-items: center; text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; height: 100%; }
.seg b { font-size: .88rem; font-weight: 600; }
.seg small { font-size: .7rem; white-space: nowrap; color: var(--muted); }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; min-width: 0; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; }
.field-row output { font-size: .82rem; color: var(--accent); font-weight: 500; }
select {
  font: inherit; font-size: .88rem; color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
select:focus-visible, button:focus-visible, a:focus-visible, input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 2px 0; }
.scale { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.adv { border-top: 1px solid var(--line); padding-top: 12px; }
.adv summary { cursor: pointer; font-size: .86rem; font-weight: 600; color: var(--muted); list-style: none; display: flex; align-items: center; gap: 8px; }
.adv summary::-webkit-details-marker { display: none; }
.adv summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
.adv[open] summary::before { transform: rotate(45deg); }
.adv summary:hover { color: var(--ink); }
.adv summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.adv .grid2 { margin-top: 12px; }
.hint { margin: 10px 0 0; font-size: .74rem; color: var(--muted); }

.actions { display: flex; gap: 8px; }
.primary, .ghost {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 10px 16px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent;
}
.primary { background: var(--accent); color: var(--accent-ink); flex: 1; }
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.ghost:hover { border-color: var(--muted); }
.sm { padding: 5px 12px; font-size: .85rem; flex: none; }
.engine { margin: 0; font-size: .76rem; color: var(--muted); }
.engine:empty { display: none; }

.foot { color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); padding-top: 14px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; }
.foot p { margin: 0; }
.foot a { color: var(--accent); font-weight: 600; text-decoration: none; }
.foot a:hover { text-decoration: underline; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }