:root {
  --bg: #0a0c10;
  --panel: #11141a;
  --panel-2: #171b23;
  --panel-3: #1e2330;
  --line: #232935;
  --line-2: #2f3646;
  --text: #e8eaf0;
  --muted: #8a92a6;
  --faint: #5d6578;
  --accent: #ff7a1a;
  --keep: #34c47c;
  --cut: #e5484d;
  --undecided: #5b6273;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

button, a.btn {
  font: inherit;
  color: inherit;
  background: var(--panel-3);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled), a.btn:hover { background: #262c3b; border-color: #3b4357; }
a.btn { text-decoration: none; }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1c0e02; font-weight: 650; }
button.primary:hover { background: #ff8c3a; border-color: #ff8c3a; }
button.danger { color: #ff9497; border-color: #552a2e; background: #241416; }
button.danger:hover { background: #3a1a1d !important; border-color: #7a3036 !important; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.icon-btn { padding: 5px 8px; min-width: 30px; }
button svg { width: 16px; height: 16px; fill: currentColor; }

kbd {
  font: 600 10px/1 var(--mono);
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  color: var(--muted);
}
code { font: 12px var(--mono); background: rgba(255, 255, 255, .06); padding: 1px 5px; border-radius: 4px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 122, 26, .16); }
input:disabled { opacity: .45; }
textarea { resize: vertical; min-height: 52px; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[type="range"] { width: 90px; padding: 0; accent-color: var(--accent); background: none; border: 0; }
::placeholder { color: var(--faint); }

.grow { flex: 1; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  flex: none;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #fff 0 12%, var(--accent) 13% 34%, transparent 35% 52%, var(--accent) 53% 62%, transparent 63%);
  box-shadow: 0 0 14px rgba(255, 122, 26, .45);
}
.brand-name { font-weight: 800; letter-spacing: .14em; font-size: 13px; }
.brand-sub { color: var(--muted); font-size: 11px; }
.top-stats { display: flex; gap: 22px; }
.top-stat { display: flex; flex-direction: column; }
.top-stat span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.top-stat b { font: 600 15px var(--mono); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.save-state { font-size: 11px; color: var(--muted); }
.save-state.saved::before { content: "●"; color: var(--keep); margin-right: 5px; }
.save-state.dirty::before, .save-state.saving::before { content: "●"; color: #e0b33a; margin-right: 5px; }
.save-state.error, .save-state.conflict { color: #ff9497; }
.save-state.conflict button { margin-left: 6px; }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr) 380px;
}

/* ---------- episode list ---------- */
.episodes {
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ep-item {
  display: block;
  text-align: left;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  white-space: normal;
}
.ep-item:hover { background: var(--panel-2) !important; border-color: var(--line) !important; }
.ep-item.active { background: var(--panel-3) !important; border-color: rgba(255, 122, 26, .55) !important; }
.ep-row { display: flex; align-items: center; justify-content: space-between; }
.ep-num { font: 700 13px var(--mono); color: var(--accent); }
.ep-status { font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 600; }
.ep-status.st-todo { color: var(--faint); }
.ep-status.st-progress { color: #e0b33a; background: rgba(224, 179, 58, .12); }
.ep-status.st-done { color: var(--keep); background: rgba(52, 196, 124, .14); }
.ep-title { font-size: 12px; color: var(--text); margin: 2px 0 6px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ep-bar { display: flex; height: 5px; border-radius: 3px; overflow: hidden; gap: 1px; background: var(--bg); }
.ep-bar i { display: block; min-width: 1px; }
.ep-bar .d-keep { background: var(--keep); }
.ep-bar .d-cut { background: var(--cut); opacity: .75; }
.ep-bar .d-none { background: #2b3140; }
.ep-meta { font-size: 11px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.player-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 200px;
  background: #000;
  display: flex;
}
.player-wrap video { width: 100%; height: 100%; object-fit: contain; display: block; cursor: pointer; }
.player-wrap:fullscreen { background: #000; }
.rec-stack { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.rec-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px;
  background: rgba(10, 12, 16, .82);
  border: 1px solid var(--c);
  border-radius: 20px;
  font-size: 12px; font-weight: 700; letter-spacing: .04em;
  color: var(--c);
  backdrop-filter: blur(6px);
}
.rec-pill i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); animation: blink 1s infinite; }
.rec-pill b { font: 600 12px var(--mono); color: #fff; }
.rec-pill span { color: var(--muted); font-weight: 500; letter-spacing: 0; }
@keyframes blink { 50% { opacity: .25; } }
.player-msg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; background: rgba(0, 0, 0, .78); color: var(--text); font-size: 14px; line-height: 1.6;
}

.transport {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.t-group, .q-group { display: flex; gap: 4px; align-items: center; }
.play-btn { width: 40px; height: 32px; background: var(--accent) !important; border-color: var(--accent) !important; color: #1c0e02; }
.play-btn svg { width: 18px; height: 18px; }
.tc-display { font: 600 16px var(--mono); font-variant-numeric: tabular-nums; }
.tc-display span { color: var(--faint); font-size: 12px; margin-left: 6px; }
.section-pill { font-size: 11px; padding: 3px 9px; border-radius: 12px; background: var(--panel-3); color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-pill b { letter-spacing: .05em; }
.section-pill.dec-keep { background: rgba(52, 196, 124, .14); color: #8fe3b8; }
.section-pill.dec-keep b { color: var(--keep); }
.section-pill.dec-cut { background: rgba(229, 72, 77, .14); color: #f3a3a5; }
.section-pill.dec-cut b { color: var(--cut); }
.show-tc { font-size: 11px; color: var(--muted); }
.show-tc b { font: 600 12px var(--mono); color: var(--text); }
.t-speed { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.t-speed select { width: auto; padding: 3px 6px; }

.timeline-wrap { flex: none; position: relative; background: var(--panel); border-top: 1px solid var(--line); padding: 6px 0 2px; }
#timeline { display: block; width: 100%; touch-action: none; }
.thumb-preview {
  position: absolute; bottom: calc(100% - 4px);
  background: #000; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden;
  pointer-events: none; z-index: 5; box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.tp-img { width: 160px; height: 90px; background-repeat: no-repeat; }
.thumb-preview span { display: block; text-align: center; font: 600 11px var(--mono); padding: 2px 6px; background: var(--panel-2); }

.quickbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 12px 10px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.q-keep { color: #8fe3b8; }
.q-cut { color: #f3a3a5; }
.cue-btn i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.cue-btn.rec { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--panel-3)) !important; color: #fff; }
.cue-btn.rec i { animation: blink 1s infinite; }
.q-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }

/* ---------- side panel ---------- */
.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
}
.inspector { flex: 0 1 auto; max-height: 64%; overflow-y: auto; padding: 14px; border-bottom: 1px solid var(--line); }
.insp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.insp-head b { font-size: 15px; }
.type-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); flex: none; }
.type-select { width: auto; font-weight: 650; font-size: 14px; padding: 4px 8px; }
.tc-grid { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 6px; align-items: end; margin-bottom: 8px; }
.tc-grid label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; display: flex; flex-direction: column; gap: 3px; }
.tc { font: 600 13px var(--mono) !important; }
button.small { padding: 6px 7px; font-size: 11px; }
.meta-line { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.meta-line b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.warn { font-size: 12px; color: #ffb0b2; background: rgba(229, 72, 77, .12); border: 1px solid rgba(229, 72, 77, .35); padding: 6px 9px; border-radius: 6px; margin-bottom: 10px; }
.fields { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 3px 9px; font-size: 12px; border-radius: 14px; }
.chip.on, .chip.on:hover:not(:disabled) { background: color-mix(in srgb, var(--c, var(--accent)) 24%, var(--panel-3)); border-color: var(--c, var(--accent)); color: #fff; }
.scale { display: flex; }
.scale button { flex: 1; border-radius: 0; margin-left: -1px; padding: 4px 4px; font-size: 12px; }
.scale button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.scale button:last-child { border-radius: 0 6px 6px 0; }
.scale button.on, .scale button.on:hover:not(:disabled) { background: color-mix(in srgb, var(--c, var(--accent)) 30%, var(--panel-3)); border-color: var(--c, var(--accent)); color: #fff; position: relative; }
.btn-row { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
button.on { border-color: var(--accent); color: #fff; }
.hint { font-size: 11px; color: var(--faint); margin-top: 10px; }
.sub-title { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 6px; }

.decision { display: flex; margin-bottom: 12px; }
.decision button { flex: 1; border-radius: 0; margin-left: -1px; padding: 8px; font-weight: 600; }
.decision button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.decision button:last-child { border-radius: 0 6px 6px 0; }
.decision .dec-keep.on { background: rgba(52, 196, 124, .22); border-color: var(--keep); color: #b6f0d1; position: relative; }
.decision .dec-cut.on { background: rgba(229, 72, 77, .22); border-color: var(--cut); color: #ffc4c6; position: relative; }
.decision .dec-none.on { background: #2a303d; border-color: #687088; position: relative; }

.ep-head { margin-bottom: 12px; }
.ep-big { font: 700 18px var(--mono); color: var(--accent); }
.ep-name { font-size: 15px; font-weight: 600; }
.status-toggle { display: flex; margin-bottom: 12px; }
.status-toggle button { flex: 1; border-radius: 0; margin-left: -1px; font-size: 12px; }
.status-toggle button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.status-toggle button:last-child { border-radius: 0 6px 6px 0; }
.status-toggle button.on.st-todo { background: #2a303d; border-color: #687088; position: relative; }
.status-toggle button.on.st-progress { background: rgba(224, 179, 58, .18); border-color: #e0b33a; color: #f5dc9a; position: relative; }
.status-toggle button.on.st-done { background: rgba(52, 196, 124, .2); border-color: var(--keep); color: #b6f0d1; position: relative; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.stat-grid div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; }
.stat-grid span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-grid b { font: 600 15px var(--mono); }
.c-keep { color: var(--keep); }
.c-cut { color: var(--cut); }
.type-counts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.type-counts span { display: inline-flex; align-items: center; gap: 5px; }
.type-counts i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.type-counts b { color: var(--text); }
.howto ol { margin: 0 0 10px; padding-left: 18px; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; gap: 5px; }

/* ---------- cue list ---------- */
.cue-list { flex: 1 1 0; min-height: 140px; display: flex; flex-direction: column; }
.cue-list-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px 8px; }
.filters { display: flex; gap: 3px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.filter { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 10px; border-color: var(--c); color: var(--c); background: transparent; }
.filter.off { opacity: .35; border-color: var(--line-2); }
.cue-rows { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.cue-row {
  display: grid;
  grid-template-columns: 48px auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}
.cue-row:hover { background: var(--panel-2); }
.cue-row.selected { background: var(--panel-3); border-color: var(--c); }
.cue-chip { font-size: 9px; font-weight: 800; letter-spacing: .05em; text-align: center; padding: 2px 0; border-radius: 4px; background: var(--c); color: #0b0d12; }
.cue-tc { font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.cue-label { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cue-label em { color: var(--faint); }
.cue-warn { color: var(--cut); font-size: 12px; }
.empty { color: var(--faint); font-size: 12px; padding: 14px 8px; text-align: center; }

/* ---------- key moment selector ---------- */
.star { color: #f2ead3; font-size: 12px; line-height: 1; }
.moments-btn b { font: 600 12px var(--mono); color: #f2ead3; }
.popover {
  position: fixed; top: 58px; right: 16px; z-index: 40;
  width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 640px);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.mo-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.mo-head b { font-size: 14px; }
.mo-filter { display: flex; margin-left: auto; }
.mo-filter button { border-radius: 0; margin-left: -1px; font-size: 11px; padding: 4px 8px; }
.mo-filter button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.mo-filter button:last-child { border-radius: 0 6px 6px 0; }
.mo-filter button.on { background: rgba(242, 234, 211, .14); border-color: #f2ead3; position: relative; }
.mo-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.mo-ep { display: flex; gap: 8px; align-items: baseline; font-size: 11px; color: var(--muted); padding: 10px 6px 4px; text-transform: uppercase; letter-spacing: .05em; }
.mo-ep span { font: 700 12px var(--mono); color: var(--accent); }
.mo-ep.current { color: var(--text); }
.mo-row {
  display: grid; grid-template-columns: 38px auto 1fr auto; gap: 8px; align-items: center;
  width: 100%; text-align: left; white-space: normal;
  background: transparent; border-color: transparent; padding: 6px;
}
.mo-row.active { background: var(--panel-3); border-color: #f2ead3; }
.mo-stars { color: #f2ead3; font-size: 11px; letter-spacing: -1px; }
.mo-stars.unset { color: var(--faint); }
.mo-tc { font: 11px var(--mono); color: var(--muted); }
.mo-name { font-size: 12px; display: flex; flex-direction: column; min-width: 0; }
.mo-name small { color: var(--muted); font-size: 11px; }
.mo-name em { color: var(--faint); }
.mo-foot { font-size: 11px; color: var(--faint); padding: 8px 14px 10px; border-top: 1px solid var(--line); }

/* ---------- modals & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 18px 20px 20px; width: min(860px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.modal-card.narrow { width: min(520px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 15px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.help-grid h4 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.help-grid dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0; font-size: 12px; }
.help-grid dt { white-space: nowrap; color: var(--muted); }
.help-grid dd { margin: 0; }
.export-opts { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.export-opts button { flex-direction: column; align-items: flex-start; text-align: left; padding: 10px 12px; white-space: normal; gap: 2px; }
.export-opts span { font-size: 12px; color: var(--muted); }
.export-result { font-size: 12px; color: var(--muted); word-break: break-all; }
.export-result a { color: var(--accent); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #252b39; border: 1px solid var(--line-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font-size: 12px; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; z-index: 60; box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- narrower windows ---------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr) 330px; }
  .top-stats { gap: 14px; }
}
@media (max-width: 1080px) {
  .layout { grid-template-columns: 74px minmax(0, 1fr) 310px; }
  .ep-title, .ep-meta { display: none; }
  .ep-item { padding: 7px 6px; }
  .ep-row { flex-direction: column; gap: 3px; }
  .ep-bar { margin-top: 4px; }
  .brand-sub, .top-stat span { display: none; }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .topbar { gap: 12px; padding: 0 12px; }
  .top-stats { display: none; }
  .layout { display: flex; flex-direction: column; flex: none; }
  .episodes { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .ep-item { min-width: 64px; width: auto; }
  .player-wrap { min-height: 0; aspect-ratio: 16 / 9; flex: none; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .inspector { max-height: none; }
  .cue-list { min-height: 220px; }
}
