@font-face {
  font-family: 'Nunito Sans';
  src: url('/fonts/nunito-sans-5.3.0.woff2') format('woff2');
  font-weight: 200 1000;
  font-display: swap;
  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;
}

/* Matches translate.avkean.com. Spacing is on a 4px grid. */
:root {
  color-scheme: light dark;
  --font: 'Nunito Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;

  --page: #f6f6f4;
  --panel: #ffffff;
  --line: #e3e3df;
  --well: #f1f1ee;
  --hover: rgb(17 17 17 / 0.05);
  --press: rgb(17 17 17 / 0.09);
  --select: rgb(17 17 17 / 0.12);
  --ink: #111111;
  --on-ink: #f6f6f4;
  --muted: #62625e;
  --good: #1f7a3f;
  --danger: #b3261e;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2362625e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  --gutter: 32px;
  --header: 112px;
  --logo: 40px;
  --ring: rgb(17 17 17 / 0.28);
  --inset: 32px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #111111;
    --panel: #191918;
    --line: #2c2c2a;
    --well: #222221;
    --hover: rgb(244 244 242 / 0.06);
    --press: rgb(244 244 242 / 0.1);
    --select: rgb(244 244 242 / 0.2);
    --ink: #f4f4f2;
    --on-ink: #111111;
    --muted: #a4a49e;
    --good: #6fcf8f;
    --danger: #ff8f86;
    --ring: rgb(244 244 242 / 0.3);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a4a49e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: var(--select); }

body {
  height: 100dvh; display: grid; grid-template-rows: auto 1fr auto;
  font: 400 16px/24px var(--font); color: var(--ink); background: var(--page);
  text-rendering: optimizeLegibility;
}

button, select, input { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.col { width: min(960px, 100% - 2 * var(--gutter)); margin-inline: auto; }

.sprite { position: absolute; width: 0; height: 0; }
svg.i { width: 16px; height: 16px; display: block; flex-shrink: 0; }

/* ── Header ─────────────────────────────────────────────── */

.top { height: var(--header); display: flex; align-items: center; justify-content: space-between; }

.logo { display: block; color: var(--ink); border-radius: 4px; }
.logo svg { display: block; height: var(--logo); width: auto; }
.logo .on-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .logo .on-light { display: none; }
  .logo .on-dark { display: block; }
}

.top-end { display: flex; align-items: center; gap: 4px; margin-right: -14px; }

.text-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  font-weight: 500; color: var(--muted); text-decoration: none; white-space: nowrap;
  transition: color 0.15s, background-color 0.15s, opacity 0.2s;
}
.text-btn:hover { color: var(--ink); background: var(--hover); }
.text-btn:active { background: var(--press); }

.solid-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 16px; border-radius: 8px;
  font-weight: 600; white-space: nowrap;
  color: var(--on-ink); background: var(--ink);
  transition: opacity 0.2s, transform 0.2s var(--ease);
}
.solid-btn:hover { opacity: 0.88; }
.solid-btn:active { transform: scale(0.97); }

.icon-btn {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 8px; color: var(--muted);
  transition: color 0.15s, background-color 0.15s, opacity 0.2s, transform 0.2s var(--ease);
}
.icon-btn:hover { color: var(--ink); background: var(--hover); }
.icon-btn:active { background: var(--press); transform: scale(0.94); }

.link-btn {
  font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--line); transition: text-decoration-color 0.15s;
}
.link-btn:hover { text-decoration-color: currentColor; }

/* ── Panel ──────────────────────────────────────────────── */

.panel {
  position: relative; min-height: 0;
  display: grid; grid-template-rows: 56px minmax(0, 1fr) 56px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
}

.tools {
  display: flex; align-items: center; gap: 8px;
  padding: 0 calc(var(--inset) - 8px); border-bottom: 1px solid var(--line);
}

.quality { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 8px; }
.quality .label { font-weight: 600; }
.quality output { width: 3ch; color: var(--muted); font-variant-numeric: tabular-nums; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 160px; height: 24px; background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(var(--ink), var(--ink)) 0 / var(--fill, 64%) 100% no-repeat, var(--line);
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--ink);
  transition: transform 0.2s var(--ease);
}
input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--ink);
}
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]:focus-visible { outline: none; }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--select); }

