/* Layout: header bar; workspace grid = video (left) + sidebar (right) over a full-width timeline.
   A dark range-officer palette: slate ground, cyan for start beeps, amber for shots (matches the overlay timer). */
:root {
  --bg: #0e1115;
  --panel: #161a20;
  --panel2: #1d222a;
  --line: #2a313b;
  --text: #e7eaef;
  --muted: #8d97a5;
  --beep: #48c4ff;
  --shot: #ffb347;
  --off: #5b6472;
  --danger: #ff6b6b;
  --ok: #5ad18a;
  --play: #ff4d5e;
  --sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Inter, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, "DejaVu Sans Mono", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* Several blocks set their own display, which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--sans); display: flex; flex-direction: column; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: #3d4654; background: #232933; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #23415a; border-color: #2f5d80; }
button.primary:hover:not(:disabled) { background: #2b5272; }
button.danger { color: var(--danger); }
button.small { padding: 2px 7px; font-size: 12px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--beep); outline-offset: 1px; }
input[type=text], input[type=number], select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
input[type=number] { width: 70px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); }
.small { font-size: 12px; }
code { font-family: var(--mono); background: var(--panel2); padding: 1px 5px; border-radius: 4px; }

.bar { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.mark { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--shot); box-shadow: inset 0 0 0 2px var(--panel), inset 0 0 0 6px var(--shot); }
.file { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 0; }
.pathform { display: flex; gap: 6px; flex: 1; min-width: 0; max-width: 520px; }
.pathform input { flex: 1; min-width: 0; }
.fileinfo { position: relative; display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; }
/* A long name gives way first: it is cut short so the info button and save status always show. */
.status { color: var(--muted); min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn { width: 22px; height: 22px; padding: 0; border-radius: 50%; font: italic 600 12px/1 Georgia, "Times New Roman", serif; color: var(--muted); flex: none; }
.iconbtn:hover:not(:disabled), .iconbtn[aria-expanded="true"] { color: var(--text); }
.popover { position: absolute; top: calc(100% + 8px); right: 0; z-index: 15; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.45); min-width: 240px; max-width: 420px; }
.popover dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.popover dt { color: var(--muted); }
.popover dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.status b { color: var(--text); font-weight: 600; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: minmax(0, 1fr) auto; }
.stage { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--line); }
.videowrap { flex: 1; min-height: 0; position: relative; background: #000; cursor: pointer; }
.videowrap video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.videowrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.videoerror { position: absolute; inset: auto 16px 16px 16px; background: rgba(40, 10, 12, .9); border: 1px solid var(--danger); padding: 10px 12px; border-radius: 8px; }
.transport { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.transport .play { min-width: 64px; background: #3a1f25; border-color: #6a2a35; }
.readout { margin: 0 8px; font-size: 14px; }
label.inline { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); margin-left: 6px; }

.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; border: 0; border-radius: 0; background: none; padding: 9px 4px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--shot); }
.tabbody { flex: 1; overflow: auto; padding: 12px; min-height: 0; }

