:root {
  --bg: #f6f3ee;
  --card: #fffdf9;
  --ink: #2b2620;
  --muted: #776e64;
  --line: #ddd5ca;
  --accent: #c8643f;
  --accent-ink: #fff;
  --cloth: #f6f3ec;
  --check-a: #fff;
  --check-b: #e8e8e8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1b19; --card: #262320; --ink: #eee8e0; --muted: #a59b90; --line: #3d3833;
    --accent: #e07a52; --check-a: #3a3632; --check-b: #322e2b;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1b19; --card: #262320; --ink: #eee8e0; --muted: #a59b90; --line: #3d3833;
  --accent: #e07a52; --check-a: #3a3632; --check-b: #322e2b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; padding: 16px; background: var(--bg); color: var(--ink);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}
header { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 12px; }
header img { image-rendering: pixelated; }
header h1 { font-size: 1.5rem; margin: 0; }
header .ver { font-size: .8rem; color: var(--muted); font-weight: normal; }
header .tag { flex-basis: 100%; margin: 0; color: var(--muted); }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
h3 { font-size: .95rem; margin: 12px 0 4px; }
h2 small, h3 small { font-weight: normal; color: var(--muted); }
.muted { color: var(--muted); font-size: .9rem; }

main { display: grid; grid-template-columns: minmax(280px, 340px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { main { grid-template-columns: 1fr; } }
aside { display: flex; flex-direction: column; gap: 12px; }
section, .help, .banner {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}

button, .button {
  display: block; width: 100%; margin: 6px 0 0; padding: 9px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; text-align: center;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button:disabled, .button.disabled { opacity: .45; cursor: default; }
button:not(:disabled):hover, .button:not(.disabled):hover { filter: brightness(.96); }
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file:first-child { margin-top: 0; }

.grid { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 8px; align-items: center; }
input:not([type=checkbox]), select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
  color: var(--ink); font: inherit;
}
.check { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: .95rem; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { margin-top: 0; }
.row button { width: auto; flex: 0 0 auto; }
#file-name { margin-top: 6px; overflow-wrap: anywhere; }
#stats { margin-top: 8px; }

#threads { margin: 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
#threads li { display: grid; grid-template-columns: 22px 1.6em 1fr; gap: 6px; align-items: center; }
.swatch { width: 20px; height: 20px; border-radius: 4px; border: 1px solid var(--muted); }
#threads select { padding: 3px 6px; }

.work { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
figure { margin: 0; }
figcaption { font-weight: 600; margin-bottom: 4px; display: flex; flex-wrap: wrap; justify-content: space-between;
  gap: 4px 12px; }
figcaption .check { margin: 0; font-weight: normal; }
.panel { border: 1px solid var(--line); border-radius: 8px; display: grid; place-items: center; overflow: hidden; }
.pair .panel { aspect-ratio: 1; }
.panel img { max-width: 100%; max-height: 100%; image-rendering: auto; }
.panel img:not([src]) { visibility: hidden; }
.checker {
  background: repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 0 0 / 16px 16px;
}
.hoop { background: var(--cloth); max-width: 640px; aspect-ratio: 1; }
.hoop img { width: 100%; }
#status { padding: 8px 12px; border-left: 4px solid var(--accent); background: var(--card); border-radius: 6px; }
#status.error { border-left-color: #c03030; }

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 12px; }
.banner small { flex-basis: 100%; color: var(--muted); }
.banner.error { border-color: #c03030; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

.help { margin-top: 16px; }
.help summary, #zip-box summary { cursor: pointer; font-weight: 600; }
#zip-box { margin-top: 10px; }
#zip-box summary { font-weight: normal; color: var(--muted); font-size: .9rem; }
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
  max-width: min(420px, 90vw); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog .row { justify-content: flex-end; }

.fm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column;
  gap: 6px; background: var(--bg); }
.card img { width: 100%; max-width: 160px; align-self: center; image-rendering: pixelated;
  border: 1px solid var(--line); border-radius: 4px; }
.card .row { gap: 4px; }
.card .row button { flex: 1 1 0; width: auto; padding: 6px 4px; font-size: .9rem; }
.card.empty { justify-content: center; min-height: 80px; border-style: dashed; }
