:root {
  --bg: #100e16;
  --bg-raised: #17141f;
  --panel: #1c1828;
  --panel-alt: #241f33;
  --border: #322b47;
  --border-soft: #241f33;
  --text: #eae5da;
  --text-dim: #a79fc0;
  --text-faint: #6e6688;
  --accent-violet: #8c7bf0;
  --accent-blue: #5b96f0;
  --accent-gold: #cba135;
  --accent-shard: #5fd0c4;
  --danger: #e0607a;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-ms: 'Source Serif 4', Georgia, serif;
  --radius: 6px;
}

* { box-sizing: border-box; }

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

::selection { background: var(--accent-violet); color: #fff; }

a { color: var(--accent-blue); }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

input, textarea, select {
  font-family: var(--font-body);
}

/* ---------- Auth screens ---------- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 15%, rgba(140, 123, 240, 0.12), transparent 45%),
    radial-gradient(circle at 80% 85%, rgba(203, 161, 53, 0.08), transparent 40%),
    var(--bg);
}

.auth-card {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px 28px;
  text-align: center;
}

.shard-mark {
  width: 22px;
  height: 22px;
  margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--accent-violet), var(--accent-shard));
  transform: rotate(45deg);
  border-radius: 3px;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}

.auth-sub {
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 14px;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.auth-card label {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-card input {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}

.auth-card input:focus {
  outline: 2px solid var(--accent-violet);
  outline-offset: 1px;
}

.auth-card button {
  margin-top: 6px;
  background: var(--accent-violet);
  border: none;
  color: #fff;
  padding: 11px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
}

.auth-card button:hover { filter: brightness(1.08); }

.auth-hint {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.5;
}

.auth-hint code {
  color: var(--text-dim);
}

/* ---------- App shell ---------- */

#app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg-raised);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.brand {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border-soft);
}

.brand .shard-mark { margin: 0 0 10px; }

.brand h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.brand .tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-faint);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border-soft);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 11px 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 2px solid transparent;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent-violet);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
}

.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 14px 18px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 18px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  border-left: 2px solid transparent;
}

.nav-item-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item:hover { background: var(--panel); color: var(--text); }

.nav-item.active {
  background: var(--panel);
  color: var(--text);
  border-left-color: var(--accent-shard);
}

.nav-item .count {
  font-size: 11px;
  color: var(--text-faint);
}

.ms-tree-node { padding-left: 0; }
.ms-tree-node .ms-tree-children { padding-left: 14px; }
.ms-book-row, .ms-chapter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 18px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
}
.ms-book-row:hover, .ms-chapter-row:hover { background: var(--panel); color: var(--text); }
.ms-book-row.active, .ms-chapter-row.active { background: var(--panel); color: var(--text); }
.ms-caret { width: 10px; color: var(--text-faint); font-size: 10px; }

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding: 10px 18px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.sidebar-footer a { color: var(--text-faint); text-decoration: none; }
.sidebar-footer a:hover { color: var(--text-dim); }

/* ---------- Main content ---------- */

.main {
  overflow-y: auto;
  padding: 26px 40px 60px;
}

.main-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 20px;
}

.main-header h2 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  margin: 0;
}

.search-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  width: 220px;
}

.search-box:focus { outline: 1px solid var(--accent-violet); }

.btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
}

.btn:hover { border-color: var(--accent-violet); }

.btn-primary {
  background: var(--accent-violet);
  border-color: var(--accent-violet);
  color: #fff;
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }

.btn-row { display: flex; gap: 10px; margin-top: 4px; }

/* Card grid (codex list + corkboard) */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color .12s ease;
}

.card:hover { border-color: var(--accent-violet); }

.card h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 6px;
}

