:root {
  --bg: #edf0f4;
  --surface: #ffffff;
  --sunken: #f4f6f9;
  --ink: #101a33;
  --muted: #566178;
  --line: #d3dae6;
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --accent-soft: #fde8de;
  --ok: #17803d;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --err-bg: #fde4e4;
  --err-ink: #8a1c1c;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1522;
    --surface: #172033;
    --sunken: #121a2b;
    --ink: #e8ecf5;
    --muted: #9aa6bf;
    --line: #2a3550;
    --accent: #ff7a3d;
    --accent-ink: #1d0d04;
    --accent-soft: #3a2218;
    --ok: #4cc27a;
    --warn-bg: #3a3012;
    --warn-ink: #f3dc9a;
    --err-bg: #3d1a1c;
    --err-ink: #ffb4b4;
  }
}

* { box-sizing: border-box; }

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

.lead, .hint, .mode-desc, .foot p, .drop-sub, .item-notes li { text-wrap: pretty; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  font-feature-settings: "palt";
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 20px max(48px, env(safe-area-inset-bottom));
}

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

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.top { margin: 8px 0 28px; }

.title {
  margin: 0;
  font-size: clamp(2.6rem, 11vw, 4.2rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.title .arrow { color: var(--accent); margin: 0 0.12em; }

.lead {
  margin: 14px 0 0;
  max-width: 34em;
  color: var(--muted);
}

/* ---------- banner ---------- */
.banner {
  margin: 0 0 20px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.94rem;
}

/* ---------- drop zone ---------- */
.drop {
  display: block;
  padding: 36px 20px;
  border: 2px dashed var(--line);
  border-radius: 16px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}

.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.drop-main { display: block; font-size: 1.3rem; font-weight: 700; }
.drop-sub { display: block; margin-top: 4px; color: var(--muted); font-size: 0.9rem; }

/* ---------- queue ---------- */
.queue { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.queue[hidden] { display: none; }

.item {
  padding: 14px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.item-head { display: flex; align-items: flex-start; gap: 10px; }
.item-name { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; line-height: 1.5; }

.icon-btn {
  flex: none;
  width: 32px; height: 32px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem; line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }

.item-meta { margin-top: 2px; color: var(--muted); font-size: 0.88rem; }

.item-plan {
  margin-top: 8px;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.item-plan b { font-weight: 700; }

.item-notes { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.item-notes:empty { display: none; }
.item-notes li {
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.86rem;
  line-height: 1.55;
}
.item-notes li.err { background: var(--err-bg); color: var(--err-ink); }

.item-run, .item-done { display: none; margin-top: 12px; }
.item[data-status="running"] .item-run { display: block; }
.item[data-status="done"] .item-done { display: flex; }
.item[data-status="running"] .remove { visibility: hidden; }

.bar { height: 8px; border-radius: 99px; background: var(--sunken); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; }
.run-text { margin-top: 6px; color: var(--muted); font-size: 0.86rem; font-variant-numeric: tabular-nums; }

.item-done { flex-wrap: wrap; gap: 8px; align-items: center; }
.result-info { flex-basis: 100%; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.result-info b { color: var(--ok); }

.preview-video { display: block; width: 100%; max-height: 360px; margin-top: 12px; border-radius: 10px; background: #000; }
.preview-video[hidden] { display: none; }

/* ---------- panel ---------- */
.panel {
  margin-top: 20px;
  padding: 22px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.panel-title { margin: 0 0 14px; font-size: 1.15rem; font-weight: 800; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled { opacity: .45; }
fieldset:disabled * { cursor: not-allowed !important; }

.mode { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-opt { display: block; position: relative; }
.mode-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.mode-card {
  display: block; height: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.mode-name { display: block; font-weight: 700; line-height: 1.4; }
.mode-desc { display: block; margin-top: 2px; color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.mode-opt input:checked + .mode-card { border-color: var(--ink); background: var(--sunken); }
.mode-opt input:focus-visible + .mode-card { outline: 3px solid var(--accent); outline-offset: 2px; }
.mode-opt input:disabled + .mode-card { opacity: .45; cursor: not-allowed; }

.settings { margin-top: 22px; }
.group { margin: 0 0 22px; padding: 0; }
.group-title { display: block; padding: 0; font-weight: 700; margin-bottom: 8px; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.group-head .group-title { margin: 0; }

.hint { margin: 8px 0 0; color: var(--muted); font-size: 0.84rem; line-height: 1.6; }
.hint .link {
  padding: 0; border: 0; background: none;
  color: var(--accent); font-weight: 700; text-decoration: underline; cursor: pointer;
}
.hint .warn { color: var(--warn-ink); background: var(--warn-bg); padding: 1px 6px; border-radius: 5px; }

/* resolution picker: each option shows its frame at true relative size */
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.res { position: relative; display: block; }
.res input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.res-card {
  display: flex; flex-direction: column; justify-content: space-between;
  height: 100%; min-height: 108px;
  padding: 10px 10px 9px;
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .12s, background-color .12s;
}
.res-card:hover { border-color: var(--muted); }
.res-stage { display: flex; align-items: flex-end; height: 46px; margin-bottom: 8px; }
.res-frame {
  display: block;
  border: 2px solid var(--muted);
  border-radius: 3px;
  background: var(--sunken);
  transition: border-color .12s, background-color .12s;
}
.res-name { display: block; font-weight: 700; line-height: 1.3; }
.res-px { display: block; color: var(--muted); font-size: 0.76rem; font-variant-numeric: tabular-nums; line-height: 1.4; }
.res input:checked + .res-card { border-color: var(--ink); background: var(--sunken); }
.res input:checked + .res-card .res-frame { border-color: var(--accent); background: var(--accent); }
.res input:focus-visible + .res-card { outline: 3px solid var(--accent); outline-offset: 2px; }

/* bitrate */
.num-wrap { display: flex; align-items: baseline; gap: 6px; }
.num {
  width: 5.2em;
  padding: 6px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 1.15rem; font-weight: 700; text-align: right;
  font-variant-numeric: tabular-nums;
}
.num:focus { border-color: var(--ink); outline: none; }
.unit { color: var(--muted); font-weight: 600; }

.range {
  display: block; width: 100%; height: 32px; margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.range-scale {
  display: flex; justify-content: space-between;
  margin-top: -2px; padding: 0 6px;
  color: var(--muted); font-size: 0.74rem; font-variant-numeric: tabular-nums;
}

/* advanced */
.more { border-top: 1px solid var(--line); padding-top: 14px; }
.more summary { cursor: pointer; font-weight: 700; padding: 2px 0; }
.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.field { display: block; }
.field-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.84rem; }
select {
  width: 100%;
  padding: 9px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
select:focus { border-color: var(--ink); outline: none; }

.check { display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.check span { font-size: 0.95rem; }

/* ---------- actions ---------- */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  padding: 10px 20px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-weight: 700; text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--sunken); }
.btn[hidden] { display: none; }
.btn.primary { min-width: 160px; border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: 0.9rem; }
.btn.fill { background: var(--ink); color: var(--bg); }
.btn.fill:hover { background: var(--ink); filter: brightness(1.15); }

.status-line { flex: 1; min-width: 12em; margin: 0; color: var(--muted); font-size: 0.9rem; }

/* ---------- footer ---------- */
.foot { margin-top: 36px; color: var(--muted); font-size: 0.82rem; line-height: 1.7; }
.foot p { margin: 0 0 6px; max-width: 42em; }
.foot a { color: inherit; }

@media (max-width: 520px) {
  .page { padding-left: 16px; padding-right: 16px; }
  .mode { grid-template-columns: 1fr; }
  .more-grid { grid-template-columns: 1fr; }
  .res-grid { grid-template-columns: repeat(3, 1fr); }
  .btn.primary { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
