/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed; top: 48px; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--card-border);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform .3s var(--ease);
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--card-border);
}

.logo {
  font-family: var(--font-head);
  font-size: 22px; font-weight: 700;
  color: var(--gold-l);
  letter-spacing: 1.5px;
}

.logo-sub {
  font-size: 11px; color: var(--text3);
  text-transform: uppercase; letter-spacing: .5px;
  margin-top: 2px;
}

/* Main nav */
.nav-section { padding: 12px 0; }
.nav-section + .nav-section { border-top: 1px solid var(--card-border); }

.nav-label {
  padding: 6px 20px;
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text3);
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  font-size: 14px; color: var(--text2);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .15s;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,.03); }
.nav-item.active {
  color: var(--gold-l);
  border-left-color: var(--gold);
  background: var(--gold-dim);
}

.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-count {
  margin-left: auto;
  font-size: 11px; color: var(--text3);
  background: var(--bg4);
  padding: 1px 7px; border-radius: 10px;
}

/* Sub-nav (encyclopedia sections) */
.nav-sub { padding-left: 20px; }
.nav-sub .nav-item { padding: 7px 20px; font-size: 13px; }

/* Nav group (collapsible, e.g. magic) */
.nav-group-toggle { position: relative; }
.nav-arrow {
  margin-left: auto;
  font-size: 10px;
  transition: transform .2s;
  color: var(--text3);
}
.nav-group.open .nav-arrow { transform: rotate(90deg); }
.nav-group-items {
  display: none;
  padding-left: 16px;
}
.nav-group.open .nav-group-items { display: block; }
.nav-child { padding: 5px 20px; font-size: 12px; }

/* Lore arc navigation */
.nav-book .expand-arrow {
  margin-left: auto;
  font-size: 10px;
  transition: transform .2s;
  color: var(--text3);
}
.nav-book.expanded .expand-arrow { transform: rotate(90deg); }
.arc-list {
  display: none;
  padding-left: 16px;
}
.arc-list.open { display: block; }
.nav-arc {
  padding: 6px 20px;
  font-size: 13px;
}
.arc-loading { font-size: 12px; color: var(--text3); padding: 6px 20px; cursor: default; }

/* Lore nav extras */
.nav-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 12px;
}
.nav-series {
  cursor: pointer;
}
.nav-series.active {
  background: var(--bg3);
  color: var(--gold);
}

/* Sidebar Lore nav */
#sidebar-lore-nav {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding-bottom: 16px;
}

/* Sidebar TOC for reader */
#sidebar-toc {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.toc-books { flex: 1; overflow-y: auto; padding: 8px 0; }

.toc-book-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 20px;
  font-family: var(--font-head);
  font-size: 15px; font-weight: 600;
  color: var(--text2);
  cursor: pointer;
  transition: color .15s;
}
.toc-book-header:hover { color: var(--gold-l); }
.toc-book-header .arrow {
  font-size: 10px;
  transition: transform .2s;
}
.toc-book-header.open .arrow { transform: rotate(90deg); }

.toc-chapters { display: none; }
.toc-chapters.open { display: block; }

.toc-chapter {
  display: block;
  padding: 5px 20px 5px 40px;
  font-size: 13px; color: var(--text3);
  cursor: pointer;
  transition: all .15s;
  border-left: 2px solid transparent;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.toc-chapter:hover { color: var(--text); background: rgba(255,255,255,.02); }
.toc-chapter.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: var(--gold-dim);
}
.toc-chapter.read { color: var(--text2); }

/* ===== Main content ===== */
.main {
  margin-left: var(--sidebar-w);
  margin-top: 48px;
  flex: 1; min-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
}

/* ===== Section containers ===== */
.section { display: none; flex: 1; flex-direction: column; }
.section.active { display: flex; }

/* ===== Reader ===== */
.reader-area {
  max-width: var(--content-w);
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.chapter-header {
  text-align: center;
  padding: 20px 0 40px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 40px;
}

.chapter-title {
  font-family: var(--font-head);
  font-size: 38px; font-weight: 700;
  color: var(--gold-l);
  line-height: 1.2;
}

.chapter-meta {
  font-size: 13px; color: var(--text3);
  margin-top: 8px;
}

/* Prose */
.chapter-content {
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.75;
  color: var(--text);
}

.chapter-content p {
  text-indent: 1.5em;
  margin-bottom: .6em;
  text-align: justify;
  hyphens: auto;
}
.chapter-content p:first-of-type { text-indent: 0; }

/* Drop cap — disabled */

.chapter-content h2, .chapter-content h3 {
  font-family: var(--font-head);
  color: var(--gold-l);
  margin: 1.5em 0 .5em;
}
.chapter-content h2 { font-size: 28px; }
.chapter-content h3 { font-size: 22px; }

.chapter-content blockquote {
  border-left: 3px solid var(--gold-d);
  padding: 8px 16px;
  margin: 1em 0;
  color: var(--text2);
  font-style: italic;
}

.chapter-content em { color: var(--text2); }
.chapter-content strong { color: var(--gold-l); font-weight: 600; }

.chapter-content hr {
  border: none;
  text-align: center;
  margin: 2em 0;
  color: var(--gold-d);
}
.chapter-content hr::after {
  content: '\25C6  \25C6  \25C6';
  font-size: 14px;
  letter-spacing: 8px;
}

/* Hide empty paragraphs (artifacts from markdown line breaks between dialogues) */
.chapter-content p:empty {
  display: none;
}

/* Dialogue lines (- replicas) */
.chapter-content p.dialogue {
  text-indent: 0;
  padding-left: 0;
}

/* Subvocalization (text in guillemets) */
.chapter-content p.subvocal {
  font-style: italic;
  text-indent: 0;
  padding-left: 1.5em;
  color: var(--text2);
}

/* AI messages */
.ai-msg {
  display: block;
  background: rgba(42,122,122,.08);
  border: 1px solid rgba(74,186,186,.2);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 1em 0;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--cyan-l);
  white-space: pre-line;
}
.ai-msg .ai-label {
  font-weight: 600;
  color: var(--cyan-l);
  margin-right: 6px;
}

/* Chapter navigation */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 40px 0;
  margin-top: 40px;
  border-top: 1px solid var(--card-border);
}

.chapter-nav-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  background: var(--bg3);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  font-size: 14px; color: var(--text2);
  transition: all .2s;
}
.chapter-nav-btn:hover {
  border-color: var(--gold-d);
  color: var(--gold-l);
}
.chapter-nav-btn:disabled {
  opacity: .3;
  pointer-events: none;
}

/* Reader settings */
.header-settings-wrap {
  position: relative;
}