.card p {
  color: var(--text-dim);
  font-size: 12.5px;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-link-row {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}
.history-link-row .back-link { font-size: 12.5px; }

.snapshot-row {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.snapshot-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.snapshot-preview {
  font-family: var(--font-ms);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 10px;
}
.snapshot-preview-full { white-space: pre-wrap; }

.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  transform: rotate(45deg);
  display: inline-block;
  background: var(--text-faint);
  flex: none;
}
.status-dot.status-outline { background: var(--text-faint); }
.status-dot.status-draft { background: var(--accent-blue); }
.status-dot.status-revised { background: var(--accent-gold); }
.status-dot.status-final { background: var(--accent-shard); }

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

/* Detail / form panel */

.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 26px 30px;
  max-width: 780px;
}

.field {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.field input, .field select, .field textarea {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 11px;
  font-size: 13.5px;
  resize: vertical;
}

.field textarea { min-height: 90px; line-height: 1.55; }

.field input:focus, .field select:focus, .field textarea:focus {
  outline: 1px solid var(--accent-violet);
}

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }

.back-link {
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 14px;
  display: inline-block;
}
.back-link:hover { color: var(--text-dim); }

/* Scene editor */

.editor-wrap {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 20px;
  max-width: 1100px;
}

.editor-main textarea.content-area {
  width: 100%;
  min-height: 60vh;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--text);
  padding: 24px 28px;
  font-family: var(--font-ms);
  font-size: 16px;
  line-height: 1.75;
  resize: vertical;
}

.editor-main textarea.content-area:focus { outline: 1px solid var(--accent-violet); }

.editor-side .field { margin-bottom: 14px; }

.word-count {
  color: var(--text-faint);
  font-size: 12px;
  margin-top: 6px;
}

.save-flash {
  color: var(--accent-shard);
  font-size: 12px;
  margin-left: 10px;
}

.save-notice {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  padding: 11px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
  transition: opacity .2s ease, transform .2s ease;
}
.save-notice-pending { color: var(--text-dim); }
.save-notice-success { border-color: var(--accent-shard); color: var(--accent-shard); }
.save-notice-error { border-color: var(--danger); color: var(--danger); }
.save-notice-hidden { opacity: 0; transform: translateY(8px); pointer-events: none; }

.project-switch-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-faint);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 11px;
  margin-top: 4px;
}
.project-switch-btn:hover { color: var(--accent-violet); border-color: var(--accent-violet); }

.launchpad {
  grid-column: 1 / -1;
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 24px 60px;
}

.launchpad-topbar {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-link-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-body);
  font-size: 12.5px;
  color: var(--text-faint);
  cursor: pointer;
}
.topbar-link-btn:hover { color: var(--text-dim); }

.launchpad-signout {
  font-size: 12.5px;
  color: var(--text-faint);
}
.launchpad-signout:hover { color: var(--text-dim); }

.launchpad-header {
  text-align: center;
  margin: 40px 0 44px;
}

.launchpad-mark { margin: 0 auto 16px; width: 30px; height: 30px; }

.launchpad-header h1 {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  margin: 0;
}

.launchpad-header .tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  margin-top: 4px;
}

.launchpad-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin: 14px 0 0;
}

.launchpad-body { width: 100%; max-width: 900px; }

.launchpad-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.launchpad-tile {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color .12s ease, transform .12s ease;
}
.launchpad-tile:hover { border-color: var(--accent-violet); transform: translateY(-1px); }
.launchpad-tile-active { border-color: var(--accent-shard); }

.launchpad-tile-cover {
  width: 100%;
  height: 130px;
  border-radius: calc(var(--radius) - 2px);
  background: var(--panel-alt);
  margin-bottom: 12px;
  overflow: hidden;
}
.launchpad-tile-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.launchpad-recent { margin-bottom: 22px; }
.launchpad-recent-row { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap; }
.launchpad-tile-compact {
  padding: 12px 16px;
  min-width: 220px;
  flex: 0 0 auto;
}
.launchpad-tile-compact h3 { font-size: 15px; }

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

