/* ── SHELL LAYOUT: sidebar + main ── */

.shell {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: #1a130a;
  border-right: 1px solid rgba(139,105,20,0.25);
  display: flex;
  flex-direction: column;
  z-index: 100;
  scrollbar-width: thin;
  scrollbar-color: rgba(139,105,20,0.3) transparent;
}

.sidebar-header {
  padding: 1.4rem 1.2rem 1rem;
  border-bottom: 1px solid rgba(139,105,20,0.2);
  flex-shrink: 0;
}

.sidebar-title {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: rgba(201,162,39,0.5);
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}

.sidebar-book-title {
  font-family: 'Cinzel', serif;
  font-size: 14px;
  color: #f0e4c0;
  letter-spacing: 0.05em;
}

/* ── SEARCH ── */
.toc-search-wrap {
  padding: 0.6rem 1rem 0.55rem;
  border-bottom: 1px solid rgba(139,105,20,0.18);
  flex-shrink: 0;
  background: rgba(0,0,0,0.08);
}

.toc-search {
  width: 100%;
  padding: 0.4rem 0.65rem 0.4rem 2rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(139,105,20,0.3);
  border-radius: 3px;
  color: rgba(240,228,192,0.88);
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23c9a22790' d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.099zM6.5 12a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.5rem center;
  background-size: 12px;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.toc-search::-webkit-search-cancel-button { display: none; }
.toc-search::placeholder { color: rgba(201,162,39,0.35); font-style: italic; font-size: 12px; }
.toc-search:focus {
  border-color: rgba(201,162,39,0.55);
  background-color: rgba(0,0,0,0.35);
  box-shadow: 0 0 0 2px rgba(139,105,20,0.15);
  color: rgba(240,228,192,1);
}

.toc-item.search-match {
  color: var(--gold-light, #c9a227) !important;
  opacity: 1 !important;
}

.sidebar-nav {
  padding: 0.8rem 0;
  flex: 1;
}

.toc-item {
  display: block;
  padding: 0.45rem 1.2rem;
  font-family: 'EB Garamond', serif;
  font-size: 14px;
  color: rgba(240,228,192,0.55);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  line-height: 1.35;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.toc-item:hover {
  color: rgba(240,228,192,0.9);
  background: rgba(139,105,20,0.12);
}

.toc-item.active {
  color: var(--gold-light, #c9a227);
  background: rgba(139,105,20,0.18);
}

.toc-item-number {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 0.15em;
  opacity: 0.5;
  margin-right: 0.5em;
}

/* ── HEADING HIERARCHY ── */
.toc-item.toc-level-1 {
  /* base .toc-item styles, no override needed */
}

.toc-item.toc-level-2 {
  padding-left: 1.9rem;
  font-size: 13px;
  color: rgba(240,228,192,0.45);
}

.toc-item.toc-level-2::before {
  content: '–';
  display: inline-block;
  margin-right: 0.45em;
  font-size: 10px;
  opacity: 0.45;
  vertical-align: middle;
}

.toc-item.toc-level-3 {
  padding-left: 2.7rem;
  font-size: 12px;
  color: rgba(240,228,192,0.35);
}

.toc-item.toc-level-3::before {
  content: '·';
  display: inline-block;
  margin-right: 0.4em;
  opacity: 0.5;
  vertical-align: middle;
}

.toc-item.toc-level-2.active,
.toc-item.toc-level-3.active {
  color: var(--gold-light, #c9a227);
  background: rgba(139,105,20,0.14);
}

.toc-item.toc-level-2:hover,
.toc-item.toc-level-3:hover {
  color: rgba(240,228,192,0.8);
}

/* ── COMPONENT BADGE (vignettes, etc.) ── */
.toc-item--component {
  font-style: italic;
}

.toc-item-badge {
  display: inline-block;
  margin-right: 0.4em;
  font-size: 9px;
  color: rgba(201,162,39,0.55);
  font-style: normal;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* Mode controls at bottom of sidebar */
.sidebar-controls {
  padding: 1rem 1.2rem;
  border-top: 1px solid rgba(139,105,20,0.2);
  flex-shrink: 0;
}

.mode-label {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 0.25em;
  color: rgba(201,162,39,0.45);
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}

.mode-buttons {
  display: flex;
  gap: 0.4rem;
}

.mode-btn {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  background: rgba(139,105,20,0.12);
  border: 1px solid rgba(139,105,20,0.25);
  color: rgba(240,228,192,0.5);
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn:hover {
  background: rgba(139,105,20,0.22);
  color: rgba(240,228,192,0.8);
}

.mode-btn.active {
  background: rgba(139,105,20,0.35);
  border-color: rgba(139,105,20,0.6);
  color: var(--gold-light, #c9a227);
}

/* ── MAIN CONTENT AREA ── */
.main {
  flex: 1;
  min-width: 0;
}

/* ── MOBILE: sidebar as drawer ── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  background: #1a130a;
  border: 1px solid rgba(139,105,20,0.4);
  color: rgba(201,162,39,0.8);
  padding: 0.5rem 0.7rem;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  letter-spacing: 0.1em;
  cursor: pointer;
}

@media (max-width: 800px) {
  .shell { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    height: 100%;
    transition: left 0.25s ease;
    z-index: 300;
  }

  .sidebar.open { left: 0; }

  .sidebar-toggle { display: block; }

  .main { padding-top: 0; }
}

/* ── PAGE FLIP MODE ── */
body[data-mode="book"] .page-section {
  display: none;
}

body[data-mode="book"] .page-section.active {
  display: block;
}

/* Page flip controls */
.book-controls {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: #1a130a;
  border-top: 1px solid rgba(139,105,20,0.25);
  position: sticky;
  bottom: 0;
  z-index: 50;
}

body[data-mode="book"] .book-controls {
  display: flex;
}

.book-nav-btn {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: rgba(201,162,39,0.7);
  background: rgba(139,105,20,0.12);
  border: 1px solid rgba(139,105,20,0.3);
  padding: 0.5rem 1.2rem;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.15s;
}

.book-nav-btn:hover:not(:disabled) {
  background: rgba(139,105,20,0.25);
  color: rgba(201,162,39,1);
}

.book-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.book-page-counter {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: rgba(201,162,39,0.45);
  text-transform: uppercase;
}

/* Flip animation */
.page-section {
  animation: none;
}

body[data-mode="book"] .page-section.active {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── READER MODE ── */
body[data-mode="reader"] {
  background: #fafaf8;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body[data-mode="reader"] .page {
  max-width: 700px;
  background: #fafaf8;
  box-shadow: none;
}

body[data-mode="reader"] .page::before { display: none; }

body[data-mode="reader"] .cover { display: none; }

body[data-mode="reader"] .page-header {
  background: #e8e5e0;
  padding: 0.8rem 2rem;
}

body[data-mode="reader"] .page-header-title {
  font-family: system-ui, sans-serif;
  color: #333;
  letter-spacing: 0.05em;
}

body[data-mode="reader"] .page-header-sub {
  font-family: system-ui, sans-serif;
  color: #666;
}

body[data-mode="reader"] .content {
  padding: 2.5rem 2rem;
}

body[data-mode="reader"] h1,
body[data-mode="reader"] h2,
body[data-mode="reader"] h3 {
  font-family: system-ui, sans-serif;
}

body[data-mode="reader"] p,
body[data-mode="reader"] li {
  font-family: system-ui, sans-serif;
  font-size: 16px;
  color: #222;
}

body[data-mode="reader"] .lead {
  font-family: system-ui, sans-serif;
  font-style: normal;
  font-size: 17px;
  color: #333;
  border-left: 3px solid #999;
}

body[data-mode="reader"] .callout {
  background: #f0ede8;
  border: 1px solid #ccc;
  border-left: 3px solid #666;
}

body[data-mode="reader"] .callout-label {
  font-family: system-ui, sans-serif;
  color: #555;
}

body[data-mode="reader"] .callout p,
body[data-mode="reader"] .callout li {
  color: #333;
}

body[data-mode="reader"] .callout.warning {
  border-left-color: #a00;
  background: #fdf0f0;
}

body[data-mode="reader"] .vignette {
  background: #f5f3ef;
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  font-family: system-ui, sans-serif;
  font-style: normal;
}

body[data-mode="reader"] .vignette-title {
  font-family: system-ui, sans-serif;
  color: #666;
}

body[data-mode="reader"] .vignette p { color: #333; }

body[data-mode="reader"] .ornament { display: none; }

body[data-mode="reader"] .cover-corner,
body[data-mode="reader"] .cover::before,
body[data-mode="reader"] .cover::after { display: none; }

body[data-mode="reader"] .section-divider::before,
body[data-mode="reader"] .section-divider::after { opacity: 0.2; }

body[data-mode="reader"] .page-footer {
  background: #ece9e3;
  border-top: 1px solid #ccc;
}

body[data-mode="reader"] .page-footer span {
  font-family: system-ui, sans-serif;
  color: #777;
}

body[data-mode="reader"] .char-header {
  background: #555 !important;
}

body[data-mode="reader"] .char-stats {
  background: #f0ede8;
  border-color: #ccc;
}

body[data-mode="reader"] .char-stat-value { color: #333; }

body[data-mode="reader"] .race-tag {
  background: #555;
}

body[data-mode="reader"] .district-name { color: #444; }
