/* Reading Progress Bar */
.reading-progress {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--color-light-gray);
  z-index: 1001;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.reading-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-electric-blue), var(--color-hot-pink));
  width: 0%;
  transition: width 0.1s ease-out;
}

/* Reader Layout */
.reader-container {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--spacing-2xl);
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--spacing-lg);
}

.reader-toc {
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  padding: var(--spacing-lg);
  background: linear-gradient(180deg,
    rgba(98, 71, 170, 0.06) 0%,
    rgba(0, 217, 255, 0.06) 100%
  ),
  var(--color-white);
  border-right: 2px solid var(--color-border-gray);
  border-radius: var(--radius-sm);
}


.reader-content {
  max-width: 800px;
  line-height: 1.7;
}

/* Anchor scroll offset - ensures titles are visible below sticky breadcrumb */
.reader-content h1[id],
.reader-content h2[id],
.reader-content h3[id],
.reader-content [id^="ch-"],
.reader-content [id^="part-"] {
  scroll-margin-top: 5rem;
}

/* TOC Styling */
.toc-root,
.toc-list,
.toc-root ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list li {
  margin-bottom: var(--spacing-xs);
}

.toc-list a {
  display: block;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  color: var(--color-ink-black);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.toc-list a:hover {
  background: var(--color-light-blue);
  color: var(--color-electric-blue);
}

.toc-root a.active,
.toc-list a.active {
  color: var(--color-hot-pink);
  font-weight: 700;
  border-left: 3px solid var(--color-hot-pink);
  padding-left: var(--spacing-xs);
}

/* Add bottom margin to last nested TOC list for scrollability */
.toc-root > li:last-child > ul {
  margin-bottom: 100px;
}

/* Content Typography */
.reader-content h1 {
  color: var(--color-electric-blue);
  font-size: 2.75rem;
  margin-top: var(--spacing-2xl);
  margin-bottom: var(--spacing-lg);
}

.reader-content h2 {
  color: var(--color-electric-blue);
  font-size: 2rem;
  margin-top: var(--spacing-xl);
  margin-bottom: var(--spacing-md);
  border-bottom: 2px solid var(--color-border-gray);
  padding-bottom: var(--spacing-sm);
}

.reader-content h3 {
  color: var(--color-hot-pink);
  font-size: 1.4rem;
  margin-top: var(--spacing-lg);
  margin-bottom: var(--spacing-sm);
}

.reader-content h4 {
  color: var(--color-ink-black);
  font-size: 1.1rem;
  margin-top: var(--spacing-md);
  margin-bottom: var(--spacing-sm);
  font-weight: 600;
}

/* Tables */
.reader-content table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--spacing-lg) 0;
  font-size: 0.95rem;
}

.reader-content thead {
  background: var(--color-light-purple);
}

.reader-content th {
  padding: var(--spacing-sm) var(--spacing-md);
  text-align: left;
  font-weight: 600;
  color: var(--color-deep-purple);
  border-bottom: 2px solid var(--color-deep-purple);
}

.reader-content td {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-border-gray);
}

.reader-content tr:hover {
  background: var(--color-light-gray);
}

/* Lists */
.reader-content ul,
.reader-content ol {
  margin: var(--spacing-md) 0;
  padding-left: var(--spacing-xl);
}

.reader-content li {
  margin-bottom: var(--spacing-xs);
}

/* Code blocks */
.reader-content .example,
.reader-content .gm {
  background: var(--color-light-blue);
  border-left: 4px solid var(--color-electric-blue);
  padding: var(--spacing-md) var(--spacing-lg);
  margin: var(--spacing-lg) 0;
  border-radius: var(--radius-md);
}

.reader-content .gm {
  border-left-color: var(--color-deep-purple);
  background: var(--color-light-purple);
}

/* Breadcrumb Navigation */
.breadcrumb {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-md) var(--spacing-lg);
  padding-top: calc(var(--spacing-md) + 4px);
  padding-bottom: calc(var(--spacing-md) - 4px);
  margin-bottom: var(--spacing-lg);
  font-size: 0.9rem;
  color: var(--color-medium-gray);
  position: sticky;
  top: -25px; /* Overlaps header slightly */
  background: var(--color-white);
  z-index: 999; /* Just below header (1000) but above content */
  margin-left: calc(var(--spacing-lg) * -1);
  margin-right: calc(var(--spacing-lg) * -1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow: visible;
}

.breadcrumb > a {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  position: relative;
  color: var(--color-electric-blue);
  text-decoration: none;
}