.launchpad-tile h3 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
}

.launchpad-tile p {
  color: var(--text-dim);
  font-size: 12.5px;
  margin: 8px 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.launchpad-tile-actions {
  display: flex;
  gap: 14px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}

.btn-ghost {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  color: var(--text-faint);
}
.btn-ghost:hover { color: var(--accent-blue); }
.btn-ghost-danger:hover { color: var(--danger); }

.launchpad-tile-new {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-style: dashed;
  color: var(--text-faint);
  font-size: 13px;
  min-height: 120px;
}
.launchpad-tile-new:hover { color: var(--accent-violet); }

.launchpad-tile-new-plus {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1;
  margin-bottom: 6px;
}

.current-project-badge {
  color: var(--accent-shard);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 0;
}

.nav-manage {
  margin-top: 6px;
  border-top: 1px solid var(--border-soft);
  color: var(--text-faint);
  font-size: 12px;
}
.nav-manage:hover { color: var(--accent-violet); }

/* Sections manager */

.section-hint {
  color: var(--text-dim);
  font-size: 12.5px;
  max-width: 560px;
  margin: -8px 0 20px;
  line-height: 1.6;
}

.builtin-toggle-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 480px;
}

.builtin-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
}

.builtin-toggle-row .btn {
  padding: 5px 12px;
  font-size: 12px;
}

.mentions-panel {
  margin-top: 16px;
  max-width: 780px;
}

.mention-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}
.mention-row:last-child { border-bottom: none; }
.mention-row:hover .mention-title { color: var(--accent-violet); }

.mention-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 3px;
}

.mention-field {
  font-weight: 400;
  color: var(--text-faint);
  text-transform: none;
}

.mention-snippet {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  color: var(--accent-shard);
}

.stat-label {
  font-size: 11.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.status-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: capitalize;
}

.status-chip-count {
  color: var(--text-faint);
}

.goal-row { margin-bottom: 16px; }
.goal-row:last-child { margin-bottom: 0; }

.goal-row-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.goal-row-count { color: var(--text-faint); }

.goal-row-hint { font-size: 12px; color: var(--text-faint); }

.progress-track {
  height: 7px;
  background: var(--panel-alt);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-violet), var(--accent-shard));
  border-radius: 4px;
}

.stat-grid, .status-breakdown, .goal-row { max-width: 780px; }

.field-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 18px 0 8px;
}

.section-field-row {
  display: grid;
  grid-template-columns: 1fr 130px 1fr 30px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.section-field-row input, .section-field-row select {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

.sf-options-spacer { display: block; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-faint);
  border-radius: var(--radius);
  width: 30px;
  height: 34px;
  font-size: 16px;
  line-height: 1;
}
.btn-icon:hover { color: var(--danger); border-color: var(--danger); }

@media (max-width: 700px) {
  .section-field-row { grid-template-columns: 1fr; }
}

/* Gallery */

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

.gallery-card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .12s ease;
}

.gallery-card:hover { border-color: var(--accent-violet); }

.gallery-thumb {
  width: 100%;
  height: 160px;
  background: var(--bg-raised);
  overflow: hidden;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-thumb-empty {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 12px;
}

.gallery-card-body { padding: 12px 14px 14px; }
.gallery-card-body h3 { font-size: 15px; margin: 0; }

.gallery-detail-wrap {
  display: grid;
  grid-template-columns: minmax(260px, 480px) 1fr;
  gap: 22px;
  max-width: 1000px;
  align-items: start;
}

.gallery-detail-image img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  display: block;
}

.gallery-upload-box {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}

.gallery-upload-box label {
  display: inline-block;
  background: var(--accent-violet);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.gallery-upload-box input[type="file"] { display: none; }

.gallery-upload-hint {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-faint);
}

.gallery-replace-label {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: underline;
}
.gallery-replace-label input[type="file"] { display: none; }

.gallery-detail-form { max-width: none; }

