/* ── Custom confirm dialog ────────────────────────────────────── */

#confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
#confirm-overlay.active { display: flex; }

#choice-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
#choice-overlay.active { display: flex; }
#choice-dialog {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  width: min(520px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
#choice-message {
  font-size: 0.82rem;
  color: #d1d5db;
  line-height: 1.5;
}
#choice-dialog .confirm-actions {
  flex-wrap: nowrap;
}
#choice-a, #choice-b, #choice-cancel {
  border-radius: 6px;
  padding: 0.3rem 0.85rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid #4b5563;
}
#choice-a {
  background: #374151;
  color: #f9fafb;
}
#choice-a:hover { background: #4b5563; }
#choice-b {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}
#choice-b:hover { background: #991b1b; }
#choice-cancel {
  background: #374151;
  color: #9ca3af;
}
#choice-cancel:hover { background: #4b5563; color: #d1d5db; }

#confirm-dialog {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

#confirm-message {
  font-size: 0.92rem;
  color: #d1d5db;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

#confirm-ok {
  background: #7f1d1d;
  color: #fca5a5;
  border: 1px solid #991b1b;
  border-radius: 6px;
  padding: 0.3rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}
#confirm-ok:hover { background: #991b1b; }
#confirm-ok.warn {
  background: #f5a623;
  color: #111827;
  border-color: #e09518;
}
#confirm-ok.warn:hover { background: #e09518; }

#confirm-cancel {
  background: #374151;
  color: #9ca3af;
  border: 1px solid #4b5563;
  border-radius: 6px;
  padding: 0.3rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.12s;
}
#confirm-cancel:hover { background: #4b5563; color: #d1d5db; }

/* ── Node context menu ────────────────────────────────────────── */

#landing-ctx-menu {
  display: none;
  position: fixed;
  z-index: 1000;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 7px;
  padding: 0.3rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 160px;
}
#landing-ctx-menu button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #d1d5db;
  padding: 0.45rem 0.75rem;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 5px;
}
#landing-ctx-menu button:hover { background: #374151; }
#bg-ctx-menu {
  display: none;
  position: fixed;
  z-index: 1000;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 7px;
  padding: 0.3rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 160px;
}
#bg-ctx-menu button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #d1d5db;
  padding: 0.45rem 0.75rem;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 5px;
}
#bg-ctx-menu button:hover { background: #374151; }
#bg-ctx-menu .ctx-submenu-trigger { display: flex; align-items: center; }
.ctx-connector-item { padding-left: 1.7rem !important; position: relative; }
.ctx-connector-item::before { content: ''; position: absolute; left: 0.6rem; }
.ctx-connector-item.active::before { content: '✓'; color: #60a5fa; }

#bg-move-overlay {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(17,24,39,0.85);
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.5rem 1.2rem;
  font-size: 0.8rem;
  color: #9ca3af;
  pointer-events: none;
}

#node-ctx-menu {
  display: none;
  position: fixed;
  z-index: 1000;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 7px;
  padding: 0.3rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 115px;
}

#node-ctx-menu button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #d1d5db;
  padding: 0.45rem 0.75rem;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 5px;
}
#node-ctx-menu button:hover { background: #374151; }
#ctx-delete-btn { color: #f87171 !important; }
#ctx-delete-btn:hover { background: #7f1d1d !important; }