.settings-panel {
  position: absolute;
  top: 100%; right: 0;
  margin-top: 8px;
  background: var(--bg2);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 16px;
  min-width: 200px;
  display: none;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 100;
}
.settings-panel.open { display: block; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0;
  font-size: 13px; color: var(--text2);
}

.setting-controls {
  display: flex; gap: 6px;
}

.setting-btn {
  width: 30px; height: 30px;
  background: var(--bg4);
  border-radius: 6px;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.setting-btn:hover { background: var(--gold-dim); color: var(--gold-l); }
.setting-btn.active { background: var(--gold-dim); color: var(--gold); border: 1px solid var(--gold-d); }

/* Scroll progress */
.scroll-progress {
  position: fixed; top: 48px; left: var(--sidebar-w); right: 0;
  height: 3px; z-index: 90;
  background: transparent;
}
.scroll-progress .bar {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-d), var(--gold-l));
  width: 0;
  transition: width .1s;
}

/* ===== Encyclopedia ===== */
.enc-header {
  padding: 32px 40px 24px;
}
.enc-header h2 {
  font-family: var(--font-head);
  font-size: 34px; font-weight: 700;
  color: var(--gold-l);
}
.enc-header .subtitle {
  font-size: 14px; color: var(--text3);
  margin-top: 4px;
}

.enc-filters {
  display: flex; flex-direction: column; gap: 12px;
  padding: 0 40px 20px;
}

.filter-btn {
  padding: 6px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  color: var(--text3);
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--gold-d); color: var(--text2); }
.filter-btn.active {
  background: var(--gold-dim);
  border-color: var(--gold-d);
  color: var(--gold);
}

/* Grid */
.enc-grid {
  display: grid;
  gap: 20px;
  padding: 0 40px 40px;
}
.enc-grid.grid-3 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.enc-grid.grid-4 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Cards */
.card {
  background: rgba(18,18,26,.85);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 20px;
  cursor: pointer;
  position: relative;
  transition: all .25s var(--ease);
}
.card:hover {
  border-color: var(--gold-d);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.card-head {
  display: flex; gap: 12px;
  margin-bottom: 12px;
}

.card-icon {
  width: 48px; height: 48px;
  background: var(--bg4);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

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

.card-title {
  font-family: var(--font-head);
  font-size: 20px; font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}
.card-subtitle {
  font-size: 12px; color: var(--text3);
  margin-top: 2px;
}

.card-desc {
  font-size: 13px; color: var(--text2);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}

.tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg4);
  color: var(--text3);
}
.tag-gold   { background: var(--gold-dim); color: var(--gold); }
.tag-red    { background: rgba(139,58,58,.2); color: var(--red-l); }
.tag-blue   { background: rgba(58,90,139,.2); color: var(--blue-l); }
.tag-green  { background: rgba(58,107,58,.2); color: var(--green-l); }
.tag-cyan   { background: rgba(42,122,122,.2); color: var(--cyan-l); }
.tag-purple { background: rgba(90,58,122,.2); color: var(--purple-l); }
.tag-orange { background: rgba(139,90,42,.2); color: var(--orange-l); }

/* Threat badge */
.threat {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head);
  font-size: 15px; font-weight: 700;
}
.threat-E { background: var(--bg4); color: var(--text3); }
.threat-D { background: rgba(58,107,58,.3); color: var(--green-l); }
.threat-C { background: rgba(58,90,139,.3); color: var(--blue-l); }
.threat-B { background: rgba(139,90,42,.3); color: var(--orange-l); }
.threat-A { background: rgba(139,58,58,.3); color: var(--red-l); }
.threat-S { background: var(--gold-dim); color: var(--gold-l); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease);
}
.modal-overlay.open {
  opacity: 1; pointer-events: auto;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--gold-d);
  border-radius: 12px;
  max-width: 640px; width: 94%;
  max-height: 90vh;
  padding: 32px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(20px) scale(.97);
  transition: transform .25s var(--ease);
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 20px;
}

.modal-portrait {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 2px solid var(--gold-d);
  background: var(--bg4);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-head);
  font-size: 26px; font-weight: 700;
  color: var(--gold-l);
}
.modal-subtitle {
  font-size: 13px; color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-top: 2px;
}

.modal-close {
  position: absolute; top: 0; right: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg4);
  font-size: 18px; color: var(--text3);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  z-index: 3;
}
.modal-close:hover { color: var(--text); background: var(--bg3); }

.modal-body { font-size: 14px; color: var(--text2); line-height: 1.7; overflow-y: auto; flex: 1; min-height: 0; }
.modal-top {
  flex-shrink: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--bg4);
  position: relative;
}
.modal-body h3 {
  font-family: var(--font-head);
  font-size: 18px; color: var(--gold);
  margin: 20px 0 8px;
}
.modal-body p { margin-bottom: 8px; }

.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }

.modal-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.stat {
  background: var(--bg4);
  border-radius: 6px;
  padding: 10px;
  text-align: center;
}
.stat-val {
  font-family: var(--font-head);
  font-size: 20px; font-weight: 700;
  color: var(--gold-l);
}
.stat-label {
  font-size: 11px; color: var(--text3);
  text-transform: uppercase;
}

/* Divider */
.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--card-border), transparent);
  margin: 16px 0;
}

/* ===== Lore ===== */
.lore-area, .scenario-area {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.lore-content {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
}
.lore-content h1 {
  font-family: var(--font-head);
  font-size: 34px; color: var(--gold-l);
  margin-bottom: 24px;
}
.lore-content h2 {
  font-family: var(--font-head);
  font-size: 26px; color: var(--gold);
  margin: 32px 0 12px;
}
.lore-content h3 {
  font-family: var(--font-head);
  font-size: 20px; color: var(--gold-d);
  margin: 24px 0 8px;
}
.lore-content p { margin-bottom: .8em; }
.lore-content ul, .lore-content ol {
  padding-left: 24px;
  margin-bottom: 1em;
}
.lore-content li { margin-bottom: .3em; }
.lore-content strong { color: var(--gold-l); }
.lore-content em { color: var(--text2); }
.lore-content hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--card-border), transparent);
  margin: 2em 0;
}

/* ===== Header bar ===== */
.header-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--bg2);
  border-bottom: 1px solid var(--card-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  z-index: 120;
}
.header-left, .header-right {
  display: flex; align-items: center; gap: 8px;
}
.header-btn {
  width: 36px; height: 36px;
  background: var(--bg3);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: all .15s;
}
.header-btn:hover { border-color: var(--gold-d); color: var(--gold-l); }
.header-btn.active { background: var(--gold-dim); border-color: var(--gold-d); color: var(--gold); }
.header-username {
  font-size: 13px; color: var(--text2); font-weight: 500;
}
.header-logout {
  width: auto; padding: 0 12px; font-size: 12px; color: var(--text3);
}
.header-logout:hover { border-color: var(--red); color: var(--red-l); }
.header-menu-btn { display: none; }
.header-toc-btn { display: none; }