/* Visual timeline */

.timeline-viz-wrap {
  overflow-x: auto;
  padding: 10px 0 6px;
  margin-bottom: 20px;
}

.timeline-rail {
  position: relative;
  display: flex;
  align-items: center;
  gap: 34px;
  min-height: 250px;
  padding: 0 20px;
  width: max-content;
  min-width: 100%;
}

.timeline-rail-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border), var(--border), transparent);
}

.timeline-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 150px;
  flex: none;
  cursor: pointer;
}

.timeline-node-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--text-faint);
  transition: border-color .12s ease, background .12s ease, transform .12s ease;
  z-index: 2;
}

.timeline-node:hover .timeline-node-dot { border-color: var(--accent-violet); }

.timeline-node-active .timeline-node-dot {
  border-color: var(--accent-shard);
  background: var(--accent-shard);
  transform: scale(1.25);
}

.timeline-node-label {
  position: absolute;
  width: 100%;
  text-align: center;
  padding: 0 4px;
}

.timeline-node-up .timeline-node-label { bottom: 50%; margin-bottom: 20px; }
.timeline-node-down .timeline-node-label { top: 50%; margin-top: 20px; }

.timeline-node-era {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 3px;
}

.timeline-node-title {
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text-dim);
}

.timeline-node:hover .timeline-node-title { color: var(--accent-violet); }
.timeline-node-active .timeline-node-title { color: var(--text); }

.timeline-detail-panel { max-width: 780px; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 40vh; }
  .editor-wrap { grid-template-columns: 1fr; }
}

/* Character relationship graph */

.graph-wrap {
  max-width: 780px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 20px;
}

.graph-svg { width: 100%; height: auto; display: block; }

.graph-edge { stroke: var(--border); stroke-width: 1; transition: stroke .12s ease; }
.graph-edge-active { stroke: var(--accent-shard); stroke-width: 1.8; }
.graph-edge-dim { stroke: var(--border-soft); opacity: 0.35; }

.graph-node { cursor: pointer; }
.graph-node-dim { opacity: 0.3; }

.graph-dot { fill: var(--bg); stroke: var(--accent-violet); stroke-width: 2; }
.graph-dot-active { fill: var(--accent-shard); stroke: var(--accent-shard); stroke-width: 2; }
.graph-dot-isolated { fill: var(--bg); stroke: var(--text-faint); stroke-width: 2; }

.graph-node:hover .graph-dot { stroke: var(--accent-shard); }

.graph-label {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--text-dim);
}
.graph-label-active { fill: var(--text); font-weight: 600; }
.graph-node:hover .graph-label { fill: var(--accent-violet); }

.graph-detail { max-width: 780px; }

/* Map pins */

.map-canvas { position: relative; display: inline-block; line-height: 0; }
.map-canvas img { display: block; max-width: 100%; height: auto; }
.map-canvas-placing { cursor: crosshair; }
.map-canvas-placing img { outline: 2px dashed var(--accent-shard); outline-offset: -2px; }

.map-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  line-height: 1.2;
}

.map-pin-dot {
  width: 13px;
  height: 13px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--accent-violet);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.6);
  order: 2;
}

.map-pin-active .map-pin-dot { background: var(--accent-shard); transform: rotate(-45deg) scale(1.25); }

.map-pin-label {
  order: 1;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text);
  background: rgba(16,14,22,.85);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  margin-bottom: 3px;
  white-space: nowrap;
}

.map-pins-panel { max-width: 780px; margin-top: 16px; }

.pin-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}
.pin-row:last-child { border-bottom: none; }
.pin-row-active { background: var(--panel-alt); }

.pin-row-num {
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 50%;
  background: var(--panel-alt);
  color: var(--text-dim);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-row-body { flex: 1; display: flex; flex-direction: column; gap: 6px; }

.pin-label-input, .pin-location-select {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 6px 9px;
}

.pin-open-link { font-size: 11.5px; color: var(--accent-blue); cursor: pointer; }

/* Daily writing bars */

.day-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 18px;
  max-width: 400px;
}