select {
  appearance: none; -webkit-appearance: none;
  height: 40px; max-width: 100%; padding: 0 32px 0 8px;
  field-sizing: content;
  font-weight: 600; letter-spacing: -0.005em;
  background: transparent var(--chevron) no-repeat right 8px center;
  border: none; border-radius: 8px; cursor: pointer;
  transition: background-color 0.15s;
}
select:hover { background-color: var(--hover); }
select:focus-visible { outline: none; background-color: var(--press); }
select option { font-weight: 450; }

@supports (appearance: base-select) {
  select, ::picker(select) { appearance: base-select; }
  select { align-items: center; }
  select::picker-icon { display: none; }
  ::picker(select) {
    min-width: 200px; margin-top: 4px; padding: 6px;
    background: var(--panel); color: var(--ink);
    border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 16px 40px -12px rgb(0 0 0 / 0.25);
    opacity: 0; translate: 0 -4px;
    transition: opacity 0.18s var(--ease), translate 0.18s var(--ease), overlay 0.18s allow-discrete, display 0.18s allow-discrete;
  }
  ::picker(select):popover-open { opacity: 1; translate: 0 0; }
  @starting-style { ::picker(select):popover-open { opacity: 0; translate: 0 -4px; } }
  option {
    display: flex; align-items: center; min-height: 36px; padding: 0 12px;
    border-radius: 8px; font-weight: 450; cursor: pointer;
  }
  option + option { margin-top: 3px; }
  option::checkmark { display: none; }
  option:hover, option:focus-visible { outline: none; background: var(--hover); }
  option:checked { background: var(--press); font-weight: 600; }
}

.toggle { margin-left: auto; }
.toggle[aria-pressed=true] { color: var(--on-ink); background: var(--ink); }
.toggle[aria-pressed=true]:hover { opacity: 0.88; }
.add { margin-right: -6px; }
body:not(.has-files) .add { display: none; }

/* ── Stage ──────────────────────────────────────────────── */

.stage { position: relative; min-height: 0; overflow-y: auto; }

.empty {
  height: 100%; min-height: 240px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; text-align: center; color: var(--muted); cursor: pointer;
}
.empty .big { width: 48px; height: 48px; margin-bottom: 16px; color: var(--ink); opacity: 0.8; }
.empty .lead { font-size: 24px; line-height: 32px; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
.empty p + p { margin-top: 4px; }
.empty .link-btn { color: var(--ink); }
.empty .hint { margin-top: 20px; font-size: 13px; line-height: 16px; }
.empty .local-note { margin-top: 8px; color: var(--ink); }
body:not(.local) .local-note { display: none; }
body.has-files .empty { display: none; }

.list { list-style: none; padding: 8px calc(var(--inset) - 16px); }

.item {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto auto; align-items: center; gap: 16px;
  min-height: 72px; padding: 12px 16px; border-radius: 12px;
  animation: rise 0.35s var(--ease);
}
.item + .item { margin-top: 2px; }
.item:hover { background: var(--hover); }

.thumb {
  position: relative; width: 48px; height: 48px; border-radius: 8px; overflow: hidden;
  background: var(--well); display: grid; place-items: center; color: var(--muted);
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.35s var(--ease); }
.thumb img.ready { opacity: 1; }
/* Keeps white images visible */
.thumb::before { content: ''; position: absolute; inset: 0; z-index: 1; border-radius: inherit; box-shadow: inset 0 0 0 1px var(--hover); }
.item.busy .thumb::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%, var(--hover) 50%, transparent 80%) 0 0 / 200% 100%;
  animation: sweep 1.2s linear infinite;
}

.info { min-width: 0; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  font-size: 13px; line-height: 20px; color: var(--muted);
  overflow: hidden; white-space: nowrap;
}
.detail > span { overflow: hidden; text-overflow: ellipsis; }
.item.error .detail { color: var(--danger); }
.item.stale .detail, .item.stale .saving { opacity: 0.4; }

