:root {
  --bg: #15171c; --panel: #1d2027; --panel2: #252933; --line: #323743;
  --text: #e6e8ee; --dim: #8b92a3; --accent: #4f8cff; --ok: #3ecf8e; --warn: #f5b84a; --err: #ff6b6b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; background: var(--bg); color: var(--text);
  font: 14px/1.4 "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: .4; cursor: not-allowed; }
button.ghost { background: transparent; }
input, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ── 크기 조절 경계선 ── */
.splitter { flex: none; background: var(--line); position: relative; z-index: 2; }
.splitter:hover, .splitter.drag { background: var(--accent); }
#vsplit { width: 5px; cursor: col-resize; }
#hsplit { height: 5px; cursor: row-resize; }
body.resizing { user-select: none; }
body.resizing.col { cursor: col-resize; }
body.resizing.row { cursor: row-resize; }

/* ── 좌측 메뉴 ── */
#side {
  width: var(--side-w, 330px); min-width: 200px; max-width: 70vw; flex: none; display: flex; flex-direction: column; gap: 8px;
  padding: 12px; background: var(--panel);
}
#side h1 { font-size: 16px; margin: 0 0 4px; }
#side .row { display: flex; gap: 6px; }
#side .row button { flex: 1; }
.chk { color: var(--dim); font-size: 13px; }
#drop {
  border: 2px dashed var(--line); border-radius: 8px; padding: 18px 8px;
  text-align: center; color: var(--dim); font-size: 13px;
}
body.dragging #drop { border-color: var(--accent); color: var(--accent); background: #4f8cff14; }
#pathInput { width: 100%; font-size: 12px; }
#listInfo { color: var(--dim); font-size: 12px; }
#list { flex: 1; overflow-y: auto; margin: 0 -12px; padding: 0 6px; }
.grp { margin: 8px 0 2px; padding: 0 6px; font-size: 12px; color: var(--dim); display: flex; gap: 6px; }
.grp b { color: var(--text); }
.item {
  display: flex; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 6px;
  cursor: pointer; font-size: 12px;
}
.item:hover { background: var(--panel2); }
.item.sel { background: #4f8cff2e; outline: 1px solid var(--accent); }
.item .pt { width: 20px; text-align: center; font-weight: 700; color: var(--accent); flex: none; }
.item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sz { color: var(--dim); flex: none; }
.item.done .nm { color: var(--ok); }
.item.done .pt::after { content: "✓"; color: var(--ok); margin-left: 1px; }

/* ── 우측 ── */
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
#curName { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#curInfo { color: var(--dim); font-size: 12px; white-space: nowrap; }
.view { display: flex; gap: 6px; }
.view select { font-size: 12px; }

/* 이미지 수·영역 크기에 맞춰 JS(fitGrid)가 열 수와 크기를 정해 스크롤 없이 전부 보이게 함 */
#grid {
  flex: 1; min-height: 120px; overflow: hidden; padding: 10px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 6px; align-content: center; justify-content: center;
}
.shot { position: relative; background: #000; border-radius: 6px; overflow: hidden; cursor: zoom-in; aspect-ratio: 4/3; }
.shot.flat { aspect-ratio: 16/9; }
.shot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.shot .t {
  position: absolute; left: 4px; top: 4px; background: #000a; padding: 1px 6px;
  border-radius: 4px; font-size: 12px; font-weight: 600;
}
.shot.loading::after {
  content: "불러오는 중…"; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--dim); font-size: 12px;
}
.shot.fail::after { content: "추출 실패"; color: var(--err); }
.empty { color: var(--dim); padding: 30px; grid-column: 1/-1; text-align: center; }