.ctx-submenu-wrap { position: relative; }
.ctx-submenu-trigger {
  display: flex;
  align-items: center;
}
.ctx-submenu-panel {
  display: none;
  position: absolute;
  left: 100%;
  top: -0.3rem;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 7px;
  padding: 0.3rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 140px;
  z-index: 1001;
}
.ctx-submenu-wrap:hover .ctx-submenu-panel { display: block; }
.ctx-submenu-panel.ctx-submenu-flip-x { left: auto; right: 100%; }
.ctx-submenu-panel.ctx-submenu-flip-y { top: auto; bottom: -0.3rem; }
#ctx-priority-high-btn { color: #4ade80; }
#ctx-priority-low-btn  { color: #f87171; }
#ctx-priority-high-btn:hover { background: #14532d !important; }
#ctx-priority-low-btn:hover  { background: #450a0a !important; }
#ctx-color-wrap .ctx-submenu-panel { min-width: 0; width: fit-content; }
.ctx-color-grid {
  display: grid;
  grid-template-columns: repeat(4, 22px);
  gap: 4px;
  padding: 0.35rem 0.35rem 0.2rem;
}
.ctx-color-swatch {
  width: 22px !important; height: 22px !important;
  padding: 0 !important;
  border: 2px solid rgba(0,0,0,0.4) !important;
  border-radius: 4px !important;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.ctx-color-swatch:hover { transform: scale(1.15); border-color: rgba(255,255,255,0.75) !important; }
.ctx-color-swatch.active { box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(255,255,255,0.4) !important; }
#ctx-color-clear-btn { color: #9ca3af !important; font-size: 0.78rem !important; padding: 0.25rem 0.75rem !important; }

/* ── Edit modal ───────────────────────────────────────────────── */

#portal-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
#portal-modal-overlay.active { display: flex; }
#portal-modal {
  background: #1f2937;
  border: 1px solid #0e7490;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
#portal-modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #38bdf8;
}
#portal-book-select {
  width: 100%;
  background: #111827;
  color: #e2e8f0;
  border: 1px solid #374151;
  border-radius: 5px;
  padding: 0.3rem 0.5rem;
}
#portal-modal-cancel {
  background: transparent;
  border: 1px solid #374151;
  border-radius: 5px;
  color: #9ca3af;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
}
#portal-modal-cancel:hover { background: #374151; color: #f3f4f6; }

#note-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
#note-modal-overlay.active { display: flex; }

#note-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
  width: 391px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

#note-modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f5a623;
}

#edit-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
#edit-modal-overlay.active { display: flex; }

#start-node-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
#start-node-modal-overlay.active { display: flex; }
#start-node-input {
  width: 4rem;
  text-align: center;
  background: #111827;
  border: 1px solid #4b5563;
  color: #f9fafb;
  border-radius: 5px;
  padding: 0.2rem 0.3rem;
  font-size: 0.9rem;
}
#start-node-modal .modal-actions { justify-content: flex-end; }
#start-node-modal .modal-actions .primary-btn,
#start-node-modal .modal-actions .secondary-btn {
  flex: none; width: auto; padding: 0.25rem 0.8rem; font-size: 0.82rem;
}
#start-node-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  width: fit-content;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#start-node-modal .modal-title {
  font-size: 0.9rem;
  margin-bottom: 0;
}

#alt-start-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
#alt-start-modal-overlay.active { display: flex; }
#alt-start-input {
  width: 6rem;
  text-align: center;
  background: #111827;
  border: 1px solid #4b5563;
  color: #f9fafb;
  border-radius: 5px;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
}
#alt-start-row { justify-content: flex-start !important; }
#alt-start-modal .modal-actions { justify-content: flex-end; }
#alt-start-modal .modal-actions .primary-btn,
#alt-start-modal .modal-actions .secondary-btn {
  flex: none; width: auto; padding: 0.3rem 0.9rem; font-size: 0.82rem;
}
#alt-start-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  width: 14.5rem;
  max-width: calc(100vw - 2rem);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
#alt-start-modal .modal-title {
  font-size: 0.9rem;
  margin-bottom: 0;
}
#alt-start-modal .dice-count-row.no-stepper .dice-adj-btn { display: none; }

#edit-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

.modal-title, #edit-modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f5a623;
}

