:root {
  --sidebar-w: 270px;
  --legend-w:  195px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── App tooltip ──────────────────────────────────────────────── */

#app-tooltip {
  display: none;
  position: fixed;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 7px;
  color: #d1d5db;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 4000;
}
#app-tooltip.tip-wrap {
  white-space: normal;
  max-width: 260px;
  line-height: 1.6;
}

/* ── 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; }

#confirm-dialog {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 1.5rem;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  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: 7px;
  padding: 0.5rem 1.1rem;
  font-size: 0.88rem;
  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: 7px;
  padding: 0.5rem 1.1rem;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.12s;
}
#confirm-cancel:hover { background: #4b5563; color: #d1d5db; }

/* ── vis-network tooltip ──────────────────────────────────────── */

.vis-tooltip {
  background:    #1f2937 !important;
  border:        1px solid #374151 !important;
  border-radius: 7px !important;
  color:         #d1d5db !important;
  font-family:   'Segoe UI', system-ui, sans-serif !important;
  font-size:     0.82rem !important;
  padding:       0.45rem 0.75rem !important;
  box-shadow:    0 8px 24px rgba(0,0,0,0.5) !important;
  white-space:   nowrap !important;
}

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

#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: 140px;
}

#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-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; }

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

#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: 1.5rem;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  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; }

#edit-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 1.5rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  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-actions {
  display: flex;
  gap: 0.5rem;
}

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

#profile-modal .modal-actions .primary-btn,
#profile-modal .modal-actions #profile-cancel-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}
#edit-book-modal .modal-actions,
.new-book-form .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 {
  flex: none !important;
  width: auto !important;
  padding: 0.25rem 0.65rem !important;
  font-size: 0.78rem !important;
}

#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 {
  flex: 1;
  background: #374151;
  color: #9ca3af;
  border: 1px solid #4b5563;
  border-radius: 7px;
  padding: 0.6rem;
  cursor: pointer;
  font-size: 0.88rem;
  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 { background: #4b5563; }

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

/* ── Landing layout ───────────────────────────────────────────────────────── */

#covers-panel {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  width: 480px;
  height: 100vh;
  flex-direction: column;
  border-right: 1px solid #1f2937;
  padding: 2.5rem 1.5rem;
  overflow: hidden;
  background: #111827;
  transition: transform 0.25s ease;
}

#covers-panel.covers-searching {
  overflow-y: auto;
}

#covers-panel.active { display: flex; }
body.covers-collapsed #covers-panel { transform: translateX(-480px); }

#covers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.covers-search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#covers-search {
  background: transparent;
  border: none;
  border-bottom: 1px solid #374151;
  color: #d1d5db;
  font-size: 0.75rem;
  font-family: inherit;
  padding: 0.1em 1.2em 0.1em 0.25em;
  outline: none;
  width: 110px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
  transition: border-color 0.15s;
}
#covers-search::placeholder { color: #4b5563; }
#covers-search:focus { border-bottom-color: #f5a623; }

#covers-search-clear {
  display: none;
  position: absolute;
  right: 0;
  background: transparent;
  border: none;
  color: #6b7280;
  font-size: 0.65rem;
  cursor: pointer;
  padding: 0.1em 0.2em;
  line-height: 1;
  transition: color 0.12s;
}
#covers-search-clear:hover { color: #f5a623; }

#covers-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.cover-thumb {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #374151;
  background: #1f2937;
  cursor: pointer;
  transition: border-color 0.15s;
}

.cover-load-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, #0891b2, #67e8f9);
  z-index: 1;
  pointer-events: none;
}
.cover-thumb:hover { border-color: #6b7280; }

.cover-no-img {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  font-size: 0.65rem;
  color: #6b7280;
  text-align: center;
  line-height: 1.3;
  word-break: break-word;
  hyphens: auto;
}

.cover-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#landing-wrapper {
  height: 100vh;
  overflow-y: auto;
  padding-right: 480px;
  padding-left: 480px;
  transition: padding-left 0.25s ease, padding-right 0.25s ease;
}
body.covers-collapsed #landing-wrapper { padding-left: 0; }
body.right-collapsed  #landing-wrapper { padding-right: 0; }

#app-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: #1f2937 url('/banner-bg.svg') center / cover no-repeat;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
}

#app-banner-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

#app-banner-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f9fafb;
  letter-spacing: -0.01em;
}

#app-version {
  font-size: 0.75rem;
  font-weight: 400;
  color: #c8894a;
  vertical-align: middle;
  margin-left: 0.3rem;
}

#app-footer {
  text-align: center;
  font-size: 0.7rem;
  color: #4b5563;
  padding: 1.5rem 0 1rem;
  pointer-events: none;
  user-select: none;
}

#app-banner-sub {
  font-size: 0.75rem;
  color: #6b7280;
}

#app-banner-guide-btn {
  display: inline-block;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 7px;
  color: #9ca3af;
  font-size: 0.82rem;
  font-family: 'Segoe UI', system-ui, sans-serif;
  padding: 0.35rem 0.9rem;
  line-height: normal;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.12s, color 0.12s;
}
#app-banner-guide-btn:hover { border-color: #6b7280; color: #e2e8f0; }

#app-banner-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

#app-banner-brand {
  font-size: 0.75rem;
  color: #c8894a;
  letter-spacing: 0.04em;
}

