/* CoverBooth: light, social-app look. White cards on soft grey, hairline borders, a sunset gradient accent. */
:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --line: #dbdbdb;
  --line-soft: #efefef;
  --field: #fafafa;
  --field-line: #dbdbdb;
  --text: #262626;
  --muted: #737373;
  --soft: #efefef;
  --soft-hover: #e0e0e0;
  --primary: #0095f6;
  --primary-hover: #1877f2;
  --rec: #ff3040;
  --ok: #34c759;
  --warn: #f5a623;
  --error: #ed4956;
  --grad: linear-gradient(45deg, #feda75 0%, #fa7e1e 25%, #d62976 50%, #962fbf 75%, #4f5bd5 100%);
  --radius: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
}
p { margin: 0; }
h2 { margin: 0; font-size: 13px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }

/* ---- header ---- */
header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -0.03em; }
.brand h1 span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.header-actions { display: flex; gap: 4px; }
.header-actions button { font-weight: 600; }

/* ---- controls ---- */
button { font: inherit; font-weight: 600; color: var(--text); background: var(--soft); border: 1px solid transparent; border-radius: 8px; padding: 7px 14px; cursor: pointer; transition: background .12s; }
button:hover { background: var(--soft-hover); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-hover); }
button.small { padding: 5px 12px; font-size: 13px; }
button.ghost { background: transparent; color: var(--text); }
button.ghost:hover { background: var(--soft); }
button.link { background: none; border: 0; padding: 0; color: var(--primary); font-size: inherit; font-weight: 600; }
button.danger, #discardBtn.danger { color: var(--error); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--rec); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }

label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text); font-weight: 400; }
label.slider { grid-template-columns: 52px 1fr 60px; align-items: center; font-weight: 600; }
output { font-variant-numeric: tabular-nums; text-align: right; color: var(--text); font-size: 12px; }
select, input[type=text], input[type=url], input[type=number], textarea {
  font: inherit; font-size: 13px; color: var(--text); background: var(--field); border: 1px solid var(--field-line); border-radius: 8px; padding: 7px 9px; width: 100%;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: #a8a8a8; }
input[type=range] { width: 100%; accent-color: var(--text); }
input[type=checkbox] { accent-color: var(--primary); }
input[type=file] { color: var(--muted); max-width: 100%; font-size: 12px; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; border: 0; border-radius: 8px; background: var(--soft); color: var(--text); padding: 5px 12px; margin-right: 8px; cursor: pointer; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.error { color: var(--error); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
code { font-family: ui-monospace, Menlo, monospace; background: var(--soft); padding: 0 4px; border-radius: 4px; }

/* segmented control */
.seg.pills { display: inline-flex; background: var(--soft); border-radius: 9px; padding: 2px; gap: 2px; }
.seg.pills label { display: block; cursor: pointer; }
.seg.pills input { position: absolute; opacity: 0; pointer-events: none; }
.seg.pills span { display: block; padding: 4px 11px; border-radius: 7px; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg.pills input:checked + span { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.pills input:focus-visible + span { outline: 2px solid var(--primary); }
.seg.pills input:disabled + span { opacity: .5; }

/* level meters */
.meter { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.meter > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--ok) 0 70%, #ffcc00 70% 88%, var(--rec) 88%); transition: width .05s linear; }

/* ---- home ---- */
.gate { flex: 1; overflow: auto; padding: 28px 24px 40px; }
.home-empty { max-width: 420px; margin: 8vh auto 0; display: grid; gap: 14px; justify-items: center; text-align: center; }
.home-empty svg { width: 72px; height: 72px; }
.home-empty h2 { font-size: 24px; letter-spacing: -0.02em; }
.home-empty p { color: var(--muted); }
.home-full { max-width: 1200px; margin: 0 auto; display: grid; gap: 18px; }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.home-head h2 { font-size: 22px; letter-spacing: -0.02em; }
.home-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
button.big { padding: 11px 22px; font-size: 15px; border-radius: 10px; }
#gateError { text-align: center; margin-top: 16px; }
.brand { cursor: default; }
.brand.clickable { cursor: pointer; }

/* ---- layout: one screen. Video top-left, controls on the right, track along the bottom ---- */
main {
  flex: 1; min-height: 0; overflow: hidden;
  padding: 12px 16px 14px; display: grid; gap: 12px;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "stage side" "seq side";
}
.stage { grid-area: stage; min-height: 0; min-width: 0; display: flex; }
.side { grid-area: side; min-height: 0; overflow-y: auto; display: grid; gap: 12px; align-content: start; }
.seq { grid-area: seq; }
@media (max-width: 860px) { main { grid-template-columns: minmax(0, 1fr) 270px; } }

/* ---- video ---- */
.preview-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; background: #111; border-radius: 18px; overflow: hidden; }
.preview-wrap::after { content: ''; position: absolute; inset: 0; border-radius: 18px; pointer-events: none; border: 3px solid transparent; }
.preview-wrap.recording::after { border-color: var(--rec); }
#preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
#preview.mirrored { transform: scaleX(-1); }
.yt-pane { position: absolute; right: 12px; bottom: 12px; width: clamp(220px, 34%, 420px); max-height: calc(100% - 24px); aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; box-shadow: 0 8px 28px rgba(0,0,0,.35); border: 2px solid #fff; z-index: 1; }
.yt-pane iframe, .yt-pane > div { width: 100%; height: 100%; border: 0; display: block; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: min(160px, 30vh); font-weight: 800; color: #fff; background: rgba(0,0,0,.35); z-index: 2; text-shadow: 0 4px 24px rgba(0,0,0,.3); }
.rec-badge { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.55); color: #fff; padding: 4px 12px; border-radius: 999px; font-weight: 600; font-variant-numeric: tabular-nums; z-index: 2; backdrop-filter: blur(6px); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.paused-tag { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--warn); }
.rec-badge.paused .dot { background: var(--warn); animation: none; }

/* ---- cards in the right pane ---- */
.strip { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px; min-width: 0; }
.strip-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.strip-row h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.strip-row.levels { display: grid; gap: 4px; }
.url-row, .file-row { display: flex; gap: 6px; flex-basis: 100%; min-width: 0; align-items: center; }
.url-row input { flex: 1; min-width: 0; }
.yt-info { display: flex; gap: 8px; align-items: flex-start; min-width: 0; }
.yt-info span:last-child { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sync-line { gap: 8px; }
#monLatency { flex-basis: 100%; }

/* ---- sequencer ---- */
.seq { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
.seq-head { display: flex; gap: 16px; align-items: center; flex-wrap: nowrap; }
.seq-head .label { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.chord-now { font-size: 32px; font-weight: 800; line-height: 1; padding: 8px 16px; border-radius: 12px; background: var(--soft); min-width: 96px; text-align: center; letter-spacing: -0.02em; transition: background .15s, color .15s; }
.chord-next { font-size: 20px; font-weight: 700; line-height: 1.2; color: var(--muted); }
.bar-beat { font-size: 20px; font-weight: 700; line-height: 1.2; }
.beat-dots { display: flex; gap: 6px; margin-top: 6px; }
.beat-dots span { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.beat-dots span.on { background: var(--text); }
.beat-dots span.on.down { background: var(--rec); }
.seq-info { flex: 1; min-width: 0; display: grid; gap: 2px; align-self: center; }
.seq-info span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.seq-info span:empty { display: none; }
.seq-transport { flex: none; margin-left: auto; display: flex; gap: 8px; align-items: center; }
.seq-status { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
@media (max-width: 1150px) { .seq-head { flex-wrap: wrap; row-gap: 6px; } .seq-info { order: 9; flex-basis: 100%; } }

.listen { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 999px; background: var(--text); color: #fff; }
.listen:hover { background: #000; }
.listen .icon { font-size: 11px; width: 12px; text-align: center; }
.listen.playing { background: var(--soft); color: var(--text); }
.rewind { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 13px; }
.record { display: inline-flex; align-items: center; gap: 8px; padding: 8px 18px 8px 10px; border-radius: 999px; background: #fff; border: 1px solid var(--line); white-space: nowrap; }
.record:hover { background: var(--bg); }
.record .ring { width: 20px; height: 20px; border-radius: 50%; background: var(--grad); box-shadow: inset 0 0 0 3px #fff, 0 0 0 1.5px #d62976; transition: border-radius .15s; }
.record.active { border-color: var(--rec); }
.record.recording .ring { width: 16px; height: 16px; border-radius: 2px; background: transparent; box-shadow: none; border-left: 5px solid var(--text); border-right: 5px solid var(--text); }
.record.paused .ring { animation: blink 1s infinite; }
.stop { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px 8px 12px; border-radius: 999px; }
.stop .sq { width: 13px; height: 13px; border-radius: 3px; background: var(--text); }

.timeline-wrap { position: relative; flex: 1; min-height: 90px; }
.timeline-wrap #timeline { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 10px; cursor: pointer; }
#overview { flex: none; width: 100%; height: 34px; display: block; border-radius: 8px; cursor: pointer; }

.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: #d62976; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* short windows (small laptops, or Chrome's sharing bar) */
@media (max-height: 760px) {
  header { padding: 6px 16px; }
  .chord-now { font-size: 24px; padding: 6px 12px; min-width: 72px; }
  .chord-next, .bar-beat { font-size: 17px; }
  .seq-head .label { margin-bottom: 2px; }
  #overview { height: 24px; }
  .strip { padding: 8px 12px; gap: 5px; }
}

/* ---- drawers ---- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 11; overflow-y: auto; padding: 0 16px 24px; display: grid; gap: 14px; align-content: start; box-shadow: -12px 0 40px rgba(0,0,0,.12); }
.drawer-head { position: sticky; top: 0; background: var(--panel); display: flex; align-items: center; justify-content: space-between; padding: 14px 0 12px; border-bottom: 1px solid var(--line-soft); z-index: 1; }
.drawer-head h2 { font-size: 16px; }
.drawer .close { font-size: 16px; padding: 4px 10px; }
.drawer .nudges { display: flex; gap: 4px; flex-wrap: wrap; }
.drawer .nudges button { padding: 5px 9px; font-size: 12px; }
fieldset { border: 1px solid var(--line-soft); background: var(--panel); border-radius: 12px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; min-width: 0; }
legend { padding: 0 6px; font-weight: 700; }
textarea { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }

/* ---- my tracks ---- */
#takeList { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.take { display: grid; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.take video { width: 100%; border-radius: 10px; background: #000; }
.take-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inst-badge { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--soft); color: var(--text); }
.remixed-tag { font-size: 11px; color: var(--muted); }
.take .actions { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.take .actions > :last-child { margin-left: auto; }

/* Files menu */
details.menu { position: relative; }
details.menu summary { list-style: none; cursor: pointer; font-weight: 600; font-size: 13px; padding: 5px 12px; border-radius: 8px; background: var(--soft); user-select: none; }
details.menu summary::-webkit-details-marker { display: none; }
details.menu summary::after { content: ' ▾'; font-size: 10px; color: var(--muted); }
details.menu[open] summary { background: var(--soft-hover); }
.menu-list { position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; min-width: 240px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 6px; display: grid; }
.menu-list a { display: grid; gap: 1px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.menu-list a:hover { background: var(--soft); }
.menu-list a span { font-weight: 600; font-size: 13px; }
.menu-list a small { color: var(--muted); font-size: 11px; }

/* ---- dialogs ---- */
dialog.confirm { background: var(--panel); color: var(--text); border: 0; border-radius: 18px; padding: 22px 24px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 24px 64px rgba(0,0,0,.18); }
dialog.confirm::backdrop { background: rgba(0,0,0,.4); }
dialog.confirm h2 { font-size: 18px; margin-bottom: 8px; }
dialog.confirm form, .calib { display: grid; gap: 10px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
dialog.save { width: min(520px, calc(100vw - 32px)); }
#savePreview, #remixPreview { width: 100%; max-height: 230px; border-radius: 12px; background: #000; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { display: block; cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: block; padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 13px; font-weight: 600; }
.chips input:checked + span { background: var(--text); border-color: var(--text); color: #fff; }
.chips input:focus-visible + span { outline: 2px solid var(--primary); }
.sync-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sync-row .field-label { flex: 1; }
#syncOut, #mixShiftOut, #mixAvOut { min-width: 64px; text-align: center; font-size: 13px; font-weight: 600; }
label.slider.mix { grid-template-columns: 104px 1fr 60px; font-size: 13px; color: var(--text); }

/* sync check */
.calib ol { margin: 0; padding-left: 18px; display: grid; gap: 2px; }
.calib-dots { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 6px 0; }
.calib-dots span { width: 16px; height: 16px; border-radius: 50%; background: var(--line); }
.calib-dots span.count { background: #fff; border: 1.5px dashed #b5b5b5; }
.calib-dots span.on { background: var(--grad); border-color: transparent; }
.calib-cue { text-align: center; font-weight: 700; min-height: 20px; }
.calib-listen { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.calib-listen .spacer { flex: 1; }
#calibShift { min-width: 56px; text-align: center; font-weight: 600; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #262626; color: #fff; border-radius: 12px; padding: 10px 10px 10px 16px; display: flex; gap: 12px; align-items: center; z-index: 12; box-shadow: 0 8px 28px rgba(0,0,0,.25); max-width: calc(100vw - 32px); font-weight: 600; }
.toast button.primary { background: #fff; color: var(--text); }

.minus-status { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.minus-status::before { content: ''; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); border-top-color: #d62976; animation: spin .8s linear infinite; flex: none; }
.minus-status.error { color: var(--error); }
.minus-status.error::before { display: none; }

/* zoom-out pill, floating top-left on the video */
.zoom-pill { position: absolute; top: 12px; left: 12px; z-index: 3; display: flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 999px; background: rgba(255,255,255,.88); backdrop-filter: blur(8px); box-shadow: 0 2px 10px rgba(0,0,0,.18); color: var(--text); }
.zoom-pill svg { width: 15px; height: 15px; flex: none; }
.zoom-pill select { width: auto; border: 0; background: transparent; padding: 3px 6px; font-weight: 700; font-size: 13px; cursor: pointer; }
.zoom-pill select:disabled { cursor: default; opacity: .5; }

/* ---- track rows: name, details and menu; a player opens only for the track you press play on ---- */
.track-row { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "play main" ". actions" "player player"; column-gap: 12px; row-gap: 6px; align-items: center; padding: 12px; }
.track-row .play-btn { grid-area: play; width: 40px; height: 40px; padding: 0; border-radius: 50%; background: var(--text); color: #fff; display: grid; place-items: center; font-size: 13px; }
.track-row .play-btn span { margin-left: 2px; }
.track-row.playing .play-btn { background: var(--grad); }
.track-row.playing .play-btn span { margin: 0; }
.track-row.playing .play-btn span::before { content: '■'; }
.track-row.playing .play-btn span { font-size: 0; }
.track-row.playing .play-btn span::before { font-size: 12px; }
.track-row .tr-main { grid-area: main; min-width: 0; display: grid; gap: 2px; }
.track-row .take-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.track-row .actions { grid-area: actions; margin-top: 0; }
.track-row .player-slot { grid-area: player; }
.track-row .player-slot:empty { display: none; }
.track-row .player-slot video { width: 100%; max-height: 60vh; border-radius: 10px; background: #000; display: block; }
/* home: a single column list, actions on the right */
.home-grid { grid-template-columns: 1fr; max-width: 860px; gap: 10px; }
.home-full { max-width: 860px; }
#homeGrid .track-row { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "play main actions" "player player player"; }

.calib-h { font-size: 14px; margin: 4px 0 0; }
.calib-sep { border: 0; border-top: 1px solid var(--line-soft); margin: 6px 0; width: 100%; }
/* picture check: full-screen black that flashes white */
dialog.flash { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; color: #666; display: grid; place-items: center; }
dialog.flash:not([open]) { display: none; }
dialog.flash::backdrop { background: #000; }
dialog.flash.white { background: #fff; }
dialog.flash p { font-size: 18px; font-weight: 600; }