.breadcrumb > a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--color-hot-pink);
  transition: width var(--transition-normal);
}

.breadcrumb > a:hover {
  background: var(--color-light-pink);
  color: var(--color-deep-purple);
  text-decoration: none;
}

.breadcrumb > a:hover::after {
  width: 100%;
}

.breadcrumb-search-btn {
  background: none;
  border: none;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  color: var(--color-electric-blue);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 500;
  position: relative;
}

.breadcrumb-search-btn::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--color-hot-pink);
  transition: width var(--transition-normal);
}

.breadcrumb-search-btn:hover {
  background: var(--color-light-pink);
  color: var(--color-deep-purple);
}

.breadcrumb-search-btn:hover::after {
  width: 100%;
}

.breadcrumb-search-btn:active {
  transform: scale(0.98);
}

.breadcrumb-feedback-link {
  background: none;
  border: none;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  color: var(--color-hot-pink);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}

.breadcrumb-feedback-link:hover {
  background: var(--color-light-pink);
  color: var(--color-deep-purple);
  text-decoration: none;
}

.breadcrumb-feedback-link:active {
  transform: scale(0.98);
}

.breadcrumb-icon-btn {
  background: none;
  border: none;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  color: var(--color-electric-blue);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 500;
  position: relative;
}

.breadcrumb-icon-btn::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--color-hot-pink);
  transition: width var(--transition-normal);
}

.breadcrumb-icon-btn:hover {
  background: var(--color-light-pink);
  color: var(--color-deep-purple);
}

.breadcrumb-icon-btn:hover::after {
  width: 100%;
}

.breadcrumb-icon-btn:active {
  transform: scale(0.98);
}

/* Breadcrumb corner decorations - bottom corners */
.breadcrumb::before {
  content: '';
  position: absolute;
  bottom: -6px;
  left: -10px;
  width: 50px;
  height: 50px;
  background: url('/images/decorative/corner-bl.png') no-repeat;
  background-size: contain;
  opacity: 0.5;
  pointer-events: none;
  z-index: 1;
}

.breadcrumb::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: -10px;
  width: 50px;
  height: 50px;
  background: url('/images/decorative/corner-br.png') no-repeat;
  background-size: contain;
  opacity: 0.5;
  pointer-events: none;
  z-index: 1;
}

.breadcrumb a {
  color: var(--color-electric-blue);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb-separator {
  color: var(--color-medium-gray);
}

.breadcrumb-current {
  font-weight: 600;
  color: var(--color-ink-black);
}

@media (max-width: 768px) {
  .breadcrumb {
    font-size: 0.85rem;
    padding: var(--spacing-sm) 0;
  }
}

/* Chapter Navigation (Prev/Next buttons) */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: var(--spacing-2xl) 0;
  padding: var(--spacing-lg);
  background: var(--color-light-blue);
  border-radius: var(--radius-md);
  gap: var(--spacing-md);
}

.chapter-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-lg);
  background: var(--color-electric-blue);
  color: var(--color-white);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.chapter-nav-btn:hover {
  background: var(--color-hot-pink);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.chapter-nav-btn.prev::before {
  content: '←';
  font-size: 1.2em;
}

.chapter-nav-btn.next::after {
  content: '→';
  font-size: 1.2em;
}

.chapter-nav-spacer {
  flex: 1;
}

@media (max-width: 768px) {
  .chapter-nav {
    flex-direction: column;
    gap: var(--spacing-sm);
  }

  .chapter-nav-btn {
    width: 100%;
    justify-content: center;
  }

  .chapter-nav-spacer {
    display: none;
  }
}

/* Quick Jump Modal (Ctrl+K) */
.quick-jump-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  justify-content: center;
  align-items: flex-start;
  padding-top: 15vh;
  backdrop-filter: blur(4px);
}

.quick-jump-modal.open {
  display: flex;
}