/* ===== Mobile-only elements (hidden on desktop) ===== */
.bottom-tabs { display: none; }
.enc-mobile-pills { display: none; }

/* ===== Right sidebar (notes) ===== */
.sidebar-right {
  position: fixed; top: 48px; right: 0; bottom: 0;
  width: 260px;
  background: var(--bg2);
  border-left: 1px solid var(--card-border);
  display: flex; flex-direction: column;
  z-index: 100;
  transform: translateX(100%);
  transition: transform .3s var(--ease);
}
.sidebar-right.open { transform: translateX(0); }
.sidebar-right-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--card-border);
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text3);
}
.sidebar-right-content {
  flex: 1; overflow-y: auto; padding: 8px 12px;
}

/* ===== Nickname modal ===== */
.nickname-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.nickname-box {
  text-align: center;
  max-width: 340px; width: 90%;
  background: var(--bg2);
  border: 1px solid var(--gold-d);
  border-radius: 12px;
  padding: 32px;
}
.nickname-box h2 {
  font-family: var(--font-head);
  font-size: 24px; color: var(--gold-l);
  margin-bottom: 8px;
}
.nickname-box p {
  font-size: 14px; color: var(--text3);
  margin-bottom: 20px;
}
.nickname-box input {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  text-align: center;
  margin-bottom: 16px;
}
.nickname-box button {
  width: 100%;
  padding: 12px;
  background: var(--gold-d);
  color: var(--bg);
  font-size: 14px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: 6px;
  transition: background .2s;
}
.nickname-box button:hover { background: var(--gold); }

/* ===== Info badge (card top-right) ===== */
.info-badge {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  font-family: var(--font-head);
  background: rgba(200,154,74,.15); color: var(--gold);
  border: 1px solid rgba(200,154,74,.3);
  transition: all .2s; z-index: 2;
  cursor: pointer;
}
.card:hover .info-badge {
  background: rgba(200,154,74,.3);
  border-color: var(--gold);
}

/* ===== Rarity borders (items) ===== */
.rarity-common    { border-left: 3px solid #888; }
.rarity-uncommon  { border-left: 3px solid var(--green-l); }
.rarity-rare      { border-left: 3px solid var(--blue-l); }
.rarity-epic      { border-left: 3px solid var(--purple-l); }
.rarity-legendary { border-left: 3px solid var(--gold-l); }

/* ===== Stat row (inline stats on cards) ===== */
.stat-row {
  display: flex; gap: 16px; margin: 10px 0; flex-wrap: wrap;
}
.stat-row .stat-inline {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--text2);
}
.stat-row .stat-inline .stat-val {
  color: var(--gold-l); font-weight: 600;
  font-family: var(--font-head); font-size: 16px;
}
.stat-row .stat-inline .stat-label {
  color: var(--text3); font-size: 12px;
}

/* ===== Bar progress ===== */
.bar-wrap { margin: 4px 0; }
.bar-label {
  display: flex; justify-content: space-between;
  font-size: 13px; margin-bottom: 3px;
}
.bar-label span:first-child { color: var(--text2); }
.bar-label span:last-child { color: var(--gold); }
.bar-sm {
  height: 6px; background: var(--bg4);
  border-radius: 2px; overflow: hidden;
}
.bar-fill {
  height: 100%; border-radius: 2px;
  transition: width .6s ease;
}
.bar-gold .bar-fill { background: linear-gradient(90deg, var(--gold-d), var(--gold-l)); }

/* ===== Filter pills (active) ===== */
.filter-row {
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* ===== Tabs (core, wormhole) ===== */
.enc-tabs {
  display: flex; gap: 8px; padding: 0 0 16px;
  grid-column: 1 / -1;
}
.enc-tab {
  padding: 7px 18px;
  font-size: 13px;
  font-family: var(--font-ui);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  transition: all .2s;
}
.enc-tab:hover { border-color: var(--gold-d); color: var(--text2); }
.enc-tab.active {
  background: var(--gold-d);
  border-color: var(--gold);
  color: var(--gold-l);
}
.enc-tab-content { display: none; grid-column: 1 / -1; }
.enc-tab-content.active { display: block; }

/* ===== Section wrappers (bestiary classes, location cats) ===== */
.enc-section-title {
  font-family: var(--font-head);
  font-size: 22px; color: var(--gold);
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--card-border);
  display: flex; align-items: center; gap: 10px;
}
.enc-section-title .count {
  font-size: 13px; font-family: var(--font-ui);
  color: var(--text3); font-weight: 400;
}

/* ===== Modal section labels ===== */
.modal-section-label {
  font-size: 12px; color: var(--text3);
  text-transform: uppercase; letter-spacing: 1px;
  margin: 16px 0 8px;
}

/* ===== Modal features (diamond dots) ===== */
.modal-features {
  display: flex; flex-direction: column;
  gap: 8px; margin-top: 8px;
}
.modal-features .feat {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 14px; color: var(--text2);
}
.modal-features .feat-dot {
  color: var(--gold); flex-shrink: 0;
  margin-top: 2px;
}

/* ===== Skill tree (magic) ===== */
.skill-tree { margin: 8px 0; }
.skill-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; font-size: 14px;
}
.skill-rank { display: flex; gap: 2px; }
.skill-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1px solid var(--gold-d);
}
.skill-dot.filled { background: var(--gold); border-color: var(--gold); }
.skill-name { color: var(--text2); }
.skill-cost { color: var(--text3); font-size: 13px; margin-left: auto; }

/* ===== Combo table ===== */
.combo-table {
  width: 100%; border-collapse: collapse; margin: 8px 0;
}
.combo-table td, .combo-table th {
  padding: 10px 14px; font-size: 14px;
  border-bottom: 1px solid rgba(200,154,74,.1);
}
.combo-table th {
  color: var(--gold); font-weight: 500;
  text-align: left; font-size: 13px;
  text-transform: uppercase; letter-spacing: .5px;
}
.combo-table td { color: var(--text2); }

/* ===== Technique list ===== */
.technique-list { display: flex; flex-direction: column; gap: 8px; }
.technique-row {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 18px; cursor: pointer;
  transition: border-color .2s;
}
.technique-row:hover { border-color: var(--gold-dim); }
.technique-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.technique-name { font-weight: 600; color: var(--text1); font-size: 15px; }
.technique-cost { margin-left: auto; color: var(--gold); font-size: 13px; font-weight: 500; }
.technique-desc { color: var(--text3); font-size: 13px; line-height: 1.5; }