.modal-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-close-btn {
  background: none;
  border: none;
  color: #6b7280;
  font-size: 1rem;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  line-height: 1;
  flex-shrink: 0;
}
.modal-close-btn:hover { color: #d1d5db; }

.modal-actions {
  display: flex;
  gap: 0.5rem;
}

.modal-actions .primary-btn { flex: 1; }

#profile-modal .modal-actions {
  justify-content: flex-end;
}
#profile-modal .modal-actions .primary-btn,
#profile-modal .modal-actions #profile-cancel-btn {
  flex: none !important;
  width: auto !important;
  padding: 0.25rem 0.65rem !important;
  font-size: 0.78rem !important;
}
#edit-book-modal .modal-actions,
.new-book-form .modal-actions,
#edit-modal .modal-actions,
#note-modal .modal-actions,
#add-book-overlay .modal-actions,
#add-comp-overlay .modal-actions,
#add-series-overlay .modal-actions,
#add-stash-overlay .modal-actions,
#edit-stash-overlay .modal-actions,
#edit-comp-overlay .modal-actions,
#edit-series-overlay .modal-actions {
  justify-content: flex-end;
}
#edit-book-modal .modal-actions .primary-btn,
#edit-book-modal .modal-actions #edit-book-cancel,
.new-book-form .modal-actions .primary-btn,
.new-book-form .modal-actions #new-book-cancel-btn,
#edit-modal .modal-actions .primary-btn,
#edit-modal .modal-actions #edit-modal-cancel,
#note-modal .modal-actions .primary-btn,
#note-modal .modal-actions #note-modal-cancel,
#add-book-overlay .modal-actions .primary-btn,
#add-book-overlay .modal-actions #cb-cancel,
#add-comp-overlay .modal-actions .primary-btn,
#add-comp-overlay .modal-actions #cc-cancel,
#add-series-overlay .modal-actions .primary-btn,
#add-series-overlay .modal-actions #csr-cancel,
#add-stash-overlay .modal-actions .primary-btn,
#add-stash-overlay .modal-actions #cst-cancel,
#edit-stash-overlay .modal-actions .primary-btn,
#edit-stash-overlay .modal-actions #est-cancel,
#edit-comp-overlay .modal-actions .primary-btn,
#edit-comp-overlay .modal-actions #ecc-cancel,
#edit-series-overlay .modal-actions .primary-btn,
#edit-series-overlay .modal-actions #esr-cancel {
  flex: none !important;
  width: auto !important;
  padding: 0.25rem 0.65rem !important;
  font-size: 0.78rem !important;
}
.modal-actions button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: saturate(0.45);
  box-shadow: none;
  transform: none;
}
.modal-actions button:disabled:hover {
  background: inherit;
  color: inherit;
}

#edit-modal-cancel, #edit-book-cancel, #profile-cancel-btn, #crop-cancel-btn, #note-modal-cancel,
#feedback-cancel-btn, #inbox-close-btn, #inbox-conv-close-btn, #new-book-cancel-btn,
#cb-cancel, #cc-cancel, #csr-cancel, #cst-cancel, #est-cancel, #ecc-cancel, #esr-cancel {
  flex: 1;
  background: #374151;
  color: #9ca3af;
  border: 1px solid #4b5563;
  border-radius: 7px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
}
#edit-modal-cancel:hover, #edit-book-cancel:hover, #profile-cancel-btn:hover, #crop-cancel-btn:hover,
#note-modal-cancel:hover, #inbox-close-btn:hover, #inbox-conv-close-btn:hover,
#cb-cancel:hover, #cc-cancel:hover, #csr-cancel:hover, #cst-cancel:hover, #est-cancel:hover, #ecc-cancel:hover, #esr-cancel:hover { background: #4b5563; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #111827;
  color: #d1d5db;
  height: 100vh;
  overflow: hidden;
}

/* ── Stats ────────────────────────────────────────────────────── */

#stats {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.52rem 0.75rem;
  margin: -0.7rem -0.5rem -0.85rem -0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: #9ca3af;
}

.stats-row--missing {
  padding-bottom: 0.18rem;
}

.stats-row--playthroughs {
  border-top: 1px solid #374151;
  padding-top: 0.22rem;
}

.missing-label {
  color: #f9fafb;
  cursor: default;
}

#mapped-count, #total-count       { color: #3d9be9; }
#discovered-count, #discovered-total { color: #606060; }

