/* WebP Converter — light/dark, responsive, no external resources. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #d3d8e0;
  --border-strong: #b3bbc7;
  --text: #16191f;
  --text-muted: #5a6373;
  --accent: #1d5fd0;
  --accent-text: #ffffff;
  --accent-soft: #e6eefc;
  --good: #146c43;
  --good-soft: #e3f3ea;
  --warn: #8a5300;
  --warn-soft: #fdf1dd;
  --error: #b32218;
  --error-soft: #fdeceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-alt: #232830;
    --border: #353c47;
    --border-strong: #4a5462;
    --text: #e8eaee;
    --text-muted: #a3acba;
    --accent: #7aa7ff;
    --accent-text: #0e1116;
    --accent-soft: #23304a;
    --good: #6fd39b;
    --good-soft: #1b3128;
    --warn: #e9b562;
    --warn-soft: #34291642;
    --error: #ff9a91;
    --error-soft: #3a1f1d;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* Several components below set `display`, which would otherwise win over the
   user-agent rule for [hidden] and leave hidden elements visible. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.wrap {
  width: min(100% - 2rem, 62rem);
  margin-inline: auto;
}

h1, h2, h3 { line-height: 1.25; }

a { color: var(--accent); }

code, kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

kbd {
  padding: 0.1em 0.4em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-alt);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 0.5rem; top: -4rem;
  z-index: 10;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  transition: top 0.15s;
}
.skip-link:focus { top: 0.5rem; }

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

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

.site-header {
  padding-block: 2.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-header h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.6rem, 1.1rem + 2vw, 2.2rem);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  max-width: 48rem;
  color: var(--text-muted);
}

.site-footer {
  margin-top: 3rem;
  padding-block: 1.5rem 2.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
}
.site-footer p { margin: 0; }

main { padding-block: 1.75rem; }

main > section + section { margin-top: 1.75rem; }

/* ---------- Banners ---------- */

.banner {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
}
.banner--info { background: var(--accent-soft); border-color: transparent; }
.banner--error { background: var(--error-soft); border-color: var(--error); color: var(--text); }
#browser-warning { margin-bottom: 1.5rem; }

/* ---------- Drop zone ---------- */

.dropzone {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  padding: 2.5rem 1.25rem;
  border: 2px dashed var(--border-strong);
  border-radius: calc(var(--radius) * 1.4);
  background: var(--surface);
  text-align: center;
  transition: background-color 0.12s, border-color 0.12s;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone__icon { width: 40px; height: 40px; color: var(--text-muted); }
.dropzone__title { margin: 0.25rem 0 0; font-size: 1.15rem; font-weight: 600; }
.dropzone__hint { margin: 0; color: var(--text-muted); font-size: 0.9375rem; }
.dropzone__formats { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.8125rem; }
.dropzone .button { margin-top: 0.85rem; }

/* ---------- Buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}

.button:hover:not(:disabled) { background: var(--surface-alt); }

.button--primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
}
.button--primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }

.button--quiet { border-color: transparent; background: transparent; color: var(--text-muted); }
.button--quiet:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }

.button--small { min-height: 2.1rem; padding: 0.3rem 0.75rem; font-size: 0.875rem; }

.button:disabled { opacity: 0.45; cursor: not-allowed; }

/* the file input lives inside its label, so give the label the focus ring */
.dropzone label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Settings ---------- */

.settings {
  padding: 1.25rem 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings h2 { margin: 0 0 0.35rem; font-size: 1.15rem; }
.settings__intro { margin: 0 0 1.25rem; color: var(--text-muted); font-size: 0.9375rem; }

.settings__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 1rem 1.5rem;
  margin-bottom: 1.25rem;
}

.field--wide { grid-column: 1 / -1; }

.field > label, .field__row label { display: block; margin-bottom: 0.3rem; font-weight: 500; }

.field__row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.field__row label { margin-bottom: 0.3rem; }

.field__row output {
  min-width: 2.75rem;
  padding: 0.05rem 0.4rem;
  border-radius: 6px;
  background: var(--surface-alt);
  font-variant-numeric: tabular-nums;
  text-align: center;
  font-size: 0.9375rem;
}

.field__help { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.8125rem; }

input[type="number"], input[type="text"] {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

.checkbox { display: flex; align-items: center; gap: 0.55rem; font-weight: 500; cursor: pointer; }
.checkbox input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.field.is-disabled { opacity: 0.5; }
.field.is-disabled input { cursor: not-allowed; }

/* ---------- Results ---------- */

.results__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.results__head h2 { margin: 0; font-size: 1.15rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.summary { margin: 0 0 1rem; color: var(--text-muted); font-size: 0.9375rem; }

.list { display: grid; gap: 0.75rem; margin: 0; padding: 0; list-style: none; }

.item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.9rem;
  align-items: center;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.item[data-status="done"] { border-left-color: var(--good); }
.item[data-status="error"] { border-left-color: var(--error); }
.item[data-status="converting"] { border-left-color: var(--accent); }

.item__thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 72px; height: 72px;
  border-radius: 8px;
  background: var(--surface-alt);
  overflow: hidden;
}

/* checkerboard so transparency is visible */
.item__thumb::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(45deg, var(--border) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  opacity: 0.5;
}

.item__thumb img {
  position: relative;
  width: 100%; height: 100%;
  object-fit: contain;
}

.item__spinner {
  position: relative;
  width: 20px; height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.item[data-status="pending"] .item__spinner { animation-play-state: paused; }
.item[data-status="done"] .item__spinner,
.item[data-status="error"] .item__spinner { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .item__spinner { animation: none; }
  .skip-link { transition: none; }
}

.item__body { min-width: 0; }

.item__name {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item__status { margin: 0.15rem 0 0; color: var(--text-muted); font-size: 0.875rem; }
.item[data-status="error"] .item__status { color: var(--error); }

.item__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0.4rem 0 0;
  font-size: 0.875rem;
}
.item__stats div { display: flex; gap: 0.35rem; }
.item__stats dt { color: var(--text-muted); }
.item__stats dt::after { content: ":"; }
.item__stats dd { margin: 0; font-variant-numeric: tabular-nums; }

.item__stats dd.is-good { color: var(--good); font-weight: 600; }
.item__stats dd.is-bad { color: var(--warn); font-weight: 600; }

.item__actions { display: flex; flex-direction: column; gap: 0.4rem; }

@media (max-width: 34rem) {
  .item { grid-template-columns: auto minmax(0, 1fr); }
  .item__actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
  .results__head { flex-direction: column; align-items: stretch; }
  .toolbar .button { flex: 1 1 auto; }
}