/* ===== Wormhole phases ===== */
.wormhole-phases {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.wormhole-phase-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  border-left: 3px solid var(--purple-l);
}
.wormhole-phase-num {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--purple-l); margin-bottom: 4px;
}
.wormhole-phase-name { font-size: 17px; font-weight: 600; color: var(--text1); margin-bottom: 8px; }
.wormhole-phase-dur { font-size: 12px; color: var(--gold); margin-bottom: 8px; }
.wormhole-phase-desc { font-size: 13px; color: var(--text2); line-height: 1.6; margin-bottom: 8px; }
.wormhole-phase-ctrl { font-size: 12px; color: var(--cyan-l); font-weight: 500; }

/* Wormhole symptoms */
.wormhole-symptom-group { margin-bottom: 20px; }
.wormhole-symptom-cat {
  font-size: 14px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--purple-l); margin-bottom: 8px; font-weight: 600;
}
.wormhole-symptom-list { list-style: none; padding: 0; margin: 0; }
.wormhole-symptom-item {
  padding: 8px 12px; margin-bottom: 4px;
  background: var(--card-bg); border-radius: 6px;
  font-size: 13px; color: var(--text2); line-height: 1.5;
}
.wormhole-severity {
  display: inline-block; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 4px; margin-right: 6px;
  vertical-align: middle;
}
.wormhole-severity--низкая     { background: rgba(46,204,113,.15); color: #2ecc71; }
.wormhole-severity--средняя    { background: rgba(241,196,15,.15); color: #f1c40f; }
.wormhole-severity--высокая    { background: rgba(231,76,60,.15);  color: #e74c3c; }
.wormhole-severity--критическая { background: rgba(192,57,43,.25); color: #ff4444; }

/* ===== Reader progress (sidebar footer) ===== */
.sidebar-progress {
  padding: 12px 20px;
  border-top: 1px solid var(--card-border);
  font-size: 12px; color: var(--text3);
}
.sidebar-progress .progress-text {
  display: flex; justify-content: space-between;
  margin-bottom: 4px;
}
.sidebar-progress .progress-bar {
  height: 4px; background: var(--bg4);
  border-radius: 2px; overflow: hidden;
}
.sidebar-progress .progress-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, var(--gold-d), var(--gold-l));
  transition: width .3s;
}

/* ===== Read indicator dots in TOC ===== */
.toc-chapter.read::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold-d);
  margin-right: 6px;
  flex-shrink: 0;
}

/* ===== Chapter nav counter ===== */
.chapter-nav-counter {
  font-size: 14px; color: var(--text3);
  font-family: var(--font-ui);
}

/* ===== Portrait letter (character cards) ===== */
.portrait-letter {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 2px solid var(--gold-d);
  background: var(--bg4);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head);
  font-size: 22px; font-weight: 700;
  color: var(--gold-l);
  flex-shrink: 0;
}

/* ===== Login ===== */
.login-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 300;
  display: none; align-items: center; justify-content: center;
}
.login-overlay.visible {
  display: flex;
}

.login-box {
  text-align: center;
  max-width: 320px;
  width: 90%;
}

.login-box h1 {
  font-family: var(--font-head);
  font-size: 32px; color: var(--gold-l);
  margin-bottom: 8px;
}

.login-box .login-sub {
  font-size: 14px; color: var(--text3);
  margin-bottom: 24px;
}

.login-box input {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  text-align: center;
  margin-bottom: 16px;
}

.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--gold-d);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: 6px;
  transition: background .2s;
}
.login-box button:hover { background: var(--gold); }

.login-error {
  color: var(--red-l);
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

/* (mobile-toggle removed — hamburger is now in header-bar) */

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text3);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 15px; }

/* ===== Continue reading card ===== */
.continue-card {
  margin-top: 24px;
  padding: 20px 24px;
  background: var(--bg3);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  display: inline-block;
  text-align: center;
}
.continue-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text3);
  margin-bottom: 6px;
}
.continue-title {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 600;
  color: var(--gold-l);
  margin-bottom: 4px;
}
.continue-meta {
  font-size: 13px;
  color: var(--text3);
  margin-bottom: 14px;
}
.continue-btn {
  padding: 8px 24px;
  background: var(--gold-d);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-radius: 6px;
  transition: background .2s;
}
.continue-btn:hover { background: var(--gold); }

/* ===== Loading ===== */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 60px; color: var(--text3);
}
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--bg4);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin-right: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Notes ===== */