/* ── 입력 폼 ── */
#form {
  flex: none; height: var(--form-h, auto); overflow-y: auto; min-height: 120px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 6px 20px;
  padding: 10px 14px 12px; background: var(--panel);
}
.col { display: flex; flex-direction: column; gap: 6px; }
.field { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 32px; }
.lbl { width: 48px; color: var(--dim); font-size: 13px; flex: none; }
.radio { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.radio input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.radio.group { margin-left: 8px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; }
#actor { width: 150px; }
input.md { width: 130px; }
input.sm { width: 52px; text-align: center; }
input.xs { width: 40px; text-align: center; text-transform: uppercase; }
#dbState { font-size: 12px; }
#dbState.ok { color: var(--ok); }
#dbState.new { color: var(--warn); }
.dis { opacity: .35; pointer-events: none; }
.hint { color: var(--dim); font-size: 12px; }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  min-width: 34px; padding: 4px 9px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); cursor: pointer; text-align: center; font-size: 13px; user-select: none;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#part .chip { min-width: 28px; padding: 4px 6px; }
#codeView { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#codeText { font: 700 16px Consolas, monospace; }
#partText {
  font: 700 16px Consolas, monospace; min-width: 28px; text-align: center;
  padding: 1px 8px; border-radius: 6px; background: var(--accent); color: #fff;
}
#partText.missing { background: var(--err); }
#partNote { font-size: 12px; }
#partNote.ok { color: var(--ok); }
#partNote.warn { color: var(--warn); }
#partNote.err { color: var(--err); font-weight: 600; }
#partNote.manual { color: var(--accent); }
#codeEdit { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex-basis: 100%; padding-left: 54px; }
#codeEdit[hidden] { display: none; }
button.link { background: none; border: none; padding: 0 4px; color: var(--dim); text-decoration: underline; font-size: 12px; }
button.link:hover { color: var(--text); }
.item .pt.warn { color: var(--warn); }
.item .pt.err { color: var(--err); }
.chip.skip { min-width: 0; padding: 4px 7px; font-size: 12px; }
.chip.skip.on { background: var(--warn); border-color: var(--warn); color: #000; }
input.skipped { opacity: .3; text-decoration: line-through; }

#phases { display: flex; flex-direction: column; gap: 4px; }
.phase { display: flex; align-items: center; gap: 6px; }
.phase .lbl { width: 26px; font-weight: 700; color: var(--dim); }
.phase .chip { font-size: 12px; padding: 3px 7px; min-width: 0; }
.phase.filled .lbl { color: var(--accent); }

.bottom { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
#warn {
  font-size: 13px; padding: 6px 10px; border-radius: 6px;
  background: #f5b84a1f; border: 1px solid var(--warn); color: var(--warn);
}
#warn div { color: var(--text); font-size: 12px; word-break: break-all; }
#warn b.done { color: var(--ok); }
.item .ew { color: var(--warn); flex: none; }
#preview {
  font: 600 15px/1.4 Consolas, "Malgun Gothic", monospace; padding: 8px 10px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); word-break: break-all; min-height: 38px;
}
#preview .miss { color: var(--warn); font-weight: 400; }
.actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
#msg { flex: 1; font-size: 13px; }
#msg.ok { color: var(--ok); }
#msg.err { color: var(--err); }

/* ── 확대 보기 ── */
#lightbox {
  position: fixed; inset: 0; background: #000e; display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 10; cursor: zoom-out;
}
#lightbox img { max-width: 88vw; max-height: 90vh; }
#lbCap { margin-top: 8px; color: var(--dim); }
.lbnav, .lbx {
  position: absolute; background: #0008; border: 1px solid #fff3; color: #fff; cursor: pointer;
}
.lbnav { top: 50%; transform: translateY(-50%); width: 56px; height: 120px; font-size: 44px; line-height: 1; }
#lbPrev { left: 12px; }
#lbNext { right: 12px; }
.lbx { top: 12px; right: 12px; width: 44px; height: 44px; font-size: 20px; border-radius: 50%; }
.lbnav:disabled { opacity: .2; cursor: default; }

/* ── 삭제 ── */
button.danger { border-color: var(--err); color: var(--err); background: transparent; }
button.danger:hover { background: var(--err); color: #fff; }
.modal {
  position: fixed; inset: 0; background: #000b; z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal .dlg {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; width: min(720px, 100%); max-height: 90vh; display: flex; flex-direction: column; gap: 10px;
}
.modal h3 { margin: 0; }
#delBox .dim { margin: 0; color: var(--dim); font-size: 13px; }
#delBox .quick { display: flex; gap: 8px; }
#delBox .quick button { flex: 1; padding: 10px; font-weight: 600; }
#delList { overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
#delList label {
  display: flex; gap: 8px; align-items: center; padding: 6px 10px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--line);
}
#delList label:last-child { border-bottom: none; }
#delList label:hover { background: var(--panel2); }
#delList .pt { width: 20px; font-weight: 700; color: var(--accent); text-align: center; flex: none; }
#delList .nm { flex: 1; word-break: break-all; }
#delList .sz { color: var(--dim); flex: none; }
#delList input { width: 16px; height: 16px; accent-color: var(--err); flex: none; }
#delMsg { flex: 1; font-size: 13px; color: var(--err); }

/* ── 폴더 탐색 (폰에서 폴더 고르기) ── */
#brPath { font: 600 13px Consolas, "Malgun Gothic", monospace; color: var(--accent); word-break: break-all; }
#brList { overflow: auto; border: 1px solid var(--line); border-radius: 6px; min-height: 200px; }
#brList .br { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; word-break: break-all; }
#brList .br:hover { background: var(--panel2); }
#brList .br.up { color: var(--dim); }
#brInfo { flex: 1; font-size: 13px; color: var(--dim); }

