:root {
  color-scheme: dark;
  --bg: #101216;
  --panel: #1a1e24;
  --panel-2: #20252c;
  --line: #343b45;
  --text: #eef2f7;
  --muted: #98a2b3;
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, .23);
  --yellow: #f6c344;
  --green: #18794e;
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, .16);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 980px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}
button, input, select { font: inherit; }
button, .tool-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #292e36;
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled), .tool-button:hover { background: #343b45; }
button:disabled { opacity: .42; cursor: not-allowed; }
button.primary { background: #245fbe; border-color: #3776d6; }

.topbar {
  height: 74px;
  display: flex;
  align-items: stretch;
  gap: 18px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#252a31, #1d2127);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 290px; }
.brand-mark {
  display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 9px; background: #235cae; font-weight: 900;
}
.brand strong, .brand small { display: block; }
.brand small { max-width: 235px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); margin-top: 3px; }
.toolbar { display: flex; gap: 6px; }
.tool-button {
  min-width: 98px; padding: 6px 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 12px;
}
.tool-button .tool-icon { font-size: 21px; line-height: 1; }
.top-status { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
#versionBadge { padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; }

.app-shell { height: calc(100vh - 74px); padding: 8px; display: grid; grid-template-rows: minmax(300px, 1fr) auto; gap: 8px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.upper-workspace { min-height: 0; display: grid; grid-template-columns: minmax(390px, 42%) 1fr; gap: 8px; }
.panel-title { min-height: 42px; padding: 9px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.panel-title span { color: var(--muted); font-size: 12px; margin-left: 10px; }

.video-pane { min-height: 0; display: grid; grid-template-rows: auto auto minmax(160px, 1fr) auto; }
.video-url-form {
  min-width: 0; padding: 7px 10px; display: grid; grid-template-columns: auto minmax(120px, 1fr) auto auto;
  align-items: center; gap: 6px; border-bottom: 1px solid var(--line); background: #15181d;
}
.video-url-form label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.video-url-form input {
  min-width: 0; height: 31px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: #0e1115; color: var(--text);
}
.video-url-form input:focus { outline: 2px solid #3b82f680; border-color: var(--blue); }
.video-url-form button { height: 31px; padding: 4px 9px; white-space: nowrap; }
.video-frame { min-height: 0; position: relative; display: grid; place-items: center; background: #050607; overflow: hidden; }
.video-frame video { width: 100%; height: 100%; object-fit: contain; }
.youtube-wrap { position: absolute; inset: 0; }
.youtube-wrap iframe { width: 100%; height: 100%; border: 0; }
.empty-state { position: absolute; inset: 0; display: grid; place-items: center; color: #7c8797; }
.video-subtitle { position: absolute; left: 6%; right: 6%; bottom: 7%; text-align: center; font-size: clamp(16px, 2.3vw, 30px); font-weight: 750; line-height: 1.3; text-shadow: 0 2px 4px #000, 0 0 8px #000; pointer-events: none; }
.transport { padding: 9px 12px; background: #15181d; border-top: 1px solid var(--line); }
.time-readout { display: flex; justify-content: center; gap: 8px; color: #d0d5dd; font-variant-numeric: tabular-nums; }
#seekBar { width: 100%; }
.transport-buttons { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 5px; }
.transport-buttons button, .transport-buttons select { height: 31px; padding: 4px 9px; }
.transport-buttons .round { width: 38px; border-radius: 999px; }
.inline-control { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.inline-control input { width: 70px; }

.editor-pane { min-height: 0; display: grid; grid-template-rows: auto auto 1fr; }
.editor-heading { align-items: flex-start; }
.edit-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.edit-actions button { padding: 5px 8px; font-size: 12px; }
.global-issues { padding: 7px 10px; max-height: 76px; overflow: auto; border-bottom: 1px solid #6e3b3b; background: #3a2022; color: #fecaca; font-size: 12px; }
.table-scroll { min-height: 0; overflow: auto; background: #f7f8fa; color: #101828; }
.cue-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 14px; }
.cue-table thead { position: sticky; top: 0; z-index: 3; background: #e7ebf0; }
.cue-table th { height: 32px; border-bottom: 1px solid #c6ccd4; text-align: left; padding: 5px 6px; }
.cue-table th:nth-child(1) { width: 48px; }
.cue-table th:nth-child(2), .cue-table th:nth-child(3) { width: 145px; }
.cue-table th:nth-child(5) { width: 94px; }
.cue-table th:nth-child(6) { width: 45px; }
.cue-row { border-left: 5px solid var(--yellow); border-bottom: 1px solid #d9dde3; background: #fff; }
.cue-row:hover { background: #f0f5ff; }
.cue-row.selected { background: #e4efff; box-shadow: inset 0 0 0 2px #6aa1f4; }
.cue-row.confirmed { border-left-color: var(--green); }
.cue-row.invalid { border-left-color: var(--red); background: #fff0f0; }
.cue-row td { padding: 5px; vertical-align: middle; }
.cue-row input { width: 100%; min-width: 0; height: 34px; border: 1px solid #c4cad3; border-radius: 5px; background: #fff; color: #101828; padding: 5px 7px; }
.cue-row input:focus { outline: 2px solid #72a8f6; border-color: #3b82f6; }
.cue-row.invalid input { border-color: #e77b7b; }
.cue-number { font-weight: 800; font-variant-numeric: tabular-nums; }
.cue-status { display: inline-block; padding: 3px 7px; border-radius: 999px; background: #fff0c2; color: #7a4d00; font-size: 11px; }
.cue-row.confirmed .cue-status { background: #d5f5e5; color: #0c6841; }
.cue-row.invalid .cue-status { background: #ffd5d5; color: #9b1c1c; }
.row-play { width: 31px; height: 29px; }
.table-empty { padding: 60px 20px !important; text-align: center; color: #667085; }

.timeline-panel { height: 364px; min-height: 250px; max-height: 600px; display: grid; grid-template-rows: auto 1fr 8px auto; }
.timeline-toolbar { min-height: 49px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 11px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.timeline-toolbar > div:first-child span { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.wave-controls { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.wave-controls label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; }
.wave-controls input[type=range] { width: 94px; }
.wave-controls output { min-width: 53px; color: #d0d5dd; font-variant-numeric: tabular-nums; }
.wave-controls button { width: 29px; height: 28px; }
.check-control input { width: auto !important; }
.wave-scroll { min-height: 0; overflow-x: auto; overflow-y: hidden; position: relative; background: #11151a; outline: none; }
.wave-content { height: 100%; min-width: 100%; position: relative; }
#waveCanvas { position: absolute; top: 0; left: 0; cursor: crosshair; touch-action: none; }
.wave-cue-text-editor {
  position: absolute; z-index: 6; height: 29px; min-width: 120px; padding: 4px 7px;
  border: 2px solid #7db0ff; border-radius: 5px; background: #f8fbff; color: #101828;
  font-size: 12px; box-shadow: 0 2px 10px #0008;
}
.timeline-resize { cursor: ns-resize; background: linear-gradient(90deg, transparent, #56606d 45%, #56606d 55%, transparent); }
.statusbar { min-height: 29px; padding: 5px 11px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; background: #171a20; border-top: 1px solid var(--line); }
.statusbar > :last-child { text-align: right; }
.legend { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; margin-left: 6px; }
.legend i.review { background: var(--yellow); }.legend i.confirmed { background: var(--green); }.legend i.invalid { background: var(--red); }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 30; max-width: 470px; padding: 11px 14px; border: 1px solid #536071; border-radius: 8px; background: #242a33; box-shadow: 0 8px 28px #0008; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s; }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: #bd4242; background: #3c2023; color: #fecaca; }

@media (max-height: 760px) {
  .topbar { height: 64px; }
  .app-shell { height: calc(100vh - 64px); }
  .timeline-panel { height: 300px; }
  .tool-button { min-width: 86px; }
}
