/* MoreLight - Masonic Education & Memorization Tool */

:root {
  --color-primary: #1e3a5f;
  --color-primary-light: #2d5a8c;
  --color-primary-dark: #0f1f33;
  --color-gold: #c9a227;
  --color-gold-light: #e8c84a;
  --color-surface: #faf9f7;
  --color-surface-alt: #f0ede8;
  --color-surface-dark: #e5e1d8;
  --color-text: #1a1a1a;
  --color-text-muted: #5c5c5c;
  --color-text-light: #8a8a8a;
  --color-border: #d4d0c8;
  --color-memorized: #15803d;
  --color-partial: #ea580c;
  --color-none: #9ca3af;
  --font-main: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, sans-serif;
  --header-height: 56px;
  --sidebar-width: 320px;
}

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

html, body {
  font-size: 16px;
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  /* Prevent iOS Safari rubber-banding from shifting layout */
  overscroll-behavior: none;
}

body {
  font-family: var(--font-main);
  background: var(--color-surface);
  color: var(--color-text);
  line-height: 1.6;
  /* Prevent iOS tap-highlight and text size adjust */
  -webkit-text-size-adjust: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — follows iOS Safari chrome */
  overflow: hidden;
  position: fixed;
  inset: 0;
}

/* ============================================
   Header
   ============================================ */

.header {
  height: var(--header-height);
  background: var(--color-primary-dark);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  flex-shrink: 0;
  position: relative;
  z-index: 110;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.logo {
  width: 40px;
  height: 40px;
  color: var(--color-gold);
}

.brand-title {
  font-family: var(--font-main);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 3px;
}

.mode-toggle .btn-mode {
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.7);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-toggle .btn-mode.active {
  background: white;
  color: var(--color-primary-dark);
}

.mode-toggle .btn-mode:hover:not(.active) {
  color: white;
}

.btn-ghost {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.8);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.125rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

/* Mobile position indicator - hidden on desktop */
.mobile-position {
  display: none;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.8);
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   Main Layout
   ============================================ */

.main-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ============================================
   Content Area (Megascroller)
   ============================================ */

.content-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: white;
}

.content {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem 2rem 5rem;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  color: var(--color-text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Page Blocks */
.page-block {
  margin-bottom: 2rem;
}

/* Front Matter - Original PDF page images */
.page-block.page-image {
  display: flex;
  justify-content: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--color-border);
}

.page-block.page-image img {
  max-width: 100%;
  height: auto;
  max-height: 80vh;
}

/* General Instructions Pages */
.page-block.general-instructions .ritual-line {
  display: block;
  padding: 0;
  margin: 0;
}

.page-block.general-instructions .ritual-line .ln {
  display: none;
}

.page-block.general-instructions .ritual-line .text {
  font-size: 0.9375rem;
  line-height: 1.7;
}

.page-block.general-instructions .ritual-line.section-header {
  display: block;
  text-align: center;
  padding: 1rem 0 0.5rem;
}

.page-block.general-instructions .ritual-line.section-header .text {
  font-weight: 700;
  font-size: 1rem;
}

.page-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-text-light);
}

/* Even pages: number left, section right (default) */
/* Odd pages: section left, number right */
.page-header-bar.page-odd {
  flex-direction: row-reverse;
}

.page-num {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--color-text);
}

.page-section {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Ritual Lines */
.ritual-line {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  margin: 0 -0.5rem;
  border-radius: 3px;
  transition: background 0.15s;
}

.ritual-line:hover {
  background: var(--color-surface-alt);
}

.ln {
  flex-shrink: 0;
  width: 1.75rem;
  font-size: 0.6875rem;
  color: var(--color-text-light);
  text-align: right;
  padding-top: 0.25rem;
}

.role-tag {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-primary);
  background: rgba(30, 58, 95, 0.08);
  padding: 0.125rem 0.375rem;
  border-radius: 2px;
  min-width: 2.5rem;
  text-align: center;
}

.text {
  flex: 1;
  font-family: var(--font-main);
  font-size: 1rem;
  line-height: 1.7;
}

