:root {
  --bg: #f5f6f8; --card: #ffffff; --ink: #18202a; --muted: #5a6573; --line: #dfe3e9; --soft: #eef1f5;
  --brand: #1f5f8b; --brand-ink: #ffffff; --brand-soft: #e3eef6; --accent: #c8642a;
  --warn: #8a5300; --warn-bg: #fff3dc; --err: #b3261e; --err-bg: #fde8e6; --ok: #1d7445; --ok-bg: #e2f4ea;
  --info-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #11151a; --card: #1a2027; --ink: #e7ebf0; --muted: #9ba6b3; --line: #2c343e; --soft: #222a33;
  --brand: #6aaee0; --brand-ink: #0b1724; --brand-soft: #1c2d3c; --accent: #f0955a;
  --warn: #f3b75c; --warn-bg: #2f2617; --err: #ff8f86; --err-bg: #3a1d1b; --ok: #74d6a1; --ok-bg: #173226;
  --info-bg: #232b35;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }
a { color: var(--brand); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; background: var(--soft); padding: 1px 5px; border-radius: 5px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--card); padding: 6px 10px; z-index: 50; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.lnk { color: var(--muted); text-decoration: none; font-size: 14px; }
.pill { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); white-space: nowrap; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.btn:hover:not(:disabled) { border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 14px; min-height: 32px; }
.btn-xs { padding: 2px 8px; font-size: 13px; min-height: 26px; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 17px; }
.icon-btn { font: inherit; background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 10px; width: 38px; height: 38px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.icon-btn.sm { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .drop:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }

.hero { padding: 28px 0 8px; }
.hero h1 { font-size: clamp(26px, 4.4vw, 40px); line-height: 1.15; margin: 0 0 10px; letter-spacing: -.01em; }
.lede { margin: 0; max-width: 780px; color: var(--muted); font-size: 17px; }
.lede strong { color: var(--ink); }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; padding: 18px 0 40px; align-items: start; }
.col-main, .col-side { display: grid; gap: 20px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 20px; margin: 0 0 14px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

.drop { border: 2px dashed var(--line); border-radius: 12px; background: var(--soft); cursor: pointer; min-height: 150px; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; text-align: center; padding: 16px; transition: border-color .15s; }
.drop:hover, .drop.dragging { border-color: var(--brand); background: var(--brand-soft); }
.drop-icon { font-size: 30px; color: var(--brand); line-height: 1; }

.queue { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.q-item { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.q-thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--soft); }
.q-body { min-width: 0; display: grid; gap: 6px; }
.q-top { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.q-n { font-size: 13px; color: var(--brand); font-weight: 700; }
.q-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.q-dim { font-size: 12px; white-space: nowrap; }
.q-row { display: flex; gap: 6px; min-width: 0; }
.q-row select { flex: none; font-size: 14px; padding: 5px 8px; }
.q-row input { min-width: 0; font-size: 14px; padding: 5px 8px; }
.q-ctl { display: flex; gap: 4px; }
.queue-actions { display: flex; justify-content: flex-end; margin-top: 6px; }

.lbl { display: block; font-weight: 600; font-size: 14px; margin: 0 0 6px; }
.lbl-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
textarea, input[type="text"], input[type="number"], select {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
select, input[type="number"] { width: auto; }
textarea { resize: vertical; }
#contextNote { margin: 4px 0 0; min-height: 1em; }

.opts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.opt { display: grid; gap: 4px; font-size: 14px; font-weight: 600; min-width: 0; }
.opt select { width: 100%; }
.num-wrap { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); }
.num-wrap input { width: 84px; }

.run-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.meter { margin: 0; color: var(--muted); font-size: 14px; }
.gate { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--ink); font-size: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.free { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.free p { margin: 0; flex: 1 1 320px; font-size: 14px; color: var(--muted); }
.free p strong { color: var(--ink); }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.tag-free { background: var(--ok-bg); color: var(--ok); border-color: transparent; }

.progress { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft); }
.progress-head { display: flex; justify-content: space-between; gap: 8px; }
.psteps { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.pstep { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.step-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.step-note { margin-left: auto; font-size: 12px; }
.pstep-on { color: var(--ink); font-weight: 600; }
.pstep-on .step-dot { border-color: var(--brand); background: var(--brand-soft); animation: pulse 1.2s infinite; }
.pstep-done .step-dot { background: var(--ok); border-color: var(--ok); }
.pstep-done { color: var(--ink); }
.pstep-failed .step-dot { background: var(--err); border-color: var(--err); }
@keyframes pulse { 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .pstep-on .step-dot { animation: none; } }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.sum-cell { background: var(--soft); border-radius: 10px; padding: 8px 10px; display: grid; }
.sum-cell strong { font-size: 20px; }
.sum-warn strong { color: var(--warn); }
.sum-bad strong { color: var(--err); }
.notice { background: var(--warn-bg); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-bottom: 12px; }
.notice p { margin: 4px 0; }
.export-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.results { display: grid; gap: 14px; }
.res { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.res-media { min-width: 0; }
.res-img { width: 100%; max-height: 220px; object-fit: contain; border-radius: 8px; background: repeating-conic-gradient(var(--soft) 0% 25%, var(--card) 0% 50%) 50% / 16px 16px; border: 1px solid var(--line); }
.res-noimg { height: 120px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 8px; }
.res-body { min-width: 0; display: grid; gap: 10px; }
.res-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.res-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 120px; }
.res-kind { font-size: 13px; padding: 4px 8px; }
.res-state { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; }
.st-ok, .st-info { background: var(--ok-bg); color: var(--ok); }
.st-warn { background: var(--warn-bg); color: var(--warn); }
.st-error { background: var(--err-bg); color: var(--err); }
.rf { display: grid; gap: 4px; }
.rf-head { display: flex; align-items: center; gap: 8px; }
.rf-lbl { font-weight: 600; font-size: 14px; }
.rf-count { font-size: 12px; margin-left: auto; }
.rf-count.over { color: var(--err); font-weight: 700; }
.rf-input { font-size: 15px; }
.rf-alt .rf-input { font-size: 16px; border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.rf-tags { font-size: 14px; color: var(--brand); }
.rf-tagrow { display: flex; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; line-height: 1.35; padding: 3px 9px; border-radius: 8px; background: var(--info-bg); color: var(--ink); }
.chip-ok { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-error { background: var(--err-bg); color: var(--err); font-weight: 600; }
.chip-info { background: var(--info-bg); color: var(--muted); }
.res-text { margin: 0; overflow-wrap: anywhere; }
.res-flags { margin: 0; padding-left: 18px; color: var(--warn); }
.res-rewrite { display: flex; gap: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.res-rewrite input { min-width: 0; font-size: 14px; padding: 6px 10px; }
.disclaimer { font-size: 13px; color: var(--muted); margin: 14px 0 0; }

.guide { padding-left: 20px; margin: 0 0 10px; display: grid; gap: 6px; }
.check-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.check-row input { width: 76px; }
.check-out { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 10px; }
.co-item { border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 4px; }
.co-text { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.co-count { font-size: 12px; }
.hist-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hist-item { display: flex; align-items: center; gap: 6px; }
.hist-open { flex: 1; min-width: 0; text-align: left; font: inherit; background: var(--soft); border: 1px solid transparent; border-radius: 10px; padding: 6px 10px; cursor: pointer; color: var(--ink); display: grid; }
.hist-open:hover { border-color: var(--brand); }
.hist-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.how ol { padding-left: 20px; margin: 0 0 8px; display: grid; gap: 6px; }

.foot { border-top: 1px solid var(--line); padding: 18px 0 28px; font-size: 14px; color: var(--muted); }
.foot-in { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(560px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); z-index: 60; font-size: 14px; background: var(--card); border: 1px solid var(--line); }
.toast-ok { border-color: var(--ok); }
.toast-err { border-color: var(--err); }

@media (max-width: 960px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .opts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .card { padding: 16px; }
  .res { grid-template-columns: minmax(0, 1fr); }
  .res-img { max-height: 200px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .q-item { grid-template-columns: 56px minmax(0, 1fr); }
  .q-thumb { width: 56px; height: 56px; }
  .q-ctl { grid-column: 1 / -1; justify-content: flex-end; }
  .q-row { flex-wrap: wrap; }
  .q-row select { flex: 1 1 100%; }
  .brand span { font-size: 15px; }
}
@media (max-width: 400px) {
  .opts { grid-template-columns: minmax(0, 1fr); }
  .pill { display: none; }
}
.res-rewrite .btn { white-space: nowrap; flex: none; }