.saving {
  min-width: 56px; text-align: right;
  font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  transition: opacity 0.35s var(--ease);
}
.saving.good { color: var(--good); }
.saving.flat { color: var(--muted); font-weight: 500; }

.row-actions { display: flex; gap: 2px; margin-right: -8px; }
.item:not(.done) .dl { visibility: hidden; }

.dots { display: inline-flex; gap: 4px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink); animation: pulse 1.1s var(--ease) infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

/* ── Bottom bar ─────────────────────────────────────────── */

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 calc(var(--inset) - 12px) 0 var(--inset); border-top: 1px solid var(--line); min-width: 0;
}
body:not(.has-files) .bar { visibility: hidden; }
.summary { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; line-height: 16px; color: var(--muted); }
.summary > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary b { color: var(--good); font-weight: 700; }
.actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
#all-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

/* ── Dropping ───────────────────────────────────────────── */

.drop {
  position: absolute; inset: 8px; z-index: 2; pointer-events: none;
  display: grid; place-items: center;
  border: 2px dashed var(--ring); border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(2px);
  font-size: 20px; line-height: 28px; font-weight: 600;
  opacity: 0; scale: 0.99;
  transition: opacity 0.2s var(--ease), scale 0.2s var(--ease);
}
body.dragging .drop { opacity: 1; scale: 1; }

.foot {
  display: grid; place-items: center; height: 72px;
  font-size: 13px; line-height: 16px; color: var(--muted); text-align: center;
}

/* ── About ──────────────────────────────────────────────── */

dialog {
  margin: auto; width: min(480px, 100% - 32px); max-height: calc(100dvh - 32px);
  padding: 24px; overflow: auto;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 24px 48px -16px rgb(0 0 0 / 0.25);
}
dialog[open] { animation: dialog-in 0.35s var(--ease); }
dialog::backdrop { background: rgb(17 17 17 / 0.4); backdrop-filter: blur(2px); }
dialog[open]::backdrop { animation: fade 0.25s ease-out; }
dialog h2 { font-size: 20px; line-height: 28px; font-weight: 600; letter-spacing: -0.015em; margin-bottom: 16px; padding-right: 40px; }
dialog p { color: var(--muted); text-wrap: pretty; }
dialog p + p { margin-top: 12px; }
dialog .intro { color: var(--ink); }
dialog .made { margin-top: 20px; font-size: 13px; line-height: 16px; }
dialog a { color: var(--ink); text-underline-offset: 3px; }
dialog form { position: absolute; top: 16px; right: 16px; }

/* ── Motion ─────────────────────────────────────────────── */

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes sweep { from { background-position: 100% 0; } to { background-position: -100% 0; } }

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

/* ── Phones ─────────────────────────────────────────────── */

@media (max-width: 720px) {
  :root { --gutter: 16px; --header: 80px; --logo: 28px; --inset: 16px; }
  .panel { grid-template-rows: auto minmax(0, 1fr) auto; }
  .tools { gap: 0; padding: 4px 4px 4px 8px; }
  .quality { flex: 1; min-width: 0; gap: 10px; padding: 0 8px; }
  input[type=range] { flex: 1; min-width: 0; width: auto; }
  .add, .toggle { width: 36px; padding: 0; justify-content: center; margin: 0; }
  .toggle { margin-left: 4px; }
  .add span, .toggle span { display: none; }
  .list { padding: 4px 0; }
  .item { gap: 12px; padding: 10px 16px; border-radius: 0; grid-template-columns: 44px minmax(0, 1fr) auto auto; }
  .thumb { width: 44px; height: 44px; }
  .saving { min-width: 0; }
  .dims { display: none; }
  .bar { flex-wrap: wrap; gap: 8px; padding: 8px 12px 8px 16px; min-height: 56px; }
  .summary { flex: 1 1 100%; padding-top: 4px; }
  .summary:empty { display: none; }
  .actions { margin-left: auto; }
  .empty .lead { font-size: 20px; line-height: 28px; }
  .foot { height: auto; padding: 20px 0 max(20px, env(safe-area-inset-bottom)); }
}