#app-banner-btns {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#demo-btn,
#feedback-btn,
#inbox-btn {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 7px;
  color: #9ca3af;
  font-size: 0.82rem;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, color 0.12s;
}
#demo-btn:hover    { border-color: #f5a623; color: #f5a623; }
#feedback-btn:hover  { border-color: #6b7280; color: #e2e8f0; }
#inbox-btn:hover     { border-color: #6b7280; color: #e2e8f0; }
#inbox-btn.inbox-btn--active              { border-color: #16a34a; color: #4ade80; }
#inbox-btn.inbox-btn--active:hover        { border-color: #22c55e; color: #86efac; }

/* ── Demo banner ──────────────────────────────────────────────────────────── */

#demo-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #92400e;
  color: #fef3c7;
  font-size: 0.85rem;
  padding: 0.45rem 1rem;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
#demo-banner.active { display: flex; }
#demo-exit-btn {
  background: #78350f;
  border: 1px solid #b45309;
  border-radius: 5px;
  color: #fef3c7;
  font-size: 0.8rem;
  padding: 0.22rem 0.7rem;
  cursor: pointer;
}
#demo-exit-btn:hover { background: #92400e; border-color: #d97706; }

/* Push page content down when banner is visible */
body.demo-active #landing-wrapper,
body.demo-active #main-screen {
  margin-top: 34px;
}

/* Fixed elements that need to clear the demo banner */
body.demo-active #main-screen        { height: calc(100vh - 34px); }
body.demo-active #covers-panel,
body.demo-active #landing-right      { top: 34px; height: calc(100vh - 34px); }
body.demo-active #run-trail-float,
body.demo-active #legend             { top: calc(12px + 34px); }

/* Hide profile/logout in demo */
body.demo-active #profile-btn,
body.demo-active #logout-btn {
  display: none;
}

#feed-panel {
  width: max(896px, 35vw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 2.5rem 2rem;
}

#feed-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
  margin-bottom: 1rem;
}

.feed-day-card {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin-bottom: 0.6rem;
}

.feed-day-header {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  margin-bottom: 0.5rem;
}

.feed-entry {
  font-size: 0.85rem;
  color: #d1d5db;
  padding: 0.2rem 0;
  line-height: 1.4;
}

