:root {
  --bg: #f8f5f0;
  --surface: #fffdfa;
  --line: #e8e1d6;
  --text: #2a2622;
  --muted: #7d746a;
  --accent: #a4552a;
  --accent-ink: #fff;
  --accent-soft: #f3e6dc;
  --ok: #4d7a50;
  --warn: #9a6a12;
  --bad: #b0412e;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

.masthead, main { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
.masthead { padding-top: 56px; padding-bottom: 32px; }
.eyebrow { margin: 0 0 6px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -.01em; }
.lede { margin: 6px 0 0; color: var(--muted); }
h2 { margin: 0; font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 10px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  margin-bottom: 32px;
}

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 16px; }
.section-head:not(:first-child) { margin-top: 36px; }
.step {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 600;
}

.muted { color: var(--muted); margin: 8px 0 0; font-size: 14px; }
.error { color: var(--bad); margin: 8px 0 0; font-size: 14px; }
.banner { padding: 12px 16px; background: #fbeeea; border-radius: var(--radius); margin: 16px 0; }

/* ---- drop zone ---- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 40px 24px;
  border: 1.5px dashed #d6ccbe; border-radius: var(--radius);
  background: var(--bg); text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone span { color: var(--muted); font-size: 14px; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone.locked { pointer-events: none; opacity: .5; }

/* ---- queue ---- */
.queue {
  list-style: none; margin: 20px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px;
}
.queue li { position: relative; font-size: 13px; }
.queue .thumb {
  aspect-ratio: 1; background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  display: grid; place-items: center; overflow: hidden;
}
.queue .thumb img { width: 100%; height: 100%; object-fit: contain; }
.queue .name { margin: 8px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .msg { margin: 2px 0 0; font-size: 12px; line-height: 1.4; }
.queue .msg.bad { color: var(--bad); }
.queue .msg.warn { color: var(--warn); }
.queue .remove {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255, 253, 250, .92); color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1;
}
.queue .remove:hover { color: var(--text); border-color: #cfc5b8; }
.queue.locked .remove { display: none; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  background: #efebe5; color: var(--muted);
}
.badge.ok { background: #e6efe5; color: var(--ok); }
.badge.warn { background: #f6ecd7; color: var(--warn); }
.badge.bad { background: #f7e3de; color: var(--bad); }

/* ---- levels ---- */
.levels { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: center; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; cursor: pointer; user-select: none; font-variant-numeric: tabular-nums;
  transition: background .15s, border-color .15s, color .15s;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.custom { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.custom input {
  width: 160px; padding: 8px 12px; font: inherit; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.custom input:focus { outline: none; border-color: var(--accent); }
.custom input.invalid { border-color: var(--bad); }

/* ---- buttons ---- */
.actions { margin-top: 36px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.actions .muted { margin: 0; }
.button {
  display: inline-block; padding: 10px 22px; border-radius: var(--radius);
  font: 600 14px/1.4 var(--font); text-decoration: none; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, opacity .15s;
}
.button.primary { background: var(--accent); color: var(--accent-ink); }
.button.primary:hover { background: #8e4822; }
.button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.button.ghost:hover { border-color: #cfc5b8; }
.button:disabled, .button.disabled { opacity: .4; pointer-events: none; cursor: default; }
.link { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; text-decoration: underline; }

/* ---- results ---- */
.results-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.results-head .muted { margin-top: 4px; }
.results-actions { display: flex; gap: 10px; }
.progress { height: 4px; background: #efe9e0; border-radius: 2px; margin: 20px 0 28px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }

.grid-scroll { overflow-x: auto; }
.grid { display: grid; gap: 14px; min-width: min-content; }
.grid .colhead { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.grid .rowhead { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 10px; margin-top: 10px; font-size: 14px; }
.grid .rowhead .fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid .rowhead .state { color: var(--muted); font-size: 13px; }
.grid .rowhead .state.bad { color: var(--bad); }

.cell { min-width: 140px; }
.cell .frame {
  aspect-ratio: 1; background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 13px; text-align: center; padding: 0;
}
.cell button.frame { width: 100%; cursor: zoom-in; }
.cell button.frame:hover { border-color: #cfc5b8; }
.cell .frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cell .frame.running { animation: pulse 1.6s ease-in-out infinite; }
.cell .frame.failed { color: var(--bad); padding: 12px; font-size: 12px; }
.cell .below { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); min-height: 20px; }
.cell .below a { color: var(--accent); text-decoration: none; font-weight: 600; }
.cell .below a:hover { text-decoration: underline; }
.span-levels { grid-column: 2 / -1; align-self: center; color: var(--bad); font-size: 13px; }

@keyframes pulse { 50% { background: #f6f1ea; } }

/* ---- lightbox ---- */
dialog#lightbox {
  border: 0; padding: 0; background: #fff; border-radius: 12px;
  max-width: min(94vw, 1100px); max-height: 94vh; overflow: hidden;
  box-shadow: 0 20px 60px rgba(30, 22, 14, .25);
}
dialog#lightbox::backdrop { background: rgba(42, 38, 34, .6); }
dialog#lightbox figure { margin: 0; padding: 24px 24px 16px; }
dialog#lightbox img { display: block; max-width: 100%; max-height: calc(94vh - 90px); margin: 0 auto; object-fit: contain; }
dialog#lightbox figcaption { margin-top: 10px; text-align: center; font-size: 13px; color: var(--muted); }
dialog#lightbox .close {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: var(--bg); color: var(--text); font-size: 20px; cursor: pointer;
}

@media (max-width: 640px) {
  .panel { padding: 20px; }
  .masthead { padding-top: 32px; }
}
