html { scroll-padding-bottom: 70px; }
body { font-size: 14px; }
[hidden] { display: none !important; }

.app-header {
  display: grid;
  grid-template-columns: minmax(185px, 1fr) minmax(220px, 1.35fr) minmax(max-content, 1fr);
  align-items: center;
  min-height: 62px;
  padding: 0 var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-project, .header-actions { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.header-project { justify-content: center; }
.header-project input { width: min(200px, 48%); padding: 6px 9px; background: var(--surface); }
#saved { white-space: nowrap; font-size: 12px; color: var(--muted); }
#saved::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--success); vertical-align: 1px; }
.header-actions { justify-content: end; }
.language-link { display: grid; min-width: 34px; min-height: 35px; place-items: center; font: 600 12px var(--mono); color: var(--muted); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; }
.language-link:hover { border-color: var(--border-strong); color: var(--text); }
.workspace { padding: 0 12px 12px; margin: 0 auto; max-width: 1920px; }
.projectbar, .project-actions, .project-menu, .head, .pair, .transport, .track-tools, .cut-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.projectbar { min-height: 54px; justify-content: space-between; gap: 8px 16px; padding: 7px 0; }
.work-context { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; min-width: 0; }
.work-context h1 { margin: 0; font-size: 14px; font-weight: 700; }
#status { margin: 0; max-width: 45ch; overflow-wrap: anywhere; font-size: 12px; color: var(--muted); }
.projectpick { display: flex; align-items: center; gap: 7px; margin: 0; color: var(--muted); font-size: 12px; }
.projectpick select { width: min(150px, 28vw); }
.project-actions button, .project-actions select { font-size: 12px; }
.editor-nav { display: none; }

.desk {
  display: grid;
  grid-template-columns: 78px minmax(200px, 235px) minmax(0, 1fr) minmax(246px, 286px);
  grid-template-rows: minmax(390px, 1fr) minmax(296px, 34vh);
  grid-template-areas: "tools sources monitor inspector" "tools timeline timeline inspector";
  height: calc(100dvh - 129px);
  min-height: 694px;
  gap: 8px;
}
.workspace-tools, .desk > section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  min-width: 0;
  min-height: 0;
}
.workspace-tools { grid-area: tools; display: flex; flex-direction: column; gap: 4px; padding: 7px; }
.workspace-tools button { display: grid; grid-template-rows: 21px auto; place-items: center; align-content: center; gap: 5px; height: 58px; min-width: 0; padding: 6px 2px; border-color: transparent; background: none; font-size: 11px; color: var(--muted); white-space: nowrap; }
.workspace-tools button .icon { width: 20px; height: 20px; }
.workspace-tools button:hover { background: var(--control); color: var(--text); }
.workspace-tools button.on { background: var(--accent-tint); border-color: var(--accent-border); color: var(--accent); }
.sources { grid-area: sources; padding: 12px; overflow: auto; }
.head { justify-content: space-between; min-height: 32px; margin: 0 0 8px; }
.head label { margin: 0; }
.head h2, .inspector h3 { font-size: 14px; font-weight: 700; }
.head > span { font: 12px var(--mono); color: var(--muted); }
.drop { display: grid; place-items: center; width: 100%; min-height: 84px; gap: 4px; padding: 11px; border-style: dashed; border-color: var(--border-strong); color: var(--accent); background: var(--accent-tint); }
.drop b { display: inline-flex; align-items: center; gap: 5px; }
.linkbtn { width: 100%; margin: 7px 0; justify-content: flex-start; }
.sources .linkbtn { font-size: 12px; }
#cliplist { display: grid; gap: 5px; margin-top: 8px; }
.card { display: flex; align-items: center; gap: 4px; }
.card > button { min-height: 32px; padding: 4px; font-size: 12px; }
.card .select { flex: 1; min-width: 0; justify-content: flex-start; text-align: left; }
.card .select.on { background: var(--accent-tint); border-color: var(--accent-border); color: var(--text); }
.card img { display: block; width: 54px; height: 40px; object-fit: cover; border-radius: var(--radius); }
.card .select span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card small { display: block; font-family: var(--mono); font-size: 10px; margin-top: 2px; }
#poolbox { margin-top: 8px; }
#poolbox summary { cursor: pointer; color: var(--muted); }

.monitor { grid-area: monitor; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; padding: 8px 10px; background: var(--surface); --preview-zoom: 1; }
.monitor .head { margin: 0 0 4px; padding: 0 3px; }
.monitor-options { display: flex; align-items: center; gap: 12px; }
.monitor-options label { display: flex; align-items: center; gap: 4px; }
.monitor-options select { min-height: 30px; width: auto; }
.stage { position: relative; display: grid; align-items: center; justify-items: center; container-type: size; min-height: 0; overflow: auto; background: var(--preview); border: 1px solid var(--border); border-radius: var(--radius); }
.screenbox { position: relative; line-height: 0; margin: 6px; box-shadow: 0 0 0 1px var(--border-strong); }
#screen { display: block; width: auto; height: calc((100cqh - 12px) * var(--preview-zoom)); aspect-ratio: 9/16; }
#guide { position: absolute; inset: 10% 16% 19% 7%; border: 1px dashed #fff9; pointer-events: none; }
.preview-empty { position: absolute; display: grid; place-items: center; align-content: center; justify-self: center; gap: 10px; width: min(100% - 12px, 220px); padding: 12px; color: var(--muted); text-align: center; }
.preview-empty > .icon { width: 30px; height: 30px; color: var(--accent); }
.workspace:not(.has-clips) .screenbox { visibility: hidden; }
.workspace:not(.has-clips) .stage::before { position: absolute; width: calc((100cqh - 18px)*.5625); height: calc(100% - 18px); border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-panel); content: ""; }
.has-clips .preview-empty { display: none; }
.transport { min-height: 45px; gap: 4px; padding-top: 6px; }
.transport button { min-width: 34px; padding: 4px 7px; }
#play { min-width: 66px; }
.transport label, .transport select { margin: 0; font-size: 12px; white-space: nowrap; }
.transport select { width: auto; max-width: 116px; }
#clock { margin-left: auto; font: 11px var(--mono); color: var(--muted); white-space: nowrap; }

