:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --text: #13201e;
  --muted: #5b6b68;
  --line: #d9e2e0;
  --brand: #0f766e;
  --brand-strong: #0b5e57;
  --brand-soft: #e3f3f1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1615;
    --surface: #17211f;
    --text: #e6eeec;
    --muted: #9aaba7;
    --line: #2a3734;
    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --brand-soft: #123532;
    --danger: #f97066;
    --danger-soft: #3a1a17;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

body > * { max-width: 720px; margin-inline: auto; }

[hidden] { display: none !important; }

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.5rem; line-height: 1.1; letter-spacing: -0.01em; }
.brand h1 span { color: var(--brand); }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.875rem; }

.lang { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.lang button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--brand); color: var(--surface); }

/* ---------- Tabs ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}
.tabs button {
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 10px 4px;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-strong); }

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  padding: 28px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover, .drop.over, .drop:focus-within { border-color: var(--brand); background: var(--brand-soft); }
.drop strong { color: var(--brand-strong); }
.drop small { color: var(--muted); }

/* ---------- Daftar file ---------- */
.list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.list:empty { display: none; }
.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.list li.bad { border-color: var(--danger); background: var(--danger-soft); }
.list > li > img, .badge {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
}
.badge {
  display: grid;
  place-items: center;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--danger);
  border: 1px solid var(--line);
}
.info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.meta { color: var(--muted); font-size: 0.8125rem; }
.bad .meta { color: var(--danger); }
.tools { display: flex; gap: 4px; flex-shrink: 0; }
.icon {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.icon:disabled { opacity: 0.35; cursor: default; }

/* ---------- Opsi ---------- */
.options {
  margin: 16px 0 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 10px;
}
.options legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.options label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.options label > span:first-child:not(:only-child) { min-width: 110px; }
.options select, .options input[type="text"] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  flex: 1;
  min-width: 0;
}
.options input[type="radio"] { accent-color: var(--brand); width: 18px; height: 18px; margin: 0; }
.range-field { padding-left: 26px; }
.range-field small { width: 100%; color: var(--muted); }

/* ---------- Tombol ---------- */
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.primary, .ghost {
  font: inherit;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.primary { background: var(--brand); color: var(--surface); border: 1px solid var(--brand); flex: 1; }
.primary:hover { background: var(--brand-strong); }
.primary:disabled { opacity: 0.45; cursor: default; background: var(--brand); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* ---------- Status & hasil ---------- */
.status {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-strong);
}
.status.error { background: var(--danger-soft); color: var(--danger); }

.result {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand-soft);
  display: grid;
  gap: 10px;
}
.result-text { margin: 0; font-weight: 500; }
.download { display: block; overflow-wrap: anywhere; }

footer { padding: 20px 0 28px; display: grid; gap: 6px; }
.privacy { margin: 0; text-align: center; color: var(--muted); font-size: 0.875rem; }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.options label.choice { flex-wrap: nowrap; align-items: flex-start; }
.options label.choice input { margin-top: 3px; flex-shrink: 0; }

/* ---------- Halaman dokumen (privasi) ---------- */
a { color: var(--brand-strong); }
a.brand { color: inherit; text-decoration: none; }
.brand-name { margin: 0; font-size: 1.5rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; }
.brand-name span { color: var(--brand); }
.privacy a { color: inherit; }

.doc {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 20px 20px;
}
.doc-lang { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0 4px; }
.doc-lang a {
  font-size: 0.875rem;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
}
.doc article + article { border-top: 1px solid var(--line); margin-top: 28px; }
.doc h1 { font-size: 1.375rem; margin: 20px 0 4px; }
.doc h2 { font-size: 1.0625rem; margin: 22px 0 6px; }
.doc p, .doc li { overflow-wrap: anywhere; }
.doc ul { padding-left: 20px; }
.doc li + li { margin-top: 4px; }
.muted { color: var(--muted); margin-top: 0; font-size: 0.875rem; }
.summary { background: var(--brand-soft); border-radius: 10px; padding: 12px 14px; }

/* ---------- Thumbnail halaman ---------- */
.list li { flex-wrap: wrap; }
.pages { flex-basis: 100%; min-width: 0; }
.pages.strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 6px;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}
.pages.strip .thumb { flex: 0 0 72px; scroll-snap-align: start; }
.pages.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
  padding: 4px 0;
}
.pages.failed::after { content: "—"; color: var(--muted); }

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: zoom-in;
  min-width: 0;
}
.thumb-img {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1 / 1.414;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
}
.thumb img { display: none; max-width: 100%; max-height: 100%; background: #fff; }
.thumb.ready img { display: block; }
.thumb.ready .thumb-img { background: var(--surface); }
.thumb:not(.ready):not(.failed) .thumb-img {
  background: linear-gradient(90deg, var(--bg), var(--line), var(--bg));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.thumb.failed .thumb-img::after { content: "!"; color: var(--danger); font-weight: 700; }
.thumb:hover .thumb-img, .thumb:focus-visible .thumb-img { border-color: var(--brand); }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .thumb .thumb-img { animation: none !important; } }

.result-preview-title { margin: 4px 0 0; font-size: 0.875rem; color: var(--muted); }
.result-preview-title strong { color: var(--text); }
.result-preview { display: grid; gap: 10px; min-width: 0; }
.result-preview:empty { display: none; }
.part-name { margin: 0; font-size: 0.8125rem; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- Penampil halaman ---------- */
.viewer {
  width: min(100vw - 16px, 900px);
  height: min(100dvh - 16px, 1100px);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer::backdrop { background: rgb(0 0 0 / 0.6); }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--line);
}
.viewer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer-count { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.viewer-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  background: var(--bg);
  overflow: auto;
  touch-action: pan-y pinch-zoom;
}
.viewer-stage canvas { background: #fff; box-shadow: 0 1px 6px rgb(0 0 0 / 0.18); }
.viewer-msg { color: var(--muted); }
.viewer-nav { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
.viewer-nav button { flex: 1; }
.viewer-nav button:disabled { opacity: 0.4; cursor: default; }