/* Stage Directions - bold + underlined to match PDF */
.ritual-line.stage-direction .text {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ritual-line.stage-direction .role-tag {
  background: rgba(30, 58, 95, 0.15);
  font-style: italic;
}

/* Section Headers within pages - centered and bold like PDF */
.ritual-line.section-header {
  justify-content: center;
  padding: 0.5rem 0;
  margin: 0.25rem 0;
}

.ritual-line.section-header .text {
  flex: none;
  font-weight: 700;
  font-size: 1.0625rem;
  text-align: center;
  letter-spacing: 0.02em;
}

.ritual-line.section-header .ln {
  display: none;
}

/* Role Highlighted Lines */
.role-highlight {
  background: rgba(30, 58, 95, 0.06);
  border-left: 3px solid var(--color-primary);
  padding-left: calc(0.5rem - 3px);
}

.role-highlight:hover {
  background: rgba(30, 58, 95, 0.1);
}

/* Practice Mode States */

/* Hidden: text invisible, tap to reveal */
.practice-hidden {
  background: var(--color-surface-dark);
  border-left: 4px solid var(--color-none);
  cursor: pointer;
}

.practice-hidden .text {
  color: transparent;
  user-select: none;
}

.practice-hidden:hover {
  background: var(--color-border);
}

/* Needs Work: revealed, not yet memorized */
.practice-partial {
  background: rgba(180, 83, 9, 0.12);
  border-left: 5px solid var(--color-partial);
  cursor: pointer;
}

.practice-partial .role-tag {
  background: var(--color-partial);
  color: white;
}

/* Memorized: confident */
.practice-memorized {
  background: rgba(22, 101, 52, 0.10);
  border-left: 5px solid var(--color-memorized);
  cursor: pointer;
}

.practice-memorized .role-tag {
  background: var(--color-memorized);
  color: white;
}

/* Flash animation */
.flash {
  animation: flash-bg 1.5s ease-out;
}

@keyframes flash-bg {
  0%, 100% { background: inherit; }
  25%, 75% { background: var(--color-gold-light); }
}

/* ============================================
   Navigation Sidebar
   ============================================ */

.nav-sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--color-surface-alt);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.nav-section {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.nav-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 0.625rem;
}

/* Role Select */
.role-select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-text);
  cursor: pointer;
}

.role-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.1);
}

/* Current Position */
.position-display {
  background: white;
  border-radius: 6px;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
}

.position-section {
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary-dark);
  margin-bottom: 0.25rem;
}

.position-page {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

/* Section List */
.section-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: 280px;
  overflow-y: auto;
}

.section-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}

.section-item:hover {
  border-color: var(--color-border);
}

.section-item.active {
  border-color: var(--section-color, var(--color-primary));
  background: rgba(30, 58, 95, 0.08);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.3);
}

.section-item.active .section-color {
  width: 6px;
}

.section-color {
  width: 4px;
  height: 28px;
  border-radius: 2px;
  flex-shrink: 0;
}

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

.section-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-meta {
  font-size: 0.6875rem;
  color: var(--color-text-light);
}

/* Role Timeline */
.role-timeline-section {
  flex: 1;
  min-height: 200px;
  max-height: 50vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.role-count {
  font-weight: normal;
  color: var(--color-text-light);
}

.role-timeline {
  flex: 1;
  background: white;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 150px;
  max-height: 400px;
  scroll-behavior: smooth;
}

.timeline-track {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0.5rem;
  min-height: 100%;
}

/* Timeline Section Headers */
.timeline-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  margin-top: 0.5rem;
  background: var(--color-surface-alt);
  border-radius: 4px;
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 1;
}

.timeline-section-header:first-child {
  margin-top: 0;
}

.timeline-section-header:hover {
  background: var(--color-surface-dark);
}

