/* Image converter. Colors follow ethantyoung.com (ivory paper, ink, one clay accent).
   Every text/background pair below meets WCAG 1.4.3 (4.5:1) and every UI boundary
   meets 1.4.11 (3:1) in both themes. */

:root {
  --bg: #f4f1ea;
  --surface: #fbfaf6;
  --surface-2: #efebe1;
  --text: #1a1917;
  --text-dim: #4f4a42;
  --border: #ddd7c8;
  --control-border: #7d7566;
  --accent: #a44a28;
  --accent-hover: #7f3a1f;
  --on-accent: #ffffff;
  --focus: #1f4fbf;
  --ok: #2f6b2f;
  --error: #a3221b;
  --error-bg: #fbeceb;
  --drop-bg: #f7e9e2;
  --radius: 12px;
  --max: 960px;
  --gutter: clamp(1rem, 4vw, 2rem);
  --font: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1c1a17;
    --surface-2: #26231f;
    --text: #eeeae1;
    --text-dim: #b9b2a5;
    --border: #3a362f;
    --control-border: #8f8778;
    --accent: #e48b66;
    --accent-hover: #f0a684;
    --on-accent: #1a1917;
    --focus: #8fb4ff;
    --ok: #8fd18f;
    --error: #ff9b94;
    --error-bg: #3a1c1a;
    --drop-bg: #2a1f1a;
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
}

h1, h2, p { margin: 0; }

a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { color: var(--accent-hover); }

/* One visible focus style for everything (2.4.7, 2.4.13). */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }
main:focus, h2:focus { outline: none; }

.wrap {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

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

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -10rem;
  z-index: 10;
  padding: 0.75rem 1rem;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--text);
  border-radius: 8px;
  font-weight: 600;
}
.skip-link:focus { top: 0.75rem; }

/* Header / footer */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding-block: 0.75rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.brand:hover { color: var(--accent); text-decoration: underline; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 0.875rem;
}

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-block: 1.25rem;
  color: var(--text-dim);
  font-size: 0.875rem;
}

main {
  padding-block: clamp(1.5rem, 5vw, 3rem);
  display: grid;
  gap: 1.25rem;
}

.intro { display: grid; gap: 0.5rem; margin-bottom: 0.5rem; }
h1 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
}
.lede { color: var(--text-dim); max-width: 60ch; font-size: 1.0625rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.5rem);
  display: grid;
  gap: 1rem;
  min-width: 0;
}
.panel[hidden] { display: none; }
h2 { font-size: 1.125rem; line-height: 1.3; }

.hint { color: var(--text-dim); font-size: 0.875rem; }
.hint:empty, .error-text:empty { display: none; }
.unit { color: var(--text-dim); font-weight: 400; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-weight: 600; margin-bottom: 0.5rem; }

/* Format picker: radio inputs styled as cards. The native radio stays
   in the accessibility tree and keyboard order (arrow keys move within). */
.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr));
  gap: 0.5rem;
}
.format-option { position: relative; }
.format-option input {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.format-option label {
  display: grid;
  gap: 0.125rem;
  height: 100%;
  min-height: 44px;
  padding: 0.625rem 0.75rem 0.625rem 2.25rem;
  border: 1px solid var(--control-border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
}
.format-option label::before {
  content: "";
  position: absolute;
  left: 0.75rem;
  top: 0.9rem;
  width: 1rem; height: 1rem;
  border: 2px solid var(--control-border);
  border-radius: 50%;
  background: var(--surface);
}
.format-option .fmt-name { font-weight: 700; }
.format-option .fmt-desc { font-size: 0.8125rem; color: var(--text-dim); line-height: 1.35; }
.format-option input:hover + label { border-color: var(--accent); }
.format-option input:checked + label {
  border: 2px solid var(--accent);
  padding: calc(0.625rem - 1px) calc(0.75rem - 1px) calc(0.625rem - 1px) calc(2.25rem - 1px);
  background: var(--drop-bg);
}
.format-option input:checked + label::before {
  border-color: var(--accent);
  background: radial-gradient(circle, var(--accent) 0 45%, transparent 50%);
  left: calc(0.75rem - 1px);
  top: calc(0.9rem - 1px);
}
.format-option input:focus-visible + label {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.format-option input:disabled + label {
  cursor: not-allowed;
  border-style: dashed;
}
.format-option input:disabled { cursor: not-allowed; }

/* Settings row */
.settings-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1rem 1.5rem;
  align-items: start;
}
.field { display: grid; gap: 0.375rem; align-content: start; }
.field[hidden] { display: none; }
.field > label, .dim label { font-weight: 600; }
.field.resize legend { margin-bottom: 0.25rem; }
.value { font-variant-numeric: tabular-nums; font-weight: 700; margin-left: 0.25rem; }

/* Custom track so the unfilled part meets 3:1 against the panel (1.4.11). */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--surface-2);
}
input[type="range"]::-moz-range-track {
  height: 8px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--surface-2);
}
input[type="range"]::-moz-range-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -9px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.color-row { display: flex; align-items: center; gap: 0.75rem; }
input[type="color"] {
  width: 3.5rem;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
code { font-family: var(--mono); font-size: 0.875rem; color: var(--text-dim); }

.radio-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
}
.radio-line input {
  width: 1.25rem; height: 1.25rem;
  margin: 0;
  accent-color: var(--accent);
  flex: none;
}
.radio-line label { cursor: pointer; padding-block: 0.5rem; }

