:root {
  --sidebar-width: 280px;
  --accent: #c0392b;
  --accent-soft: #fbeae7;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e5e5e5;
  --bg: #ffffff;
  --sidebar-bg: #fafaf7;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 20px;
}

.sidebar-header {
  padding: 0 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.sidebar-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav .chapter-group {
  margin-bottom: 8px;
}

.sidebar-nav .chapter-label {
  display: block;
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.sidebar-nav .chapter-title {
  display: block;
  padding: 0 8px 6px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.sidebar-nav .chapter-group ul {
  margin-bottom: 4px;
}

.sidebar-nav a {
  display: block;
  padding: 6px 12px;
  margin: 1px 0;
  color: #333;
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
  background: #f0ebe5;
}

.sidebar-nav a.active {
  background: var(--accent);
  color: white;
  font-weight: 500;
}

/* ----- Content ----- */
.content {
  flex: 1;
  padding: 48px 64px;
  max-width: 900px;
  min-width: 0;
}

.content section {
  margin-bottom: 80px;
  scroll-margin-top: 24px;
}

.content section:last-child { margin-bottom: 24px; }

.content h1 {
  margin: 0 0 24px;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--accent);
  font-size: 28px;
  color: var(--text);
}

.content h2 {
  margin: 32px 0 12px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.content section > p:first-of-type em:only-child {
  display: inline-block;
  margin: -12px 0 8px;
  padding: 4px 10px;
  font-size: 13px;
  font-style: normal;
  color: var(--muted);
  background: #f4f2ee;
  border-radius: 12px;
  letter-spacing: 0.3px;
}

/* ----- Tables ----- */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 24px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.content thead {
  background: var(--accent-soft);
}

.content th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--accent);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.content td {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.content tbody tr:nth-child(even) {
  background: #fdfcfa;
}

/* Person/speaker column emphasis (first column in dialog tables) */
.content td:first-child {
  font-weight: 600;
  color: #555;
  white-space: nowrap;
}

/* ----- Mobile drawer controls (hidden on desktop) ----- */
.menu-toggle,
.sidebar-backdrop { display: none; }

.menu-icon { width: 26px; height: 26px; display: block; }
.menu-icon-close { display: none; }

/* ----- Mobile ----- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(86vw, 340px);
    height: 100vh;
    max-height: none;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }

  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .menu-toggle {
    display: flex;
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    right: max(20px, env(safe-area-inset-right, 0px));
    z-index: 101;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s ease, background 0.15s ease;
  }

  .menu-toggle:active { transform: scale(0.94); }

  .menu-toggle[aria-expanded="true"] .menu-icon-open { display: none; }
  .menu-toggle[aria-expanded="true"] .menu-icon-close { display: block; }

  .content {
    padding: 24px 20px 96px; /* extra bottom padding so the FAB doesn't cover content */
    max-width: none;
  }

  .content table { font-size: 14px; }
  .content th, .content td { padding: 8px 10px; }
}