.section-badge {
  font-size: 0.625rem;
  font-weight: 700;
  color: white;
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-title {
  flex: 1;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-count {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  background: white;
  padding: 0.125rem 0.375rem;
  border-radius: 10px;
}

/* Timeline Markers */
.timeline-marker {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  padding-left: 0.25rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
  font-size: 0.6875rem;
}

.timeline-marker:hover {
  background: var(--color-surface-alt);
}

.marker-section-bar {
  width: 3px;
  height: 100%;
  min-height: 20px;
  border-radius: 2px;
  flex-shrink: 0;
}

.timeline-marker.status-none {
  background: var(--color-surface);
}

.timeline-marker.status-partial {
  background: rgba(180, 83, 9, 0.2);
  border-left: 3px solid var(--color-partial);
}

.timeline-marker.status-partial .marker-section-bar {
  background: var(--color-partial) !important;
}

.timeline-marker.status-partial .marker-page,
.timeline-marker.status-partial .marker-section-tag {
  color: var(--color-partial);
  font-weight: 600;
}

.timeline-marker.status-memorized {
  background: rgba(22, 101, 52, 0.2);
  border-left: 3px solid var(--color-memorized);
}

.timeline-marker.status-memorized .marker-section-bar {
  background: var(--color-memorized) !important;
}

.timeline-marker.status-memorized .marker-page,
.timeline-marker.status-memorized .marker-section-tag {
  color: var(--color-memorized);
  font-weight: 600;
}

.timeline-marker.current {
  background: rgba(201, 162, 39, 0.25);
  font-weight: 600;
}

.timeline-marker.current .marker-section-bar {
  width: 5px;
  box-shadow: 0 0 4px var(--color-gold);
}

.marker-page {
  font-family: var(--font-main);
  font-weight: 700;
  color: var(--color-primary);
  min-width: 2.5rem;
}

.marker-line {
  color: var(--color-text-muted);
  font-size: 0.6875rem;
}

.marker-section-tag {
  display: none;
  font-size: 0.5625rem;
  font-weight: 600;
  color: var(--section-color, var(--color-text-muted));
  margin-right: 0.375rem;
  flex-shrink: 0;
}

.marker-preview {
  flex: 1;
  color: var(--color-text-muted);
  font-size: 0.6875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-legend {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.625rem;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.625rem;
  color: var(--color-text-muted);
}

.legend-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.dot.none { background: var(--color-none); }
.dot.partial { background: var(--color-partial); }
.dot.memorized { background: var(--color-memorized); }

/* Progress Section */
.progress-bar-large {
  height: 12px;
  background: var(--color-surface-dark);
  border-radius: 6px;
  overflow: hidden;
}

.progress-fill-large {
  height: 100%;
  background: var(--color-memorized);
  border-radius: 6px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
}

.progress-stats .stat {
  color: var(--color-text-muted);
}

.progress-stats .stat.memorized {
  color: var(--color-memorized);
}

.progress-stats .stat.partial {
  color: var(--color-partial);
}

.btn-reset {
  margin-top: 0.625rem;
  width: 100%;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-reset:hover {
  border-color: #dc2626;
  color: #dc2626;
  background: rgba(220, 38, 38, 0.05);
}

/* ============================================
   Modal
   ============================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  width: 90%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content.modal-large {
  max-width: 500px;
}

.modal-content h3 {
  font-family: var(--font-main);
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--color-primary-dark);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-light);
}

/* Help Content */
.help-content section {
  margin-bottom: 1rem;
}

.help-content h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
  color: var(--color-primary);
}

.help-content p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.help-content ul {
  list-style: none;
  padding-left: 0;
}

.help-content li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  padding: 0.25rem 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-dot.status-none { background: var(--color-none); }
.status-dot.status-partial { background: var(--color-partial); }
.status-dot.status-memorized { background: var(--color-memorized); }

/* ============================================
   Prev/Next Line Navigator
   ============================================ */

.line-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: var(--sidebar-width);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  background: var(--color-primary-dark);
  color: white;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.15);
}

.line-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 40px;
}

.line-nav-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.line-nav-btn:active {
  background: rgba(255, 255, 255, 0.25);
}

.line-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.line-nav-btn:disabled:hover {
  background: rgba(255, 255, 255, 0.1);
}

.line-nav-pos {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  min-width: 4rem;
  text-align: center;
  letter-spacing: 0.02em;
}