.quick-jump-container {
  width: 100%;
  max-width: 600px;
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.quick-jump-search {
  width: 100%;
  padding: var(--spacing-lg);
  font-size: 1.125rem;
  border: none;
  border-bottom: 2px solid var(--color-border-gray);
  font-family: 'Inter', sans-serif;
  outline: none;
}

.quick-jump-search:focus {
  border-bottom-color: var(--color-electric-blue);
}

.quick-jump-results {
  max-height: 400px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

.quick-jump-result {
  padding: var(--spacing-md) var(--spacing-lg);
  cursor: pointer;
  border-bottom: 1px solid var(--color-light-gray);
  transition: background var(--transition-fast);
}

.quick-jump-result:hover,
.quick-jump-result.selected {
  background: var(--color-light-blue);
}

.quick-jump-result.selected {
  border-left: 4px solid var(--color-electric-blue);
}

.quick-jump-result-title {
  font-weight: 600;
  color: var(--color-ink-black);
  margin-bottom: var(--spacing-xs);
}

.quick-jump-result-path {
  font-size: 0.875rem;
  color: var(--color-medium-gray);
}

.quick-jump-hint {
  padding: var(--spacing-md) var(--spacing-lg);
  text-align: center;
  color: var(--color-medium-gray);
  font-size: 0.875rem;
  border-top: 1px solid var(--color-border-gray);
}

.quick-jump-hint kbd {
  display: inline-block;
  padding: 0.15em 0.4em;
  background: var(--color-light-gray);
  border: 1px solid var(--color-border-gray);
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.85em;
  margin: 0 0.2em;
}

.quick-jump-empty {
  padding: var(--spacing-xl);
  text-align: center;
  color: var(--color-medium-gray);
}

@media (max-width: 768px) {
  .quick-jump-modal {
    padding-top: 10vh;
  }

  .quick-jump-container {
    margin: 0 var(--spacing-md);
  }

  .quick-jump-results {
    max-height: 50vh;
  }
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Tablet Responsive (768px and below) */
@media (max-width: 768px) {
  .reader-container {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

  .reader-toc {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100vh;
    background: var(--color-white);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: left var(--transition-normal);
    padding: var(--spacing-lg);
  }

  .reader-toc.open {
    left: 0;
  }

  .reader-content {
    padding: var(--spacing-lg);
  }

  .toc-toggle {
    display: block;
    position: fixed;
    top: var(--spacing-md);
    left: var(--spacing-md);
    z-index: 999;
    background: var(--color-electric-blue);
    color: var(--color-white);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-md);
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-md);
  }

  .toc-toggle:hover {
    background: var(--color-deep-purple);
  }
}

/* Desktop - hide toggle */
@media (min-width: 769px) {
  .toc-toggle {
    display: none;
  }
}

/* Mobile (480px and below) */
@media (max-width: 480px) {
  .reader-content h1 {
    font-size: 2rem;
  }

  .reader-content h2 {
    font-size: 1.5rem;
  }

  .reader-content h3 {
    font-size: 1.2rem;
  }
}

/* ============================================================================
   BOOKMARKING SYSTEM
   ============================================================================ */

/* Bookmark buttons on headings */
.bookmark-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--color-medium-gray);
  cursor: pointer;
  padding: 0.25rem;
  margin-left: 0.5rem;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: all var(--transition-fast);
  vertical-align: middle;
}

.reader-content h2:hover .bookmark-btn,
.reader-content h3:hover .bookmark-btn,
.bookmark-btn:focus {
  opacity: 1;
}

.bookmark-btn:hover {
  background: var(--color-light-blue);
  color: var(--color-electric-blue);
}

.bookmark-btn.bookmarked {
  opacity: 1;
  color: var(--color-hot-pink);
}

.bookmark-btn.bookmarked:hover {
  background: var(--color-light-pink);
  color: var(--color-hot-pink);
}

/* Bookmarks dropdown in header */
.bookmarks-dropdown {
  position: relative;
}

.bookmarks-toggle {
  position: relative;
}

.bookmarks-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: var(--color-hot-pink);
  color: var(--color-white);
  border-radius: 9px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

.bookmarks-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--color-white);
  border: 2px solid var(--color-border-gray);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 350px;
  z-index: 1001;
  overflow: hidden;
}

.bookmarks-menu.open {
  display: block;
  animation: dropdownSlideIn 0.2s ease-out;
}

@keyframes dropdownSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bookmarks-header {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 2px solid var(--color-border-gray);
  background: linear-gradient(135deg,
    var(--color-light-blue) 0%,
    var(--color-light-purple) 100%
  );
}

.bookmarks-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-deep-purple);
}

.bookmarks-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 350px;
  overflow-y: auto;
}

.bookmark-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-light-gray);
  transition: background var(--transition-fast);
}

.bookmark-item:hover {
  background: var(--color-light-blue);
}

