:root {
  --bg: #14161a;
  --panel: #1d2026;
  --card: #22262e;
  --ink: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #e8623d;
  --danger: #d6504a;
  --line: #2a2e36;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

header {
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.5px;
}

.tagline { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.95rem; }

main { padding: 1.5rem; max-width: 880px; margin: 0 auto; }

.muted { color: var(--muted); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}
.toolbar h2 { margin: 0; font-size: 1.2rem; }

.back { color: var(--muted); font-size: 0.95rem; }
.back:hover { color: var(--ink); }

/* Buttons */
.btn {
  background: #2c313b;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover { border-color: #3a404c; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1004; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: rgba(214, 80, 74, 0.12); }

/* Project grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
}
.project-card { cursor: pointer; transition: border-color 0.12s, transform 0.12s; }
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.project-card h3 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.9rem;
  min-height: 2.6em;
}
.pill {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: #181b21;
  border: 1px solid var(--line);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

/* Panels & forms */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.panel h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.placeholder { text-align: center; color: var(--muted); }
.placeholder h2 { color: var(--ink); }

.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }

input, textarea {
  width: 100%;
  background: #14171c;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  resize: vertical;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.title-edit { font-size: 1.25rem; font-weight: 600; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 0.5rem; }

.error {
  background: rgba(214, 80, 74, 0.12);
  border: 1px solid var(--danger);
  color: #f2b3b0;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  margin-top: 1rem;
}

/* Outline board */
.small { font-size: 0.8rem; }
.board-cols {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 760px) {
  .board-cols { grid-template-columns: 1fr; }
}
.col h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.col.parking { background: #1a1d23; }

.beat-list { min-height: 12px; }
.children-wrap { margin: 0.4rem 0 0 1.1rem; padding-left: 0.6rem; border-left: 2px solid var(--line); }
.children-wrap .beat-list { min-height: 6px; }

.beat {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: 9px;
  padding: 0.5rem 0.6rem;
  margin: 0.45rem 0;
}
/* Type accents */
.beat.type-cold_open { border-left-color: #6cc6ff; }
.beat.type-thesis    { border-left-color: #e8623d; }
.beat.type-segment   { border-left-color: #7bd88f; }
.beat.type-subpoint  { border-left-color: #b8a3ff; }
.beat.type-tangent   { border-left-color: #f0b35b; }
.beat.type-callback  { border-left-color: #ff8fb3; }
.beat.type-outro     { border-left-color: #9aa1ad; }
.beat.type-parking   { border-left-color: #5a6072; }

.beat-head { display: flex; align-items: center; gap: 0.4rem; }
.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  user-select: none;
  padding: 0 0.1rem;
}
.drag-handle:active { cursor: grabbing; }

.type-select, .type-badge {
  font-size: 0.75rem;
  background: #14171c;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.35rem;
}
.type-badge { white-space: nowrap; }
.type-select { width: auto; }

.beat-title { flex: 1; padding: 0.3rem 0.45rem; font-size: 0.95rem; }
.wc { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }
.beat-body { margin-top: 0.4rem; font-size: 0.9rem; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.15rem 0.3rem;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--danger); background: rgba(214,80,74,0.1); }

.btn.tiny { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
.add-sub { margin-top: 0.35rem; color: var(--muted); }
.add-beat { margin-top: 0.6rem; }

.drag-ghost { opacity: 0.4; border-style: dashed; }

/* Pacing panel */
.pacing { margin-bottom: 1.25rem; }
.pace-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.pace-headline { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.pace-total { font-size: 1.5rem; font-weight: 700; }
.pace-target { color: var(--muted); font-size: 0.95rem; }
.pace-status {
  font-size: 0.78rem;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.pace-status.on { color: #7bd88f; border-color: #2f6b3f; background: rgba(123,216,143,0.1); }
.pace-status.under { color: #f0b35b; border-color: #6b542a; background: rgba(240,179,91,0.1); }
.pace-status.over { color: #ff8f8f; border-color: #6b2f2f; background: rgba(255,143,143,0.1); }
.pace-status.neutral { color: var(--muted); }

.wpm-field { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); }
.wpm-field > span:first-child { white-space: nowrap; }
.wpm-input { width: 4.5rem; padding: 0.3rem 0.4rem; font-size: 0.85rem; }

.pace-bar {
  height: 10px;
  background: #14171c;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.8rem 0 0.4rem;
}
.pace-fill { display: block; height: 100%; border-radius: 999px; background: var(--muted); }
.pace-fill.on { background: #7bd88f; }
.pace-fill.under { background: #f0b35b; }
.pace-fill.over { background: #ff8f8f; }

.pace-foot { margin-bottom: 0.6rem; }
.pace-breakdown { display: flex; flex-direction: column; gap: 0.35rem; }
.pace-row { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; align-items: center; gap: 0.6rem; }
.pace-name { font-size: 0.82rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pace-track { height: 6px; background: #14171c; border-radius: 999px; overflow: hidden; }
.pace-seg-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.pace-min { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

/* Evidence chips on beats */
.evidence {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-top: 0.4rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  background: #181b21;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.12rem 0.2rem 0.12rem 0.55rem;
  color: var(--ink);
}
.chip a { color: #9cc7ff; }
.chip-x {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 0.25rem;
}
.chip-x:hover { color: var(--danger); }
.evidence-picker {
  width: auto;
  font-size: 0.72rem;
  padding: 0.12rem 0.3rem;
  background: #14171c;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 999px;
}

/* Research shelf */
.research-shelf { margin-top: 1.25rem; }
.research-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}
.research-card { display: flex; flex-direction: column; gap: 0.4rem; }
.rc-head { display: flex; align-items: center; gap: 0.4rem; }
.rc-kind { width: auto; font-size: 0.72rem; padding: 0.2rem 0.3rem; }
.rc-title { flex: 1; font-size: 0.9rem; font-weight: 600; }
.rc-content { font-size: 0.85rem; }
.rc-source { font-size: 0.78rem; }
.rc-tags { font-size: 0.78rem; color: var(--muted); }
.rc-link { color: #9cc7ff; }
.research-card .pill { align-self: flex-start; margin-top: 0; }

/* Flash toast */
.flash {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(150%);
  background: #2c313b;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
}
.flash.show { transform: translateX(-50%) translateY(0); opacity: 1; }
