:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dde1e8;
  --text: #171a21;
  --muted: #5d6573;
  --accent: #d6402b;
  --accent-ink: #ffffff;
  --accent-soft: #fbe7e3;
  --focus: #2b6cd6;
  --good: #1d7f46;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 2px 8px rgb(16 24 40 / .05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #242832;
    --border: #2f3440;
    --text: #e9ebf0;
    --muted: #9aa2b1;
    --accent: #ef5b45;
    --accent-ink: #ffffff;
    --accent-soft: #3a1f1b;
    --focus: #6ea1ff;
    --good: #4cc27f;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; }
.home-link { color: var(--muted); font-size: 13px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-link:hover { color: var(--text); }

.intro { padding: 28px 0 8px; }
.intro h1 { margin: 0 0 6px; font-size: clamp(22px, 4vw, 30px); letter-spacing: -.01em; text-wrap: balance; }
.intro p { margin: 0; color: var(--muted); max-width: 62ch; }

.tabs { display: flex; gap: 4px; margin: 20px 0 16px; padding: 4px; background: var(--surface-2); border-radius: 10px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 550; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel-head h2 { margin: 0 0 2px; font-size: 18px; }
.panel-head p { margin: 0 0 16px; color: var(--muted); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 132px; padding: 20px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--surface-2);
  color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone strong { color: var(--accent); }
.dropzone small { font-size: 12.5px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.compact { min-height: 0; padding: 12px; flex-direction: row; flex-wrap: wrap; gap: 0 6px; }
.dropzone.compact strong { white-space: nowrap; }
.dropzone.compact small { display: none; }

/* Daftar file (gabung) */
.file-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.file-item {
  display: grid; grid-template-columns: auto 44px 1fr auto; align-items: center; gap: 12px;
  padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.file-item .no { width: 22px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.file-item .thumb { width: 44px; height: 56px; display: grid; place-items: center; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.file-item .thumb img { max-width: 100%; max-height: 100%; }
.file-item .thumb img:not([src]) { width: 70%; height: 70%; }
.file-item .meta { min-width: 0; }
.file-item .name { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-item .sub { color: var(--muted); font-size: 13px; }
.file-item .ops { display: flex; gap: 4px; }
.file-item { cursor: grab; touch-action: pan-y; }

/* Grid halaman */
.page-grid { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; }
.page {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 10px;
  user-select: none; -webkit-user-select: none;
}
.page .frame { aspect-ratio: 1; display: grid; place-items: center; background: var(--surface-2); border-radius: 6px; overflow: hidden; cursor: zoom-in; }
.page .frame img { max-width: 100%; max-height: 100%; box-shadow: 0 0 0 1px var(--border); background: #fff; transition: transform .2s; }
.page .frame img:not([src]) { width: 70%; aspect-ratio: 1 / 1.414; box-shadow: none; background: var(--surface); }
.page-grid.selectable .page .frame { cursor: pointer; }
.page .label { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 12.5px; color: var(--muted); min-height: 28px; }
.page .label b { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.page .src { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page .ops { display: flex; gap: 2px; }

.page-grid.selectable .page { cursor: pointer; }
.page-grid.selectable .page.selected { border-color: var(--accent); background: var(--accent-soft); }
.check {
  position: absolute; top: 14px; left: 14px; width: 22px; height: 22px; border-radius: 6px; z-index: 1;
  border: 1.5px solid var(--border); background: var(--surface); display: grid; place-items: center;
}
.selected .check { background: var(--accent); border-color: var(--accent); }
.selected .check::after { content: ""; width: 10px; height: 5px; border: solid var(--accent-ink); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }

.page-grid.sortable .page { cursor: grab; }
.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: 0 6px 18px rgb(0 0 0 / .15); }
.sortable-drag { cursor: grabbing; }

/* Tombol */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; padding: 9px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; position: relative;
}
.icon-btn::before { content: ""; position: absolute; inset: -4px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.danger:hover { color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.page .icon-btn { width: 26px; height: 26px; }
.page .icon-btn svg { width: 16px; height: 16px; }

.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.actions.sticky { position: sticky; bottom: 0; background: var(--surface); padding-bottom: 4px; margin-bottom: -4px; z-index: 2; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); flex: 1 1 220px; max-width: 320px; }
.field input, .range input {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px; width: 100%;
}

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 16px; }
.file-chip { font-weight: 550; min-width: 0; flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip span { color: var(--muted); font-weight: 400; }
.range { display: flex; gap: 6px; flex: 1 1 260px; max-width: 360px; }
.range input { padding: 5px 10px; font-size: 13px; }
.mode { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; font-size: 14px; }
.mode span { font-weight: 600; font-variant-numeric: tabular-nums; }
.mode label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.mode input { accent-color: var(--accent); }
.mode .select, .options .select { gap: 8px; color: var(--muted); font-size: 13px; cursor: default; }
.options { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px; margin-top: 16px; }
.options .select { display: flex; align-items: center; }
.options input[type="range"] { accent-color: var(--accent); width: 140px; }
.options output { min-width: 2ch; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.hint { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12.5px; }
.summary { font-size: 14px; color: var(--muted); align-self: center; }
.summary b, .file-item .sub b { color: var(--text); }
.good { color: var(--good); font-weight: 600; }
.bad { color: var(--accent); font-weight: 600; }
#kompres-list .thumb img { object-fit: cover; width: 100%; height: 100%; }
.mode select, .options select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; cursor: pointer;
}

.foot { color: var(--muted); font-size: 13px; padding-top: 24px; padding-bottom: 32px; }

dialog#preview { border: 0; padding: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog#preview::backdrop { background: rgb(0 0 0 / .6); }
dialog#preview form { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 8px; background: var(--surface); }
.preview-body { padding: 0 16px 16px; }
.preview-body canvas { display: block; max-width: 100%; height: auto; margin: 0 auto; background: #fff; }

.busy { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgb(0 0 0 / .35); color: #fff; font-weight: 600; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgb(255 255 255 / .3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgb(0 0 0 / .2); font-size: 14px; animation: rise .2s ease-out; }
.toast.error { background: var(--accent); color: var(--accent-ink); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 560px) {
  .tabs { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .tabs a:last-child:nth-child(odd) { grid-column: span 2; }
  .tabs a { flex: 1; text-align: center; padding: 8px 6px; font-size: 14px; }
  .page .ops { gap: 0; }
  .page { padding: 6px; }
  .panel { padding: 14px; border-radius: 10px; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .file-item { grid-template-columns: 36px 1fr auto; }
  .file-item .no { display: none; }
  .file-item .thumb { width: 36px; height: 46px; }
  .actions .btns { width: 100%; }
  .actions .btn.primary { flex: 1; }
  .field { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