/* Popup editor */
.note-popup {
  position: fixed;
  z-index: 350;
  background: var(--bg2);
  border: 1px solid var(--gold-d);
  border-radius: 10px;
  padding: 14px;
  width: 300px;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
.note-popup.hidden { display: none; }

.note-popup-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.note-popup-title {
  font-family: var(--font-head);
  font-size: 16px; font-weight: 600;
  color: var(--gold-l);
}
.note-popup-close {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg4);
  font-size: 14px; color: var(--text3);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.note-popup-close:hover { color: var(--text); background: var(--bg3); }

.note-popup-body {
  width: 100%;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 10px;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 60px;
  outline: none;
}
.note-popup-body:focus { border-color: var(--gold-d); }

.note-popup-actions {
  display: flex; justify-content: flex-end; gap: 8px;
}
.note-btn-save {
  padding: 6px 16px;
  background: var(--gold-d);
  color: var(--bg);
  font-size: 13px; font-weight: 600;
  border-radius: 6px;
  transition: background .2s;
}
.note-btn-save:hover { background: var(--gold); }
.note-btn-delete {
  padding: 6px 12px;
  color: var(--red-l);
  font-size: 13px;
  border: 1px solid rgba(139,58,58,.3);
  border-radius: 6px;
  transition: all .15s;
}
.note-btn-delete:hover { background: rgba(139,58,58,.15); border-color: var(--red); }

/* Inline highlights */
.note-highlight {
  cursor: pointer;
  border-radius: 2px;
  padding: 0 1px;
  transition: opacity .15s;
}
.note-highlight:hover { opacity: .8; }
.note-color-yellow { background: rgba(200,154,74,.25); }
.note-color-blue   { background: rgba(90,138,192,.25); }
.note-color-green  { background: rgba(90,155,90,.25); }
.note-color-pink   { background: rgba(196,80,80,.25); }

/* Mobile selection FAB buttons */
.note-sel-fab, .fb-sel-fab {
  position: fixed;
  z-index: 260;
  padding: 6px 14px;
  border-radius: 18px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .2s, transform .2s;
}
.note-sel-fab.visible, .fb-sel-fab.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.note-sel-fab {
  background: var(--gold-d);
  color: var(--bg);
}
.fb-sel-fab {
  background: var(--bg2);
  color: var(--gold-l);
  border: 1px solid var(--gold-d);
}

/* Page notes add button (used in sidebar-right) */
.page-notes-add {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg4);
  font-size: 16px; color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.page-notes-add:hover { background: var(--gold-dim); }

.page-note-item, .enc-note-item {
  background: var(--bg3);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  border-left: 3px solid var(--gold-d);
  transition: border-color .15s;
  font-size: 13px;
}
.page-note-item:hover, .enc-note-item:hover { border-left-color: var(--gold-l); }

.note-border-yellow { border-left-color: var(--gold-d) !important; }
.note-border-blue   { border-left-color: var(--blue) !important; }
.note-border-green  { border-left-color: var(--green) !important; }
.note-border-pink   { border-left-color: var(--red) !important; }

.page-note-body, .enc-note-body {
  color: var(--text2);
  line-height: 1.5;
  word-break: break-word;
}
.page-note-meta, .enc-note-meta {
  font-size: 11px;
  color: var(--text3);
  margin-top: 6px;
}
.note-author {
  font-weight: 600;
  color: var(--text2);
}
.page-note-quote {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
  margin-bottom: 4px;
}
.page-note-empty {
  font-size: 13px;
  color: var(--text3);
  text-align: center;
  padding: 16px 0;
}

.enc-note-quote {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
  margin-top: 4px;
}

.enc-notes-list { margin: 8px 0; }

.enc-note-add {
  display: block;
  width: 100%;
  padding: 8px;
  background: var(--bg4);
  border-radius: 6px;
  font-size: 13px;
  color: var(--gold);
  text-align: center;
  margin-top: 8px;
  transition: background .15s;
}
.enc-note-add:hover { background: var(--gold-dim); }

/* Note status badges */
.note-status {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  vertical-align: middle;
  margin-left: 6px;
}
.note-status-open     { background: rgba(90,138,192,.15); color: var(--blue-l); }
.note-status-resolved { background: rgba(58,107,58,.2); color: var(--green-l); }
.note-status-wontfix  { background: rgba(139,58,58,.15); color: var(--red-l); }
.note-status-deferred { background: rgba(200,154,74,.15); color: var(--gold); }

.note-resolved .page-note-body,
.note-resolved .enc-note-body,
.note-resolved .notes-overview-body {
  text-decoration: line-through;
  opacity: .55;
}

/* Note popup status controls */
.note-popup-status {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--bg4);
}
.note-status-btn {
  flex: 1;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--bg4);
  color: var(--text3);
  transition: all .15s;
  cursor: pointer;
}
.note-status-btn:hover { color: var(--text1); }
.note-status-btn.active { font-weight: 600; }
.note-status-btn.active[data-status="open"]     { background: rgba(90,138,192,.2); color: var(--blue-l); }
.note-status-btn.active[data-status="resolved"]  { background: rgba(58,107,58,.25); color: var(--green-l); }
.note-status-btn.active[data-status="wontfix"]   { background: rgba(139,58,58,.2); color: var(--red-l); }
.note-status-btn.active[data-status="deferred"]  { background: rgba(200,154,74,.2); color: var(--gold); }

/* ===== Feedback ===== */

