:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f2f0ec;
  --border: #e6e3dc;
  --text: #1b1b18;
  --text-muted: #6e6b64;
  --text-faint: #a6a299;
  --shadow: rgba(30, 25, 15, .06);

  --audio: #6d4cf5;
  --audio-soft: #efeaff;
  --video: #ee6a1f;
  --video-soft: #ffede1;
  --image: #0f9e93;
  --image-soft: #e0f7f3;
  --danger: #d8383f;
  --danger-soft: #fbe9e8;

  --accent: var(--audio);
  --accent-soft: var(--audio-soft);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Consolas, "Roboto Mono", monospace;
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131214;
    --surface: #1b1a1d;
    --surface-2: #232226;
    --border: #322f34;
    --text: #f3f1ee;
    --text-muted: #9d9a9f;
    --text-faint: #6a676c;
    --shadow: rgba(0, 0, 0, .35);

    --audio: #a68bff;
    --audio-soft: #2a2340;
    --video: #ff9955;
    --video-soft: #3a2618;
    --image: #3fdac9;
    --image-soft: #133430;
    --danger: #ff7069;
    --danger-soft: #3a1e1e;
  }
}

:root[data-theme="dark"] {
  --bg: #131214;
  --surface: #1b1a1d;
  --surface-2: #232226;
  --border: #322f34;
  --text: #f3f1ee;
  --text-muted: #9d9a9f;
  --text-faint: #6a676c;
  --shadow: rgba(0, 0, 0, .35);

  --audio: #a68bff;
  --audio-soft: #2a2340;
  --video: #ff9955;
  --video-soft: #3a2618;
  --image: #3fdac9;
  --image-soft: #133430;
  --danger: #ff7069;
  --danger-soft: #3a1e1e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--sans);
  transition: background .2s ease, color .2s ease;
}

body[data-active-category="audio"] { --accent: var(--audio); --accent-soft: var(--audio-soft); }
body[data-active-category="video"] { --accent: var(--video); --accent-soft: var(--video-soft); }
body[data-active-category="image"] { --accent: var(--image); --accent-soft: var(--image-soft); }

button, input {
  font-family: inherit;
  color: inherit;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 20px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
}
.brand-mark {
  display: flex;
  color: var(--accent);
  transition: color .2s ease;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  color: var(--text-muted);
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-faint); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

/* ---------- page ---------- */

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

.lede {
  text-align: center;
  color: var(--text-muted);
  font-size: 14.5px;
  margin: 10px 0 26px;
}

/* ---------- category nav ---------- */

.categories {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.category-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.category-btn .cat-icon { color: var(--text-faint); transition: color .15s ease; }
.category-btn:hover { border-color: var(--text-faint); color: var(--text); }
.category-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.category-btn[data-category="audio"].active { --accent: var(--audio); --accent-soft: var(--audio-soft); }
.category-btn[data-category="video"].active { --accent: var(--video); --accent-soft: var(--video-soft); }
.category-btn[data-category="image"].active { --accent: var(--image); --accent-soft: var(--image-soft); }

.category-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.category-btn.active .cat-icon { color: var(--accent); }

/* ---------- card ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 20px 40px -28px var(--shadow);
}

/* ---------- dropzone ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 34px 16px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); }
.dropzone:focus-visible { outline: none; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }

.drop-icon { color: var(--text-faint); margin-bottom: 2px; }
.drop-text { margin: 0; font-weight: 600; font-size: 14.5px; }
.drop-sub { margin: 0; font-size: 12.5px; color: var(--text-muted); }

/* ---------- file info ---------- */

.file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.file-info-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.file-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-size {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
  flex-shrink: 0;
}
.file-clear {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 6px;
}
.file-clear:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- format chips ---------- */

.format-panel { margin-top: 20px; }

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 9px;
}
#quality-hint {
  font-weight: 400;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 11.5px;
}

.chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}

.chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor: pointer;
  text-align: left;
  transition: border-color .12s ease, background .12s ease, color .12s ease;
}
.chip-label { font-size: 13px; font-weight: 700; }
.chip-note { font-size: 10.5px; color: var(--text-faint); }

.chip:hover { border-color: var(--accent); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.chip.active .chip-label { color: var(--accent); }

/* ---------- quality ---------- */

.quality-section { margin-top: 20px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.segment {
  border: none;
  background: transparent;
  padding: 9px 6px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.segment:hover { color: var(--text); }
.segment:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.segment.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 4px var(--shadow);
}

.lossless-note {
  margin: 20px 0 0;
  font-size: 12.5px;
  color: var(--text-faint);
  font-style: italic;
}

/* ---------- run button ---------- */

.run-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 22px;
  padding: 14px;
  font-size: 14.5px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: opacity .12s ease, transform .08s ease;
}
.run-btn:active { transform: translateY(1px); }
.run-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.run-btn:hover { opacity: .92; }
.run-btn:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
  cursor: not-allowed;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}
.ghost-btn:hover { border-color: var(--text-faint); color: var(--text); }
.ghost-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- progress ---------- */

.progress { margin-top: 20px; }
.progress-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .2s ease;
}
.progress-fill.indeterminate {
  width: 40% !important;
  animation: indeterminate 1.1s ease-in-out infinite;
}
@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
.progress-status {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- banners / result ---------- */

.banner {
  margin-top: 18px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.banner--error {
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}

.result {
  margin-top: 20px;
  padding: 16px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-md);
}
.result-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
}
.result .file-info { background: var(--surface); }
.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.result-actions .run-btn { margin-top: 0; flex: 2; }

/* ---------- footer ---------- */

.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 20px;
}

@media (max-width: 480px) {
  .categories { gap: 8px; }
  .category-btn { padding: 12px 6px; font-size: 12px; }
  .card { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill.indeterminate { animation: none; }
  * { transition: none !important; }
}