.stagebox { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; background: var(--panel2); }
.stagebox .big { font: 600 22px/1.2 var(--mono); }
.stagebox .cls { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #3b2f12; color: var(--shot); font-weight: 700; margin-left: 6px; }
.strlist { display: flex; flex-direction: column; gap: 8px; }
.str { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.str.cur { border-color: var(--beep); }
.str.excluded { opacity: .55; }
.str .top { display: flex; align-items: baseline; gap: 8px; cursor: pointer; }
.str .name { font-weight: 700; }
.str .time { margin-left: auto; font: 600 16px var(--mono); }
.str .dropped { color: var(--muted); text-decoration: line-through; }
.str .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.str .ctl { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 6px; align-items: center; }
.str .ctl label { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); }
.str .ctl input[type=number] { width: 52px; padding: 2px 5px; }
.str .ctl .official { display: inline-flex; gap: 6px; align-items: center; }
.str .ctl .official input[type=number] { width: 64px; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.dropped { border-color: #5a4a2a; color: var(--shot); }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.beeplist { display: flex; flex-direction: column; gap: 4px; }
.beeprow { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.beeprow .mono { color: var(--text); }

table.shots { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.shots th { text-align: right; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px 6px; border-bottom: 1px solid var(--line); position: sticky; top: -12px; background: var(--panel); }
table.shots td { text-align: right; padding: 4px 6px; font-family: var(--mono); border-bottom: 1px solid #1f242c; }
table.shots th:first-child, table.shots td:first-child { text-align: left; }
table.shots tr { cursor: pointer; }
table.shots tr:hover td { background: #1b2027; }
table.shots tr.sel td { background: #20303d; }
table.shots tr.off td { color: var(--off); }
table.shots td.reason { font-family: var(--sans); font-size: 11px; color: var(--muted); text-align: left; }
.shothead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.shothead select { flex: 1; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 6px; }
.form input[type=text], .form select { width: 100%; }
.sliders { display: flex; flex-direction: column; gap: 12px; }
.sliders label { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; color: var(--muted); }
.sliders input[type=range] { grid-column: 1 / -1; width: 100%; }
.sliders .val { color: var(--text); font-family: var(--mono); }
.sliders .desc { grid-column: 1 / -1; font-size: 11px; }

.timeline { grid-column: 1 / -1; border-top: 1px solid var(--line); background: var(--panel); padding: 6px 10px 6px; }
.tlbar { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.tlbar .group { display: flex; gap: 6px; align-items: center; }
.selinfo { flex: 1; color: var(--muted); font-family: var(--mono); font-size: 12px; text-align: center; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
canvas.overview { width: 100%; height: 34px; display: block; border-radius: 4px; background: var(--bg); cursor: pointer; }
canvas.wave { width: 100%; height: 210px; display: block; margin-top: 6px; border-radius: 4px; background: var(--bg); cursor: crosshair; }
.keys { margin-top: 4px; }

.welcome { flex: 1; display: grid; place-items: center; padding: 24px; }
.welcome .card { max-width: 560px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px 28px; }
.welcome h1 { margin: 0 0 8px; font-size: 22px; }
.openrow { display: flex; align-items: center; gap: 12px; margin: 18px 0 10px; flex-wrap: wrap; }
button.big { font-size: 15px; padding: 9px 18px; }
.pathform.wide { max-width: none; display: flex; }
#welcomeStatus { margin-top: 10px; color: var(--text); }

.progress { position: fixed; left: 50%; top: 60px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; z-index: 5; min-width: 320px; }
.ptrack { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; min-width: 160px; }
.pfill { height: 100%; width: 0; background: var(--beep); transition: width .2s; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 10; padding: 16px; }
.dialog { width: min(640px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.modal.over { z-index: 11; }
.dialog.small { width: min(420px, 100%); }
.dialog.small p { margin: 0 0 12px; overflow-wrap: anywhere; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
legend { color: var(--muted); padding: 0 6px; }
.radio { display: flex; gap: 8px; align-items: center; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.grow input { flex: 1; min-width: 0; }
.row label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.exportprog { display: flex; gap: 10px; align-items: center; margin: 4px 0 8px; }
.msg { min-height: 1em; }
.msg.err { color: var(--danger); white-space: pre-wrap; }
.msg.ok { color: var(--ok); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; z-index: 20; max-width: 80vw; }
.toast.err { border-color: var(--danger); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(240px, 1fr) auto auto; overflow: auto; }
  .side { max-height: 360px; }
}
@media (prefers-reduced-motion: reduce) { .pfill { transition: none; } }

.calib { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; background: var(--panel2); display: flex; flex-direction: column; gap: 8px; }
.calib h4 { margin: 0; font-size: 13px; }
.calib .result { color: var(--text); font-size: 12px; }
.calib .result p { margin: 0 0 4px; }
.calib label { display: flex; gap: 6px; align-items: center; color: var(--muted); }

/* stage picker */
.field { display: flex; flex-direction: column; gap: 4px; }
.flabel { color: var(--muted); }
.stagebtn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--bg); padding: 5px 8px; }
.stagebtn .caret { margin-left: auto; color: var(--muted); }
.stagebtn[aria-expanded=true] { border-color: var(--beep); }
.sthumb { flex: none; width: 44px; height: 34px; border-radius: 4px; background: var(--panel2) center / contain no-repeat; border: 1px solid var(--line); }
.sthumb.has { background-color: #fff; }
.stagemenu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.stopt { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 6px; text-align: left; white-space: normal; background: var(--bg); }
.stopt[aria-selected=true] { border-color: var(--shot); box-shadow: 0 0 0 1px var(--shot); }
.stopt .pic { position: relative; aspect-ratio: 4 / 3; border-radius: 4px; background: #fff; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.stopt .pic img { width: 100%; height: 100%; object-fit: contain; display: block; }
.stopt .pic .ph { color: #6b7380; font: 600 13px var(--mono); }
.stopt.none .pic { background: var(--panel2); }
.stopt.none .pic .ph { color: var(--muted); font: inherit; }
.stopt .nm { font-weight: 600; color: var(--text); line-height: 1.2; }
.stopt .cd { color: var(--muted); font-size: 11px; }
#maxString { width: 80px; }
.calib .row { align-items: center; }
input[type=date] { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; color-scheme: dark; width: 100%; min-width: 0; max-width: 100%; display: block; }
/* Safari on iPad gives a date field its own width, wider than the panel, unless it's drawn
   as a plain field. */
@supports (-webkit-touch-callout: none) {
  input[type=date] { -webkit-appearance: none; appearance: none; min-height: 36px; }
  input[type=date]::-webkit-date-and-time-value { text-align: left; }
}
.form, .form label, .tabbody { min-width: 0; }
/* Browser-only build: a video or project file being dragged over the page. */
body.dropping::after { content: "Drop to open"; position: fixed; inset: 12px; border: 3px dashed var(--shot); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; background: rgba(0,0,0,.45); color: #fff; pointer-events: none; z-index: 100; }

/* Browser-only build: where the project is saved, recent videos, the projects folder. */
/* Save status: a quiet indicator (a dot and a word) that only becomes a button when
   something needs you. */
.chip { padding: 2px 6px; font-size: 12px; color: var(--muted); white-space: nowrap; flex: none; background: none; border: 0; pointer-events: none; display: inline-flex; align-items: center; gap: 5px; min-height: 0 !important; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #4caf7a; flex: none; }
.chip.busy::before { background: var(--muted); }
.chip.warn { color: var(--danger); border: 1px solid var(--danger); border-radius: 999px; padding: 2px 9px; pointer-events: auto; cursor: pointer; }
.chip.warn::before { background: var(--danger); }
/* Header buttons: an icon and a short word; on narrower screens the icon alone, except Export. */
.withico { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex: none; }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
@media (max-width: 1280px) {
  #btnPick .lbl, #btnSaveProj .lbl, #btnLoadProj .lbl { display: none; }
  #btnPick.withico, #btnSaveProj.withico, #btnLoadProj.withico { padding-left: 9px; padding-right: 9px; }
  .brand .name { display: none; }
}
#savePop { left: 0; right: auto; }
#savePop p { margin: 0 0 8px; }
#savePop .actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.recent { margin-top: 18px; }
.recent h2, .folderrow h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; text-transform: none; }
.recent ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.recent li { display: flex; align-items: center; gap: 6px; }
.recent li .open { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent li .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.recent li .forget { padding: 2px 7px; color: var(--muted); }
.folderrow { margin-top: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.folderrow .hint { flex: 1 1 220px; }
#savePop .err { color: var(--danger); }

/* Touch screens (iPad): the waveform takes every gesture itself (pinch to zoom, drag to pan
   or move a marker, touch and hold to select), buttons are bigger, and a double tap on the
   page doesn't zoom it. */
canvas.wave, canvas.overview { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
@media (pointer: coarse) {
  button, select, input[type=text], input[type=number], input[type=date] { min-height: 36px; }
  button.small { min-height: 30px; }
  .bar { gap: 10px; }
  .iconbtn { width: 30px; height: 30px; min-height: 30px; }
  canvas.wave { height: 240px; }
  canvas.overview { height: 40px; }
  input[type=checkbox] { width: 20px; height: 20px; }
}
@media (pointer: coarse) { #tab-shots tr[data-id] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }
/* Narrow screens (an iPad held upright): the file name and save status get their own row. */
@media (max-width: 900px) {
  .bar { flex-wrap: wrap; row-gap: 6px; }
  .bar .file { flex: 0 0 auto; }
  .bar .fileinfo { order: 10; flex: 1 1 100%; }
  .bar #btnSaveProj { margin-left: auto; }
}
/* On touch screens the transport row already has the string-start buttons. */
@media (pointer: coarse) { #btnPrevString2, #btnNextString2 { display: none; } }