.pt-lost { color: #ef4444; }
.pt-won  { color: #4ade80; }
#pt-outcomes { font-size: 0.75rem; font-weight: 400; margin-left: 0.3rem; }

.stat-bar-wrap {
  height: 3px;
  background: #1f2937;
  border-radius: 2px;
  overflow: hidden;
  margin: 3px 0 5px;
}
.stat-bar-wrap--split { display: flex; }
.stat-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.stat-bar--mapped    { background: #3d9be9; }
.stat-bar--discovered { background: #4b5563; }
.stat-bar--wins   { background: #4ade80; border-radius: 2px 0 0 2px; }
.stat-bar--losses { background: #ef4444; border-radius: 0 2px 2px 0; }

.stat-value {
  color: #f5a623;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── Playthrough panel ────────────────────────────────────────── */

#playthrough-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow: hidden;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.05rem 0 0.1rem;
}

.section-display {
  font-size: 2rem;
  font-weight: 700;
  color: #f5a623;
  line-height: 1;
}
.section-cross-book {
  font-size: 0.85rem;
  font-weight: 600;
  color: #38bdf8;
  line-height: 1;
}

.section-label {
  font-size: 0.72rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.run-controls-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.undo-ft-row {
  display: flex;
  gap: 0.35rem;
}

.undo-run-btn, .fasttravel-btn {
  flex: 1;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.undo-run-btn:hover:not(:disabled), .fasttravel-btn:hover:not(:disabled) { background: #4b5563; color: #f3f4f6; }
.undo-run-btn:disabled, .fasttravel-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.end-run-group { display: flex; flex-direction: column; gap: 0.2rem; }
.win-loss-row { display: flex; gap: 0.35rem; }
.win-btn, .loss-btn {
  flex: 1; padding: 0.1rem 0.4rem; font-size: 0.75rem;
  border-radius: 4px; cursor: pointer; text-align: center; border: 1px solid;
  display: inline-flex; align-items: center; justify-content: center;
}
.win-btn  { background: #14532d; color: #86efac; border-color: #166534; }
.win-btn:hover  { background: #166534; color: #bbf7d0; }
.loss-btn { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
.loss-btn:hover { background: #7f1d1d; color: #fecaca; }
.battle-death-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-bottom: 0;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  background: #431407;
  color: #fb923c;
  border: 1px solid #7c2d12;
  border-radius: 4px;
  cursor: pointer;
}
.battle-death-btn:hover { background: #7c2d12; color: #fed7aa; }

/* ── Fast travel dialog ─────────────────────────────────────────── */
#ft-dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
#ft-dialog-overlay.active { display: flex; }

#ft-dialog {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

.ft-dialog-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: #d1d5db;
}

.ft-dialog-input {
  flex: 1;
  min-width: 0;
  background: #111827;
  border: 1px solid #374151;
  border-left: none;
  border-right: none;
  border-radius: 0;
  padding: 0.35rem 0.4rem;
  font-size: 0.88rem;
  color: #f9fafb;
  text-align: center;
  font-family: inherit;
}
.ft-dialog-input:focus { outline: none; background: #1a2332; }

.ft-dialog-modes {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ft-dialog-mode-btn {
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-radius: 6px;
  padding: 0.28rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.12s;
}
.ft-dialog-mode-btn:hover { background: #4b5563; color: #f3f4f6; }

.ft-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.ft-dialog-cancel,
.ft-dialog-ok {
  border-radius: 6px;
  padding: 0.32rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.ft-dialog-cancel {
  background: #374151;
  color: #9ca3af;
  border: 1px solid #4b5563;
}
.ft-dialog-cancel:hover { background: #4b5563; color: #d1d5db; }
.ft-dialog-ok {
  background: #1d4ed8;
  color: #f9fafb;
  border: 1px solid #3b82f6;
}
.ft-dialog-ok:hover { background: #2563eb; }

#start-picker-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
#start-picker-overlay.active { display: flex; }
#start-picker-dialog {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  width: 300px;
  max-width: calc(100vw - 2rem);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
#start-picker-options { max-height: 40vh; overflow-y: auto; }
.start-picker-default-tag { color: #9ca3af; font-size: 0.74rem; font-weight: 400; }

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

@keyframes pulse-choices-input {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 166, 35, 0); }
  50%       { box-shadow: 0 0 0 4px rgba(245, 166, 35, 0.35); }
}
.choices-input--pulse {
  border-color: #f5a623;
  animation: pulse-choices-input 1.8s ease-in-out infinite;
}

#cb-authors-row,
#edit-book-authors-row {
  display: flex !important;
  flex-direction: column;
}

.autocomplete-wrap {
  position: relative;
}
.autocomplete-wrap input {
  width: 100%;
  box-sizing: border-box;
}
.autocomplete-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 999;
  background: #1f2937;
  border: 1px solid #374151;
  border-top: none;
  border-radius: 0 0 6px 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
}
.autocomplete-dropdown.open { display: block; }
.autocomplete-dropdown li {
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  color: #d1d5db;
  cursor: pointer;
  border-bottom: 1px solid #374151;
}
.autocomplete-dropdown li:last-child { border-bottom: none; }
.autocomplete-dropdown li:hover,
.autocomplete-dropdown li.ac-active { background: #374151; color: #f9fafb; }
.autocomplete-dropdown li .ac-sub {
  font-size: 0.72rem;
  color: #6b7280;
  margin-left: 0.4rem;
}

.autocomplete-dropdown li .ac-sub.ac-owned {
  color: #f5a623;
}

.input-group label {
  font-size: 0.78rem;
  color: #9ca3af;
}

.input-group small {
  font-size: 0.72rem;
  color: #4b5563;
}

.input-group textarea {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  resize: none;
  line-height: 1.5;
}
.input-group textarea:focus {
  outline: none;
  border-color: #6b7280;
}
.input-group textarea::placeholder { color: #4b5563; }

.label-optional {
  font-size: 0.72rem;
  color: #4b5563;
  font-weight: 400;
}

.choices-label {
  font-size: 0.78rem;
  color: #9ca3af;
}

.choice-buttons {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
  max-height: 9rem;
  overflow-y: auto;
}

.choice-btn {
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 0;
  width: 100%;
  text-align: center;
  transition: background 0.12s, border-color 0.12s;
}
.choice-btn:hover { background: #4b5563; border-color: #6b7280; }

.death-btn { background: #7f1d1d; border-color: #991b1b; color: #fca5a5; }
.death-btn:hover { background: #991b1b; }

.win-btn { background: #14532d; border-color: #166534; color: #86efac; }
.win-btn:hover { background: #166534; }

.terminal-msg {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.4rem 0;
}
.terminal-msg.death { color: #f87171; }
.terminal-msg.win   { color: #4ade80; }

.pt-done-count {
  text-align: center;
  font-size: 0.75rem;
  color: #4b5563;
  margin-top: 0.15rem;
}

/* ── Runs list ────────────────────────────────────────────────── */

.runs-section {
  flex: 1;
  min-height: 0;
  margin-top: 0.5rem;
  border-top: 1px solid #374151;
  padding-top: 0.6rem;
  display: flex;
  flex-direction: column;
}


.runs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.72rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.new-run-btn {
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  text-transform: none;
  letter-spacing: 0;
}
.new-run-btn:hover { background: #4b5563; }

.runs-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.new-run-alt-btn {
  background: #374151;
  color: #9ca3af;
  border: 1px solid #4b5563;
  border-radius: 5px;
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.new-run-alt-btn:hover { background: #4b5563; color: #d1d5db; }

@keyframes pulse-new-run {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 166, 35, 0); }
  50%       { box-shadow: 0 0 0 5px rgba(245, 166, 35, 0.35); }
}
.new-run-btn.pulse {
  border-color: #f5a623;
  color: #f5a623;
  animation: pulse-new-run 1.8s ease-in-out infinite;
}

.runs-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow-y: auto;
}

.runs-empty {
  font-size: 0.78rem;
  color: #4b5563;
  text-align: center;
  padding: 0.3rem 0;
}

.run-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
}

.run-item-active {
  border-color: #f5a623;
}

.run-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.run-num {
  font-size: 0.78rem;
  font-weight: 600;
  color: #d1d5db;
}

.run-status {
  font-size: 0.72rem;
  color: #6b7280;
}
.run-active-label { color: #f5a623; }
.run-death        { color: #f87171; }
.run-battle       { color: #fb923c; }
.run-win          { color: #4ade80; }
.run-portal       { color: #38bdf8; }

.run-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.run-item-viewing {
  border-color: #60a5fa;
  background: #1e3a5f;
  box-shadow: inset 3px 0 0 #60a5fa;
}

.pre-series-runs-section {
  border-top: 1px dashed #374151;
  margin-top: 0.5rem;
  padding-top: 0.25rem;
}
.pre-series-runs-header {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #4b5563;
  padding: 0.3rem 0.5rem 0.2rem;
}
.run-item-preseries {
  opacity: 0.75;
}
.run-item-preseries:hover { opacity: 1; }
.run-num-preseries { color: #6b7280; }

.run-load-btn, .run-view-btn, .run-del-btn {
  background: #1f2937;
  color: #9ca3af;
  border: 1px solid #374151;
  border-radius: 5px;
  padding: 0 0.5rem;
  height: 1.5rem;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}
.run-load-btn:hover, .run-view-btn:hover { background: #374151; color: #d1d5db; }
.run-view-active { background: #1e3a5f; border-color: #3d9be9; color: #93c5fd; }
.run-del-btn { color: #6b7280; }
.run-del-btn:hover { background: #7f1d1d; border-color: #991b1b; color: #fca5a5; }

/* ── Path trail ───────────────────────────────────────────────── */

/* ── Run public toggle ─────────────────────────────────────────── */
.run-public-btn {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0;
  height: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  width: 3rem;
}
.run-public-btn:hover { background: #2d3748; border-color: #4b5563; color: #9ca3af; }
.run-public-btn.is-public { background: #0f2e1a; border-color: #27ae60; color: #4ade80; }
.run-public-btn.is-public:hover { background: #14532d; }
.run-view-public-btn {
  padding: 0.2rem 0.45rem;
  border: 1px solid #374151;
  border-radius: 4px;
  background: #1a1f2e;
  color: #93c5fd;
  font-size: 0.75rem;
  cursor: pointer;
}
.run-view-public-btn:hover { background: #1e3a5f; border-color: #3d9be9; }

/* ── Open world public run journey ──────────────────────────────── */
.pub-journey { display: flex; flex-direction: column; }
.pub-journey-segment {
  border-left: 2px solid #374151;
  padding: 0.75rem 0 0.75rem 1rem;
  margin-left: 0.5rem;
}
.pub-journey-segment:first-child { padding-top: 0.25rem; }
.pub-journey-book {
  font-size: 0.7rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.pub-graph-seg {
  width: 100%;
  height: 260px;
  border-radius: 6px;
  background: #0d1117;
}
.pub-journey-portal {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.75rem -1rem 0 -1rem;
  padding: 0.55rem 1rem;
  background: linear-gradient(90deg, #0e3a3a 0%, #0a2a2a 100%);
  border-top: 1px solid #0d9488;
  border-bottom: 1px solid #0d9488;
  color: #2dd4bf;
}
.pub-journey-portal-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}
.pub-journey-portal-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5eead4;
  flex-shrink: 0;
}
.pub-journey-portal-dest {
  font-size: 0.85rem;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pub-journey-result {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ── Run trail float (graph overlay) ─────────────────────────── */

#run-trail-float {
  position: fixed;
  top: 12px;
  left: calc(var(--sidebar-w) + 12px);
  max-width: calc(100vw - var(--sidebar-w) - var(--legend-w) - 36px);
  z-index: 10;
  background: rgba(31, 41, 55, 0.9);
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.5rem 0.85rem 0.6rem;
  backdrop-filter: blur(6px);
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: left 0.25s ease, max-width 0.25s ease;
}

#run-trail-float:empty {
  display: none;
}

.trail-header {
  font-size: 0.72rem;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  pointer-events: auto;
  cursor: pointer;
}
.trail-toggle-btn {
  pointer-events: auto;
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  user-select: none;
  margin-left: auto;
  transition: transform 0.15s, color 0.12s;
}
.trail-toggle-btn:hover { color: #d1d5db; }
#run-trail-float.trail-collapsed .trail { display: none; }
#run-trail-float.trail-collapsed .trail-header { margin-bottom: 0; }
#run-trail-float.trail-collapsed .trail-toggle-btn { transform: rotate(-90deg); }

.trail {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
}

.trail-node {
  background: #374151;
  color: #9ca3af;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.trail-current  { background: #f5a623; color: #111827; }
.trail-death    { background: #991b1b; color: #fca5a5; }
.trail-battle   { background: #7c2d12; color: #fdba74; }
.trail-win      { background: #166534; color: #86efac; }
.trail-arrow    { color: #4b5563; font-size: 0.7rem; padding: 0 1px; }

/* ── Legend (floating overlay, top-right of graph) ───────────── */

#legend {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  width: var(--legend-w);
  z-index: 10;
  background: rgba(31, 41, 55, 0.9);
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.5rem 0.85rem 0.6rem;
  backdrop-filter: blur(6px);
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  flex-direction: column;
  gap: 0.3rem;
}

#legend-header {
  pointer-events: auto;
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  gap: 0.5rem;
}

.legend-title {
  font-size: 0.72rem;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: 1;
}

.legend-collapse-btn {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: transform 0.15s, color 0.12s;
}
.legend-collapse-btn:hover { color: #d1d5db; }
#legend.legend-collapsed .legend-collapse-btn { transform: rotate(-90deg); }
#legend.legend-collapsed #legend-body { display: none; }
#legend.legend-collapsed { padding-bottom: 0.5rem; gap: 0; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: #9ca3af;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid transparent;
  flex-shrink: 0;
}

/* ── Data controls ────────────────────────────────────────────── */

#data-controls {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid #374151;
}

#find-node-row, #export-reset-row {
  display: flex;
  flex-direction: row;
  gap: 0.3rem;
}
#export-reset-row button { flex: 1; }
#find-node-input {
  flex: 1 1 0;
  min-width: 0;
  box-sizing: border-box;
  background: #1f2937;
  color: #d1d5db;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.28rem 0.5rem;
  font-size: 0.78rem;
  outline: none;
  transition: border-color 0.15s;
}
#find-node-input:focus { border-color: #6b7280; }
#find-node-input.not-found { border-color: #ef4444; }
#find-node-btn {
  flex: 1 1 0;
  background: #1f2937;
  color: #9ca3af;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.28rem 0.5rem;
  cursor: pointer;
  font-size: 0.78rem;
  transition: background 0.12s, color 0.12s;
}
#find-node-btn:hover { background: #374151; color: #d1d5db; }
#data-controls button {
  background: #1f2937;
  color: #9ca3af;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.28rem 0.5rem;
  cursor: pointer;
  font-size: 0.78rem;
  transition: background 0.12s, color 0.12s;
  width: 100%;
}
#data-controls button:hover { background: #374151; color: #d1d5db; }
#data-controls button:disabled { opacity: 0.35; cursor: not-allowed; }
#data-controls button:disabled:hover { background: #1f2937; color: #9ca3af; }
#reset-btn { color: #f87171 !important; }
#reset-btn:hover { background: #7f1d1d !important; border-color: #991b1b !important; }
#export-book-btn { color: #93c5fd !important; }
#export-book-btn:hover { background: #1e3a5f !important; border-color: #2563eb !important; }