.dims {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.25rem;
}
.dims[hidden] { display: none; }
.dims-help { grid-column: 1 / -1; }
.dim { display: grid; gap: 0.25rem; }
.dim input {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.625rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 8px;
}
.dim input[aria-invalid="true"] { border: 2px solid var(--error); }
.error-text {
  grid-column: 1 / -1;
  color: var(--error);
  font-size: 0.875rem;
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.5rem 1.125rem;
  border-radius: 10px;
  border: 2px solid transparent;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: var(--drop-bg); color: var(--accent-hover); border-color: var(--accent-hover); }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--control-border); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: 1; background: var(--surface-2); color: var(--text-dim); border-color: var(--border); }
.btn-small { min-height: 44px; padding: 0.375rem 0.875rem; font-size: 0.9375rem; }
.btn[hidden] { display: none; }

/* Drop zone */
.dropzone {
  display: grid;
  justify-items: center;
  gap: 0.75rem;
  padding: clamp(1.25rem, 5vw, 2.5rem) 1rem;
  border: 2px dashed var(--control-border);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  transition: background-color 0.15s, border-color 0.15s;
}
.dropzone.is-over {
  border-color: var(--accent);
  border-style: solid;
  background: var(--drop-bg);
}
.drop-icon { color: var(--text-dim); }
.drop-text { color: var(--text); }
kbd {
  font-family: var(--mono);
  font-size: 0.8125rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--control-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  white-space: nowrap;
}

/* Results */
.results-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem 1rem;
}
.summary { color: var(--text-dim); font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.progress-wrap { display: grid; gap: 0.25rem; font-size: 0.875rem; color: var(--text-dim); }
.progress-wrap[hidden] { display: none; }
progress {
  width: 100%;
  height: 0.625rem;
  appearance: none;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  accent-color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.file-row {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.file-row[data-state="error"] { border-color: var(--error); background: var(--error-bg); }
.thumb {
  width: 3.5rem; height: 3.5rem;
  border-radius: 8px;
  overflow: hidden;
  background:
    repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 12px 12px;
  border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb img[hidden] { display: none; }
.file-info { min-width: 0; display: grid; gap: 0.125rem; }
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-meta { color: var(--text-dim); font-size: 0.875rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.file-status { display: flex; align-items: center; gap: 0.375rem; font-size: 0.875rem; font-weight: 600; }
.status-icon { width: 1rem; height: 1rem; flex: none; display: inline-grid; place-items: center; }
.file-row[data-state="queued"] .file-status { color: var(--text-dim); }
.file-row[data-state="working"] .file-status { color: var(--text); }
.file-row[data-state="done"] .file-status { color: var(--ok); }
.file-row[data-state="error"] .file-status { color: var(--error); }
.file-row[data-state="queued"] .status-icon::before { content: ""; width: 0.6rem; height: 0.6rem; border: 2px solid currentColor; border-radius: 50%; }
.file-row[data-state="working"] .status-icon::before {
  content: ""; width: 0.8rem; height: 0.8rem;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.file-row[data-state="done"] .status-icon::before { content: "✓"; font-weight: 800; }
.file-row[data-state="error"] .status-icon::before { content: "!"; font-weight: 800; }
@keyframes spin { to { transform: rotate(360deg); } }

.row-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }

@media (max-width: 34rem) {
  .file-row { grid-template-columns: 3rem minmax(0, 1fr); }
  .thumb { width: 3rem; height: 3rem; }
  .row-actions { grid-column: 1 / -1; justify-content: stretch; }
  .row-actions .btn { flex: 1 1 8rem; }
  .actions, .actions .btn { width: 100%; }
  .dims { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Windows High Contrast / forced colors: keep the selected format and states visible. */
@media (forced-colors: active) {
  .format-option input:checked + label { border: 3px solid Highlight; }
  .format-option input:checked + label::before { background: Highlight; forced-color-adjust: none; }
  .btn { border-color: ButtonText; }
  .btn:disabled { border-color: GrayText; color: GrayText; }
  .dropzone.is-over { border-color: Highlight; }
  .file-row[data-state="error"] { border: 2px solid Mark; }
  .btn[aria-disabled="true"] { border-color: GrayText; color: GrayText; }
  progress { forced-color-adjust: none; background: Canvas; border-color: CanvasText; }
  progress::-webkit-progress-bar { background: Canvas; }
  progress::-webkit-progress-value { background: Highlight; }
  progress::-moz-progress-bar { background: Highlight; }
  input[type="range"]::-webkit-slider-runnable-track { border-color: CanvasText; }
  input[type="range"]::-webkit-slider-thumb { forced-color-adjust: none; background: Highlight; }
  input[type="range"]::-moz-range-thumb { background: Highlight; }
}