.bookmark-link {
  flex: 1;
  color: var(--color-ink-black);
  text-decoration: none;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-link:hover {
  color: var(--color-electric-blue);
  text-decoration: underline;
}

.bookmark-remove {
  background: none;
  border: none;
  color: var(--color-medium-gray);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.bookmark-remove:hover {
  background: var(--color-light-pink);
  color: var(--color-hot-pink);
}

.bookmarks-empty {
  padding: var(--spacing-xl);
  text-align: center;
  color: var(--color-medium-gray);
  font-size: 0.9rem;
}

/* ============================================================================
   READER MODE (Distraction-Free)
   ============================================================================ */

.reader-mode-toggle {
  /* Inherits from .breadcrumb-icon-btn */
}

/* Hide elements in reader mode */
body.reader-mode .site-header,
body.reader-mode .site-footer,
body.reader-mode .breadcrumb,
body.reader-mode .chapter-nav,
body.reader-mode .reader-toc,
body.reader-mode .toc-toggle,
body.reader-mode .bookmark-btn,
body.reader-mode .bookmarks-dropdown,
body.reader-mode .reading-progress {
  display: none !important;
}

/* Expand content in reader mode */
body.reader-mode {
  overflow-x: hidden; /* Prevent horizontal scroll */
}

body.reader-mode .reader-container {
  grid-template-columns: 1fr;
  max-width: 900px;
  margin: 0 auto;
  padding: var(--spacing-2xl);
  overflow-x: hidden;
}

body.reader-mode .reader-content {
  max-width: 100%;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Keep reader mode toggle visible */
body.reader-mode .reader-mode-toggle {
  position: fixed;
  top: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: 1000;
  background: var(--color-white);
  border: 2px solid var(--color-border-gray);
  padding: 0.75rem;
  box-shadow: var(--shadow-lg);
  opacity: 0.3;
  transition: opacity var(--transition-fast);
}

body.reader-mode .reader-mode-toggle:hover {
  opacity: 1;
}

/* Reader mode close button */
.reader-mode-close {
  display: none; /* Hidden by default */
  position: fixed;
  top: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: 1001; /* Above reader-mode-toggle */
  background: var(--color-white);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  cursor: pointer;
  box-shadow: var(--shadow-xl);
  transition: all var(--transition-fast);
  color: var(--color-primary);
}

body.reader-mode .reader-mode-close {
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-mode-close:hover {
  background: var(--color-primary);
  color: var(--color-white);
  transform: scale(1.1);
}

.reader-mode-close:active {
  transform: scale(0.95);
}

/* ============================================================================
   KEYBOARD SHORTCUTS HELP PANEL
   ============================================================================ */

.shortcuts-help-panel {
  position: fixed;
  top: 0;
  right: -320px;
  width: 300px;
  height: 100vh;
  background: var(--color-white);
  border-left: 2px solid var(--color-border-gray);
  box-shadow: var(--shadow-xl);
  z-index: 1002;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.shortcuts-help-panel.open {
  right: 0;
}

.shortcuts-help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--color-border-gray);
  background: linear-gradient(135deg,
    rgba(98, 71, 170, 0.08) 0%,
    rgba(0, 217, 255, 0.08) 100%
  );
}

.shortcuts-help-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-primary);
}

.shortcuts-help-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--color-medium-gray);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.shortcuts-help-close:hover {
  color: var(--color-primary);
  background: rgba(98, 71, 170, 0.1);
}

.shortcuts-help-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md) var(--spacing-lg);
}

.shortcuts-group {
  margin-bottom: var(--spacing-lg);
}

.shortcuts-group h4 {
  margin: 0 0 var(--spacing-sm) 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-medium-gray);
}

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-xs) 0;
  font-size: 0.875rem;
}

.shortcut-row kbd {
  font-family: var(--font-body);
  font-size: 0.8rem;
  background: var(--color-light-gray);
  border: 1px solid var(--color-border-gray);
  border-radius: var(--radius-xs);
  padding: 0.15rem 0.4rem;
  color: var(--color-dark-gray);
  white-space: nowrap;
}

.shortcut-row span {
  color: var(--color-dark-gray);
}

.shortcut-note {
  font-size: 0.7rem;
  color: var(--color-medium-gray);
  margin-left: 0.25rem;
}

/* Help button in breadcrumb */
.shortcuts-help-btn {
  /* Inherits from .breadcrumb-icon-btn */
}

/* Dark mode support */
[data-theme="dark"] .shortcuts-help-panel {
  background: var(--color-dark-gray);
  border-left-color: var(--color-medium-gray);
}

[data-theme="dark"] .shortcuts-help-header {
  background: linear-gradient(135deg,
    rgba(98, 71, 170, 0.2) 0%,
    rgba(0, 217, 255, 0.2) 100%
  );
}