.inspector { grid-area: inspector; overflow: auto; padding: 0 13px 13px; scrollbar-gutter: stable; }
.inspector-head { position: sticky; top: 0; z-index: 1; margin: 0 -13px 12px; padding: 9px 13px; background: var(--surface); border-bottom: 1px solid var(--border); }
.inspector-head .icon { color: var(--muted); }
.inspector h3 { margin: 6px 0 10px; overflow-wrap: anywhere; }
.inspector p { font-size: 12px; }
fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
legend { color: var(--muted); font-size: 12px; }
.pair > * { flex: 1; min-width: 0; }
.pair > button { font-size: 12px; }
.pair label { margin-bottom: 3px; }
.colors { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.colors button { width: 27px; min-height: 27px; padding: 0; border-radius: var(--radius); }
#visualFields, #transitions { margin: 8px 0; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); }
#visualFields .pair label, #transitions .pair label { min-width: 80px; }
.cue { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-items: start; gap: 7px; margin-top: 8px; padding: 8px; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); }
.cue label { margin: 2px 0; min-width: 0; }
.cue strong { font-size: 12px; overflow-wrap: anywhere; }
.cue > button { justify-self: end; }
.cue button { font-size: 12px; }
.sound-filter { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.template-pick { display: block; width: 100%; text-align: left; margin: 10px 0; padding: 0; overflow: hidden; }
.template-pick img { display: block; width: 100%; height: auto; aspect-ratio: 16/9; object-fit: cover; background: var(--preview); }
.template-pick span { display: grid; padding: 9px; gap: 3px; }

.timeline { grid-area: timeline; display: flex; flex-direction: column; padding: 9px 11px; overflow: hidden; }
.timeline .head { margin-bottom: 3px; padding: 0 1px; }
.track-tools { gap: 5px; margin-bottom: 6px; }
.track-tools label { display: flex; align-items: center; gap: 7px; margin: 0 0 0 auto; font-size: 12px; color: var(--muted); }
.track-tools select { width: auto; min-height: 29px; }
.track-tools button, .cut-actions button { min-height: 29px; padding: 4px 8px; font-size: 12px; }
.track-scroll { overflow: auto; flex: 1; min-height: 0; border-top: 1px solid var(--border); scrollbar-color: var(--border-strong) var(--surface); }
#trackContent { --lane-label: 68px; position: relative; width: 100%; padding-right: 5px; min-width: 329px; }
.track-ruler { position: relative; height: 22px; margin-left: var(--lane-label); border-bottom: 1px solid var(--border); }
#rulerLabels { display: flex; justify-content: space-between; padding: 2px 1px 0; color: var(--muted); font: 10px var(--mono); }
#globalSeek { position: absolute; inset: 0; height: 100%; margin: 0; opacity: .01; }
#globalSeek:focus-visible { opacity: 1; outline-offset: -2px; }
.playhead-rail { pointer-events: none; position: absolute; inset: 17px 5px 0 var(--lane-label); z-index: 2; }
#timelinePlayhead { position: absolute; inset: 0 auto 0 0; width: 2px; background: var(--accent); }
#timelinePlayhead::before { position: absolute; left: -3px; top: -4px; width: 8px; height: 7px; background: var(--accent); clip-path: polygon(0 0,100% 0,50% 100%); content: ""; }
.lane { display: grid; grid-template-columns: var(--lane-label) minmax(0,1fr); align-items: center; min-height: 20px; margin: 3px 0; }
.lane > small { font-size: 11px; color: var(--muted); }
#film { display: flex; min-height: 45px; gap: 1px; background: var(--track); }
#film .segment { position: relative; height: 45px; min-width: 0; overflow: hidden; background-size: cover; background-position: center; border-radius: 3px; box-shadow: inset 0 0 0 1px var(--border-strong); }
#film .active { box-shadow: inset 0 0 0 2px var(--accent); }
#film button { border: 0; border-radius: 0; background: none; color: #fff; padding: 0; touch-action: none; }
#film .clip-body { display: grid; place-content: center; text-align: center; width: 100%; height: 100%; min-height: 0; text-shadow: 0 0 4px #000, 0 0 8px #000; cursor: grab; }
#film small { color: #fff; font: 10px var(--mono); }
#film .edge { position: absolute; top: 0; bottom: 0; width: 10px; cursor: ew-resize; }
#film .edge::after { content: ""; height: 15px; width: 2px; border-radius: 1px; background: #fff; }
#film .start { left: 0; } #film .end { right: 0; }
#film .active .edge { background: color-mix(in srgb,var(--accent) 36%, transparent); }
#film .dragging { opacity: .6; }
#film .before { border-left: 3px solid var(--accent); }
#film .after { border-right: 3px solid var(--accent); }
#film button:focus-visible { outline-offset: -2px; }
.track,#cueTrack { position: relative; min-height: 20px; border-radius: 3px; background: repeating-linear-gradient(90deg,var(--track) 0 29px,var(--border) 30px); }
#cueTrack { cursor: crosshair; }
.marker,.track-block { position: absolute; overflow: hidden; min-width: 12px; height: 20px; min-height: 20px; padding: 0 3px; font: 11px var(--sans); white-space: nowrap; touch-action: none; }
.marker { top: 2px; background: var(--audio-tint); border-color: var(--audio-border); color: var(--audio); }
#cueTrack .cue-boundary { border-color: var(--accent-border); }
#cueTrack .wave-pin { color: transparent; }
.cue-wave { position: absolute; inset: 2px; background: var(--audio); pointer-events: none; }
.cue-boundary .cue-wave { background: var(--accent); }
.track-block { display: block; text-overflow: ellipsis; text-align: left; height: 25px; }
#visualTrack .track-block { background: var(--accent-tint); border-color: var(--accent-border); color: var(--accent); }
#musicTrack .track-block { background: var(--audio-tint); border-color: var(--audio-border); color: var(--audio); }
#subTrack .track-block { background: #443a29; border-color: #9c8153; color: #ffe4ae; }
.cut-actions { margin: 6px 0 0; gap: 4px; }
#dragInfo:not(:empty) { display: block; margin: 4px 0 0; }
#planStatus { white-space: pre-line; }
#exportPanel { max-width: 470px; }
#format { max-width: 100%; min-width: 0; }
dialog .head { margin-bottom: 10px; }
dialog p, dialog progress { margin: 10px 0; }
dialog video { display: block; max-height: 34vh; max-width: 100%; margin: 10px auto; }
dialog .pair > a { min-height: 35px; display: grid; place-items: center; }
#exportDesc, #exportState { font-size: 12px; }

@media (max-width: 1180px) and (min-width:761px) {
  .desk { grid-template-columns: 66px minmax(164px,190px) minmax(0,1fr) minmax(218px,244px); }
  .work-context h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
@media (max-width: 980px) and (min-width:761px) {
  .desk { grid-template-columns: 59px 153px minmax(0,1fr) 205px; }
  .app-header { grid-template-columns: max-content minmax(0,1fr) max-content; gap: 8px; padding-inline: 12px; }
  #clock { margin-left: 0; }
  .monitor { padding-inline: 7px; }
}
@media (max-width: 760px) {
  .app-header { position: sticky; z-index: 6; top: 0; min-height: 58px; grid-template-columns: auto minmax(0,1fr) auto; gap: 7px; padding: 5px 9px; }
  .header-project { align-items: flex-start; flex-direction: column; justify-content: center; gap: 1px; }
  .header-project input { width: 100%; min-height: 27px; padding: 2px 4px; font-size: 12px; }
  #saved { font-size: 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .header-actions { gap: 3px; }
  .header-actions .icon-button { width: 36px; min-height: 38px; }
  .language-link { display: none; }
  #export { min-height: 42px; padding-inline: 8px; font-size: 12px; }
  .workspace { padding: 0 8px 77px; }
  .projectbar { padding-block: 7px; gap: 5px; }
  .work-context h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #status { max-width: none; line-height: 1.35; }
  .project-actions { gap: 4px; }
  .projectpick { gap: 4px; }
  .projectpick select { width: min(103px,26vw); }
  .project-menu { gap: 4px; }
  .project-actions button, .project-actions select { min-height: 34px; padding-inline: 6px; }
  .desk { display: grid; height: auto; min-height: 0; grid-template-columns: minmax(0,1fr); grid-template-rows: auto; grid-template-areas: "monitor" "tools" "timeline" "sources" "inspector"; gap: 7px; }
  .desk > section { scroll-margin-top: 64px; }
  .workspace-tools { overflow: auto; flex-direction: row; padding: 4px; gap: 4px; }
  .workspace-tools button { min-width: 59px; height: 52px; }
  .workspace-tools .icon { width: 19px; height: 19px; }
  .monitor { grid-template-rows: auto minmax(234px, min(34vh, 302px)) auto; padding: 6px 7px; }
  .monitor-options select { min-height: 36px; }
  .transport button { min-height: 42px; min-width: 36px; }
  .transport select { min-height: 40px; }
  #clock { margin: 0 0 2px; flex-basis: 100%; text-align: center; }
  .timeline { min-height: 247px; }
  .track-tools button, .track-tools select, .cut-actions button { min-height: 36px; }
  .track-scroll { overflow-x: auto; }
  #trackContent { min-width: 480px; }
  .inspector { overflow: visible; }
  .inspector-head { position: static; }
  .inspector input, .inspector select, .inspector button, .sources button { min-height: 42px; }
  .inspector input[type=checkbox], .inspector input[type=range] { min-height: 0; }
  .editor-nav { position: fixed; z-index: 7; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 3px; padding: 4px 6px max(4px,env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .editor-nav a,.editor-nav button { display: grid; justify-items: center; align-content: center; min-height: 48px; gap: 2px; padding: 3px 0; font-size: 11px; font-weight: 650; white-space: nowrap; text-align: center; text-decoration: none; border-radius: var(--radius); }
  .editor-nav a { color: var(--muted); touch-action: manipulation; }
  .editor-nav a:hover { background: var(--control); color: var(--text); }
  .editor-nav .icon { width: 17px; height: 17px; pointer-events: none; }
}
@media (max-width: 360px) { .sound-filter { grid-template-columns: 1fr; } }

#saved::before { background: var(--muted); }
#saved[data-kind="ready"]::before { background: var(--success); }
#saved[data-kind="problem"]::before { background: #ffb58f; }
#projectMenuToggle { display: none; }
#cliplist { grid-template-columns: minmax(0,1fr); }
.card { min-width: 0; }
.card > button:not(.select) { width: 22px; flex: 0 0 22px; }
.timeline-label { display: flex; gap: 9px; align-items: baseline; }
.timeline-label span { font: 11px var(--mono); color: var(--muted); }
.timeline .track-tools { margin-bottom: 0; }
.timeline .head { margin-bottom: 6px; }
.track:empty { height: 20px !important; }
@media(max-width:760px) {
  .projectbar { min-height: 42px; }
  .work-context { flex: 1; }
  #projectMenuToggle { display: inline-flex; min-height: 34px; padding-inline: 7px; font-size: 12px; }
  .project-actions { display: none; flex-basis: 100%; }
  .project-actions.is-open { display: flex; }
  .timeline-head { gap: 3px; }
  .timeline .track-tools { flex: 1; justify-content: flex-end; }
  .track-tools label { margin-left: 2px; }
}

.locale-control { margin: 0; }
.locale-control select { width: auto; min-height: 35px; margin: 0; font-size: 12px; }
.quick-help, .advanced { margin: 9px 0; border-top: 1px solid var(--border); padding-top: 8px; }
.quick-help summary, .advanced summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.quick-help p { margin: 6px 0; font-size: 12px; }
.quick-help a { display: inline-block; margin: 7px 0 0; font-size: 12px; }
#codecNote { color: var(--muted); font-size: 12px; }
html[lang=en] .workspace-tools button { white-space: normal; line-height: 1.1; }
html[lang=en] .editor-nav a, html[lang=en] .editor-nav button { white-space: normal; }
@media(max-width: 760px) {
  .locale-control select { max-width: 67px; padding-inline: 3px; }
  html[lang=en] .projectbar #status { font-size: 11px; }
}

.template-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 6px; margin: 10px 0; }
.template-list button { flex-direction: column; align-items: flex-start; text-align: left; min-height: 52px; white-space: normal; }
.template-list small { font-size: 11px; }
#templates .template-pick { margin-top: 10px; }

#captionFields { margin: 0; }
#captionEditor p, #musicPanel p { margin: 0 0 8px; }
#captionEditor fieldset + .advanced { margin-top: 10px; }
#bedSettings { margin-top: 12px; }
#bedName { overflow-wrap: anywhere; }
#bedVolValue { margin-left: 8px; }
.track-tools .snap-label { margin-left: 3px; white-space: nowrap; }
#musicTrack { min-height: 40px; }
.timeline-edit-block {
 position: absolute; height: 30px; min-width: 22px; overflow: hidden;
 border: 1px solid #9c8153; border-radius: 4px; background: #443a29; color: #ffe4ae;
}
.timeline-edit-block button {
 min-height: 0; border: 0; padding: 0; border-radius: 0; color: inherit; background: none; touch-action: none;
}
.timeline-edit-block .timeline-item {
 display: block; width: 100%; height: 100%; padding: 0 17px; white-space: nowrap; overflow: hidden;
 text-overflow: ellipsis; text-align: left; font-size: 11px; cursor: grab;
}
.timeline-edit-block .timeline-item.wave-pin { position: relative; isolation: isolate; font-weight: 700; }
.timeline-item .cue-wave { opacity: .43; z-index: -1; }
.timeline-edit-block .timeline-handle {
 position: absolute; top: 0; bottom: 0; width: min(26%,16px); min-width: 0; cursor: ew-resize;
}
.timeline-handle.start { left: 0; }
.timeline-handle.end { right: 0; }
.timeline-handle::after { content: ""; display: block; width: 2px; height: 13px; border-radius: 1px; background: currentColor; }
.timeline-edit-block button:focus-visible { outline-offset: -2px; }
.timeline-edit-block.selected { border-color: #fff0d1; box-shadow: inset 0 0 0 1px #fff0d1; z-index: 1; }
.timeline-edit-block.adjusting { opacity: .7; z-index: 2; }
.timeline-edit-block.legacy-caption .timeline-item { padding-inline: 6px; cursor: pointer; }
#musicTrack .timeline-edit-block { background: var(--audio-tint); border-color: var(--audio-border); color: var(--audio); }
@media (max-width: 760px) {
 .app-header .brand { font-size: 14px; }
 .app-header .brand small { display: block; margin-left: 0; font-size: 10px; line-height: 1; }
 .timeline-edit-block .timeline-handle { width: min(28%,22px); }
 .timeline-edit-block .timeline-item { padding-inline: 23px; }
}

#screen { touch-action: none; }
#overlaySelection { position: absolute; border: 1px solid var(--accent); pointer-events: none; z-index: 3; }
#overlaySelection button {
 position: absolute; width: 22px; height: 22px; min-height: 0; padding: 0;
 display: grid; place-items: center; pointer-events: auto; touch-action: none;
 background: transparent; border: 0; transform: translate(-50%,-50%);
}
#overlaySelection button::after { content: ""; width: 9px; height: 9px; background: var(--accent); border: 1px solid #201930; }
#overlaySelection [data-corner^="n"] { top: 0; }
#overlaySelection [data-corner^="s"] { top: 100%; }
#overlaySelection [data-corner$="w"] { left: 0; }
#overlaySelection [data-corner$="e"] { left: 100%; }
#overlaySelection [data-corner="nw"], #overlaySelection [data-corner="se"] { cursor: nwse-resize; }
#overlaySelection [data-corner="ne"], #overlaySelection [data-corner="sw"] { cursor: nesw-resize; }
@media (pointer: coarse) { #overlaySelection button { width: 30px; height: 30px; } }