.day-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; }

.day-bar-track {
  width: 100%;
  height: 56px;
  background: var(--panel-alt);
  border-radius: 3px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.day-bar-fill {
  width: 100%;
  background: var(--accent-violet);
  border-radius: 3px;
  min-height: 0;
}

.day-bar-today { background: var(--accent-shard); }

.day-bar-label {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.day-bar-label-today { color: var(--accent-shard); }

.snapshot-field { margin-bottom: 10px; }
.snapshot-field-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.snapshot-field div {
  font-family: var(--font-ms);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ---------- Theme panel ---------- */

.theme-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.theme-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
  width: 100%;
  max-width: 480px;
  padding: 24px;
}

.theme-panel h3 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 6px;
}

.theme-panel-sub {
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0 0 18px;
}

.theme-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.theme-preset-swatch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  width: 44px;
  height: 28px;
  padding: 0;
  cursor: pointer;
}
.theme-preset-swatch:hover { border-color: var(--accent-violet); }
.theme-preset-swatch span { flex: 1; display: block; }

.theme-color-row {
  display: flex;
  gap: 16px;
  margin-bottom: 22px;
}

.theme-color-row label {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.theme-color-row input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  background: var(--panel-alt);
  cursor: pointer;
}

.theme-panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--border-soft);
}
.backup-row:first-of-type { border-top: none; padding-top: 4px; }
.backup-row strong { font-size: 13.5px; }

/* ---------- Find & Replace ---------- */

.fr-panel { max-width: 640px; }

.fr-field-row {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
}
.fr-field-row label {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fr-field-row input[type="text"] {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}
.fr-field-row input[type="text"]:focus { outline: 1px solid var(--accent-violet); }

.fr-options-row {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.fr-options-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.fr-results {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.fr-results-list {
  max-height: 280px;
  overflow-y: auto;
  margin-top: 8px;
}

.fr-result-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.fr-result-row:last-child { border-bottom: none; }

.fr-result-loc {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.fr-result-count { color: var(--accent-violet); font-weight: 600; }

.fr-context {
  font-family: var(--font-ms);
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.5;
  margin: 2px 0;
}
.fr-context mark {
  background: var(--accent-violet);
  color: #fff;
  padding: 0 2px;
  border-radius: 2px;
}

.fr-context-more {
  font-size: 11.5px;
  color: var(--text-faint);
  font-style: italic;
}

/* ---------- Codex sidebar: grouped entry cards ---------- */

.codex-group { border-bottom: 1px solid var(--border-soft); }

.codex-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
}
.codex-group-header:hover { background: var(--panel); }

.codex-group-caret {
  width: 10px;
  color: var(--text-faint);
  font-size: 10px;
  flex-shrink: 0;
}

.codex-group-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.codex-group-count {
  font-size: 11px;
  color: var(--text-faint);
}

.codex-group-add {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  border-radius: 3px;
}
.codex-group-add:hover { color: var(--accent-violet); background: var(--panel-alt); }

.codex-group-body {
  padding: 2px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.codex-group-empty {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  padding: 4px 8px 8px;
}

.codex-entry-card {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.codex-entry-card:hover { background: var(--panel); }
.codex-entry-card.active { background: var(--panel); border-color: var(--accent-shard); }

.codex-entry-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--panel-alt);
}

.codex-entry-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--accent-violet);
}

.codex-entry-info { min-width: 0; flex: 1; }

.codex-entry-title-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.codex-entry-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.codex-entry-tag {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-blue);
  background: var(--panel-alt);
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}

.codex-entry-desc {
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

/* ---------- Image field (detail forms) ---------- */

.btn-sm {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  display: inline-block;
}
.btn-sm:hover { border-color: var(--accent-violet); }

.image-field-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.image-field-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--panel-alt);
}