[data-theme="dark"] .shortcuts-help-header h3 {
  color: var(--color-electric-blue);
}

[data-theme="dark"] .shortcut-row kbd {
  background: var(--color-medium-gray);
  border-color: var(--color-light-gray);
  color: var(--color-white);
}

[data-theme="dark"] .shortcut-row span {
  color: var(--color-light-gray);
}

/* ============================================================================
   PRINT OPTIMIZATION
   ============================================================================ */

@media print {
  /* Hide texture overlay that blocks content */
  body::after {
    display: none !important;
  }

  /* Page breaks - Tier 1: Part sections only */
  .reader-content .part-intro {
    page-break-before: always;
    page-break-after: avoid;
  }

  /* Exception: Don't force blank first page */
  .reader-content .part-intro:first-of-type {
    page-break-before: auto;
  }

  /* All H1s: no forced breaks (let content flow naturally) */
  .reader-content h1 {
    page-break-before: auto;
    page-break-after: avoid;
  }

  /* Page breaks - Tier 2: Strongly avoid breaks in content blocks */
  /* Firefox-compatible: use only page-break-* properties, not break-* */
  .reader-content table,
  .reader-content .example,
  .reader-content .gm,
  .reader-content ul,
  .reader-content ol {
    page-break-inside: avoid;
  }

  /* For glossary/index: allow breaks but keep dt+dd together */
  .reader-content dl {
    page-break-inside: auto;
  }

  .reader-content dt,
  .reader-content dd {
    page-break-inside: avoid;
  }

  /* Keep dt with its dd */
  .reader-content dt {
    page-break-after: avoid;
  }

  /* Table handling - simplified for Firefox compatibility */
  .reader-content table {
    page-break-inside: auto; /* Allow tables to break if needed */
  }

  .reader-content tr {
    page-break-inside: avoid;
  }

  /* Table headers repeat - Firefox needs thead display */
  .reader-content thead {
    display: table-header-group;
  }

  /* Prevent orphaned table cells */
  .reader-content td,
  .reader-content th {
    page-break-inside: avoid;
  }

  /* Page breaks - Tier 3: Soft guidance for headings */
  .reader-content h2 {
    page-break-after: avoid; /* Keep with following content */
    page-break-before: auto; /* Allow natural breaks if needed */
  }

  .reader-content h3,
  .reader-content h4 {
    page-break-after: avoid; /* Keep with following content */
  }

  /* Hide navigation and interactive elements */
  .site-header,
  .site-footer,
  .reader-toc,
  .toc-toggle,
  .breadcrumb,
  .chapter-nav,
  .bookmark-btn,
  .bookmarks-dropdown,
  .reader-mode-toggle,
  .reader-mode-close,
  .reading-progress {
    display: none;
  }

  /* Hide web-only content */
  #keyboard-shortcuts,
  .web-only {
    display: none;
  }

  /* Full width content */
  .reader-container {
    grid-template-columns: 1fr;
    max-width: 100%;
    padding: 20pt;
  }

  .reader-content {
    max-width: 100%;
  }

  /* Typography with spacing */
  .reader-content h1 {
    font-size: 20pt;
    margin-top: 0; /* Starts new page */
    margin-bottom: 2rem;
  }

  .reader-content h2 {
    font-size: 16pt;
    margin-top: 1.5rem;
    border-bottom: 2pt solid #000; /* Visual divider */
    padding-bottom: 0.5rem;
  }

  .reader-content h3 {
    font-size: 13pt;
    margin-top: 1rem;
  }

  .reader-content h4 {
    font-size: 12pt;
    margin-top: 0.75rem;
  }

  /* Visual distinction for special content */
  .reader-content .example {
    border-left: 4pt solid #0099cc;
    padding: 1rem;
    margin: 1rem 0;
    background: rgba(0, 217, 255, 0.1) !important;
  }

  .reader-content .gm {
    border-left: 4pt solid #7B2CBF;
    padding: 1rem;
    margin: 1rem 0;
    background: rgba(123, 44, 191, 0.1) !important;
  }

  /* Prevent orphaned borders on headings */
  .reader-content h2 {
    overflow: visible; /* Ensure border doesn't orphan */
  }

  /* Table spacing */
  .reader-content table {
    margin: 1rem 0;
  }

  /* Improved readability */
  body {
    line-height: 1.6;
  }

  /* Orphans and widows */
  .reader-content p,
  .reader-content li {
    orphans: 3;
    widows: 3;
  }
}
