:root {
  --bg: #121418;
  --panel: #1a1d22;
  --panel2: #22262d;
  --line: #2c313a;
  --text: #d8dce3;
  --muted: #8a93a0;
  --accent: #6cb6ff;
  --orange: #f0932b;
  --brown: #b0703c;
  --green: #5fbf77;
  --grey: #7b828e;
  --red: #e5534b;
  --mark: #8fd3ff;
  --conflict: #ff6b63;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--accent); }
kbd {
  font: 11px ui-monospace, Menlo, Consolas, monospace; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; white-space: nowrap;
}
button, select {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: #3d4450; background: #282d35; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: #24496c; border-color: #2f5f8c; }
button.primary:hover { background: #2a5680; }
button.on { background: #2c3e52; border-color: var(--accent); }
button.danger { border-color: #6b2c2a; color: #ffb3ae; }
input[type=text], input[type=password] {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px;
}

/* episode list */
#episodes { max-width: 680px; margin: 48px auto; padding: 0 16px; }
#episodes h1 { font-size: 20px; font-weight: 600; }
#epList { list-style: none; padding: 0; }
#epList li { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
#epList a { font-weight: 600; text-decoration: none; }
.err { color: #ffb3ae; }

/* app shell */
#app { display: flex; flex-direction: column; height: 100vh; }
#top {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
#top .ep { display: flex; align-items: center; gap: 10px; min-width: 220px; }
#top .home { text-decoration: none; font-size: 18px; color: var(--muted); }
#top h1 { font-size: 15px; margin: 0; font-weight: 600; }
#epMeta { font-size: 12px; }
#counts { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
#counts .c { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; font-size: 12px; color: var(--muted); }
#counts .c.flag { color: var(--orange); border-color: #5a3d1c; }
#counts .c.mine { color: #d9a173; }
#counts .c.keep { color: var(--green); }
#top .actions { display: flex; align-items: center; gap: 6px; }
#saveStatus { font-size: 12px; color: var(--muted); margin-right: 4px; white-space: nowrap; }
#saveStatus.ok { color: var(--green); }
#saveStatus.warn { color: var(--orange); }
#saveStatus.err { color: #ffb3ae; }
#doneBtn.sent { background: #234a33; border-color: #2f6b45; }
#doneBtn.signoff { background: #1f5a4a; border-color: #2f8a6e; }
#prevStrip { padding: 5px 14px; background: #16283a; color: #bfe6ff; font-size: 12px; border-bottom: 1px solid #24425e; border-left: 3px solid var(--mark); }
#agentStatus { padding: 5px 14px; background: #1b2530; color: #a9c9e8; font-size: 12px; border-bottom: 1px solid var(--line); }
#banner { display: flex; align-items: center; gap: 10px; padding: 7px 14px; border-bottom: 1px solid var(--line); }
#banner.warn { background: #3a2a12; color: #ffd49a; }
#banner.info { background: #1b2530; color: #a9c9e8; }
#banner span { flex: 1; }
#banner .x { background: none; border: none; color: inherit; font-size: 16px; padding: 0 4px; }

#layout { flex: 1; display: grid; grid-template-columns: 1fr 360px; min-height: 0; }
#stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 8px 10px; gap: 6px; }
#transport { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#transport .grow { flex: 1; }
#transport .sep { width: 1px; height: 18px; background: var(--line); display: inline-block; }
#playBtn { min-width: 64px; }
.clock { font: 13px ui-monospace, Menlo, Consolas, monospace; padding: 0 4px; }
.clock .sep { color: var(--line); margin: 0 4px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.ctl { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
#audioStatus { color: var(--orange); }
#inout { font: 12px ui-monospace, Menlo, Consolas, monospace; color: #c48cff; }

#overview { width: 100%; height: 40px; display: block; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
#waveWrap { position: relative; flex: 1; min-height: 220px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#wave { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; user-select: none; }
#tip {
  position: absolute; top: 22px; max-width: 460px; pointer-events: none; z-index: 2;
  background: rgba(20,23,28,.95); border: 1px solid var(--accent); border-radius: 6px; padding: 4px 8px;
  font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#tip b { font-family: ui-monospace, Menlo, Consolas, monospace; margin-right: 8px; }
#tip i { color: var(--accent); font-style: normal; font-weight: 700; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.legend .sw { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.sw.cut { background: repeating-linear-gradient(135deg, #8d939c 0 2px, #2a2e35 2px 5px); }
.sw.flag { background: var(--orange); }
.sw.mine { background: var(--brown); }
.sw.keep { border: 1px solid var(--green); }
.sw.mark { width: 10px; background: linear-gradient(90deg, var(--mark) 0 2px, rgba(143,211,255,.25) 2px); }

#inspector { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 92px; }
#inspector .hint { color: var(--muted); padding: 6px 0; }
.it-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.it-head b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; border-radius: 4px; padding: 0 6px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.badge.l-flag { color: var(--orange); border-color: #5a3d1c; }
.badge.l-mine { color: #d9a173; border-color: #5a3a20; }
.badge.l-cut { color: #b3b9c2; }
.badge.l-keep { color: var(--green); border-color: #2f5a3b; }
.it-text { font-style: italic; margin: 2px 0; }
.it-why { color: var(--muted); font-size: 12px; margin: 2px 0; }
.it-times { display: flex; gap: 14px; flex-wrap: wrap; font: 12px ui-monospace, Menlo, Consolas, monospace; margin: 4px 0 6px; }
.it-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
#noteInput { width: 100%; }
.mk-card { border-left: 3px solid var(--mark); padding-left: 8px; margin-bottom: 6px; }
.mk-card:has(.t-conflict) { border-left-color: var(--conflict); }
.mk-card + .it-head { border-top: 1px solid var(--line); padding-top: 6px; }
.badge.mk { color: var(--mark); border-color: #2a4e6a; }
.badge.mk.t-conflict { color: var(--conflict); border-color: #6b2c2a; font-weight: 600; }

#side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--panel); }
#videoWrap { position: relative; background: #000; aspect-ratio: 16 / 9; }
#videoWrap video { width: 100%; height: 100%; display: block; object-fit: contain; }
#videoWrap .novid { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; }
#videoWrap.novideo video { display: none; }
#videoWrap.novideo .novid { display: flex; }
#chips { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
#chips button { font-size: 12px; padding: 3px 9px; border-radius: 12px; }
#chips .n { color: var(--muted); margin-left: 2px; }
#list { flex: 1; overflow-y: auto; }
#list .empty { padding: 14px; }
.row { padding: 6px 10px; border-bottom: 1px solid #23272e; cursor: pointer; border-left: 3px solid transparent; }
.row:hover { background: #20242a; }
.row.sel { background: #1f2d3c; border-left-color: var(--accent); }
.row .rt { display: flex; gap: 8px; align-items: center; font-size: 12px; }
.row .t { font-family: ui-monospace, Menlo, Consolas, monospace; }
.row .et, .row .len { color: var(--muted); font-size: 11px; }
.row .kd { margin-left: auto; color: var(--muted); font-size: 11px; }
.row .dec { font-size: 11px; }
.row .dot { width: 8px; height: 8px; border-radius: 2px; background: var(--grey); flex: none; }
.row.l-flag .dot { background: var(--orange); }
.row.l-flag .dec { color: var(--orange); }
.row.l-mine .dot { background: var(--brown); }
.row.l-keep .dot { background: none; border: 1px solid var(--green); }
.row.l-keep .dec { color: var(--green); }
.row .rl { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row .note { color: #a9c9e8; }
.row.mk .mkt { color: var(--mark); }
.row.mk.t-conflict .mkt { color: var(--conflict); font-weight: 600; }
.row.mk.chk .rl, .row.mk.chk .t { color: var(--muted); }
.row .tick {
  width: 15px; height: 15px; flex: none; border: 1px solid #3f5f78; border-radius: 3px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 11px; line-height: 1; color: var(--mark); cursor: pointer;
}
.row .tick:hover { border-color: var(--mark); }
.row.mk.chk .tick { background: #1e3a4f; border-color: var(--mark); }
.row.mk.t-conflict .tick { border-color: #6b2c2a; }

/* overlays */
#help, #modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 20; }
#help .box, #modal .box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; max-width: 640px; max-height: 86vh; overflow: auto; }
#help h2, #modal h2 { margin: 0 0 10px; font-size: 16px; }
#help td { padding: 3px 12px 3px 0; vertical-align: top; }
#modal .box { max-width: 440px; }
#modal .btns { display: flex; gap: 8px; justify-content: flex-end; }
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 30;
  background: #2a2f37; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
  opacity: 0; pointer-events: none; transition: opacity .15s; max-width: 80vw;
}
#toast.show { opacity: 1; }
#toast.warn { border-color: #6b4a1e; color: #ffd49a; }
#toast.err { border-color: #6b2c2a; color: #ffb3ae; }

/* login */
.login { max-width: 360px; margin: 14vh auto; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.login h1 { font-size: 17px; margin: 0 0 6px; }
.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.login .msg { min-height: 18px; font-size: 12px; }

@media (max-width: 1000px) {
  #layout { grid-template-columns: 1fr; }
  #side { border-left: none; border-top: 1px solid var(--line); max-height: 50vh; }
}
