:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --text: #171717;
  --muted: #6b6b67;
  --line: #d8d8d3;
  --line-dark: #aaa9a2;
  --accent: #1d1d1b;
  --danger: #a62a2a;
  --success: #17683a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button, input, select { font: inherit; }
button, select, input[type="radio"], input[type="checkbox"] { cursor: pointer; }

.app-shell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 52px 0 80px;
}

.page-header, .results-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(25px, 4vw, 38px); letter-spacing: -0.04em; }
h2 { font-size: 22px; letter-spacing: -0.02em; }
.eyebrow { margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.privacy { max-width: 390px; color: var(--muted); font-size: 13px; text-align: right; }

.drop-zone {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 210px;
  padding: 30px;
  border: 1px dashed var(--line-dark);
  background: var(--surface);
  text-align: center;
  outline: none;
}

.drop-zone.is-dragging, .drop-zone:focus-visible { border-color: var(--text); background: #fbfbf9; }
.drop-zone > p { font-size: 18px; font-weight: 650; }
.drop-zone > span { color: var(--muted); font-size: 12px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 18px;
  border: 1px solid var(--text);
  border-radius: 2px;
  text-decoration: none;
  font-weight: 700;
}
.button.primary { background: var(--accent); color: white; }
.button.secondary { background: white; color: var(--text); }
.button:disabled { cursor: not-allowed; opacity: .42; }

.selection-header { display: flex; justify-content: space-between; margin: 17px 0 8px; }
.text-button, .icon-button { border: 0; background: transparent; color: var(--muted); }
.text-button:not(:disabled):hover { color: var(--text); text-decoration: underline; }

.file-list { display: grid; gap: 1px; margin: 0; padding: 0; list-style: none; }
.file-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 16px;
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid #eeeeea;
}
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); font-variant-numeric: tabular-nums; }
.remove-file { width: 28px; height: 28px; border: 0; background: transparent; color: var(--muted); font-size: 20px; }

.settings-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px 18px;
  margin-top: 34px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.full-width { grid-column: 1 / -1; }
.control { min-width: 0; }
.control > label, .control > legend, .label-row label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .08em;
}
fieldset { margin: 0; padding: 0; border: 0; }
select, input[type="number"] {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: white;
  color: var(--text);
}
select:focus, input:focus { outline: 2px solid #b9b9b2; outline-offset: 1px; }

.format-options { display: grid; grid-template-columns: repeat(5, 1fr); }
.format-options input { position: absolute; opacity: 0; pointer-events: none; }
.format-options span {
  display: block;
  padding: 10px;
  border: 1px solid var(--line);
  margin-left: -1px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}
.format-options label:first-child span { margin-left: 0; }
.format-options input:checked + span { position: relative; z-index: 1; border-color: var(--text); background: var(--text); color: white; }
.format-options input:focus-visible + span { outline: 2px solid #888; outline-offset: 2px; }

.label-row { display: flex; justify-content: space-between; }
.label-row output { font-weight: 750; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--text); }
.quality-presets { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.quality-presets button { padding: 5px 8px; border: 1px solid var(--line); background: #fafaf8; color: var(--muted); font-size: 12px; }
.quality-presets button:hover { border-color: var(--line-dark); color: var(--text); }

.input-group, .background-row { display: flex; gap: 8px; }
.input-group select { width: 80px; }
.checks { display: flex; flex-wrap: wrap; gap: 16px 26px; }
.checks legend { width: 100%; }
.checks label { display: flex; align-items: center; gap: 8px; }
.checks input { accent-color: var(--text); }
.background-row select { flex: 1; }
.background-row input[type="color"] { width: 50px; height: 42px; padding: 3px; border: 1px solid var(--line); background: white; }
.background-row code { min-width: 82px; padding: 11px 8px; border: 1px solid var(--line); color: var(--muted); text-align: center; }
.status { min-height: 21px; color: var(--muted); text-align: center; }
.status.error { color: var(--danger); }

.results-section { margin-top: 48px; }
.result-card { padding: 22px 0; border-top: 1px solid var(--line); }
.result-card:last-child { border-bottom: 1px solid var(--line); }
.result-main { display: grid; grid-template-columns: minmax(0, 1fr) 38px minmax(0, 1fr) auto; align-items: center; gap: 18px; }
.result-file { min-width: 0; }
.result-file strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-meta { margin-top: 4px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.result-arrow { color: var(--muted); text-align: center; }
.saving { min-width: 76px; text-align: right; font-size: 18px; font-weight: 750; }
.saving.positive { color: var(--success); }
.saving.negative { color: var(--danger); }
.result-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.small-button { padding: 7px 11px; border: 1px solid var(--line-dark); background: white; color: var(--text); text-decoration: none; font-weight: 650; }
.warning { margin-top: 12px; color: #805710; font-size: 13px; }
.error-card { color: var(--danger); }

.preview-dialog { width: min(960px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line-dark); background: white; }
.preview-dialog::backdrop { background: rgb(0 0 0 / .38); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.icon-button { font-size: 28px; }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
.preview-grid figure { margin: 0; padding: 20px; background: white; }
.preview-grid figcaption { margin-bottom: 12px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .08em; }
.preview-canvas { display: grid; place-items: center; height: min(50vh, 480px); overflow: hidden; background-color: #eee; background-image: linear-gradient(45deg, #ddd 25%, transparent 25%), linear-gradient(-45deg, #ddd 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ddd 75%), linear-gradient(-45deg, transparent 75%, #ddd 75%); background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0; }
.preview-canvas img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-grid figure > p { margin-top: 10px; color: var(--muted); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 680px) {
  .app-shell { width: min(100% - 22px, 920px); padding-top: 28px; }
  .page-header, .results-header { align-items: flex-start; flex-direction: column; gap: 10px; }
  .privacy { text-align: left; }
  .settings-form { grid-template-columns: 1fr; padding: 20px 15px; }
  .full-width { grid-column: 1; }
  .format-options { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .format-options span { margin: 0; }
  .result-main { grid-template-columns: 1fr auto; }
  .result-arrow { display: none; }
  .saving { grid-column: 2; grid-row: 1 / 3; }
  .preview-grid { grid-template-columns: 1fr; }
  .preview-canvas { height: 35vh; }
}
