:root {
  --bg: #0e0f12;
  --panel: #17191e;
  --panel2: #20232a;
  --line: #2c3038;
  --text: #eef0f3;
  --muted: #9aa1ad;
  --ok: #1fa35a;
  --no: #d63c3c;
  --hold: #6b717c;
  --accent: #e8b341;
  --focus: #6aa8ff;
  --dock-h: 128px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--text); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  background: rgba(14, 15, 18, .96); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 800; font-size: 20px; letter-spacing: .5px; text-decoration: none; color: var(--accent); }
.logo.big { font-size: 48px; text-align: center; margin-bottom: 16px; }
.tb-mid { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: baseline; }
.tb-batch { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-prog { color: var(--muted); font-size: 14px; white-space: nowrap; }
.hb { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.hb-ok { background: var(--ok); }
.hb-idle { background: var(--hold); }
.hb-warn { background: var(--accent); box-shadow: 0 0 0 3px rgba(232, 179, 65, .25); }
.menu { position: relative; }
.menu summary { list-style: none; width: 48px; height: 48px; display: grid; place-items: center; font-size: 22px; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu nav {
  position: absolute; right: 0; top: 48px; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.menu nav a, .menu nav button {
  display: block; width: 100%; text-align: left; min-height: 48px; padding: 12px 14px;
  border: 0; background: none; text-decoration: none; border-radius: 8px;
}
.menu nav a:hover, .menu nav button:hover { background: var(--panel2); }
.menu nav form { margin: 0; border-top: 1px solid var(--line); }
.hb-text { margin: 4px 14px 8px; font-size: 13px; color: var(--muted); }

/* ---------- 공통 ---------- */
.page { padding: 16px; max-width: 1100px; margin: 0 auto; }
.page.narrow { max-width: 520px; }
h1 { font-size: 22px; margin: 8px 0 12px; }
.lead { color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); text-decoration: none; font-weight: 600;
}
.btn.primary { background: var(--accent); color: #1a1408; border-color: transparent; }
.btn.ghost { background: none; }
.err { color: #ff8080; }
.notice { background: rgba(31, 163, 90, .15); border: 1px solid var(--ok); padding: 10px 14px; border-radius: 8px; }
.stack, .auth-box form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 15px; }
input[type=text], input[type=password], input:not([type]) {
  min-height: 48px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 16px;
}
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-box { width: 100%; max-width: 360px; }

/* ---------- 묶음 목록 ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.chip { min-height: 44px; padding: 10px 16px; border-radius: 22px; border: 1px solid var(--line); text-decoration: none; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.card.done { opacity: .65; }
.card-head { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.card h2 { font-size: 18px; margin: 0; word-break: break-all; }
.kind { font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--panel2); white-space: nowrap; }
.kind-edit { color: var(--accent); }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
progress { width: 100%; height: 8px; appearance: none; border: 0; border-radius: 4px; background: var(--panel2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--panel2); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.counts { display: flex; gap: 12px; margin: 0; font-size: 15px; }
.c-ok { color: #5fd38f; } .c-no { color: #ff7d7d; } .c-hold { color: var(--muted); } .c-rate { margin-left: auto; font-weight: 700; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- 클립 검수 ---------- */
body.review { overscroll-behavior: none; }
.rv { max-width: 900px; margin: 0 auto; padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom) + 12px); }
.stage { position: relative; background: #000; }
.stage video { display: block; width: 100%; max-height: 46vh; aspect-ratio: 16 / 9; background: #000; object-fit: contain; }
.tapstart {
  position: absolute; inset: 0; margin: auto; width: 220px; height: 64px; border-radius: 32px;
  border: 0; background: rgba(255, 255, 255, .92); color: #000; font-size: 20px; font-weight: 700;
}
.vmsg { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; text-align: center; color: var(--muted); background: #000; }
.flash {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(.8);
  font-size: 56px; font-weight: 900; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .6);
}
.flash.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.f-ok { color: #5fd38f; } .f-no { color: #ff6b6b; } .f-hold { color: #d0d4da; }

.track { position: relative; height: 18px; background: var(--panel); cursor: pointer; }
.track-fill { position: absolute; left: 0; top: 7px; height: 4px; width: 100%; background: var(--text); transform-origin: left; transform: scaleX(0); }
.track::before { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 4px; background: var(--line); }
.track-marker { position: absolute; top: 2px; width: 3px; height: 14px; margin-left: -1px; background: var(--accent); border-radius: 2px; }
.track-segs .tseg { position: absolute; top: 4px; height: 10px; background: rgba(31, 163, 90, .45); border-radius: 2px; }

.ctrls { display: flex; gap: 6px; padding: 8px 8px 4px; overflow-x: auto; scrollbar-width: none; }
.ctrls button {
  flex: 1 0 auto; min-width: 48px; min-height: 44px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); font-size: 15px;
}
.ctrls .armed { border-color: var(--ok); color: #5fd38f; }
.ctrls .ref { font-size: 20px; }
.ctrls .ref.on { color: var(--accent); border-color: var(--accent); }

.seglist { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 8px; }
.seglist:empty { display: none; }
.seg { min-height: 36px; padding: 4px 10px; border-radius: 8px; border: 1px solid rgba(31, 163, 90, .6); background: rgba(31, 163, 90, .12); font-size: 14px; }
.seg.pending { border-style: dashed; display: inline-flex; align-items: center; }

.meta { margin: 4px 8px; color: var(--muted); font-size: 14px; }
.meta summary { cursor: pointer; padding: 6px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 4px 0 8px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; color: var(--text); word-break: break-all; }

.tags { padding: 4px 8px; display: flex; flex-direction: column; gap: 6px; }
.tg { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 4px; border-radius: 10px; border: 1px solid transparent; }
.tg.active { border-color: var(--line); }
.tg-name { width: 100%; font-size: 13px; color: var(--muted); }
.tag {
  min-height: 44px; padding: 6px 12px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--panel); font-size: 16px;
}
.tag kbd { display: none; font: 12px/1 monospace; color: var(--muted); margin-right: 6px; }
.tg.active .tag kbd { display: inline; }
.tag.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tag.on kbd { color: #555; }
.memo { display: block; width: calc(100% - 16px); margin: 8px; scroll-margin-bottom: calc(var(--dock-h) + 16px); }
.keys { display: none; margin: 4px 8px; font-size: 13px; color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .keys { display: block; } }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(14, 15, 18, .97); border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.dock-row { display: flex; gap: 8px; max-width: 900px; margin: 0 auto; }
.dock-row + .dock-row { margin-top: 6px; }
.dock-row.nav button {
  flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 15px;
}
.dock-row.nav button:disabled { opacity: .4; }
.v { flex: 1; min-height: 60px; border-radius: 12px; border: 2px solid transparent; font-size: 20px; font-weight: 800; color: #fff; }
.v-ok { background: var(--ok); }
.v-no { background: var(--no); }
.v-hold { background: var(--hold); }
.v.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .25) inset; }
.v.on::after { content: " ✓"; }
.cd { position: absolute; left: 0; right: 0; top: -1px; height: 5px; background: var(--panel2); overflow: hidden; }
.cd-fill { position: absolute; inset: 0; background: var(--accent); transform-origin: left; }
body.memo-hold .cd-fill { background: var(--focus); }

.summary { max-width: 700px; margin: 0 auto; padding: 16px 16px calc(var(--dock-h) + 24px); }
body.at-summary .rv { display: none; }
body.at-summary .verdicts, body.at-summary .cd { display: none; }
.sum-dist { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 20px; }
.sd { display: grid; grid-template-columns: 48px 1fr 40px; gap: 10px; align-items: center; }
.sd-bar { height: 14px; background: var(--panel2); border-radius: 7px; overflow: hidden; }
.sd-bar i { display: block; height: 100%; }
.sd-ok i { background: var(--ok); } .sd-no i { background: var(--no); } .sd-hold i { background: var(--hold); }
.sd b { text-align: right; }
.summary h2 { font-size: 17px; }
.sum-tags { padding-left: 22px; }
.sum-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--dock-h) + 16px + env(safe-area-inset-bottom));
  z-index: 40; background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 15px;
  max-width: calc(100% - 32px);
}
.toast.err { border-color: var(--no); color: #ffb3b3; }

/* 넓은 화면: 영상 옆에 태그 */
@media (min-width: 1000px) {
  .rv { max-width: 1280px; display: grid; grid-auto-flow: row dense; grid-template-columns: minmax(0, 1fr) 380px; column-gap: 16px; padding: 12px 16px calc(var(--dock-h) + 12px); }
  .stage, .track, .ctrls, .seglist, .meta { grid-column: 1; }
  .tags, .memo, .keys { grid-column: 2; }
  .tags { grid-row: 1 / span 5; align-self: start; }
  .stage video { max-height: 70vh; }
}

/* 휴대폰·좁은 화면: 태그 묶음을 한 줄씩(옆으로 밀기) 두어 네 묶음이 한 화면에 보이게 */
@media (max-width: 999px) {
  .ctrls { gap: 4px; padding: 6px 6px 4px; }
  .ctrls button { flex: 1 1 0; min-width: 0; padding: 0 2px; font-size: 15px; }
  .tags { gap: 4px; padding: 2px 0 2px 8px; }
  .tg { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 0 8px 0 0; border: 0; border-radius: 0; gap: 6px; }
  .tg::-webkit-scrollbar { display: none; }
  .tg.active { border: 0; }
  .tg-name { width: auto; flex: none; min-width: 34px; font-size: 13px; }
  .tag { flex: none; white-space: nowrap; padding: 6px 12px; font-size: 15px; }
  .tg.active .tag kbd { display: none; }
}
body.at-summary #bMemo, body.at-summary #bNext { visibility: hidden; }