.image-field-empty {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-faint);
  text-align: center;
}

.image-field-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- Manuscript: Plan / Write mode switch ---------- */

.ms-mode-row {
  display: flex;
  margin-bottom: 18px;
}

.ms-mode-switch {
  display: inline-flex;
  background: var(--panel-alt);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.ms-mode-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 18px;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
}
.ms-mode-btn:hover { color: var(--text); }
.ms-mode-btn.active {
  background: var(--accent-violet);
  color: #fff;
}

.write-picker-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 640px;
}

.write-picker-book-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}

.write-picker-chapter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 13px;
}
.write-picker-chapter:hover { border-color: var(--accent-violet); background: var(--panel); }

.write-picker-wc {
  font-size: 11.5px;
  color: var(--text-faint);
}

.write-picker-empty {
  font-size: 12.5px;
  color: var(--text-faint);
  font-style: italic;
  padding: 4px 0;
}

/* ---------- Text to speech ---------- */

.tts-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tts-progress {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
}

.tts-bar select {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 12px;
}

/* ---------- Read view ---------- */

.read-view {
  max-width: 720px;
  margin: 0 auto;
}

.read-paragraph {
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: -6px;
  margin-right: -6px;
  border: 1px solid transparent;
}
.read-paragraph.active {
  background: var(--panel-alt);
  border-color: var(--border-soft);
}

.tts-current-word {
  background: var(--accent-violet);
  color: #fff;
  padding: 0 2px;
  border-radius: 2px;
}

.read-scene-divider-line {
  width: 40%;
  margin: 2em auto;
  border: none;
  border-top: 1px solid var(--border);
}

.read-scene-divider-marks {
  text-align: center;
  margin: 2em 0;
  color: var(--text-faint);
  letter-spacing: 0.3em;
}

/* ---------- Typography: font family ---------- */

html[data-font-family="system-serif"] .content-area,
html[data-font-family="system-serif"] .read-view { font-family: Georgia, 'Times New Roman', serif; }
html[data-font-family="source-serif"] .content-area,
html[data-font-family="source-serif"] .read-view { font-family: 'Source Serif 4', Georgia, serif; }
html[data-font-family="garamond"] .content-area,
html[data-font-family="garamond"] .read-view { font-family: 'EB Garamond', Georgia, serif; }
html[data-font-family="lora"] .content-area,
html[data-font-family="lora"] .read-view { font-family: 'Lora', Georgia, serif; }
html[data-font-family="sans"] .content-area,
html[data-font-family="sans"] .read-view { font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; }

/* ---------- Typography: text size ---------- */

html[data-text-size="sm"] .content-area, html[data-text-size="sm"] .read-view { font-size: 14px; }
html[data-text-size="md"] .content-area, html[data-text-size="md"] .read-view { font-size: 16px; }
html[data-text-size="lg"] .content-area, html[data-text-size="lg"] .read-view { font-size: 18px; }
html[data-text-size="xl"] .content-area, html[data-text-size="xl"] .read-view { font-size: 21px; }

/* ---------- Typography: line height ---------- */

html[data-line-height="tight"] .content-area, html[data-line-height="tight"] .read-view { line-height: 1.4; }
html[data-line-height="normal"] .content-area, html[data-line-height="normal"] .read-view { line-height: 1.75; }
html[data-line-height="relaxed"] .content-area, html[data-line-height="relaxed"] .read-view { line-height: 2; }
html[data-line-height="loose"] .content-area, html[data-line-height="loose"] .read-view { line-height: 2.3; }

/* ---------- Typography: text align ---------- */

html[data-text-align="left"] .content-area, html[data-text-align="left"] .read-view p { text-align: left; }
html[data-text-align="justify"] .content-area, html[data-text-align="justify"] .read-view p { text-align: justify; }

/* ---------- Typography: page width (read view only — editor keeps its layout) ---------- */