.feed-user  { font-weight: 600; color: #f5a623; }
.feed-book  { font-weight: 600; color: #e2e8f0; }
.feed-run   { font-size: 0.75rem; color: #fde047; }
.feed-verb.died    { color: #e74c3c; }
.feed-verb.lost    { color: #e74c3c; }
.feed-verb.won     { color: #27ae60; }
.feed-verb.neutral { color: #9ca3af; }
.feed-level { font-weight: 600; color: #67e8f9; }
.feed-title { color: #0891b2; font-style: italic; font-weight: 600; }
.feed-ability { color: #a78bfa; font-size: 0.88em; }

.feed-empty {
  font-size: 0.8rem;
  color: #4b5563;
}

#landing-right {
  position: fixed;
  right: 0;
  top: 0;
  width: 480px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #1f2937;
  padding: 2.5rem 1.5rem;
  overflow-y: auto;
  background: #111827;
  transition: transform 0.25s ease;
}
body.right-collapsed #landing-right { transform: translateX(480px); }

/* ── Panel toggle buttons ─────────────────────────────────────────── */

.panel-toggle {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 200;
  width: 16px;
  height: 52px;
  background: #1f2937;
  border: 1px solid #374151;
  color: #6b7280;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, left 0.25s ease, right 0.25s ease;
  padding: 0;
}
.panel-toggle:hover { color: #f9fafb; border-color: #6b7280; }
.panel-toggle.visible { display: flex; }

#covers-toggle {
  left: 480px;
  border-left: none;
  border-radius: 0 4px 4px 0;
}
body.covers-collapsed #covers-toggle { left: 0; }

#right-toggle {
  right: 480px;
  border-right: none;
  border-radius: 4px 0 0 4px;
}
body.right-collapsed #right-toggle { right: 0; }

#sidebar-toggle {
  left: 270px;
  border-left: none;
  border-radius: 0 4px 4px 0;
  transition: color 0.15s, border-color 0.15s, left 0.25s ease;
}
body.sidebar-collapsed #sidebar-toggle { left: 0; }

/* ── Login screen ─────────────────────────────────────────────── */

#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

#login-screen h1 {
  font-size: 2.4rem;
  color: #f5a623;
  letter-spacing: -0.5px;
}

.login-sub {
  color: #6b7280;
  font-size: 0.95rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 280px;
}

.auth-error {
  font-size: 0.8rem;
  color: #f87171;
}

.auth-alt-btn {
  background: none;
  border: 1px solid #374151;
  border-radius: 7px;
  color: #9ca3af;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auth-alt-btn:hover { background: #1f2937; color: #d1d5db; }

/* ── Books screen ─────────────────────────────────────────────── */

#books-screen {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
}

.books-container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.books-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.books-header h2 {
  font-size: 1.6rem;
  color: #f5a623;
  font-weight: 700;
}

.books-header-right {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.books-username {
  font-size: 0.85rem;
  color: #6b7280;
}

.logout-btn {
  background: none;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #9ca3af;
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.12s;
}
.logout-btn:hover { background: #1f2937; color: #d1d5db; }

.books-empty {
  font-size: 0.85rem;
  color: #4b5563;
  padding: 0.5rem 0;
}

#books-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.book-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
}

.book-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.book-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-sections {
  font-size: 0.78rem;
  color: #6b7280;
}

.book-isbn {
  color: #4b5563;
  font-variant-numeric: tabular-nums;
}

.book-ids {
  font-size: 0.72rem;
  color: #374151;
}

.book-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  flex-shrink: 0;
}

.book-actions .primary-btn {
  width: 100%;
  padding: 0.2rem 0.5rem;
  font-size: 0.82rem;
}

.book-secondary-actions {
  display: flex;
  gap: 0.25rem;
  width: 100%;
}

.book-edit-btn {
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-radius: 7px;
  padding: 0.15rem 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  flex: 1;
}
.book-edit-btn:hover { background: #4b5563; }

.book-del-btn {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #6b7280;
  padding: 0.15rem 0.4rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.12s;
}
.book-del-btn:hover { background: #7f1d1d; border-color: #991b1b; color: #fca5a5; }

.new-book-form {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.3rem;
}

.new-book-title {
  font-size: 0.8rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.new-book-form textarea {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  font-family: inherit;
  resize: vertical;
  line-height: 1.5;
  width: 100%;
  box-sizing: border-box;
}
.new-book-form textarea:focus { outline: none; border-color: #f5a623; }
.new-book-form textarea::placeholder { color: #4b5563; }


/* ── Main screen ──────────────────────────────────────────────── */

#main-screen {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 270px;
  min-width: 270px;
  background: #1f2937;
  border-right: 1px solid #374151;
  display: flex;
  flex-direction: column;
  padding: 0.9rem;
  gap: 0.9rem;
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease, border-width 0.25s ease;
}
body.sidebar-collapsed #sidebar {
  width: 0;
  min-width: 0;
  padding: 0;
  border-right-width: 0;
}

/* Floating elements reposition when sidebar collapses */
body.sidebar-collapsed #run-trail-float { left: 12px; }
body.sidebar-collapsed #dice-roller     { left: 12px; }
body.sidebar-collapsed #play-btns-bar   { left: calc((100vw - var(--legend-w)) / 2); }

#graph-container {
  flex: 1;
  background: #0f172a;
}

/* ── Book title ───────────────────────────────────────────────── */

.book-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

#book-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f5a623;
  padding: 0.2rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

#edit-book-btn {
  background: none;
  border: none;
  color: #4b5563;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}
#edit-book-btn:hover { color: #f5a623; background: #374151; }

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

#edit-book-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-book-modal-overlay.active { display: flex; }

#edit-book-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 1rem 1.1rem;
  width: 320px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  overflow-y: auto;
}

/* ── Book cover upload ────────────────────────────────────────── */

.cover-upload-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.cover-upload-group > label {
  font-size: 0.8rem;
  color: #9ca3af;
}

.optional-hint {
  color: #4b5563;
  font-size: 0.75rem;
}

.cover-preview-wrap {
  width: 100px;
  height: 150px;           /* 2:3 ratio */
  border: 1px solid #374151;
  border-radius: 6px;
  overflow: hidden;
  background: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.cover-placeholder {
  font-size: 0.75rem;
  color: #4b5563;
  text-align: center;
}

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

#stats {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

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

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

.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-value {
  color: #f5a623;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── Buttons ──────────────────────────────────────────────────── */

.primary-btn {
  background: #f5a623;
  color: #111827;
  border: none;
  border-radius: 7px;
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}
.primary-btn:hover { background: #e09518; }

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

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

.section-display {
  font-size: 2rem;
  font-weight: 700;
  color: #f5a623;
  text-align: center;
  line-height: 1;
  padding: 0.3rem 0;
}

.section-label {
  text-align: center;
  font-size: 0.72rem;
  color: #6b7280;
  margin-top: -0.3rem;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.undo-run-btn {
  display: block;
  width: 100%;
  margin-bottom: 0;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
}
.undo-run-btn:hover:not(:disabled) { background: #4b5563; color: #f3f4f6; }
.undo-run-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.fasttravel-btn {
  display: block;
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-top: 1px solid #6b7280;
  border-radius: 0 0 4px 4px;
  cursor: pointer;
  text-align: center;
}
.fasttravel-btn:hover:not(:disabled) { background: #4b5563; color: #f3f4f6; }
.fasttravel-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.battle-death-btn {
  display: block;
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  background: #431407;
  color: #fb923c;
  border: 1px solid #7c2d12;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
}
.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: 1.4rem;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  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; }

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

.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: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.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: 2.4rem;
  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;
}

/* ── Inputs ───────────────────────────────────────────────────── */

/* Publication type selector + identifier fields */
.pub-type-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  width: 100%;
}

.pub-type-select {
  flex-shrink: 0;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  padding: 0.45rem 1.7rem 0.45rem 0.6rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%236b7280' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  transition: border-color 0.15s;
}
.pub-type-select:focus {
  outline: none;
  border-color: #f5a623;
}

.pub-id-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.pub-id-fields input {
  width: 100%;
}

input[type="text"],
input[type="number"],
input[type="password"] {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  padding: 0.45rem 0.75rem;
  font-size: 0.88rem;
  width: 100%;
  transition: border-color 0.15s;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: #f5a623;
}
input[type="text"]:disabled,
input[type="password"]:disabled {
  opacity: 0.6;
  cursor: default;
  background: #1f2937;
  color: #9ca3af;
}

/* ── 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-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.35rem 0.6rem;
}

.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-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.run-item-viewing {
  border-color: #3d9be9;
}

.run-load-btn, .run-view-btn, .run-del-btn {
  background: #1f2937;
  color: #9ca3af;
  border: 1px solid #374151;
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  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.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  color: #6b7280;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.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; }

/* ── Public modal ──────────────────────────────────────────────── */
.pub-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
.pub-overlay.active { display: flex; }

.pub-modal {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 10px;
  width: min(560px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.7);
}
.pub-modal.pub-modal--run {
  width: 75vw;
  height: 75vh;
  max-height: none;
}

.pub-modal-hdr {
  display: flex;
  align-items: center;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #1f2937;
  gap: 0.75rem;
  flex-shrink: 0;
}

.pub-modal-hdr span {
  flex: 1;
  font-weight: 600;
  color: #f5a623;
  font-size: 0.95rem;
}

.pub-back-btn {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.2rem 0.4rem;
}
.pub-back-btn:hover { color: #e2e8f0; }

.pub-close-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
}
.pub-close-btn:hover { color: #e2e8f0; }

.pub-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

#pub-graph-container {
  width: 100%;
  height: 100%;
  min-height: 400px;
}

.pub-profile-header {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding-bottom: 1.2rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #1f2937;
}

.pub-profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.pub-profile-avatar-placeholder {
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: #9ca3af;
}

.pub-profile-info {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.pub-profile-username {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f5a623;
}

.pub-level-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: #f5a623;
  background: rgba(245,166,35,0.12);
  border-radius: 4px;
  padding: 1px 6px;
}
.pub-level-title {
  font-size: 0.78rem;
  color: #9ca3af;
}

.pub-profile-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.pub-stat {
  font-size: 0.8rem;
  color: #6b7280;
}

.pub-stat-val {
  font-weight: 700;
  color: #d1d5db;
}

.pub-stat-win  .pub-stat-val { color: #4ade80; }
.pub-stat-death .pub-stat-val { color: #f87171; }

.pub-book {
  margin-bottom: 1.5rem;
}

.pub-book-name {
  font-weight: 600;
  color: #e2e8f0;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.pub-run-btn {
  display: block;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  margin-bottom: 0.3rem;
  cursor: pointer;
  font-size: 0.82rem;
  text-align: left;
  width: 100%;
}
.pub-run-btn:hover { background: #2d3748; border-color: #4b5563; }
.pub-run-btn.pub-run-death { color: #f87171; }
.pub-run-btn.pub-run-win   { color: #4ade80; }

.pub-run-locked {
  display: block;
  padding: 0.4rem 0.75rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  color: #4b5563;
}

.pub-loading, .pub-error, .pub-empty {
  color: #6b7280;
  font-size: 0.85rem;
}

/* ── Book modal header ────────────────────────────────────────── */

.book-modal-header {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding-bottom: 0.9rem;
  margin-bottom: 0.9rem;
  border-bottom: 1px solid #374151;
}

.book-modal-cover {
  width: 72px;
  height: auto;
  border-radius: 4px;
  flex-shrink: 0;
  object-fit: cover;
}

.book-modal-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.book-modal-sections {
  font-size: 0.8rem;
  color: #9ca3af;
}

.book-modal-ids {
  font-size: 0.75rem;
  color: #6b7280;
  font-family: 'Consolas', monospace;
}

.book-modal-authors {
  font-size: 0.8rem;
  color: #d1d5db;
  font-style: italic;
}

.book-modal-description {
  font-size: 0.85rem;
  color: #9ca3af;
  line-height: 1.5;
  margin-top: 0.25rem;
}

/* ── Star rating widget ───────────────────────────────────────── */

.star-rating {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  margin-top: 0.15rem;
  cursor: pointer;
  user-select: none;
}

.star-rating .star {
  font-size: 1.15rem;
  line-height: 1;
  color: #374151;
  transition: color 0.07s;
}

.star-rating .star.on   { color: #f5a623; }

.star-rating .star.half {
  background: linear-gradient(90deg, #f5a623 50%, #374151 50%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.star-label {
  font-size: 0.75rem;
  color: #6b7280;
  margin-left: 0.4rem;
  transition: color 0.15s;
}

.star-xp-flash { color: #4ade80 !important; font-weight: 600; }

/* ── Cover activity view ──────────────────────────────────────── */

.cover-activity-view {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cover-act-entry {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.9rem 1rem;
}

.cover-act-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.cover-act-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.cover-act-avatar-ph {
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #9ca3af;
}

.cover-act-username {
  background: none;
  border: none;
  color: #f5a623;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
}
.cover-act-username:hover { text-decoration: underline; }

.cover-act-username-plain {
  color: #e2e8f0;
  font-weight: 600;
  font-size: 0.9rem;
}

.cover-act-altname {
  font-size: 0.72rem;
  color: #6b7280;
  font-style: italic;
  margin-bottom: 0.5rem;
}

.cover-act-runs {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

/* Feed clickable links */
.feed-user-pub {
  background: none;
  border: none;
  font-weight: 600;
  color: #f5a623;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.feed-user-pub:hover { color: #fbbf24; }

.feed-verb-pub {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.feed-verb-pub.died { color: #e74c3c; }
.feed-verb-pub.died:hover { color: #f87171; }
.feed-verb-pub.lost { color: #e74c3c; }
.feed-verb-pub.lost:hover { color: #f87171; }
.feed-verb-pub.won  { color: #27ae60; }
.feed-verb-pub.won:hover  { color: #4ade80; }

.feed-book-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  font-weight: 600;
  color: #e2e8f0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.feed-book-btn:hover { color: #f5a623; }

/* Feed image preview */
#feed-img-preview {
  position: fixed;
  z-index: 9999;
  display: none;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  pointer-events: none;
}
#feed-img-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, #0891b2, #67e8f9);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}
#feed-img-preview-img {
  display: block;
  object-fit: cover;
}

/* Profile public toggle */
.profile-public-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.profile-public-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #d1d5db;
  font-size: 0.9rem;
  cursor: pointer;
}
.profile-public-hint {
  font-size: 0.75rem;
  color: #6b7280;
}

/* ── Custom scrollbars (global) ───────────────────────────────── */

* {
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
}
*::-webkit-scrollbar { width: 5px; height: 5px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: #4b5563; }

/* ── 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;
}
.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 {
  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);
  display: flex;
  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;
}

/* ── Dice roller ──────────────────────────────────────────────── */

#dice-roller {
  position: fixed;
  bottom: 1rem;
  left: calc(var(--sidebar-w) + 12px);
  z-index: 10;
  background: rgba(31, 41, 55, 0.9);
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.4rem 0.6rem 0.5rem;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  min-width: 180px;
  display: none; /* shown only in tracker */
  transition: left 0.25s ease;
}
#dice-roller.visible { display: block; }

#dice-roller-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

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

.dice-collapse-btn {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: transform 0.15s;
}
.dice-collapse-btn:hover { color: #d1d5db; }
#dice-roller.dice-collapsed .dice-collapse-btn { transform: rotate(-90deg); }

#dice-roller-body {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#dice-roller.dice-collapsed #dice-roller-body { display: none; }

.dice-count-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.dice-adj-btn {
  background: #374151;
  border: 1px solid #4b5563;
  color: #d1d5db;
  border-radius: 5px;
  width: 1.6rem;
  height: 1.6rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
.dice-adj-btn:hover { background: #4b5563; }

#dice-count-input {
  width: 2rem;
  text-align: center;
  background: #111827;
  border: 1px solid #4b5563;
  color: #f9fafb;
  border-radius: 5px;
  font-size: 0.85rem;
  padding: 0.2rem 0;
}

#dice-throw-btn {
  flex: 1;
  background: #4b5563;
  border: 1px solid #6b7280;
  color: #9ca3af;
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
#dice-throw-btn:hover { background: #6b7280; }

#dice-result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  min-height: 0;
}
#dice-result:empty { display: none; }

.die-face {
  width: 2.5rem;
  height: 2.5rem;
  background: #1f2937;
  border: 2px solid #6b7280;
  border-radius: 7px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 0.28rem;
  gap: 0.05rem;
  color: #f9fafb;
  flex-shrink: 0;
  box-sizing: border-box;
  animation: die-pop 0.18s ease-out;
}
.die-face[data-val="6"] { border-color: #f5a623; color: #f5a623; }
.die-face[data-val="1"] { border-color: #dc2626; color: #ef4444; }
.die-face.no-anim { animation: none; }

.die-pip {
  border-radius: 50%;
  width: 0.3rem;
  height: 0.3rem;
  margin: auto;
}
.die-pip.on { background: currentColor; }

.dice-sum {
  font-size: 1.05rem;
  font-weight: 700;
  color: #9ca3af;
  padding: 0 0.2rem;
}
.dice-sum-sep {
  color: #6b7280;
  font-size: 0.85rem;
}

@keyframes die-pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

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

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

#data-controls button {
  background: #1f2937;
  color: #9ca3af;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.45rem;
  cursor: pointer;
  font-size: 0.78rem;
  transition: background 0.12s, color 0.12s;
  width: 100%;
}
#data-controls button:hover { background: #374151; color: #d1d5db; }
#reset-btn { color: #f87171 !important; }
#reset-btn:hover { background: #7f1d1d !important; border-color: #991b1b !important; }


/* ── Avatar circle ────────────────────────────────────────────── */

.avatar-circle {
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #374151 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236b7280'%3E%3Cpath d='M12 12c2.7 0 4.8-2.1 4.8-4.8S14.7 2.4 12 2.4 7.2 4.5 7.2 7.2 9.3 12 12 12zm0 2.4c-3.2 0-9.6 1.6-9.6 4.8v2.4h19.2v-2.4c0-3.2-6.4-4.8-9.6-4.8z'/%3E%3C/svg%3E") center/60% no-repeat;
  border: 2px solid #4b5563;
  overflow: hidden;
  flex-shrink: 0;
  vertical-align: middle;
}
.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-large {
  width: 80px;
  height: 80px;
}

/* ── Profile button ───────────────────────────────────────────── */

.profile-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  transition: opacity 0.12s;
}
.profile-btn:hover { opacity: 0.75; }

/* ── Feedback & Inbox ─────────────────────────────────────────── */

.inbox-badge {
  display: inline-block;
  background: #ef4444;
  color: #fff;
  border-radius: 9999px;
  font-size: 0.65rem;
  padding: 0 0.35em;
  margin-left: 0.25rem;
  vertical-align: middle;
  line-height: 1.4;
}

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

#feedback-modal,
#inbox-modal {
  background: var(--bg-card, #1f2937);
  border-radius: 0.75rem;
  padding: 1.5rem;
  width: min(480px, 95vw);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#feedback-message-input {
  width: 100%;
  resize: none;
  min-height: 5rem;
  box-sizing: border-box;
}

#inbox-modal {
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}
#inbox-threads-view,
#inbox-conv-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0.75rem;
}
#inbox-threads-view .modal-actions {
  justify-content: flex-end;
}
#inbox-close-btn {
  flex: none !important;
  padding: 0.25rem 0.65rem !important;
  font-size: 0.78rem !important;
}
#feedback-modal .modal-actions {
  justify-content: flex-end;
}
#feedback-modal .modal-actions .primary-btn,
#feedback-cancel-btn {
  flex: none !important;
  width: auto !important;
  padding: 0.25rem 0.65rem !important;
  font-size: 0.78rem !important;
}
#inbox-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
  max-height: 50vh;
}
.inbox-item {
  border: 1px solid #374151;
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.inbox-item:hover { border-color: #6b7280; }
.inbox-item--unread {
  border-color: #7c3aed;
  background: rgba(124,58,237,.08);
}
.inbox-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
}
.inbox-item-date  { color: #9ca3af; }
.inbox-item-count { color: #6b7280; }
.inbox-item-preview {
  color: #9ca3af;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inbox-empty { color: #9ca3af; text-align: center; padding: 1rem 0; }

.inbox-conv-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.inbox-conv-date { font-size: 0.8rem; color: #9ca3af; }
#inbox-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 100px;
  max-height: 40vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.25rem 0;
}
.inbox-msg {
  max-width: 80%;
  padding: 0.45rem 0.7rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  word-break: break-word;
}
.inbox-msg--user {
  align-self: flex-end;
  background: #1d4ed8;
  color: #fff;
  border-bottom-right-radius: 0.2rem;
}
.inbox-msg--admin {
  align-self: flex-start;
  background: #374151;
  color: #e5e7eb;
  border-bottom-left-radius: 0.2rem;
}
.inbox-msg-body { white-space: pre-wrap; }
.inbox-msg-time {
  font-size: 0.65rem;
  opacity: 0.55;
  margin-top: 0.15rem;
  text-align: right;
}
.inbox-msg--admin .inbox-msg-time { text-align: left; }
#inbox-reply-area { display: flex; flex-direction: column; }
#inbox-back-btn {
  background: none;
  border: 1px solid #4b5563;
  border-radius: 6px;
  color: #9ca3af;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.75rem;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}
#inbox-back-btn:hover { border-color: #6b7280; color: #e2e8f0; }

#inbox-reply-input {
  width: 100%;
  box-sizing: border-box;
  resize: none;
  min-height: 4rem;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #e5e7eb;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
  padding: 0.5rem 0.6rem;
  transition: border-color 0.15s;
}
#inbox-reply-input:focus { outline: none; border-color: #6b7280; }
#inbox-reply-input::placeholder { color: #4b5563; }
.inbox-conv-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
/* Use class+ID specificity to beat both .primary-btn (class) and #id (ID) rules */
.inbox-conv-actions #inbox-reply-send-btn,
.inbox-conv-actions #inbox-conv-delete-btn,
.inbox-conv-actions #inbox-conv-close-btn {
  flex: none;
  width: auto;
  padding: 0.35rem 1rem;
  font-size: 0.88rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: 7px;
  cursor: pointer;
}
.inbox-conv-actions #inbox-conv-delete-btn {
  background: #dc2626;
  color: #fff;
  border: none;
}
.inbox-conv-actions #inbox-conv-delete-btn:hover { background: #b91c1c; }
.inbox-conv-actions #inbox-conv-close-btn { margin-left: auto; }

/* ── Profile modal ────────────────────────────────────────────── */

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

#profile-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 1.1rem;
  width: 360px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
}
#profile-modal::-webkit-scrollbar { width: 5px; }
#profile-modal::-webkit-scrollbar-track { background: transparent; }
#profile-modal::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
#profile-modal::-webkit-scrollbar-thumb:hover { background: #4b5563; }

.profile-avatar-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#profile-xp-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
}

#profile-level-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

#profile-level-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: #f5a623;
}

#profile-title-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
}

#profile-xp-bar {
  height: 6px;
  background: #1f2937;
  border-radius: 3px;
  overflow: hidden;
}

#profile-xp-bar-fill {
  height: 100%;
  background: linear-gradient(to right, #f5a623, #fbbf24);
  border-radius: 3px;
  transition: width 0.4s ease;
}

#profile-xp-text {
  font-size: 0.72rem;
  color: #6b7280;
  text-align: right;
}

.profile-section-divider {
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-top: 1px solid #374151;
  padding-top: 0.4rem;
  margin-top: 0;
}

.profile-success {
  font-size: 0.85rem;
  color: #34d399;
}

.secondary-btn {
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-radius: 7px;
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.12s;
}
.secondary-btn:hover { background: #4b5563; }

/* ── Crop modal ───────────────────────────────────────────────── */

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

#crop-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.7);
  align-items: center;
}

.crop-hint {
  font-size: 0.82rem;
  color: #6b7280;
  text-align: center;
}

#crop-viewport {
  position: relative;
  width: 320px;
  height: 320px;
  overflow: hidden;
  background: #111827;
  border-radius: 6px;
  cursor: grab;
  user-select: none;
}
#crop-viewport:active { cursor: grabbing; }

#crop-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

#crop-frame {
  position: absolute;
  inset: 0;
  border: 3px solid #f5a623;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
}

/* ── Language switcher (UI hidden; infrastructure kept for future use) ── */

/* ── Character sheet ─────────────────────────────────────────────────────────
   Remove block + charsheet.js + import lines in main.js/ui.js to uninstall.  */

/* Play area button bar (Guide + Notebook) */
#play-btns-bar {
  display: none;
  position: fixed;
  bottom: 1rem;
  left: calc((100vw + var(--sidebar-w)) / 2);
  transform: translateX(-50%);
  z-index: 100;
  gap: 0.4rem;
  align-items: center;
  transition: left 0.25s ease;
}
#guide-btn, #notebook-btn {
  background: rgba(31, 41, 55, 0.88);
  border: 1px solid #374151;
  border-radius: 7px;
  color: #9ca3af;
  padding: 0.4rem 0.85rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  white-space: nowrap;
}
#guide-btn:hover, #notebook-btn:hover { background: #374151; }

/* Guide modal */
#guide-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
#guide-modal-overlay.active { display: flex; }
#guide-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  width: min(900px, 95vw);
  height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  overflow: hidden;
}
#guide-modal-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #374151;
  color: #f3f4f6;
  font-size: 0.88rem;
  font-weight: 600;
  flex-shrink: 0;
}
#guide-modal-close {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
#guide-modal-close:hover { background: #374151; color: #f3f4f6; }
#guide-modal-frame {
  flex: 1;
  border: none;
  width: 100%;
}

/* Notebook modal */
#notebook-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
#notebook-modal-overlay.active { display: flex; }
#notebook-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  width: min(600px, 92vw);
  height: min(520px, 80vh);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.7rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#notebook-modal-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
#notebook-modal-title {
  color: #f5a623;
  font-size: 0.82rem;
  font-weight: 600;
}
#notebook-modal-close {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
#notebook-modal-close:hover { background: #374151; color: #f3f4f6; }
#notebook-modal-input {
  flex: 1;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.55;
  padding: 0.6rem 0.75rem;
  resize: none;
  outline: none;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
}
#notebook-modal-input:focus { border-color: #6b7280; }
#notebook-modal-input::placeholder { color: #4b5563; }
#notebook-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  flex-shrink: 0;
}
#notebook-modal-cancel {
  background: #374151;
  color: #9ca3af;
  border: 1px solid #4b5563;
  border-radius: 7px;
  padding: 0.28rem 0.65rem;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
}
#notebook-modal-cancel:hover { background: #4b5563; }
#notebook-modal-save {
  flex: none !important;
  width: auto !important;
  padding: 0.28rem 0.7rem !important;
  font-size: 0.78rem !important;
}

/* Open button */
#charsheet-btn {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 100;
  background: rgba(31, 41, 55, 0.88);
  border: 1px solid #374151;
  border-radius: 7px;
  color: #9ca3af;
  padding: 0.4rem 0.85rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
#charsheet-btn:hover { background: #374151; }

/* Compact plain-text display — no background, just text */
#charsheet-display {
  position: fixed;
  bottom: 3.1rem;
  right: 1rem;
  z-index: 100;
  font-size: 0.75rem;
  color: #e5e7eb;
  line-height: 1.65;
  pointer-events: none;
  text-align: right;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6);
}
.cs-line  { display: block; }
.cs-label { color: #9ca3af; }

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

.cs-modal {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
  width: min(700px, 95vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.cs-modal-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #374151;
  color: #f3f4f6;
  font-size: 0.88rem;
  font-weight: 600;
  flex-shrink: 0;
}
#cs-modal-close {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
#cs-modal-close:hover { background: #374151; color: #f3f4f6; }

.cs-field-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 80px;
}
.cs-empty {
  color: #6b7280;
  font-size: 0.8rem;
  text-align: center;
  padding: 1.5rem 1rem;
  margin: 0;
}

/* Field rows */
.cs-field-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: #111827;
  border: 1px solid #2d3748;
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
}