.line-nav-label {
  display: inline;
}

@media (max-width: 767px) {
  .line-nav {
    right: 0;
    bottom: 56px; /* above collapsed sheet handle */
    border-radius: 0;
    padding: 0.375rem 0.75rem;
  }

  .line-nav-btn {
    padding: 0.5rem 0.875rem;
    min-height: 44px;
  }
}

@media (max-width: 400px) {
  .line-nav-label {
    display: none;
  }

  .line-nav-btn {
    padding: 0.5rem 0.75rem;
  }
}

/* ============================================
   Stage Directions (Note/rubric lines)
   Match PDF: bold + underline for instructions
   ============================================ */

.ritual-line[data-role="Note"] {
  background: transparent;
}

.ritual-line[data-role="Note"]:hover {
  background: rgba(100, 116, 139, 0.06);
}

.ritual-line[data-role="Note"] .text {
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--color-text-muted);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.ritual-line[data-role="Note"] .role-tag {
  background: rgba(100, 116, 139, 0.1);
  color: var(--color-text-muted);
  font-weight: 700;
}

/* ============================================
   Bottom Sheet & Backdrop (base)
   ============================================ */

.sheet-handle {
  display: none;
}

.sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.sheet-backdrop.visible {
  display: block;
  opacity: 1;
}

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

/* Tablet */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 280px;
  }
}

@media (max-width: 900px) {
  :root {
    --sidebar-width: 260px;
  }

  .section-list {
    max-height: 200px;
  }
}

/* ============================================
   Mobile — Bottom Sheet UX
   ============================================ */

