:root {
  color-scheme: dark;
  --sub-font-size: 30px;
  --sub-color: #fff;
  --sub-bg: 0.35;
  --sub-bottom: 12%;
  --sub-shadow: 0 2px 4px #000, 0 0 2px #000;
  font-family: Inter, Segoe UI, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: #111315; color: #f2f3f5; }
.topbar { display: flex; justify-content: space-between; gap: 16px; padding: 18px 24px; border-bottom: 1px solid #2b3138; background: #171a1f; }
h1 { margin: 0; font-size: 24px; letter-spacing: 0; }
h2 { margin: 18px 0 10px; font-size: 16px; }
p { margin: 4px 0 0; color: #b9c0ca; }
.button, button, select, input[type="number"] { border: 1px solid #3b4652; background: #20262d; color: #f5f7fa; border-radius: 6px; padding: 9px 11px; }
button { cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible, .button:focus-within { outline: 2px solid #7cc7ff; outline-offset: 2px; }
.button input { display: none; }
.file-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; padding: 18px; }
.stage { position: relative; min-height: 540px; background: #050607; border: 1px solid #282f36; border-radius: 8px; overflow: hidden; }
video { width: 100%; height: calc(100% - 74px); min-height: 460px; display: block; background: #000; object-fit: contain; }
.subtitle-layer { position: absolute; left: 3%; right: 3%; bottom: var(--sub-bottom); display: grid; gap: 8px; place-items: center; pointer-events: none; text-align: center; }
.subtitle-cue { max-width: min(92%, 1100px); white-space: pre-line; font-size: var(--sub-font-size); line-height: 1.18; color: var(--sub-color); text-shadow: var(--sub-shadow); background: rgba(0,0,0,var(--sub-bg)); padding: 4px 10px; border-radius: 6px; }
.subtitle-cue.secondary { font-size: calc(var(--sub-font-size) * .78); opacity: .94; }
.controls { position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto minmax(70px, 110px) auto auto; gap: 10px; align-items: center; padding: 14px; background: rgba(12,14,16,.92); }
.controls input[type="range"] { min-width: 0; width: 100%; }
#timeLabel { white-space: nowrap; }
.panel { background: #171a1f; border: 1px solid #2b3138; border-radius: 8px; padding: 16px; min-width: 0; }
.panel label { display: grid; gap: 6px; margin: 12px 0; color: #c9d0d9; }
.panel select, .panel input[type="number"], .panel input[type="range"] { width: 100%; }
.sync-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.track-list { margin-top: 12px; display: grid; gap: 8px; color: #c8d0d9; font-size: 13px; }
.track-item { border: 1px solid #303842; border-radius: 6px; padding: 8px; }
.empty-state { position: absolute; inset: 0 0 74px; display: grid; place-content: center; gap: 8px; text-align: center; padding: 24px; color: #d9e2ec; }
.empty-state span { color: #aeb8c4; max-width: 100%; overflow-wrap: anywhere; }
.error-box { position: absolute; top: 12px; left: 12px; right: 12px; display: none; padding: 10px 12px; border-radius: 6px; background: #551f25; color: #ffe5e8; }
.error-box.active { display: block; }
.drop-overlay { position: fixed; inset: 0; z-index: 10; display: none; place-items: center; background: rgba(4,9,14,.78); font-size: 26px; font-weight: 700; }
.drop-overlay.active { display: grid; }
.tools { grid-column: 1 / -1; background: #171a1f; border: 1px solid #2b3138; border-radius: 8px; padding: 14px 16px 16px; min-width: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid #2b3138; padding-bottom: 10px; margin-bottom: 12px; }
.tabs [role="tab"][aria-selected="true"] { background: #2d4a63; border-color: #7cc7ff; }
.tabpanel[hidden], .tools [hidden] { display: none !important; }
.tools label { display: grid; gap: 6px; color: #c9d0d9; min-width: 0; }
.tools label.inline { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.tools input[type="text"], .tools input[type="search"], .tools select { width: 100%; min-width: 0; border: 1px solid #3b4652; background: #20262d; color: #f5f7fa; border-radius: 6px; padding: 9px 11px; }
.tools .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin: 8px 0; }
.tools .row > label { flex: 1 1 200px; }
.tools fieldset { border: 1px solid #303842; border-radius: 6px; margin: 8px 0; padding: 8px 12px 12px; min-width: 0; }
.tools fieldset.point { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px 12px; align-items: end; }
.tools legend { color: #c9d0d9; padding: 0 6px; }
.hint { color: #aeb8c4; overflow-wrap: anywhere; }
.vlist { position: relative; height: 320px; overflow-y: auto; border: 1px solid #303842; border-radius: 6px; background: #101317; margin-top: 10px; }
.vlist-spacer { position: relative; width: 100%; }
.vrow { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 0 12px; border: 0; border-bottom: 1px solid #20262d; border-radius: 0; background: transparent; text-align: left; font: inherit; color: #e6eaef; overflow: hidden; }
.vrow:hover { background: #1b2229; }
.vrow.active { background: #24506f; box-shadow: inset 4px 0 0 #7cc7ff; color: #fff; }
.vrow .t { font-variant-numeric: tabular-nums; color: #9fd3ff; white-space: nowrap; }
.vrow .d { color: #8995a3; white-space: nowrap; font-size: 12px; }
.vrow .g { color: #ffd479; white-space: nowrap; font-weight: 600; }
.vrow .x { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vrow mark { background: #ffd479; color: #111; border-radius: 2px; padding: 0 1px; }
.sr-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.tools textarea { width: 100%; min-height: 96px; resize: vertical; border: 1px solid #3b4652; background: #20262d; color: #f5f7fa; border-radius: 6px; padding: 9px 11px; font: inherit; }
.tools input[aria-invalid="true"] { border-color: #ff7b72; outline: 1px solid #ff7b72; }
.tools textarea:focus-visible, .tools input:focus-visible { outline: 2px solid #7cc7ff; outline-offset: 2px; }
.edit-preview { margin: 10px 0; padding: 10px 12px; min-height: 44px; background: #050607; border: 1px dashed #3b4652; border-radius: 6px; text-align: center; white-space: pre-line; overflow-wrap: anywhere; }
#editStatus.error { color: #ff9b94; }
.vrow.selected { box-shadow: inset 0 0 0 2px #ffd479; }
.vrow.selected.active { box-shadow: inset 4px 0 0 #7cc7ff, inset 0 0 0 2px #ffd479; }
.repeat-state { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 10px 0; }
.repeat-state dt { color: #aeb8c4; }
.repeat-state dd { margin: 0; font-variant-numeric: tabular-nums; }
.warnings { color: #ffd479; padding-left: 20px; overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .tools { margin-top: 12px; padding: 12px; }
  .vlist { height: 260px; }
  .topbar, .layout { display: block; }
  .layout { padding: 10px; }
  .panel { margin-top: 12px; }
  .controls { grid-template-columns: auto minmax(0, 1fr); position: static; gap: 8px; padding: 12px; }
  .controls button, .controls select { padding: 8px 10px; min-width: 0; }
  .controls input[type="range"] { max-width: 100%; }
  #timeLabel { grid-column: 1 / -1; font-size: 12px; overflow: hidden; text-overflow: clip; text-align: center; }
  #speed { grid-column: 1 / -1; width: 100%; }
  #fullscreenButton { grid-column: 1 / -1; }
  video { height: auto; min-height: 260px; }
  .stage { min-height: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
.notices { padding: 0 18px; display: grid; gap: 10px; }
.notices:empty { display: none; }
.notice { margin-top: 12px; padding: 12px 14px; border: 1px solid #7cc7ff; background: #14283a; border-radius: 8px; }
.notice[hidden] { display: none !important; }
.notice p { white-space: pre-line; overflow-wrap: anywhere; color: #e6eaef; margin: 6px 0; }
.notice .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.save-indicator { margin-left: 8px; padding: 1px 8px; border-radius: 10px; background: #20262d; color: #c9d0d9; font-size: 12px; }
.save-indicator:empty { display: none; }
.save-indicator.error { background: #551f25; color: #ffe5e8; }
#projectStatus, #shiftPreview { white-space: pre-line; overflow-wrap: anywhere; }
.recent { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.recent li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; border: 1px solid #303842; border-radius: 6px; padding: 8px 10px; }
.recent-open { font-weight: 600; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.recent-info { flex: 1 1 220px; min-width: 0; }
.tools fieldset > legend { font-weight: 600; }
@media (max-width: 900px) { .notices { padding: 0 10px; } }
ul.plain { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 4px; overflow-wrap: anywhere; }
.mkv-sub { display: grid; gap: 2px; margin: 6px 0; }
.mkv-sub label { display: flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.mkv-sub p { margin: 0 0 0 28px; }
progress { width: 100%; height: 14px; }
.tools h3 { margin: 14px 0 4px; font-size: 14px; }
button.audio-convert { margin-left: 6px; padding: 5px 9px; }
#audioConvertStatus { overflow-wrap: anywhere; }
.gpu-indicator { margin: 4px 0 0; font-size: 12px; color: #9fd3ff; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.gpu-indicator:empty { display: none; }
label.toggle { display: inline-flex; align-items: center; gap: 6px; color: #c9d0d9; font-size: 13px; }

/* ---- layout stability: live readouts must never change the size of anything around them ---- */
html { scrollbar-gutter: stable; }
.topbar > div:first-child { flex: 1 1 0; min-width: 0; }
.topbar .file-actions { flex: 0 1 auto; }
.topbar p { min-height: 1.5em; font-variant-numeric: tabular-nums; }
.gpu-indicator { display: block; width: 100%; min-height: 1.5em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; contain: layout paint; }
.gpu-indicator:empty { display: block; }
#mkvPlayback { min-height: 2.9em; font-variant-numeric: tabular-nums; contain: layout paint; }
#projectStatus, #audioConvertStatus, #mkvExtractStatus { min-height: 1.5em; }
@media (min-width: 901px) {
  .topbar p:not(.gpu-indicator) { height: 1.5em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 900px) {
  .gpu-indicator { white-space: normal; min-height: 2.9em; }
}
#timeLabel { min-width: 17ch; text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.controls button, .controls select { font-variant-numeric: tabular-nums; }
#playButton, #muteButton { min-width: 8ch; text-align: center; } /* "Play"/"Pause" and "Mute"/"Unmute" must not resize the row */
.build-id { font-size: 11px; font-weight: 400; color: #7d8794; margin-left: 8px; white-space: nowrap; }
ul.notes li.note-warn { color: #ffd479; }
ul.notes li.note-info { color: #aeb8c4; }

.site-footer { padding: 12px 16px; font-size: 12px; opacity: .75; text-align: center; }