/* Drag handle */
.cs-drag-handle {
  cursor: grab;
  color: #4b5563;
  font-size: 1rem;
  flex-shrink: 0;
  user-select: none;
  padding: 0 0.1rem;
}
.cs-drag-handle:active { cursor: grabbing; }
.cs-field-row.cs-dragging  { opacity: 0.35; }
.cs-field-row.cs-drag-over { border-color: #f5a623; background: #1a2236; }

/* Visible toggle */
.cs-vis-toggle {
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.cs-vis-toggle input { display: none; }
.cs-dot {
  display: inline-block;
  width: 2rem;
  height: 1.1rem;
  border-radius: 999px;
  background: #374151;
  border: 1px solid #4b5563;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.cs-dot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: #6b7280;
  transition: left 0.15s, background 0.15s;
}
.cs-vis-toggle input:checked + .cs-dot {
  background: rgba(96, 165, 250, 0.2);
  border-color: #60a5fa;
}
.cs-vis-toggle input:checked + .cs-dot::after {
  left: calc(100% - 0.7rem - 3px);
  background: #60a5fa;
}

/* Name input */
.cs-name-inp {
  flex: 2;
  min-width: 80px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 4px;
  color: #f3f4f6;
  padding: 0.22rem 0.45rem;
  font-size: 0.8rem;
}

/* Type selector */
.cs-type-sel {
  flex: 0 0 90px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 4px;
  color: #d1d5db;
  padding: 0.22rem 0.3rem;
  font-size: 0.8rem;
}

/* Value wrapper */
.cs-val-wrap {
  flex: 3;
  min-width: 100px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

/* Number field — hide native spinners, use custom ±  */
.cs-val-num,
.cs-num-wrap input[type="number"],
.cs-num-wrap input[type="text"] { -moz-appearance: textfield; text-align: center; }
.cs-val-num::-webkit-inner-spin-button,
.cs-val-num::-webkit-outer-spin-button,
.cs-num-wrap input[type="number"]::-webkit-inner-spin-button,
.cs-num-wrap input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.sections-pages-row {
  display: flex;
  gap: 0.75rem;
}
.sections-pages-col {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 0;
}

.cs-num-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
}
.cs-num-wrap .cs-val-num {
  flex: 1;
  min-width: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
}
.cs-num-btn {
  flex-shrink: 0;
  width: 26px;
  background: #2d3748;
  border: 1px solid #374151;
  color: #9ca3af;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.22rem 0;
  transition: background 0.1s, color 0.1s;
  font-family: inherit;
}
.cs-num-btn:first-child { border-radius: 4px 0 0 4px; }
.cs-num-btn:last-child  { border-radius: 0 4px 4px 0; }
.cs-num-btn:hover { background: #374151; color: #f3f4f6; }

/* Value inputs (shared) */
.cs-val {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 4px;
  color: #f3f4f6;
  padding: 0.22rem 0.45rem;
  font-size: 0.8rem;
  width: 100%;
  box-sizing: border-box;
}
select.cs-val { color: #d1d5db; }

.cs-bool-wrap { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.cs-bool-label { font-size: 0.8rem; color: #d1d5db; }

/* Enum options config (smaller, de-emphasised) */
.cs-enum-opts {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 4px;
  color: #6b7280;
  padding: 0.18rem 0.45rem;
  font-size: 0.72rem;
  width: 100%;
  box-sizing: border-box;
}

/* Delete button */
.cs-del-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  flex-shrink: 0;
}
.cs-del-btn:hover { background: #7f1d1d; color: #f87171; }

/* Footer */
.cs-modal-ftr {
  padding: 0.7rem 1rem;
  border-top: 1px solid #374151;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 0.5rem;
}
.cs-ftr-actions {
  display: flex;
  gap: 0.4rem;
}
.cs-btn-add {
  background: none;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  padding: 0.38rem 0.85rem;
}
.cs-btn-add:hover { background: #374151; color: #f3f4f6; }
.cs-btn-cancel {
  background: none;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  padding: 0.38rem 0.85rem;
}
.cs-btn-cancel:hover { background: #374151; color: #f3f4f6; }
.cs-btn-template {
  background: none;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  padding: 0.38rem 0.85rem;
}
.cs-btn-template:hover { background: #374151; color: #f3f4f6; }
.cs-btn-save {
  background: #1d4ed8;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  padding: 0.38rem 0.85rem;
}
.cs-btn-save:hover { background: #2563eb; }

/* ── Admin badge ──────────────────────────────────────────────── */

.admin-badge {
  color: #60a5fa;
  font-size: 0.65em;
  margin-left: 0.2em;
  vertical-align: super;
  cursor: default;
  user-select: none;
}

/* ── Responsive: compact sidebar for short viewports (e.g. 1366×768) ── */

@media (max-height: 750px) {
  #sidebar {
    padding: 0.5rem;
    gap: 0.45rem;
  }

  #stats {
    padding: 0.35rem 0.6rem;
    gap: 0.15rem;
  }

  .stats-row {
    font-size: 0.76rem;
  }

  .section-display {
    font-size: 1.35rem;
    padding: 0.1rem 0;
  }

  .section-label {
    font-size: 0.68rem;
    margin-top: -0.15rem;
    margin-bottom: 0.1rem;
  }

  .undo-run-btn,
  .fasttravel-btn,
  .battle-death-btn {
    padding: 0.15rem 0.5rem;
  }

  .choices-label {
    font-size: 0.72rem;
  }

  .choice-btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
  }

  #sidebar .primary-btn {
    padding: 0.4rem 0.75rem;
  }

  .input-group {
    gap: 0.2rem;
  }

  .runs-section {
    margin-top: 0.25rem;
    padding-top: 0.35rem;
  }

  #data-controls {
    padding-top: 0.25rem;
    gap: 0.2rem;
  }

  #data-controls button {
    padding: 0.3rem;
  }
}