/* ── 화면 모드 (PC / 폴드 / 아이패드) ── */
#modebar {
  display: flex; align-items: center; gap: 8px; padding: 4px 14px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.seg { display: flex; margin-left: auto; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; padding: 4px 10px; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
#side h1 { display: flex; align-items: center; justify-content: space-between; }
#btnSide, #btnCloseSide, #sideBack { display: none; }

/* 터치 모드 공통: 손가락으로 누르기 좋게 크게 */
body.touch .pc-only { display: none !important; }
body.touch .chip {
  min-height: 40px; padding: 8px 12px; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}
body.touch .phase .chip { min-height: 38px; padding: 6px 10px; font-size: 14px; }
body.touch .chip.skip { padding: 8px 10px; font-size: 13px; }
body.touch button { min-height: 40px; padding: 8px 14px; }
body.touch button.link { min-height: 0; padding: 6px; }
body.touch .seg button { min-height: 34px; padding: 4px 12px; font-size: 13px; }
body.touch input, body.touch select { min-height: 40px; font-size: 16px; }
body.touch .lbl { width: 56px; }
body.touch .phase .lbl { width: 28px; }
body.touch #actor { width: 170px; }
body.touch input.sm { width: 64px; }
body.touch input.xs { width: 52px; }
body.touch .item { padding: 10px 8px; font-size: 14px; }
body.touch .splitter { touch-action: none; }
body.touch #vsplit { width: 12px; }
body.touch #hsplit { height: 14px; }
body.touch .splitter::after {   /* 잡는 손잡이 표시 */
  content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--dim); border-radius: 2px;
}
body.touch #hsplit::after { width: 48px; height: 4px; }
body.touch #vsplit::after { width: 4px; height: 48px; }
body.touch .actions { flex-wrap: wrap; }
body.touch #msg { flex-basis: 100%; order: -1; }
body.touch #form { overscroll-behavior: contain; }

/* 폴드(펼침): 목록은 ☰ 버튼으로 여닫는 서랍, 입력칸은 한 줄로 */
body.mode-fold { display: block; }
body.mode-fold main { height: 100%; }
body.mode-fold #side {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 20; width: min(92vw, 460px); max-width: none;
  transform: translateX(-102%); transition: transform .2s; box-shadow: 4px 0 20px #0008;
}
body.mode-fold.side-open #side { transform: none; }
body.mode-fold.side-open #sideBack { display: block; position: fixed; inset: 0; background: #0008; z-index: 19; }
body.mode-fold #vsplit { display: none; }
body.mode-fold #btnSide, body.mode-fold #btnCloseSide { display: inline-block; }
body.mode-fold #topbar { flex-wrap: wrap; row-gap: 4px; }
body.mode-fold #curName { flex-basis: 100%; white-space: normal; word-break: break-all; font-size: 13px; }
body.mode-fold #form { grid-template-columns: minmax(0, 1fr); height: var(--form-h, 58%); }
body.mode-fold .bottom {
  position: sticky; bottom: -12px; background: var(--panel); margin-bottom: -12px; padding: 6px 0 12px;
  border-top: 1px solid var(--line);
}

/* 아이패드 프로 12.9: 목록은 옆에 두되 좁게, 세로 화면에선 입력칸 한 줄로 */
body.mode-ipad #side { width: var(--side-w, 280px); }
body.mode-ipad .phase .chip { padding: 6px 8px; font-size: 13px; }
@media (max-width: 1150px) {
  body.mode-ipad #form { grid-template-columns: minmax(0, 1fr); height: var(--form-h, 56%); }
}
body.touch input[type=checkbox], body.touch input[type=radio] { min-height: 0; width: 20px; height: 20px; margin: 0; }
body.touch .chk { display: flex; align-items: center; gap: 6px; }

/* ── 로그인 ── */
body.login-page { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px;
}
.login h1 { font-size: 18px; margin: 0 0 6px; text-align: center; }
.login input { min-height: 44px; font-size: 16px; }
.login button { min-height: 44px; font-size: 16px; }
#loginMsg { color: var(--err); font-size: 13px; min-height: 18px; text-align: center; }

/* ── 영상 재생 ── */
#topbar { flex-wrap: wrap; row-gap: 6px; }
.view { flex-wrap: wrap; align-items: center; }
.view .seg { margin-left: 0; }
body.vid-mode #vInterval { display: none; }
#player { flex: 1; min-height: 120px; display: flex; flex-direction: column; background: #000; }
#player .vbox { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }
#vid { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; background: #000; }
#vMsg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none;
  background: #000a; padding: 6px 14px; border-radius: 6px; color: var(--dim); font-size: 13px;
}
#vMsg:empty { display: none; }
.vctl {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 10px;
  background: var(--panel); border-top: 1px solid var(--line);
}
#vPlay { width: 44px; font-size: 16px; }
#vTime { font: 600 13px Consolas, monospace; white-space: nowrap; }
#vSeek { flex: 1; min-width: 160px; accent-color: var(--accent); padding: 0; }
.vjump { display: flex; gap: 4px; }
.vjump button { padding: 6px 8px; font-size: 12px; }
body.touch #vSeek { min-height: 32px; }
body.touch .vjump button { padding: 8px 10px; font-size: 14px; }
.lbplay { margin-top: 10px; }