/* Feedback popup */
.feedback-popup {
  position: fixed;
  z-index: 350;
  background: var(--bg2);
  border: 1px solid var(--orange, #c8823a);
  border-radius: 10px;
  padding: 14px;
  width: 300px;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
.feedback-popup.hidden { display: none; }

.feedback-popup-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.feedback-popup-title {
  font-family: var(--font-head);
  font-size: 16px; font-weight: 600;
  color: var(--orange-l, #e0a050);
}
.feedback-popup-close {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg4);
  font-size: 14px; color: var(--text3);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.feedback-popup-close:hover { color: var(--text); background: var(--bg3); }

.feedback-popup-quote {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
  padding: 6px 10px;
  background: var(--bg4);
  border-radius: 4px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.feedback-popup-comment {
  width: 100%;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 10px;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 60px;
  outline: none;
}
.feedback-popup-comment:focus { border-color: var(--orange, #c8823a); }

.feedback-popup-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 10px;
}
.feedback-btn-save {
  padding: 6px 16px;
  background: var(--orange, #c8823a);
  color: var(--bg);
  font-size: 13px; font-weight: 600;
  border-radius: 6px;
  transition: background .2s;
}
.feedback-btn-save:hover { background: var(--orange-l, #e0a050); }
.feedback-btn-delete {
  padding: 6px 12px;
  color: var(--red-l);
  font-size: 13px;
  border: 1px solid rgba(139,58,58,.3);
  border-radius: 6px;
  transition: all .15s;
}
.feedback-btn-delete:hover { background: rgba(139,58,58,.15); border-color: var(--red); }

/* Feedback toggle button */
.feedback-toggle {
  width: 44px; height: 44px;
  background: var(--bg3);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
  position: relative;
  margin-bottom: 8px;
}
.feedback-toggle:hover { border-color: var(--orange, #c8823a); }

.feedback-count {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  background: var(--orange, #c8823a);
  color: var(--bg);
  font-size: 11px; font-weight: 700;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.feedback-count.hidden { display: none; }

/* Feedback panel (right side) */
.feedback-panel {
  position: fixed;
  top: 80px; right: 270px;
  width: 280px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  z-index: 50;
  background: var(--bg2);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.feedback-panel.hidden { display: none; }

.feedback-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text3);
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 8px;
}
.feedback-panel-add {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg4);
  font-size: 16px; color: var(--orange, #c8823a);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.feedback-panel-add:hover { background: rgba(200,130,58,.15); }

.feedback-item {
  background: var(--bg3);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  border-left: 3px solid var(--orange, #c8823a);
  font-size: 13px;
}
.feedback-item.feedback-own { cursor: pointer; }
.feedback-item.feedback-own:hover { border-left-color: var(--orange-l, #e0a050); }

.feedback-item-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.feedback-nickname {
  font-weight: 600;
  color: var(--text2);
  font-size: 12px;
}
.feedback-date {
  font-size: 11px;
  color: var(--text3);
}
.feedback-quote {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
  margin-bottom: 4px;
}
.feedback-comment {
  color: var(--text2);
  line-height: 1.5;
  word-break: break-word;
}
.feedback-empty {
  font-size: 13px;
  color: var(--text3);
  text-align: center;
  padding: 16px 0;
}

/* Feedback status badges */
.feedback-status-badge {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 6px;
}
.feedback-status-accepted { background: rgba(58,107,58,.2); color: var(--green-l); }
.feedback-status-dismissed { background: rgba(139,58,58,.15); color: var(--red-l); }

/* Dismissed annotations (soft-delete visual) */
.annotation-dismissed {
  opacity: 0.55;
  position: relative;
}
.annotation-dismissed .feedback-comment,
.annotation-dismissed .page-note-body,
.annotation-dismissed .notes-overview-body,
.annotation-dismissed .enc-note-body {
  text-decoration: line-through;
  color: var(--text3);
}
.annotation-dismiss-reason {
  font-size: 11px;
  color: var(--text3);
  font-style: italic;
  margin-top: 4px;
  padding-left: 8px;
  border-left: 2px solid var(--card-border);
}

/* Feedback inline highlights */
.feedback-highlight {
  cursor: pointer;
  border-radius: 2px;
  padding: 0 1px;
  background: rgba(200,130,58,.2);
  border-bottom: 2px solid rgba(200,130,58,.4);
  transition: background .15s;
}
.feedback-highlight:hover { background: rgba(200,130,58,.35); }

/* ===== Notes Overview ===== */
.notes-overview {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px 80px;
}
.notes-overview h2 {
  font-family: var(--font-head);
  font-size: 34px; font-weight: 700;
  color: var(--gold-l);
  margin-bottom: 20px;
}
.notes-filters {
  display: flex; gap: 8px;
  margin-bottom: 20px;
}

.notes-group {
  margin-bottom: 24px;
}
.notes-group-header {
  font-family: var(--font-head);
  font-size: 18px; color: var(--gold);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.notes-group-count {
  font-size: 13px; font-family: var(--font-ui);
  color: var(--text3); font-weight: 400;
}

.notes-overview-item {
  background: var(--bg3);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  border-left: 3px solid var(--gold-d);
  transition: border-color .15s, background .15s;
  font-size: 13px;
}
.notes-overview-item:hover {
  border-left-color: var(--gold-l);
  background: var(--bg4);
}

.notes-overview-quote {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
  margin-bottom: 4px;
}
.notes-overview-body {
  color: var(--text2);
  line-height: 1.5;
  word-break: break-word;
}
.notes-overview-meta {
  display: flex; justify-content: space-between;
  font-size: 11px;
  color: var(--text3);
  margin-top: 6px;
}
.notes-overview-location {
  color: var(--gold-d);
  font-weight: 500;
}

/* ===== Responsive ===== */

/* Tablet breakpoint */
@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; }
  .nav-item { padding: 9px 16px; font-size: 13px; }
  .toc-chapter { padding-left: 32px; }
}

/* ===== Secondary Tabs (desktop: hidden) ===== */
.secondary-tabs { display: none; }
.tertiary-pills { display: none; }

@media (max-width: 900px) {
  /* --- Secondary Tab Bar --- */
  .secondary-tabs {
    display: flex; align-items: center;
    position: sticky; top: 48px; z-index: 110;
    background: var(--bg2);
    border-bottom: 1px solid var(--card-border);
    overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    height: 40px;
  }
  .secondary-tabs:empty { display: none; }
  .secondary-tabs::-webkit-scrollbar { display: none; }
  .secondary-tab {
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 6px 14px; white-space: nowrap;
    color: var(--text3); font-size: 11px; font-family: inherit;
    border: none; background: none; cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color .2s, border-color .2s;
    -webkit-tap-highlight-color: transparent;
  }
  .secondary-tab .stab-icon { font-size: 16px; line-height: 1; }
  .secondary-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

  /* --- Tertiary Pills --- */
  .tertiary-pills {
    display: flex; gap: 6px; align-items: center;
    overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 6px 12px;
    background: var(--bg1);
    border-bottom: 1px solid var(--card-border);
    position: sticky; top: 88px; z-index: 109;
  }
  .tertiary-pills::-webkit-scrollbar { display: none; }
  .tertiary-pills:empty { display: none; }
  .tpill {
    flex-shrink: 0; padding: 5px 12px; border-radius: 14px;
    background: var(--card); border: 1px solid var(--card-border);
    color: var(--text2); font-size: 12px; white-space: nowrap;
    cursor: pointer; transition: all .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .tpill.active { background: var(--gold-dim); color: var(--gold); border-color: var(--gold); }

  /* --- Tertiary Dropdown (replaces pills for long lists) --- */
  .tertiary-dropdown {
    padding: 6px 12px;
    background: var(--bg1);
    border-bottom: 1px solid var(--card-border);
    position: sticky; top: 88px; z-index: 109;
  }
  .tdd-trigger {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 8px 14px; border-radius: 10px;
    background: var(--card); border: 1px solid var(--card-border);
    color: var(--text2); font-size: 13px; font-family: inherit;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: all .15s;
  }
  .tdd-trigger.has-value { color: var(--gold); border-color: var(--gold); }
  .tdd-trigger::after { content: '\25BE'; margin-left: 8px; font-size: 14px; color: var(--text3); }
  .tdd-trigger.open::after { content: '\25B4'; }
  .tdd-menu {
    display: none;
    margin-top: 4px; border-radius: 10px;
    background: var(--card); border: 1px solid var(--card-border);
    max-height: 60vh; overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,.3);
  }
  .tdd-menu.open { display: block; }
  .tdd-item {
    padding: 10px 14px;
    font-size: 13px; color: var(--text2);
    cursor: pointer; transition: background .1s;
    border-bottom: 1px solid var(--card-border);
    -webkit-tap-highlight-color: transparent;
  }
  .tdd-item:last-child { border-bottom: none; }
  .tdd-item:active, .tdd-item.active { background: var(--gold-dim); color: var(--gold); }
  .tdd-item-group {
    padding: 8px 14px 4px;
    font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--text3); pointer-events: none;
    border-bottom: 1px solid var(--card-border);
  }

  .feedback-panel { display: none !important; }
  .note-popup, .feedback-popup {
    width: calc(100vw - 32px); max-width: 360px;
    left: 50% !important; transform: translateX(-50%);
  }

  /* --- Sidebar: completely hidden on mobile --- */
  .sidebar { display: none !important; }

  /* --- Right sidebar: full-width bottom sheet style --- */
  .sidebar-right {
    width: 100%; box-shadow: none; border-left: none;
    top: 0; z-index: 250;
  }
  .sidebar-right.open::before {
    content: ''; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: -1;
  }

  /* --- App: column layout on mobile --- */
  .app { flex-direction: column; padding-top: 48px; }

  /* --- Main content: full width, no sidebar margin --- */
  .main { margin-left: 0; margin-top: 0; margin-bottom: 60px; max-width: 100vw; overflow-x: hidden; }
  .scroll-progress { left: 0; }

  /* --- Header: no hamburger, no TOC btn on mobile --- */
  .header-menu-btn { display: none !important; }
  .header-toc-btn { display: none !important; }

  /* --- Bottom Tab Bar --- */
  .bottom-tabs {
    display: flex; justify-content: space-around; align-items: center;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 56px;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg2);
    border-top: 1px solid var(--card-border);
    z-index: 200;
  }
  .bottom-tabs .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    background: none; border: none; color: var(--text3);
    font-size: 10px; font-family: inherit;
    padding: 6px 0; min-width: 0; flex: 1;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: color .2s;
  }
  .bottom-tabs .tab .tab-icon { font-size: 20px; line-height: 1; }
  .bottom-tabs .tab.active { color: var(--gold); }

  /* --- Tables & pre: don't overflow --- */
  .lore-content table, .chapter-content table { display: block; overflow-x: auto; max-width: 100%; }
  .lore-content pre, .chapter-content pre { overflow-x: auto; max-width: 100%; }

  /* --- Typography --- */
  .chapter-title { font-size: 30px; }
  .chapter-content { font-size: 17px; }

  /* --- Lore content padding --- */
  .lore-content { padding: 0 16px; }

  /* --- Encyclopedia --- */
  .enc-header, .enc-filters, .enc-grid {
    padding-left: 16px; padding-right: 16px;
  }
  .enc-grid.grid-3, .enc-grid.grid-4 {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }

  /* --- Touch targets: enlarge header buttons --- */
  .header-btn { min-width: 44px; min-height: 44px; }

  /* --- Hide useless controls --- */
  #width-down, #width-up { display: none; }

  /* --- Mobile inline nav (replaces sidebar) --- */
  .mobile-nav {
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--card-border);
  }
  .mobile-nav-back {
    display: inline-flex; align-items: center; gap: 6px;
    background: none; border: none; color: var(--gold);
    font-size: 14px; font-family: inherit; padding: 8px 0;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    margin-bottom: 8px;
  }
  .mobile-nav-back::before { content: '←'; font-size: 16px; }
  .mobile-nav-title {
    font-size: 13px; color: var(--text3); text-transform: uppercase;
    letter-spacing: 1px; margin-bottom: 8px;
  }
  .mobile-nav-list {
    display: flex; flex-direction: column; gap: 2px;
  }
  .mobile-nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; border-radius: 8px;
    background: var(--card); border: 1px solid var(--card-border);
    color: var(--text1); font-size: 15px; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s;
  }
  .mobile-nav-item:active { background: var(--gold-dim); }
  .mobile-nav-item .nav-icon { font-size: 18px; flex-shrink: 0; }
  .mobile-nav-item .nav-sub-text {
    font-size: 12px; color: var(--text3); margin-left: auto;
  }
  .mobile-nav-group-title {
    font-size: 11px; color: var(--text3); text-transform: uppercase;
    letter-spacing: 1px; padding: 12px 0 4px; margin-top: 4px;
  }

  /* --- Encyclopedia: horizontal pills on mobile --- */
  .enc-mobile-pills {
    display: flex; gap: 8px; overflow-x: auto;
    padding: 8px 16px; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .enc-mobile-pills::-webkit-scrollbar { display: none; }
  .enc-mobile-pill {
    flex-shrink: 0; padding: 8px 16px; border-radius: 20px;
    background: var(--card); border: 1px solid var(--card-border);
    color: var(--text2); font-size: 13px; white-space: nowrap;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: all .15s;
  }
  .enc-mobile-pill.active { background: var(--gold-dim); color: var(--gold); border-color: var(--gold); }

  /* --- Mobile sub-items (indented) --- */
  .mobile-nav-sub {
    margin-left: 16px;
    font-size: 14px;
  }
  .mobile-book-sections {
    margin-bottom: 4px;
  }

  /* --- Hide enc header subtitle on mobile (pills replace it) --- */
  .enc-header .subtitle { display: none; }

  /* --- Empty state fix for mobile --- */
  .empty-state p { padding: 0 16px; }
}

@media (max-width: 600px) {
  .chapter-title { font-size: 26px; }
  .chapter-content { font-size: 16px; }

  .enc-grid.grid-3, .enc-grid.grid-4 {
    grid-template-columns: 1fr;
  }

  .modal { padding: 16px; margin: 8px; width: calc(100% - 16px); max-height: 90vh; }
  .modal-title { font-size: 22px; }

  .enc-header h2 { font-size: 26px; }

  .chapter-nav { flex-direction: column; gap: 12px; }

  /* Settings popup: narrower on mobile */
  .settings-panel { min-width: 180px; }

  /* Tables → cards on mobile */
  .combo-table { display: block; }
  .combo-table thead { display: none; }
  .combo-table tbody { display: block; }
  .combo-table tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 8px;
  }
  .combo-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 3px 0;
    border: none;
    font-size: 13px;
  }
  .combo-table td::before {
    content: attr(data-label);
    font-weight: 500;
    color: var(--gold);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-right: 12px;
    flex-shrink: 0;
  }
}

/* ===== Pipeline Diagram ===== */
#section-pipeline {
  padding: 0;
  overflow: hidden;
  flex-direction: column;
  height: calc(100vh - 48px);
}

.pl-header {
  height: 52px;
  background: linear-gradient(180deg, #0f151d 0%, #0a0e14 100%);
  border-bottom: 1px solid #1e2a3a;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
}

.pl-title-block {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.pl-h1 {
  font-size: 15px;
  font-weight: 700;
  color: #e8eef4;
  white-space: nowrap;
  line-height: 1;
}

.pl-h1-accent { color: #4a9eff; }

.pl-sub {
  color: #5a6a7a;
  font-size: 10px;
  line-height: 1;
  margin-top: 3px;
}

.pl-tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.pl-tab {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  letter-spacing: 0.5px;
  user-select: none;
  color: #5a6a7a;
  background: transparent;
}

.pl-tab:hover { filter: brightness(1.4); }

.pl-tab-write    { color: #4aff9e; background: rgba(74,255,158,0.06); }
.pl-tab-write.active    { border-color: #4aff9e; box-shadow: 0 0 10px rgba(74,255,158,0.2); background: rgba(74,255,158,0.1); }
.pl-tab-scenario { color: #4a9eff; background: rgba(74,158,255,0.06); }
.pl-tab-scenario.active { border-color: #4a9eff; box-shadow: 0 0 10px rgba(74,158,255,0.2); background: rgba(74,158,255,0.1); }
.pl-tab-audit    { color: #ff9e4a; background: rgba(255,158,74,0.06); }
.pl-tab-audit.active    { border-color: #ff9e4a; box-shadow: 0 0 10px rgba(255,158,74,0.2); background: rgba(255,158,74,0.1); }
.pl-tab-feedback { color: #9e4aff; background: rgba(158,74,255,0.06); }
.pl-tab-feedback.active { border-color: #9e4aff; box-shadow: 0 0 10px rgba(158,74,255,0.2); background: rgba(158,74,255,0.1); }

.pl-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.pl-canvas-wrap {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  background: #0a0e14;
}

.pl-canvas-wrap canvas {
  display: block;
}

.pl-sidebar {
  width: 300px;
  min-width: 300px;
  background: #0d1219;
  border-left: 1px solid #1e2a3a;
  padding: 16px;
  overflow-y: auto;
  flex-shrink: 0;
  font-family: 'Segoe UI', -apple-system, sans-serif;
}

.pl-sidebar h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #5a6a7a;
  margin: 16px 0 8px 0;
  font-weight: 700;
}

.pl-sidebar h3:first-child { margin-top: 0; }

.pl-sb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 12px;
  border-radius: 4px;
  color: #b0bec5;
}

.pl-sb-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pl-sb-count {
  margin-left: auto;
  color: #5a6a7a;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
}

.pl-sb-principle {
  padding: 7px 9px;
  margin: 3px 0;
  border-radius: 4px;
  font-size: 11px;
  border-left: 2px solid #4a9eff;
  background: rgba(74,158,255,0.04);
  color: #5a6a7a;
  line-height: 1.5;
}

.pl-detail-panel { display: none; }
.pl-detail-panel.visible { display: block; }

.pl-dp-back {
  font-size: 11px;
  color: #4a9eff;
  cursor: pointer;
  margin-bottom: 10px;
  display: inline-block;
}
.pl-dp-back:hover { text-decoration: underline; }

.pl-detail-panel h2 {
  font-size: 15px;
  color: #e8eef4;
  margin-bottom: 4px;
}

.pl-dp-model {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.pl-dp-model-opus   { background: rgba(158,74,255,0.2); color: #9e4aff; }
.pl-dp-model-sonnet { background: rgba(74,158,255,0.2); color: #4a9eff; }

.pl-detail-panel p {
  font-size: 12px;
  color: #b0bec5;
  line-height: 1.6;
  margin-bottom: 6px;
}

.pl-dp-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #5a6a7a;
  margin-top: 12px;
  margin-bottom: 5px;
}

.pl-detail-panel ul { list-style: none; padding: 0; }
.pl-detail-panel ul li {
  font-size: 12px;
  padding: 2px 0;
  color: #b0bec5;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.pl-detail-panel ul li::before {
  content: '\25B8';
  color: #4a9eff;
  margin-right: 7px;
}

.pl-tooltip {
  position: fixed;
  background: #1a2233;
  border: 1px solid #1e2a3a;
  border-radius: 6px;
  padding: 7px 11px;
  font-size: 12px;
  color: #e8eef4;
  pointer-events: none;
  z-index: 9999;
  max-width: 260px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  display: none;
  font-family: 'Segoe UI', -apple-system, sans-serif;
}

.pl-tt-role {
  color: #5a6a7a;
  font-size: 11px;
  margin-top: 2px;
}

@media (max-width: 900px) {
  .pl-header { padding: 0 10px; gap: 8px; height: 46px; }
  .pl-h1 { font-size: 13px; }
  .pl-sub { display: none; }
  .pl-tab { padding: 4px 9px; font-size: 10px; }
  .pl-sidebar { display: none; }
}

/* ===== Edit Page ===== */
.edit-back-btn {
  background: var(--bg3);
  border: 1px solid var(--card-border);
  color: var(--text2);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.edit-back-btn:hover {
  border-color: var(--gold-d);
  color: var(--gold-l);
}

.edit-page-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.edit-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}
.edit-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.edit-page-header h2 {
  font-family: var(--font-head);
  font-size: 22px;
  color: var(--text);
  margin: 0;
}
.edit-page-controls {
  display: flex;
  gap: 8px;
}
.edit-page-controls select {
  background: var(--bg3);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
.edit-page-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text3);
  flex-wrap: wrap;
  gap: 8px;
}
.edit-session-counter strong {
  color: var(--orange-l, #e0a050);
}
.edit-page-hint {
  font-style: italic;
}

.edit-text-wrap {
  margin-bottom: 12px;
}
.edit-textarea {
  width: 100%;
  min-height: 70vh;
  background: var(--bg3);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  color: var(--text);
  padding: 16px;
  font-size: 14px;
  font-family: 'Literata', var(--font-body), serif;
  line-height: 1.7;
  resize: vertical;
  tab-size: 4;
  box-sizing: border-box;
}
.edit-textarea:focus {
  outline: none;
  border-color: var(--orange, #c8823a);
}

.edit-loading {
  padding: 40px;
  text-align: center;
  color: var(--text3);
}
.edit-error {
  padding: 20px;
  color: var(--red-l, #e06060);
  text-align: center;
}

.edit-page-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.edit-page-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.edit-btn-save {
  background: var(--orange, #c8823a);
  color: #fff;
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.edit-btn-save:hover { opacity: .85; }
.edit-btn-reset {
  background: var(--bg4);
  color: var(--text2);
  border: 1px solid var(--card-border);
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
.edit-btn-reset:hover { background: var(--bg3); }

.edit-status {
  font-size: 13px;
  flex: 1;
  min-width: 200px;
}
.edit-status-success { color: var(--green-l, #6abf6a); }
.edit-status-error { color: var(--red-l, #e06060); }
.edit-status-info { color: var(--text3); }

.edit-diff-list {
  margin-top: 8px;
  font-size: 12px;
}
.edit-diff-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
  flex-wrap: wrap;
}
.edit-diff-num {
  color: var(--text3);
  min-width: 40px;
  font-size: 11px;
}
.edit-diff-old {
  color: var(--red-l, #e06060);
  text-decoration: line-through;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.edit-diff-arrow {
  color: var(--text3);
}
.edit-diff-new {
  color: var(--green-l, #6abf6a);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .edit-page { padding: 12px; }
  .edit-textarea { min-height: 50vh; font-size: 13px; padding: 10px; }
  .edit-page-header { flex-direction: column; align-items: flex-start; }
  .edit-diff-line { flex-direction: column; gap: 2px; }
}