html[data-page-width="narrow"] .read-view { max-width: 520px; }
html[data-page-width="medium"] .read-view { max-width: 720px; }
html[data-page-width="wide"] .read-view { max-width: 920px; }
html[data-page-width="full"] .read-view { max-width: none; }

/* ---------- Typography: paragraph style + spacing (read view only) ---------- */

html[data-paragraph-style="indent"] .read-view p {
  text-indent: 2em;
  margin: 0;
}
html[data-paragraph-style="block"][data-paragraph-spacing="compact"] .read-view p { text-indent: 0; margin: 0 0 0.6em; }
html[data-paragraph-style="block"][data-paragraph-spacing="normal"] .read-view p { text-indent: 0; margin: 0 0 1.1em; }
html[data-paragraph-style="block"][data-paragraph-spacing="relaxed"] .read-view p { text-indent: 0; margin: 0 0 1.6em; }
html[data-paragraph-style="block"][data-paragraph-spacing="spacious"] .read-view p { text-indent: 0; margin: 0 0 2.2em; }

/* ---------- Typography settings panel ---------- */

.typo-group { margin-bottom: 16px; }

.typo-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.typo-option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.typo-option-btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
}
.typo-option-btn:hover { border-color: var(--accent-violet); }
.typo-option-btn.active { background: var(--accent-violet); color: #fff; border-color: var(--accent-violet); }

.theme-panel { max-height: 82vh; overflow-y: auto; }

/* ---------- Typewriter mode ---------- */

html[data-typewriter-mode="true"] .content-area {
  padding-top: 35vh;
  padding-bottom: 35vh;
}

.typo-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 6px 0;
  cursor: pointer;
}

/* ---------- Codex density toggle ---------- */

.codex-density-row {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-soft);
}

.codex-density-btn {
  flex: 1;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 10.5px;
  padding: 4px 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.codex-density-btn.active { background: var(--accent-violet); color: #fff; border-color: var(--accent-violet); }

.codex-entry-usertag {
  font-size: 9px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  white-space: nowrap;
}

.codex-density-compact .codex-entry-card { padding: 4px 8px; }
.codex-density-compact .codex-entry-avatar { width: 24px; height: 24px; }

.codex-density-slim .codex-entry-card { padding: 2px 8px; }
.codex-density-slim .codex-entry-avatar { width: 18px; height: 18px; font-size: 9px; }
.codex-density-slim .codex-entry-tag, .codex-density-slim .codex-entry-usertag { display: none; }

/* ---------- Corkboard drag-to-reorder ---------- */

.corkboard-card { cursor: grab; transition: box-shadow .12s ease, opacity .12s ease; }
.corkboard-card.dragging { opacity: 0.4; }
.corkboard-card.drag-over { box-shadow: 0 0 0 2px var(--accent-violet) inset; }

.corkboard-synopsis {
  font-size: 12px;
  color: var(--text-dim);
  margin: 8px 0 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Codex entry color ---------- */

.color-swatch-row { display: flex; gap: 8px; flex-wrap: wrap; }

.color-swatch-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  background: var(--panel-alt);
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1;
}
.color-swatch-btn.active { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }

/* ---------- Inline mention preview ---------- */

.mention-link {
  border-bottom: 1px dotted var(--accent-violet);
  cursor: pointer;
  color: inherit;
}
.mention-link:hover { background: var(--panel-alt); }

.mention-preview-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
  width: 100%;
  max-width: 380px;
  padding: 20px;
}

.mention-preview-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.mention-preview-head .codex-entry-avatar { width: 44px; height: 44px; font-size: 16px; }

.mention-preview-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
}

.mention-preview-body {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
}

/* ---------- Archived projects ---------- */

.launchpad-archived-section { margin-top: 24px; }

.launchpad-tile-archived {
  opacity: 0.7;
  background: var(--panel-alt);
}
