:root {
  --bg: #0c0f14;
  --surface: #131822;
  --surface-2: #1a2130;
  --border: #263043;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #58a6ff;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --purple: #bc8cff;
  --cyan: #39c5cf;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.badge {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.badge-readonly {
  color: var(--cyan);
  border-color: rgba(57, 197, 207, 0.4);
  background: rgba(57, 197, 207, 0.1);
}

.live-status {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}

.dot.live {
  background: var(--green);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.65);
}

.dot.error {
  background: var(--red);
}

.nav-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.nav-switch-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.nav-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  padding: 0 4px;
}

.episode-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.proj-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 2px 6px 6px;
  display: flex;
  justify-content: space-between;
}

.ep-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 4px;
}

.ep-item:hover {
  background: var(--surface-2);
}

.ep-item.active {
  background: rgba(88, 166, 255, 0.12);
  border-color: rgba(88, 166, 255, 0.45);
}

.ep-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.ep-item-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ep-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

/* Main */
.main {
  padding: 20px 24px 36px;
  overflow-x: hidden;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1520px;
}

.hidden {
  display: none !important;
}

.ep-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.ep-header h2 {
  margin: 6px 0 4px;
  font-size: 20px;
}

.ep-idea {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.ep-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mono-pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
}

.status-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.status-pill.done {
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
}

.status-pill.running {
  background: rgba(210, 153, 34, 0.18);
  color: var(--amber);
}

.status-pill.in_progress {
  background: rgba(88, 166, 255, 0.15);
  color: var(--accent);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.stats-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 92px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
}

.stat-val {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--mono);
}

/* Panels */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: stretch;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-header h3 {
  margin: 0;
  font-size: 14px;
  display: inline;
  margin-right: 8px;
}

.panel-sub {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.panel-body {
  padding: 14px 16px;
  overflow-y: auto;
}

.two-col .panel-body {
  height: 520px;
}

.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.pill-btn:hover {
  color: var(--text);
}

.pill-btn.active {
  background: rgba(88, 166, 255, 0.16);
  border-color: rgba(88, 166, 255, 0.55);
  color: var(--accent);
}

/* Decision cards */
.decisions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.decision-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.decision-card[data-phase="script"] { border-left-color: var(--cyan); }
.decision-card[data-phase="storyboard"] { border-left-color: var(--accent); }
.decision-card[data-phase="keyframe"] { border-left-color: var(--purple); }
.decision-card[data-phase="video"] { border-left-color: var(--green); }
.decision-card[data-phase="retry"] { border-left-color: var(--amber); }
.decision-card[data-phase="edit"] { border-left-color: #ff7b72; }
.decision-card[data-phase="audio"] { border-left-color: #79c0ff; }
.decision-card[data-phase="review"] { border-left-color: #d2a8ff; }

.decision-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.decision-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.phase-tag {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
}

.shot-tag {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(188, 140, 255, 0.14);
  color: var(--purple);
}

.outcome-tag {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(63, 185, 80, 0.14);
  color: var(--green);
}

.outcome-tag.rerolled,
.outcome-tag.reverted {
  background: rgba(210, 153, 34, 0.16);
  color: var(--amber);
}

.decision-title {
  font-weight: 700;
  font-size: 14px;
}

.decision-choice {
  font-size: 13px;
  color: #cfe4ff;
  background: rgba(88, 166, 255, 0.08);
  padding: 6px 9px;
  border-radius: 6px;
}

.decision-rationale {
  font-size: 12.5px;
  color: var(--muted);
}

.decision-alts {
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--mono);
}

/* Logs */
.log-viewer {
  background: #090c10;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

.log-line {
  display: grid;
  grid-template-columns: 76px 110px 1fr;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(38, 48, 67, 0.35);
  word-break: break-word;
}

.log-ts {
  color: #65758f;
}

.log-src {
  color: var(--cyan);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-msg {
  color: #dbe5f4;
  white-space: pre-wrap;
}

.log-line.level-step .log-msg { color: #79c0ff; font-weight: 600; }
.log-line.level-warn .log-msg { color: var(--amber); }
.log-line.level-error .log-msg { color: var(--red); }

.raw-log-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c9d5e8;
}

/* Bottom outputs & docs */
.outputs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.media-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.media-card video {
  width: 100%;
  max-height: 360px;
  border-radius: 6px;
  background: #000;
}

.clips-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.clip-mini {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clip-mini video,
.clip-mini img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 5px;
  background: #000;
}

.doc-pre {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  color: #dbe5f4;
  max-height: 460px;
  overflow-y: auto;
}

.empty-hint {
  color: var(--muted);
  font-size: 13px;
  padding: 18px 8px;
  text-align: center;
}

/* Covers gallery */
.covers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.cover-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cover-card img {
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
}

.cover-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 7px;
  border: 1px solid rgba(88, 166, 255, 0.5);
  background: rgba(88, 166, 255, 0.14);
  color: #cfe4ff;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.action-btn:hover {
  background: rgba(88, 166, 255, 0.25);
}

.action-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* BGM audition & remix */
.bgm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.bgm-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bgm-row {
  display: grid;
  grid-template-columns: 220px 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
}

.bgm-row audio {
  width: 100%;
  height: 34px;
}

.bgm-name {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  word-break: break-all;
}

.bgm-status {
  font-size: 12px;
  color: var(--green);
}

.bgm-status.err {
  color: var(--red);
}

/* Characters Bible */
.characters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.char-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.char-photos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--bg);
  height: 190px;
}

.char-photos img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.char-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.char-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.char-name {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.char-trait {
  font-size: 13px;
  color: var(--text);
}

.char-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}

.char-quotes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quote-chip {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: #cfe4ff;
}

@media (max-width: 780px) {
  .bgm-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .two-col {
    grid-template-columns: 1fr;
  }
  .two-col .panel-body {
    height: 400px;
  }
}

/* Static Portfolio Hero Banner (Cloudflare Pages mode) */
.portfolio-hero {
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.12), rgba(244, 114, 182, 0.08));
  border: 1px solid rgba(88, 166, 255, 0.35);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.portfolio-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.portfolio-hero h2 {
  margin: 0;
  font-size: 18px;
}

.portfolio-hero p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.portfolio-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.portfolio-badge {
  font-size: 11px;
  font-family: var(--mono);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(13, 17, 23, 0.65);
  border: 1px solid var(--border);
  color: var(--text);
}
