/* 편집기 (영상 작업이라 어두운 화면 고정). 색·글꼴·모서리는 site.css 와 같은 토큰: 강조 = 크레파스 노랑, 버튼 8px, 판 10px */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css");
:root {
  color-scheme: dark;
  --bg: #16171a; --panel: #1f2125; --raise: #2a2d33; --line: #33363c; --text: #e8e9ec; --muted: #9aa0aa;
  --accent: #ffcc33; --on-accent: #17191e; --key: #ffcc33; --auto: #3ec97a; --interp: #7d838c; --lost: #ff5470; --sel: #4fa3ff;
  --r-ctl: 8px; --r-panel: 10px;
  --font: "Pretendard Variable", Pretendard, system-ui, "Malgun Gothic", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--font); height: 100dvh; display: flex; flex-direction: column; }
header { display: flex; gap: 8px; align-items: center; padding: 0 14px; height: 52px; flex: none; border-bottom: 1px solid var(--line); }
header .brand { display: inline-flex; align-items: center; gap: 7px; font: 700 22px/1 "Gaegu", var(--font); color: var(--text); text-decoration: none; margin-right: 6px; }
header .brand img { width: 26px; height: 26px; }
header .ghostlink { color: var(--muted); text-decoration: none; padding: 6px 8px; border-radius: var(--r-ctl); }
header .ghostlink:hover { color: var(--text); background: var(--raise); }
.hgroup { display: inline-flex; }
.hgroup > :first-child { border-radius: var(--r-ctl) 0 0 var(--r-ctl); }
.hgroup > :last-child { border-radius: 0 var(--r-ctl) var(--r-ctl) 0; border-left: none; }
#status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36vw; }
main { flex: 1; display: flex; min-height: 0; }
#left { flex: 1; display: flex; flex-direction: column; padding: 8px 12px; gap: 6px; min-width: 0; }
#right { display: flex; flex-direction: column; width: 340px; overflow-x: hidden; border-left: 1px solid var(--line); overflow-y: auto; padding: 4px 10px 0; }
button, select, input, .btn { background: var(--raise); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 5px 10px; font: inherit; cursor: pointer; transition: border-color .12s ease, background-color .12s ease; }
.btn { display: inline-flex; align-items: center; gap: 4px; }
button:hover, .btn:hover { border-color: #5a606b; }
button:active, .btn:active { transform: translateY(1px); }
:focus-visible, .btn:focus-within { outline: 2px solid var(--sel); outline-offset: 2px; }
button.on { background: #3a3f48; border-color: var(--accent); color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: #ffd65c; border-color: #ffd65c; }
button.danger { border-color: #84303f; color: #ff9aaa; }
button.danger.quiet { background: transparent; }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.primary:disabled { background: var(--raise); border-color: var(--line); color: var(--muted); opacity: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
input[type=number] { width: 70px; }
input[type=color] { padding: 0 2px; width: 40px; height: 24px; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, monospace; }
.hidden { display: none !important; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
#tools { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
#tools > button { flex: none; }
#toolHint { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#stageWrap { flex: 1; position: relative; min-height: 200px; display: flex; align-items: center; justify-content: center; background: #0c0d0f; border-radius: 6px; overflow: hidden; }
#stage { position: relative; }
#stage video, #stage svg, #stage canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
#ov { touch-action: none; }
#ov.tool-draw, #ov.tool-track { cursor: crosshair; }

#transport { display: flex; gap: 6px; align-items: center; }
#timeline { width: 100%; background: #101114; border-radius: 6px; cursor: pointer; touch-action: none; }
details { border-bottom: 1px solid var(--line); padding: 8px 0 10px; }
summary { cursor: pointer; font-weight: 700; font-size: 15px; padding: 4px 0; }
summary::marker { color: var(--muted); }
summary .muted { font-weight: 500; }
#library { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-top: 4px; }
#library .thumb { background: #1f2125; border: 1px solid var(--line); border-radius: 5px; aspect-ratio: 1; padding: 4px; cursor: pointer; }
#library .thumb:hover { border-color: var(--accent); }
#library svg { width: 100%; height: 100%; }
/* 최근 생성 / 라이브러리: 붙어 있는 두 버튼 중 하나만 켜지고, 아래 판이 그 버튼과 이어져 보임 */
.shelf { margin-top: 8px; }
.seg { display: flex; }
.seg button { flex: 1; border-radius: 0; background: #1b1d21; color: var(--muted); border-color: var(--line); padding: 6px 0; }
.seg button:first-child { border-radius: 7px 0 0 0; }
.seg button:last-child { border-radius: 0 7px 0 0; border-left: none; }
.seg button.on { background: #2a2d33; color: var(--text); border-bottom-color: #2a2d33; box-shadow: inset 0 2px 0 var(--accent); font-weight: 600; }
.seg button:not(.on) { border-bottom-color: var(--line); }
.seg button span { color: var(--muted); font-weight: 400; }
.shelf #library { background: #2a2d33; border: 1px solid var(--line); border-top: none; border-radius: 0 0 7px 7px; padding: 6px; margin-top: 0; min-height: 70px; }
.shelf #libHint { margin-top: 4px; }
#ctxMenu { position: fixed; z-index: 20; background: #2a2d33; border: 1px solid #555b64; border-radius: 6px; padding: 4px; min-width: 150px; box-shadow: 0 4px 16px #0008; }
#ctxMenu div { padding: 5px 10px; border-radius: 4px; cursor: pointer; }
#ctxMenu div:hover { background: #3a3f48; }
#ctxMenu div.danger { color: #ff9aaa; }
#ctxMenu .title { color: var(--muted); cursor: default; font-size: 12px; }
#ctxMenu .title:hover { background: none; }
#library .empty { grid-column: 1 / -1; padding: 10px 0; }
.list { display: flex; flex-direction: column; gap: 3px; margin: 4px 0; }
.list .it { display: flex; gap: 8px; align-items: center; width: 100%; min-height: 34px; padding: 5px 8px; border-radius: var(--r-ctl); background: #24262b; cursor: pointer; border: 1px solid transparent; color: var(--text); text-align: left; font: inherit; }
.list .it:hover { background: #2a2d33; }
.list .it.sel { border-color: var(--sel); background: #232c38; }
.list .it .nm { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .it .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.form { background: #24262b; border: 1px solid var(--line); border-radius: var(--r-panel); padding: 10px 12px; margin-top: 6px; }
.form .frow { display: flex; gap: 6px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.form .flabel { width: 84px; color: #c3c7ce; flex: none; }
/* 선택한 낙서·추적 이름 줄 */
.fhead { display: flex; align-items: center; gap: 8px; font-size: 15px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.fhead .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
/* 폼 안 묶음: 작은 제목 + 위 구분선 */
.fsec { padding-top: 10px; margin-top: 10px; border-top: 1px solid var(--line); }
.fhead + .fsec, .fhead + .hint + .fsec { border-top: 0; margin-top: 2px; }
.fsec h5 { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font-size: 13px; font-weight: 700; color: var(--text); }
.fsec h5 .ph { color: var(--accent); font-size: 15px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 4px 0; }
.unit { color: var(--muted); font-size: 12px; }
.form label.chk, label.chk { display: inline-flex; gap: 5px; margin: 4px 0; font-size: 13px; color: var(--text); }
.row.two > button { flex: 1; justify-content: center; }
.form button { display: inline-flex; align-items: center; gap: 5px; }
.form button .ph { font-size: 15px; }
.factions { margin: 12px 0 2px; padding-top: 10px; border-top: 1px solid var(--line); }
/* 상태 표시: 따라다니는 대상, 문제/정상 */
.pill { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--c, var(--line)); color: var(--c, var(--text)); background: color-mix(in srgb, var(--c, #888) 14%, transparent); }
.pill.warn { --c: #ffb36b; }
.pill.ok { --c: var(--auto); }
.state { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; margin: 6px 0; border-radius: var(--r-ctl); border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 10%, #1b1d21); }
.state > .ph { color: var(--c); font-size: 16px; margin-top: 2px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 3px 0 8px; vertical-align: -1px; }
.sw.key { background: var(--key); } .sw.auto { background: var(--auto); } .sw.interp { background: var(--interp); } .sw.lost { background: var(--lost); }
#modal, #busy { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; max-width: 90vw; }
#modalBody video { max-width: 80vw; max-height: 70vh; display: block; margin-top: 8px; }
.warn { color: #ffb36b; }
/* 글씨 넣기 창 */
#textDlg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
.textcard { width: min(680px, 94vw); max-height: 92vh; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; }
.textcard .row { margin: 0; }
#textIn { width: 100%; resize: vertical; min-height: 84px; font-size: 34px; line-height: 1.25; padding: 10px 14px; background: #121316; border: 1px solid var(--line); border-radius: 8px; color: var(--text); }
#textIn:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,204,51,.15); }
#textIn::placeholder { color: #8b919b; font-family: system-ui, "Malgun Gothic", sans-serif; font-size: 18px; }
.ftabs { display: flex; gap: 4px; background: #16171a; padding: 3px; border-radius: 8px; border: 1px solid var(--line); }
.ftabs button { flex: 1; border: none; background: none; color: var(--muted); padding: 6px 0; border-radius: 6px; }
.ftabs button.on { background: #2f333a; color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); font-weight: 600; }
.fontpane { display: flex; flex-direction: column; gap: 6px; }
#fontSearch { width: 100%; }
#fontList { overscroll-behavior: contain; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 210px; overflow-y: auto; padding: 1px; }
#fontList:empty { display: none; }
.fontcard { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 7px 10px; text-align: left; background: #24262b; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; min-width: 0; }
.fontcard:hover { border-color: #555b64; }
.fontcard.on { border-color: var(--accent); background: #2e2b20; }
.fontcard .fname { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fontcard.on .fname { color: var(--accent); }
.fontcard .fsample { font-size: 24px; line-height: 1.2; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fontcard.upload { border-style: dashed; justify-content: center; }
.fontcard.upload .fsample { font-size: 12px; }
#fontNote:empty { display: none; }
#fontNote button { margin-right: 6px; }
.prevhead { display: flex; justify-content: space-between; }
#textPrev { min-height: 120px; max-height: 220px; display: flex; align-items: center; justify-content: center; padding: 12px; border-radius: 8px;
  background: #0c0d0f repeating-conic-gradient(#14161a 0 25%, #0c0d0f 0 50%) 0 0 / 16px 16px; }
#textPrev svg { max-width: 100%; max-height: 196px; }
#right > * { flex-shrink: 0; }
.foot { position: sticky; bottom: 0; margin-top: auto; text-align: center; padding: 8px 0 10px; background: var(--bg); border-top: 1px solid var(--line); }
button.link { background: none; border: none; padding: 0; color: inherit; text-decoration: underline; }
button.link:hover { color: var(--text); }
.doc { width: min(560px, 86vw); max-height: 70vh; overflow-y: auto; line-height: 1.6; padding-right: 6px; }
.doc h4 { margin: 14px 0 4px; }
.doc ul { padding-left: 18px; margin: 4px 0; }
.doc a { color: var(--sel); }

/* 그림 추가: 세 가지 방법을 같은 크기 타일로 */
.addgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0; }
.addgrid > * { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px; text-align: center; }
.addgrid b { font-size: 20px; line-height: 1.1; }
.addgrid small { color: var(--muted); font-size: 11px; }
/* 렌더 진행·완료 화면 (#left 안에서 편집 화면 대신 보임) */
#renderView { display: none; flex: 1; overflow-y: auto; padding: 6px 4px; }
body.rv #renderView { display: block; }
body.rv #left > :not(#renderView) { display: none; }
body.rendering #right > details, body.rendering header > button, body.rendering header > select { pointer-events: none; opacity: .45; }
#renderView h2 { margin: 6px 0 10px; font-size: 18px; }
.rvbar { height: 8px; background: #2a2d33; border-radius: 4px; overflow: hidden; }
.rvbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s linear; }
#rvInfo { margin: 6px 0 10px; }
#rvResult video { max-width: 100%; max-height: 55vh; display: block; margin-top: 6px; border-radius: 6px; }
.rvcols { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 20px; margin-top: 14px; }
.rvcols h4 { margin: 0 0 6px; }
.rvcols ul { margin: 0; padding-left: 18px; line-height: 1.7; }
#rvSummary { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
#rvSummary dt { color: var(--muted); }
#rvSummary dd { margin: 0; overflow-wrap: anywhere; }
.ad-slot:not(:empty) { margin-top: 24px; text-align: center; }
.ad-slot.side:not(:empty) { position: sticky; bottom: 34px; margin-top: 12px; background: var(--bg); padding-top: 6px; }
/* 직접 그리기 막대 (도구 줄 오른쪽 빈 곳) */
#drawPanel { display: flex; gap: 6px; align-items: center; flex: none; }
#drawPanel button { padding: 2px 10px; }
#drawPanel button.icon { display: inline-flex; align-items: center; padding: 3px 7px; }
#drawPanel .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
#drawPanel label { display: flex; align-items: center; gap: 6px; }
/* 손떨림 슬라이더: 막대를 손잡이 반지름(6px)만큼 안쪽에 그려서 0·100 일 때 손잡이 가운데가 막대 끝에 딱 맞게 */
#smoothRange { -webkit-appearance: none; appearance: none; width: 96px; height: 16px; margin: 0; padding: 0; border: none; cursor: pointer;
  background: linear-gradient(var(--sel), var(--sel)) 6px 50% / calc((100% - 12px) * var(--p, 0)) 4px no-repeat,
              linear-gradient(#4a4e56, #4a4e56) 6px 50% / calc(100% - 12px) 4px no-repeat; }
#smoothRange::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--text); border: none; }
#smoothRange::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--text); border: none; }
#smoothRange::-moz-range-track { background: transparent; }
#smoothVal { display: inline-block; width: 3ch; text-align: right; }   /* 0 ↔ 100 바뀔 때 막대가 밀리지 않게 */

/* 웹 버전 */
#stageWrap.over { outline: 2px dashed var(--accent); outline-offset: -6px; }

.foot a { color: inherit; }
#empty a { color: var(--sel); }
#videoName { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xopts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 10px; }
.xopts:empty { display: none; }
.xopt { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.xopt h4 { margin: 0 0 4px; }
.xopt p { margin: 4px 0 8px; }
.xopt .tag { font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 4px; margin-left: 4px; font-weight: 400; }
a.btn { text-decoration: none; display: inline-block; }

#empty { position: absolute; inset: 16px; display: grid; place-content: center; justify-items: center; gap: 10px; text-align: center; border: 2px dashed var(--line); border-radius: var(--r-panel); color: var(--muted); }
#empty b { color: var(--text); font-size: 18px; }
#empty .btn { margin-top: 6px; padding: 8px 18px; }
#stageWrap.over #empty { border-color: var(--accent); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
/* 영상을 열기 전엔 재생·타임라인을 숨겨 빈 화면을 드롭 영역으로만 */
body:not(.has-video) #transport, body:not(.has-video) #timeline, body:not(.has-video) #timeline + .muted, body:not(.has-video) #toolHint { display: none; }
/* 아이콘 (Phosphor regular, 글자 크기 따라감) */
.ph { font-size: 1.15em; vertical-align: -.15em; }
#tools .ph, header .ph { margin-right: 5px; }
#transport button .ph { margin: 0; }
.addgrid .ph { font-size: 22px; margin-bottom: 2px; }
#drawPanel button.icon .ph { margin: 0; }
header > *, #tools > * { flex: none; white-space: nowrap; }
/* 좁은 창: 위쪽 막대와 도구 줄은 아이콘만 (이름은 마우스를 올리면 보임) */
@media (max-width: 1180px) {
  header .lbl, #toolHint { display: none; }
  header .ph { margin-right: 0; }
  #exportBtn .ph { margin-right: 5px; }
  #status { max-width: 22vw; }
}
@media (max-width: 1000px) {
  #tools .lbl { display: none; }
  #tools .ph { margin-right: 0; }
  #right { width: 300px; }
}
#tools { min-width: 0; overflow-x: auto; scrollbar-width: none; }   /* 아주 좁으면 옆으로 밀어서 봄 (오른쪽 판을 덮지 않게) */
#tools::-webkit-scrollbar { display: none; }
/* 작업 중 창의 진행 막대 */
#busyMsg { min-width: min(420px, 86vw); }
.busybar { height: 6px; margin-top: 12px; background: var(--raise); border-radius: 3px; overflow: hidden; }
.busybar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .15s linear; }
.busybar i.indet { width: 35% !important; animation: indet 1.1s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@media (prefers-reduced-motion: reduce) { .busybar i.indet { animation: none !important; width: 100% !important; opacity: .5; } }
#busyTime { margin-top: 6px; min-height: 1.4em; font-variant-numeric: tabular-nums; }
/* 구간 고르기 창 */
#segDlg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
.segcard { width: min(720px, 94vw); display: flex; flex-direction: column; gap: 8px; }
.segcard .row { margin: 0; }
#segVid { width: 100%; max-height: 46vh; background: #000; border-radius: var(--r-ctl); }
#segTrack { position: relative; height: 14px; background: var(--raise); border-radius: 7px; cursor: pointer; }
#segBar { position: absolute; top: 0; bottom: 0; background: var(--accent); border-radius: 7px; min-width: 6px; }
#segRange { font-variant-numeric: tabular-nums; }

.mobile-note { display: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 700px) {
  body { height: auto; min-height: 100dvh; }
  header { flex-wrap: wrap; height: auto; min-height: 48px; gap: 6px; }
  #videoName { max-width: 35vw; overflow: hidden; text-overflow: ellipsis; }
  #status { max-width: 100%; flex-basis: 100%; }
  main { flex-direction: column; }
  #left { flex: none; min-height: 55dvh; padding: 8px; }
  #right { width: 100%; max-height: none; border-left: 0; border-top: 1px solid var(--line); }
  #stageWrap { min-height: 36dvh; }
  .mobile-note { display: block; margin: 6px 8px; color: var(--muted); font-size: 12px; }
  #transport { flex-wrap: wrap; }
}

#ctxMenu button { display: block; width: 100%; text-align: left; border: 0; padding: 5px 10px; background: transparent; }
#ctxMenu button:hover { background: #3a3f48; }
#ctxMenu button.danger { color: #ff9aaa; }

/* PC 전용 진입: 안내·사용법은 모든 기기에서 볼 수 있다. */
body.device-pending > :not(script), body.unsupported-device > :not(#pcOnly):not(script) { display: none !important; }
body.unsupported-device { height: auto; min-height: 100dvh; }
#pcOnly { max-width: 600px; margin: 12vh auto; padding: 24px; line-height: 1.8; }
#pcOnly a { color: var(--accent); }

/* 키보드: 편집 화면으로 건너뛰기 (포커스 받을 때만 보임) */
.skip { position: absolute; left: 12px; top: -48px; z-index: 30; padding: 8px 12px; border-radius: var(--r-ctl); background: var(--accent); color: var(--on-accent); font-weight: 600; text-decoration: none; }
.skip:focus { top: 8px; }