@media (max-width: 767px) {
  :root {
    --header-height: 44px;
  }

  /* ---- Header ---- */
  .header {
    padding: 0 0.75rem;
  }

  .header-brand {
    display: none;
  }

  .header-nav {
    width: 100%;
    justify-content: space-between;
  }

  .mode-toggle {
    border-radius: 8px;
    padding: 3px;
  }

  .mode-toggle .btn-mode {
    padding: 0.3rem 0.875rem;
    font-size: 0.8125rem;
    border-radius: 6px;
  }

  .btn-ghost {
    width: 36px;
    height: 36px;
    font-size: 1.125rem;
  }

  .mobile-position {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
  }

  /* ---- Layout ---- */
  .main-layout {
    flex-direction: column;
    position: relative;
  }

  .content-area {
    flex: 1;
    min-height: 0;
    padding-bottom: 60px;
  }

  /* ---- Bottom Sheet ---- */
  .nav-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    width: 100%;
    height: 68vh;
    max-height: none;
    min-height: 0;
    background: var(--color-surface-alt);
    border-left: none;
    border-top: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 24px rgba(0, 0, 0, 0.08);
    transform: translateY(calc(100% - 56px));
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    will-change: transform;
  }

  .nav-sidebar.expanded {
    transform: translateY(0);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Sheet Handle ---- */
  .sheet-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    padding: 10px 16px 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    background: var(--color-surface-alt);
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
  }

  .nav-sidebar.expanded .sheet-handle {
    border-bottom-color: var(--color-border);
  }

  .sheet-grip {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
    margin-bottom: 8px;
    transition: background 0.2s;
  }

  .sheet-handle:active .sheet-grip {
    background: var(--color-text-muted);
  }

  .sheet-peek {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 20px;
  }

  .peek-role {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
  }

  .peek-stat {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-memorized);
  }

  /* ---- Sidebar Sections ---- */
  #sections-nav {
    display: none;
  }

  .current-position {
    display: none;
  }

  .nav-section {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
  }

  .nav-label {
    font-size: 0.625rem;
    margin-bottom: 0.5rem;
  }

  .role-select {
    padding: 0.5rem 0.75rem;
    font-size: 0.9375rem;
    border-radius: 10px;
    background: white;
  }

  /* ---- Timeline ---- */
  .role-timeline-section {
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: none;
  }

  .role-timeline {
    flex: 1 1 auto;
    min-height: 120px;
    max-height: none;
    border-radius: 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .timeline-section-header {
    display: none;
  }

  .timeline-track {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0.5rem;
  }

  .timeline-marker {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.5rem;
    font-size: 0.8125rem;
    border-radius: 8px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  .timeline-marker:active {
    background: var(--color-surface-dark);
  }

  .marker-section-bar {
    width: 3px;
    min-height: 20px;
    margin-right: 0.375rem;
    border-radius: 2px;
  }

  .marker-page {
    min-width: auto;
    font-size: 0.8125rem;
    margin-right: 0.375rem;
    font-weight: 700;
  }

  .marker-line {
    display: none;
  }

  .marker-section-tag {
    display: inline;
    font-size: 0.625rem;
    margin-right: 0.375rem;
  }

  .marker-preview {
    display: block;
    flex: 1;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .timeline-marker.current {
    background: rgba(201, 162, 39, 0.2);
    box-shadow: inset 0 0 0 1.5px var(--color-gold);
  }

  .timeline-marker.current .marker-section-bar {
    width: 4px;
    box-shadow: 0 0 3px var(--color-gold);
  }

  /* ---- Progress ---- */
  #progress-section.nav-section {
    flex: 0 0 auto;
    border-top: 1px solid var(--color-border);
    padding: 0.625rem 1rem;
    background: var(--color-surface);
  }

  .progress-bar-large {
    height: 6px;
    border-radius: 3px;
  }

  .progress-fill-large {
    border-radius: 3px;
  }

  .progress-stats {
    font-size: 0.8125rem;
    margin-top: 0.375rem;
  }

  .timeline-legend {
    display: none;
  }

  /* ---- Content ---- */
  .content {
    padding: 1rem 1.25rem 7rem;
    max-width: 100%;
  }

  .page-block {
    margin-bottom: 1.5rem;
  }

  .page-header-bar {
    padding: 0.5rem 0;
    margin-bottom: 0.625rem;
  }

  .page-num {
    font-size: 0.8125rem;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
  }

  .page-section {
    font-size: 0.875rem;
  }

  .ritual-line {
    padding: 0.375rem 0.5rem;
    margin: 0 -0.5rem;
    min-height: 44px;
    border-radius: 6px;
  }

  .ritual-line:active {
    background: var(--color-surface-alt);
  }

  .ln {
    width: 1.75rem;
    font-size: 0.75rem;
    padding-top: 0.125rem;
  }

  .role-tag {
    font-size: 0.6875rem;
    padding: 0.125rem 0.375rem;
    min-width: 2.25rem;
    border-radius: 4px;
  }

  .text {
    font-size: 1rem;
    line-height: 1.6;
  }

  /* ---- Modal ---- */
  .modal-content {
    padding: 1.25rem;
    width: 92%;
    border-radius: 16px;
  }

  .help-content section {
    margin-bottom: 0.75rem;
  }
}

/* ---- Small Mobile ---- */
@media (max-width: 400px) {
  .content {
    padding: 0.75rem 1rem 2.5rem;
  }

  .text {
    font-size: 0.9375rem;
  }

  .nav-sidebar {
    height: 60vh;
  }

  .timeline-marker {
    min-height: 40px;
    padding: 0.375rem;
  }

  .role-select {
    font-size: 0.875rem;
  }
}

/* Scrollbar Styling */
.section-list::-webkit-scrollbar,
.role-timeline::-webkit-scrollbar,
.content-area::-webkit-scrollbar,
.nav-sidebar::-webkit-scrollbar {
  width: 6px;
}

.section-list::-webkit-scrollbar-track,
.role-timeline::-webkit-scrollbar-track,
.content-area::-webkit-scrollbar-track,
.nav-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.section-list::-webkit-scrollbar-thumb,
.role-timeline::-webkit-scrollbar-thumb,
.content-area::-webkit-scrollbar-thumb,
.nav-sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.section-list::-webkit-scrollbar-thumb:hover,
.role-timeline::-webkit-scrollbar-thumb:hover,
.content-area::-webkit-scrollbar-thumb:hover,
.nav-sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-light);
}
