:root {
  --bg: #16171b; --bg2: #1e2025; --bg3: #262930; --line: #30343c; --line2: #3c414b;
  --text: #ececef; --muted: #9aa0ab; --accent: #ff6a1f; --accent2: #ff8a4d; --blue: #3d8bfd; --danger: #e5484d;
  --radius: 10px; --font: "Pretendard", "맑은 고딕", "Malgun Gothic", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); font-size: 13.5px; color: var(--text); background: var(--bg); display: grid; grid-template-rows: 52px 1fr var(--tl-h, 190px); overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--bg3); border: 1px solid var(--line2); border-radius: 8px; padding: 6px 12px; cursor: pointer; transition: background .12s, border-color .12s, transform .05s; }
button:hover { background: #2f333b; border-color: #4a505b; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
button.primary:hover { background: var(--accent2); }
button.ghost { background: transparent; }
button.danger { color: #ff8a8e; }
button.mini { padding: 2px 9px; line-height: 1.4; }
button.mini-text { padding: 3px 10px; font-size: 12px; }
button.icon { width: 36px; height: 34px; padding: 0; font-size: 15px; }
button.tog { width: 38px; height: 34px; padding: 0; font-size: 15px; }
button.tog.on { background: var(--accent); border-color: var(--accent); color: #fff; }
select, input[type=text], input[type=number], textarea { background: var(--bg); border: 1px solid var(--line2); border-radius: 7px; padding: 6px 8px; outline: none; }
select:focus, input:focus, textarea:focus { border-color: var(--blue); }
input[type=number] { width: 68px; }
input[type=color] { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--line2); border-radius: 7px; background: var(--bg); cursor: pointer; }
input[type=range] { accent-color: var(--accent); vertical-align: middle; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; vertical-align: -2px; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.vsep { width: 1px; height: 22px; background: var(--line2); margin: 0 6px; display: inline-block; }
.badge { background: var(--blue); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 700; margin-left: 4px; vertical-align: 1px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; letter-spacing: .2px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; display: block; }
.brand .ver { font-size: 11px; color: var(--muted); font-weight: 500; }
.brand .maker-logo { display: inline-flex; align-items: center; margin-left: 10px; padding: 3px 8px; border-radius: 7px; border: 1px solid transparent; }
.brand .maker-logo img { height: 22px; display: block; }
.brand .maker-logo:hover { background: var(--bg3); border-color: var(--line2); }
.welcome .credit { margin-top: 18px; font-size: 12px; color: var(--muted); pointer-events: auto; }
.welcome .credit a { color: var(--accent2); text-decoration: none; }
.welcome .credit-logo { height: 40px; margin-bottom: 6px; }
.credit-box { background: var(--bg); border: 1px solid var(--line2); border-radius: 8px; padding: 10px 12px; margin: 14px 0 8px; }
.credit-box a { color: var(--accent2); }
.credit-box img { height: 26px; vertical-align: middle; margin-right: 8px; }
.proj-name { width: 240px; background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 5px 8px; font-size: 14px; }
.proj-name:hover, .proj-name:focus { border-color: var(--line2); background: var(--bg); }
.top-actions { margin-left: auto; display: flex; gap: 6px; }

/* layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w, 460px); min-height: 0; position: relative; }
.stage { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr auto auto; min-height: 0; background: #0d0e11; }
.preview-wrap { position: relative; display: grid; place-items: center; min-height: 0; padding: 14px; }
#preview { max-width: 100%; max-height: 100%; background: #000; box-shadow: 0 10px 40px rgba(0,0,0,.55); border-radius: 4px; cursor: pointer; }
.welcome { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; color: #c9ccd3; }
.welcome .w-logo { width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 22px; display: block; box-shadow: 0 12px 40px rgba(120,160,230,.30); }
.welcome h1 { margin: 0 0 10px; font-size: 26px; letter-spacing: .3px; }
.welcome p { margin: 0; line-height: 1.6; color: var(--muted); }
.drop-overlay { position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 14px; background: rgba(255,106,31,.12); display: none; place-items: center; font-size: 20px; font-weight: 700; color: #fff; pointer-events: none; }
body.dragging .drop-overlay { display: grid; }
.controls { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--bg2); border-top: 1px solid var(--line); }
.tc { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 128px; }
.tc .sep { margin: 0 6px; color: var(--muted); font-weight: 400; }
#scrub { flex: 1; min-width: 0; }
.ctl-btns { display: flex; align-items: center; gap: 4px; }
.stage-opts { display: flex; align-items: center; gap: 18px; padding: 8px 14px; background: var(--bg2); border-top: 1px solid var(--line); }
.stage-opts label { display: inline-flex; align-items: center; gap: 6px; }

/* right panel */
.panel { display: grid; grid-template-rows: auto 1fr; background: var(--bg2); border-left: 1px solid var(--line); min-height: 0; }
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 0; background: var(--bg3); padding: 12px 4px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { background: var(--bg2); color: var(--text); border-bottom-color: var(--accent); }
.tab-pages { overflow: auto; min-height: 0; }
.tab-page { display: none; padding: 14px 16px 24px; }
.tab-page.active { display: block; }
.panel-title { margin: 0 0 12px; font-weight: 700; }
.step { padding: 12px 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step-h { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 8px; }
.step-h .num { width: 20px; height: 20px; border-radius: 5px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 12px; }
.step-btn { margin-left: auto; font-weight: 700; }
.step-btns { margin-left: auto; display: flex; gap: 4px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.5; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.row.small { font-size: 12px; color: var(--muted); }
.row.small input[type=range] { width: 110px; }
.row label { display: inline-flex; align-items: center; gap: 6px; }
.row label.wide { flex: 1; }
.row label.wide input { flex: 1; }
.title-row input[type=text] { flex: 1; min-width: 100px; }
.title-media { margin-top: -2px; padding-left: 22px; gap: 6px; flex-wrap: wrap; align-items: center; }
.title-media .tm-chip { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0; max-width: 210px; cursor: pointer; padding: 2px 8px 2px 2px; border: 1px solid var(--line2); border-radius: 8px; background: var(--bg); font-size: 12px; }
.title-media .tm-chip img { width: 44px; height: 26px; object-fit: cover; border-radius: 5px; background: #222; flex: 0 0 auto; }
.title-media .tm-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.title-media select { padding: 3px 6px; font-size: 12.5px; }
#titleTrimSlot .video-box { margin-top: 10px; }
.cta { text-align: center; }
.music-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line2); border-radius: 8px; background: var(--bg); max-height: 150px; overflow: auto; }
.music-list li { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.music-list li:last-child { border-bottom: 0; }
.music-list li.sel { background: rgba(61,139,253,.18); }
.music-list li.empty { color: var(--muted); justify-content: center; cursor: default; padding: 22px; }
.music-list li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.music-list li .d { color: var(--muted); font-variant-numeric: tabular-nums; }
.music-list.detail li input[type=range] { width: 90px; }
.sub-h { font-weight: 700; margin: 10px 0 6px; }
.sec-h { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: 14px 0 8px; }
.sec-h label.inline { font-weight: 400; font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.toggles { gap: 6px; }
#capText { width: 100%; resize: vertical; margin: 6px 0; }
.two { display: grid; grid-template-columns: 130px 1fr; gap: 16px; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 34px); gap: 4px; }
.pos-grid button { height: 30px; padding: 0; font-size: 11px; color: var(--muted); }
.pos-grid button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.fx-list { display: flex; flex-wrap: wrap; gap: 6px; }
.fx-list button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.nav-row { margin-top: 14px; }
.tile-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { border: 2px solid var(--line2); border-radius: 8px; background: var(--bg); padding: 0; overflow: hidden; display: grid; grid-template-rows: 56px auto; }
.tile canvas, .tile .ico { width: 100%; height: 56px; display: block; object-fit: cover; }
.tile .ico { display: grid; place-items: center; font-size: 22px; background: #0d0e11; }
.tile .lbl { font-size: 11px; padding: 4px 2px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.on { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.tile.override .lbl::after { content: " •"; color: var(--accent); }

/* timeline */
.timeline { display: grid; grid-template-rows: auto 1fr; background: var(--bg2); border-top: 1px solid var(--line); min-height: 0; position: relative; }
.tl-head { display: flex; align-items: center; padding: 6px 14px; border-bottom: 1px solid var(--line); }
.tl-title { font-weight: 700; }
.tl-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.tl-strip { display: flex; gap: 10px; padding: 10px 14px; overflow-x: auto; overflow-y: hidden; align-items: flex-start; position: relative; }
.tl-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.tl-item { flex: 0 0 auto; width: calc(150px + (var(--tl-h, 190px) - 190px) * 1.6); border: 2px solid var(--line2); border-radius: 8px; background: var(--bg); overflow: hidden; cursor: pointer; user-select: none; position: relative; transition: border-color .1s; }
.tl-item:hover { border-color: #565c68; }
.tl-item.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tl-item.dragover { border-color: var(--blue); box-shadow: -4px 0 0 var(--blue); }
.tl-item.title-card .thumb { display: grid; place-items: center; font-weight: 700; color: #f1d27a; background: linear-gradient(135deg, #0f0c29, #302b63); text-align: center; padding: 6px; font-size: 12px; line-height: 1.3; }
.tl-item .thumb { width: 100%; height: calc(84px + (var(--tl-h, 190px) - 190px) * 0.9); object-fit: cover; display: block; background: #222; }
.tl-item.title-card .thumb.has-media { background-size: cover; background-position: center; color: #fff; text-shadow: 0 1px 3px #000, 0 0 6px rgba(0,0,0,.8); box-shadow: inset 0 0 0 999px rgba(0,0,0,.32); }
.tl-item .thumb.text-card { display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #0f0c29, #24243e); font-size: 12px; padding: 6px; text-align: center; }
.tl-item .meta { display: flex; align-items: center; gap: 6px; padding: 4px 7px; font-size: 11px; }
.tl-item .meta .idx { color: var(--accent); font-weight: 700; }
.tl-item .meta .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.tl-item .meta .dur { font-variant-numeric: tabular-nums; }
.tl-item .cap-dot { position: absolute; top: 5px; right: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 6px; }
.tl-item .rot { position: absolute; top: 5px; left: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 6px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; place-items: center; z-index: 50; }
.modal.open { display: grid; }
.modal-box { width: 560px; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; background: var(--bg2); border: 1px solid var(--line2); border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.modal-box.wide { width: 720px; }
.modal-h { display: flex; align-items: center; font-weight: 800; font-size: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-h .close { margin-left: auto; padding: 2px 8px; background: transparent; border: 0; font-size: 16px; }
.modal-body { padding: 14px 18px; overflow: auto; min-height: 0; flex: 1 1 auto; }  /* only the middle scrolls, so the title and the buttons stay in view */
.modal-h, .modal-f { flex: 0 0 auto; }
.modal-f { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.btn-link { color: var(--accent2); text-decoration: none; font-weight: 700; }
.btn-link:hover { text-decoration: underline; }
.ex-info { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-top: 6px; }
#exPreview { width: 100%; height: auto; background: #000; border-radius: 8px; display: block; }
.bar { height: 10px; background: var(--bg); border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; margin: 14px 0 8px; }
#exBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ffb347); transition: width .2s; }
.ex-status { font-size: 13px; color: var(--muted); line-height: 1.6; }
.done-icon { font-size: 44px; text-align: center; margin: 10px 0; }
#exDownload { display: inline-block; text-decoration: none; padding: 8px 16px; border-radius: 8px; margin-top: 10px; }
.help h3 { margin: 14px 0 6px; font-size: 14px; color: var(--accent2); }
.help ol, .help p { margin: 6px 0; line-height: 1.65; }
.help table { border-collapse: collapse; margin-top: 6px; }
.help td { padding: 4px 14px 4px 0; }
.help td:nth-child(odd) { color: var(--accent2); font-weight: 700; font-family: Consolas, monospace; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 210px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 60; pointer-events: none; }
#toast div { background: rgba(20,22,28,.95); border: 1px solid var(--line2); color: #fff; padding: 9px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5); animation: toastIn .18s ease-out; }
#toast div.err { border-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* caption toggle glyph previews */
.tog .sh { text-shadow: 2px 2px 3px #000; }
.tog .ol { -webkit-text-stroke: 1px #000; color: #fff; }
.tog .bx { background: rgba(0,0,0,.6); padding: 0 4px; border-radius: 3px; }

@media (max-width: 1100px) { .layout { grid-template-columns: 1fr 380px; } .tile-grid { grid-template-columns: repeat(3, 1fr); } }

/* video trim */
.video-box { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line2); border-radius: 10px; background: var(--bg); }
.video-box .sub-h { margin-top: 0; }
.trimmer { position: relative; height: 64px; margin: 6px 0 22px; border-radius: 8px; background: #101114; user-select: none; touch-action: none; overflow: visible; }
.trimmer .strip { position: absolute; inset: 0; border-radius: 8px; background-color: #22242a; background-size: 100% 100%; background-repeat: no-repeat; }
.trimmer .strip.loading::after { content: "장면 미리보기 준비 중…"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.trimmer .dim { position: absolute; top: 0; bottom: 0; background: rgba(6,7,9,.72); pointer-events: none; }
.trimmer .dim-l { left: 0; border-radius: 8px 0 0 8px; } .trimmer .dim-r { right: 0; border-radius: 0 8px 8px 0; }
.trimmer .sel-box { position: absolute; top: 0; bottom: 0; border: 2px solid var(--accent); border-radius: 4px; pointer-events: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); }
.trimmer .playhead { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.6); pointer-events: none; display: none; }
.trimmer .handle { position: absolute; top: -2px; bottom: -2px; width: 18px; background: var(--accent); border-radius: 5px; cursor: ew-resize; touch-action: none; box-shadow: 0 2px 8px rgba(0,0,0,.6); outline: none; }
.trimmer .handle::before { content: ""; position: absolute; left: 7px; top: 22px; width: 4px; height: 20px; border-left: 1px solid rgba(255,255,255,.7); border-right: 1px solid rgba(255,255,255,.7); }
.trimmer .handle:hover, .trimmer .handle:focus, .trimmer .handle.drag { background: var(--accent2); }
.trimmer .handle-l { margin-left: -9px; } .trimmer .handle-r { margin-left: -9px; }
.trimmer .handle .lbl { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 3px; font-size: 11px; color: var(--text); background: var(--bg3); padding: 1px 5px; border-radius: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.trim-row .fld { display: inline-flex; align-items: center; gap: 4px; }
.trim-row input[type=number] { width: 62px; }
.trim-row .quick { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.tl-item .cap-dot.vid { background: var(--accent); }

/* ---------- mobile (phones & small tablets) ---------- */
button .ico { display: none; }
.mobile-only { display: none; }
.desktop-only { }
/* ---- free layout: drag the borders ---- */
.split { position: absolute; z-index: 6; touch-action: none; }
.split::after { content: ''; position: absolute; inset: 0; background: var(--accent); opacity: 0; transition: opacity .12s; }
.split:hover::after, .split.dragging::after { opacity: .55; }
.split-v { top: 0; bottom: 0; right: calc(var(--panel-w, 460px) - 3px); width: 7px; cursor: col-resize; }
.split-h { left: 0; right: 0; top: -4px; height: 7px; cursor: row-resize; }
.pv-grip { display: none; }
body.resizing, body.resizing * { user-select: none !important; }

/* ---- hand placement of a photo ---- */
body.placing #preview { cursor: grab; touch-action: none; outline: 2px dashed var(--accent); outline-offset: 2px; }
body.placing #preview.grabbing { cursor: grabbing; }
.place-bar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 12px; background: rgba(20,21,26,.92); border: 1px solid var(--line2); box-shadow: 0 8px 24px rgba(0,0,0,.5); z-index: 5; max-width: calc(100% - 12px); }
.place-bar input[type=range] { width: 140px; min-width: 60px; flex: 1 1 60px; }
.place-bar button { padding: 5px 9px; white-space: nowrap; }
.place-hint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); padding: 5px 12px; border-radius: 999px; background: rgba(20,21,26,.88); border: 1px solid var(--line2); font-size: 12px; color: var(--text); z-index: 5; pointer-events: none; max-width: calc(100% - 16px); text-align: center; }
#btnPlace.on { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (max-width: 900px), (pointer: coarse) and (max-width: 1100px) {
  html, body { height: 100dvh; }
  body { grid-template-rows: 48px auto auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); font-size: 14px; padding-bottom: env(safe-area-inset-bottom); overflow-x: hidden; }
  .topbar, .stage, .timeline, .panel, .controls, .stage-opts, .tl-head { min-width: 0; max-width: 100vw; }
  .stage-opts, .tl-head { flex-wrap: wrap; }
  .tl-actions { margin-left: 0; flex-wrap: wrap; }
  .tl-title { flex: 1 1 auto; }
  .brand .name { display: none; }
  .brand .maker-logo { margin-left: 2px; padding: 2px 4px; }
  .brand .maker-logo img { height: 18px; }
  .proj-name { flex: 1 1 60px; width: 60px; }
  .layout { display: contents; }
  .stage { order: 1; grid-template-rows: auto auto auto; }
  .timeline { order: 2; }
  .panel { order: 3; border-left: 0; border-top: 1px solid var(--line); }
  .topbar { padding: 0 8px; gap: 8px; }
  .brand .ver { display: none; }
  .proj-name { flex: 1; width: auto; min-width: 0; font-size: 13px; }
  .top-actions { gap: 4px; }
  .top-actions button .txt, .tl-actions button .txt { display: none; }
  button .ico { display: inline; }
  .top-actions button, .tl-actions button { padding: 6px 9px; min-height: 36px; }
  .preview-wrap { height: var(--pv-h, min(56.25vw, 36dvh)); padding: 6px 8px; }
  .split { display: none; }
  .pv-grip { display: grid; place-items: center; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); width: 96px; height: 22px; z-index: 7; touch-action: none; cursor: row-resize; }
  .pv-grip i { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line2); border: 1px solid rgba(255,255,255,.18); }
  .pv-grip.dragging i, .pv-grip:active i { background: var(--accent); }
  body.placing .preview-wrap { height: max(var(--pv-h, 0px), min(78vw, 50dvh)); }
  .place-bar { bottom: 6px; gap: 4px; padding: 5px 6px; } .place-bar input[type=range] { width: 70px; } .place-bar button { padding: 4px 7px; min-height: 32px; font-size: 12.5px; } .place-bar button.icon { width: 32px; height: 32px; }
  .place-hint { font-size: 11px; top: 6px; }
  body.typing .pv-grip { display: none; }
  /* typing on a phone: the keyboard takes half the screen, so the work panel gets the rest */
  body.typing { grid-template-rows: 48px auto minmax(0, 1fr); }  /* the hidden timeline leaves the grid, so the panel is the third row */
  body.typing .timeline, body.typing .controls, body.typing .stage-opts { display: none; }
  body.typing .preview-wrap { height: min(40vw, 20dvh); }
  input[type=text], input[type=password], input[type=number], textarea { font-size: 16px; }  /* below 16px iOS zooms the page on focus */
  #preview { border-radius: 3px; }
  .welcome h1 { font-size: 18px; } .welcome p { font-size: 12px; } .welcome .w-logo { width: 48px; height: 48px; border-radius: 12px; margin-bottom: 8px; }
  .controls { padding: 6px 8px; gap: 8px; }
  .tc { min-width: 0; font-size: 11px; white-space: nowrap; }
  #scrub { min-width: 0; }
  .ctl-btns .vsep { display: none; }
  button.icon { width: 38px; height: 38px; }
  .stage-opts { padding: 6px 8px; gap: 6px 12px; font-size: 12px; display: none; }
  body.show-opts .stage-opts { display: flex; }
  .mobile-only { display: inline-block; }
  .desktop-only { display: none !important; }
  .step-btns.mobile-only { display: inline-flex; }
  .hint.mobile-only { display: block; }
  #btnStageOpts.on { background: var(--accent); border-color: var(--accent); color: #fff; }
  .tl-title .muted, .tl-actions #sortSel { display: none; }
  .stage-opts select { padding: 5px 6px; }
  .tl-head { padding: 4px 8px; gap: 6px; }
  .tl-title { font-size: 12px; }
  .tl-actions .vsep { display: none; }
  .tl-actions #sortSel { width: 74px; padding: 5px 4px; font-size: 12px; }
  .tl-strip { padding: 6px 8px; gap: 6px; }
  .tl-item { width: 104px; }
  .tl-item .thumb { height: 50px; }
  .tl-item .meta { padding: 3px 5px; font-size: 10px; }
  .tl-item .cap-dot, .tl-item .rot { font-size: 9px; }
  .tl-empty { font-size: 12px; }
  .tabs button { padding: 10px 2px; font-size: 12.5px; }
  .tab-page { padding: 10px 12px 48px; }
  .step-h { flex-wrap: wrap; }
  .step-btn { margin-left: auto; }
  .tile-grid { gap: 6px; }
  .tile { grid-template-rows: 46px auto; }
  .tile canvas, .tile .ico { height: 46px; }
  .two { grid-template-columns: 116px 1fr; gap: 10px; }
  .pos-grid { grid-template-columns: repeat(3, 32px); }
  .pos-grid button { height: 32px; }
  button, select, input[type=text], input[type=number] { min-height: 36px; }
  button.mini { min-height: 30px; }
  .modal-box { width: 96vw; max-height: 92dvh; border-radius: 12px; }
  .modal-body { padding: 12px 14px; }
  .help table td { display: block; padding: 2px 0; }
  #toast { bottom: 40dvh; width: calc(100vw - 32px); }
  #toast div { text-align: center; }
  .video-box { padding: 8px 10px; }
}
@media (max-width: 480px) {
  .stage-opts label:not(.chk) { font-size: 11px; }
  .stage-opts { gap: 4px 8px; }
  .tabs button { padding: 9px 1px; font-size: 12px; }
  .tile-grid { grid-template-columns: repeat(4, 1fr); }
}

/* AI music generation */
button.gen { color: #ffd28a; border-color: #6b4a1f; background: #2a2116; }
button.gen:hover { background: #3a2c1a; border-color: #a8731f; }
.mg-sub { font-size: 12px; font-weight: 400; margin-left: 10px; }
.mg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mg-col textarea { width: 100%; resize: vertical; }
.mg-label { display: block; font-weight: 700; margin: 4px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.chips button { padding: 4px 10px; font-size: 12px; border-radius: 14px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.mg-provider { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
#mgKey { font-family: Consolas, monospace; letter-spacing: 1px; }
.mg-wait { display: grid; place-items: center; gap: 14px; padding: 28px 0; text-align: center; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--line2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#mgAudio { width: 100%; margin: 10px 0; }
@media (max-width: 900px) { .mg-grid { grid-template-columns: 1fr; } }

/* where-did-it-save hint on phones */
.save-hint { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line2); font-size: 12.5px; color: var(--muted); line-height: 1.6; text-align: left; }
.save-hint b { color: var(--text); }
.save-hint ol { margin: 6px 0 0; padding-left: 18px; }

/* send (share) panel on the export-done view */
.send-box { margin-top: 14px; padding: 12px; border: 1px solid var(--line2); border-radius: 10px; background: var(--bg); text-align: left; }
.send-h { font-weight: 800; margin-bottom: 8px; }
.send-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
#exShare { padding: 10px 16px; font-size: 14px; background: #fee500; border-color: #fee500; color: #191600; }
#exShare:hover { background: #ffef5a; }
.drag-file { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 2px dashed var(--line2); border-radius: 10px; color: var(--text); text-decoration: none; cursor: grab; max-width: 100%; }
.drag-file:hover { border-color: var(--accent); background: var(--bg3); }
.drag-file:active { cursor: grabbing; }
.drag-file .df-ico { font-size: 20px; }
.drag-file .df-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.drag-file small { color: var(--muted); }
.send-hint { margin-top: 10px; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.send-hint b { color: var(--text); }
.send-hint ol { margin: 4px 0 0; padding-left: 18px; }
.send-hint .warn { color: #ffb86b; }
.send-alt { margin-top: 10px; padding: 10px 12px; border-radius: 8px; border: 1px solid #a8642a; background: rgba(255,140,40,.08); font-size: 13px; line-height: 1.65; }
.send-alt ol { margin: 6px 0 8px 18px; padding: 0; } .send-alt .alt-btns { display: flex; flex-wrap: wrap; gap: 8px; }
#btnSend { border-color: #6b5f00; color: #fee500; }

.mg-provider.top { margin-top: 0; padding-top: 0; border-top: 0; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }

/* operator usage view */
.usage-body { margin-top: 10px; }
.us-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.us-card { background: var(--bg); border: 1px solid var(--line2); border-radius: 10px; padding: 10px 12px; }
.us-card .k { font-size: 12px; color: var(--muted); } .us-card .v { font-size: 20px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.us-card .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.us-meter { height: 8px; border-radius: 5px; background: var(--bg3); overflow: hidden; margin-top: 6px; } .us-meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #ffb347); }
.us-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.us-table th, .us-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.us-table th:first-child, .us-table td:first-child { text-align: left; } .us-table td.bar { width: 45%; text-align: left; }
.us-table .b { display: inline-block; height: 9px; border-radius: 4px; background: var(--accent); vertical-align: middle; min-width: 1px; }
.us-err { color: #ffb86b; font-size: 12.5px; margin-top: 8px; line-height: 1.6; }
@media (max-width: 900px) { .us-cards { grid-template-columns: repeat(2, 1fr); } }
