/* ==========================================================================
   Fiqhul Masih — Academic Reader Theme
   A scholarly, library-inspired design: ivory paper, deep green ink,
   antique gold accents, serif typography for the text itself.
   ========================================================================== */

:root {
  /* Palette — ivory paper, deep scholarly green, antique gold */
  --primary: #143c2b;
  --primary-dark: #0d2b1e;
  --primary-light: #e3ecdf;
  --primary-subtle: #eff3ea;
  --accent: #8a6d1f;
  --accent-gold: #a5842e;
  --accent-light: #f6efdb;
  --bg-page: #f4f0e5;
  --bg-card: #fdfcf6;
  --bg-sidebar: #faf6ea;
  --border-color: #ddd3ba;
  --border-subtle: #e8e1cb;
  --text-main: #23281f;
  --text-muted: #4b554a;
  --text-light: #7b8473;
  --ink-on-primary: #f4f0e2;
  --shadow-sm: 0 1px 2px rgba(62, 51, 22, 0.06);
  --shadow-md: 0 4px 14px rgba(62, 51, 22, 0.10);
  --shadow-lg: 0 12px 30px rgba(62, 51, 22, 0.16);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --font-arabic: 'Amiri', 'Traditional Arabic', 'Scheherazade New', serif;
  --font-title: 'Cormorant Garamond', 'Playfair Display', Georgia, serif;
  --font-serif: 'Source Serif 4', 'Iowan Old Style', 'Charter', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --arabic-size: 26px;
  --body-size: 16.5px;
  --line-height: 1.8;
}

[data-theme="dark"] {
  --primary: #8fc3a0;
  --primary-dark: #69a17f;
  --primary-light: #22392a;
  --primary-subtle: #1d2c22;
  --accent: #cfa854;
  --accent-gold: #d4ad56;
  --accent-light: #2b2513;
  --bg-page: #141a15;
  --bg-card: #1c251e;
  --bg-sidebar: #192219;
  --border-color: #33402f;
  --border-subtle: #28352a;
  --text-main: #eceadb;
  --text-muted: #b7bfa9;
  --text-light: #8d968a;
  --ink-on-primary: #eceadb;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.55);
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: var(--line-height);
  font-size: var(--body-size);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

::selection {
  background: var(--accent-light);
  color: var(--text-main);
}

:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}

/* Search result marks */
mark {
  background: var(--accent-light);
  color: var(--text-main);
  padding: 0.05em 0.15em;
  border-radius: 2px;
  font-weight: 600;
}

/* ==========================================================================
   Top Header / Masthead
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary-dark);
  border-bottom: 3px solid var(--accent-gold);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, border-color 0.2s;
}

.header-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: var(--ink-on-primary);
  flex-shrink: 0;
}

.brand-emblem {
  width: 44px;
  height: 44px;
  background: transparent;
  color: var(--accent-gold);
  border: 1.5px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-arabic);
  font-size: 24px;
  font-weight: bold;
  flex-shrink: 0;
}

.brand-text h1 {
  font-family: var(--font-title);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink-on-primary);
  line-height: 1.1;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.brand-text .arabic-subtitle {
  font-family: var(--font-arabic);
  font-size: 1.05rem;
  color: var(--accent-gold);
  line-height: 1;
  display: block;
  margin-top: 2px;
}

/* Search Bar */
.search-container {
  flex: 1;
  max-width: 620px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.search-input {
  width: 100%;
  padding: 0.65rem 2.8rem 0.65rem 2.75rem;
  font-size: 0.92rem;
  font-family: var(--font-body);
  background-color: rgba(255, 255, 255, 0.92);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  transition: all 0.2s ease;
}

[data-theme="dark"] .search-input {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: var(--border-color);
  color: var(--text-main);
}

.search-input::placeholder {
  color: var(--text-light);
}

.search-input:focus {
  outline: none;
  background-color: var(--bg-card);
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(165, 132, 46, 0.25);
}

.search-kbd {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  color: var(--text-light);
  pointer-events: none;
}

.clear-search-btn {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  display: none;
  padding: 4px;
}

/* Header Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--ink-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.16);
  color: var(--accent-gold);
  border-color: var(--accent-gold);
}

.badge-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent-gold);
  color: var(--primary-dark);
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 9999px;
  font-weight: 700;
}

.mobile-menu-toggle {
  display: none;
}

/* ==========================================================================
   Main Layout (Sidebar + Content)
   ========================================================================== */
.site-main {
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex: 1;
  padding: 1.75rem 1.5rem;
  gap: 2rem;
}

/* Sidebar — styled like a book's table of contents */
.sidebar {
  width: 330px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.35rem 1.15rem;
  height: calc(100vh - 120px);
  position: sticky;
  top: 92px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}

.sidebar-header {
  margin-bottom: 0.9rem;
  padding-bottom: 0.8rem;
  border-bottom: 2px solid var(--primary);
}

.sidebar-title {
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-filter {
  margin-top: 0.65rem;
  width: 100%;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  font-family: var(--font-body);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
}

.sidebar-filter:focus {
  outline: none;
  border-color: var(--accent-gold);
}

.chapter-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  margin-right: -0.5rem;
  padding-right: 0.5rem;
}

.chapter-list::-webkit-scrollbar {
  width: 5px;
}
.chapter-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 9999px;
}

.chapter-item {
  margin-bottom: 0.15rem;
}

.sidebar-divider {
  height: 1px;
  background: var(--border-color);
  margin: 0.55rem 0.5rem;
  list-style: none;
  opacity: 0.85;
}

.chapter-btn {
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: var(--font-body);
  transition: all 0.15s;
}

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

.chapter-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  border-left: 3px solid var(--accent-gold);
}

.chapter-count {
  font-size: 0.72rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.5rem;
  border-radius: 9999px;
  color: var(--text-light);
  flex-shrink: 0;
}

.chapter-btn.active .chapter-count {
  background: var(--primary);
  color: var(--ink-on-primary);
  border-color: var(--primary);
}

/* ==========================================================================
   Content Area
   ========================================================================== */
.content-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* Banner — academic masthead with rules */
.chapter-banner {
  background: transparent;
  border-top: 4px double var(--primary);
  border-bottom: 1px solid var(--border-color);
  border-radius: 0;
  padding: 1.4rem 0.5rem 1.25rem;
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

.chapter-banner::before {
  content: "فقه المسيح";
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-arabic);
  font-size: 5rem;
  color: var(--primary);
  opacity: 0.06;
  pointer-events: none;
  font-weight: bold;
}

.banner-subtitle {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.banner-title {
  font-family: var(--font-title);
  font-size: 2rem;
  color: var(--primary);
  font-weight: 700;
  line-height: 1.2;
}

.banner-stats {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.8rem;
  font-size: 0.84rem;
  color: var(--text-light);
  font-family: var(--font-body);
}

.banner-stats span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Active Filter Notice */
.filter-notice {
  background: var(--accent-light);
  border: 1px solid var(--accent-gold);
  border-left: 4px solid var(--accent-gold);
  color: var(--text-main);
  padding: 0.7rem 1.15rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
}

.filter-notice button {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

/* ==========================================================================
   Topic Cards — journal-article styling
   ========================================================================== */
.topics-container {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.topic-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.6rem 1.9rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, border-color 0.15s;
  position: relative;
}

.topic-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

/* Card Header */
.card-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 1.15rem;
}

.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.badge-id {
  background: var(--primary);
  color: var(--ink-on-primary);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.4px;
  font-family: var(--font-body);
}

.badge-chapter {
  font-size: 0.76rem;
  color: var(--text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.badge-page {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--accent);
  font-size: 0.73rem;
  font-weight: 600;
  padding: 0.12rem 0.55rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
}

.badge-status {
  font-size: 0.73rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: help;
  transition: all 0.15s ease;
  font-family: var(--font-body);
  max-width: 100%;
}

.badge-status:hover {
  box-shadow: 0 2px 5px rgba(62, 51, 22, 0.12);
}

.badge-permissible {
  background: #ecf6ec;
  color: #1f5c2e;
  border: 1px solid #b8d9bc;
}
[data-theme="dark"] .badge-permissible {
  background: #14301c;
  color: #8fd3a1;
  border-color: #2e5c3d;
}

.badge-conditional {
  background: #eff7ec;
  color: #2e6231;
  border: 1px solid #b7d8af;
}
[data-theme="dark"] .badge-conditional {
  background: #152b17;
  color: #9ccf96;
  border-color: #2f522f;
}

.badge-na {
  background: #eef0ea;
  color: #5f6a5e;
  border: 1px solid #cdd3c5;
}
[data-theme="dark"] .badge-na {
  background: #242d26;
  color: #97a294;
  border-color: #39443a;
}

.badge-concession {
  background: #edf3f8;
  color: #28517a;
  border: 1px solid #bccfe2;
}
[data-theme="dark"] .badge-concession {
  background: #1a2f44;
  color: #93c0e8;
  border-color: #2e5273;
}

.badge-sunnah {
  background: #faf6e3;
  color: #7a5b12;
  border: 1px solid #e3d398;
}
[data-theme="dark"] .badge-sunnah {
  background: #332a10;
  color: #e8d284;
  border-color: #5c4d1e;
}

.badge-prohibited {
  background: #f8ecea;
  color: #8d2920;
  border: 1px solid #e4bab4;
}
[data-theme="dark"] .badge-prohibited {
  background: #3a1613;
  color: #ef9d93;
  border-color: #6b2c26;
}

.badge-laghw {
  background: #f7f0dd;
  color: #8a671d;
  border: 1px solid #e2d0a2;
}
[data-theme="dark"] .badge-laghw {
  background: #352a12;
  color: #e2c77f;
  border-color: #594a20;
}

.badge-obligatory {
  background: #f1edf7;
  color: #53308a;
  border: 1px solid #d3c6ea;
}
[data-theme="dark"] .badge-obligatory {
  background: #2a1d45;
  color: #c1aef0;
  border-color: #4a3575;
}

.card-actions {
  display: flex;
  gap: 0.3rem;
}

.action-btn {
  background: none;
  border: none;
  color: var(--text-light);
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.action-btn.active {
  color: var(--accent-gold);
}

/* Topic Title — serif display */
.topic-title {
  font-family: var(--font-title);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
  margin-bottom: 1rem;
}

/* Continuation Banner */
.continuation-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  background: var(--accent-light);
  border-left: 3px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.83rem;
  color: var(--text-muted);
}

.cont-prefix {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.8px;
  color: var(--accent);
}

.cont-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cont-link:hover {
  color: var(--accent);
}

.cont-bridge {
  flex-basis: 100%;
  line-height: 1.55;
  color: var(--text-muted);
}

/* Analysis Box — the foreground scholarly layer */
.analysis-box {
  background: var(--accent-light);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  padding: 1.05rem 1.3rem;
  margin-bottom: 1.2rem;
}

.analysis-label {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 0.55rem;
  font-family: var(--font-body);
}

.analysis-text {
  font-family: var(--font-serif);
  font-size: calc(var(--body-size) * 0.98);
  color: var(--text-main);
  line-height: var(--line-height);
  margin: 0;
}

.analysis-just {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border-color);
}

.analysis-just-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.66rem;
  letter-spacing: 1.2px;
  color: var(--primary);
  margin-bottom: 0.3rem;
  font-family: var(--font-body);
}

.analysis-just-text {
  font-family: var(--font-serif);
  font-size: calc(var(--body-size) * 0.94);
  color: var(--text-muted);
  line-height: 1.7;
  margin: 0;
}

/* Collapsible Original Book Quote */
.original-quote {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-card);
}

.quote-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.05rem;
  background: var(--primary-subtle);
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 0.74rem;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--primary);
  list-style: none;
  font-family: var(--font-body);
}

.quote-summary::-webkit-details-marker {
  display: none;
}

.quote-summary:hover {
  background: var(--primary-light);
}

.quote-chevron {
  transition: transform 0.2s ease;
  font-size: 0.75rem;
}

.original-quote[open] .quote-chevron {
  transform: rotate(180deg);
}

.quote-inner {
  padding: 1.25rem 1.4rem;
  border-top: 1px solid var(--border-color);
}

.quote-inner .arabic-box {
  margin-top: 0;
}

/* Arabic Quotation Box */
.arabic-box {
  background: var(--primary-subtle);
  border-left: 4px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1.4rem;
  margin-bottom: 1.25rem;
  direction: rtl;
  text-align: right;
}

.arabic-text {
  font-family: var(--font-arabic);
  font-size: var(--arabic-size);
  line-height: 2.2;
  color: var(--text-main);
  word-spacing: 2px;
  overflow-wrap: break-word;
}

/* English Body — serif book text */
.topic-body {
  font-family: var(--font-serif);
  font-size: var(--body-size);
  color: var(--text-main);
  line-height: var(--line-height);
  overflow-wrap: break-word;
}

.topic-body p {
  margin-bottom: 0.85rem;
}
.topic-body p:last-child {
  margin-bottom: 0;
}

/* Honorific Badges (e.g. saw, as, ra) */
.honorific {
  color: var(--accent);
  font-size: 0.88em;
  font-weight: 600;
  white-space: nowrap;
}

/* Footnotes Section */
.card-footnotes {
  margin-top: 1.15rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border-color);
  font-size: 0.82rem;
  color: var(--text-light);
}

.footnote-title {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.footnote-item {
  margin-bottom: 0.35rem;
  line-height: 1.5;
}

/* Search Highlights */
.search-highlight {
  background-color: var(--accent-light);
  color: var(--text-main);
  padding: 0.1em 0.25em;
  border-radius: 3px;
  font-weight: 600;
}

/* ==========================================================================
   Pagination Controls
   ========================================================================== */
.pagination-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.pagination-info {
  font-size: 0.86rem;
  color: var(--text-light);
  font-family: var(--font-body);
}

.pagination-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.page-btn {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.84rem;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.15s;
}

.page-btn:hover:not(:disabled):not(.disabled) {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.page-btn.active {
  background: var(--primary);
  color: var(--ink-on-primary);
  border-color: var(--primary);
  font-weight: 600;
}

.page-btn:disabled,
.page-btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--primary-dark);
  color: var(--ink-on-primary);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-container.show {
  transform: translateY(0);
  opacity: 1;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1024px) {
  .site-main {
    padding: 1rem;
    gap: 1.25rem;
  }
  .sidebar {
    width: 280px;
  }
}

@media (max-width: 820px) {
  .mobile-menu-toggle {
    display: flex;
  }
  .search-kbd {
    display: none;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 300px;
    height: 100vh;
    z-index: 200;
    border-radius: 0;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(20, 26, 21, 0.55);
    z-index: 199;
    display: none;
  }
  .sidebar-backdrop.open {
    display: block;
  }
  .chapter-banner {
    padding: 1.1rem 0.25rem 1rem;
  }
  .banner-title {
    font-size: 1.55rem;
  }
  .topic-card {
    padding: 1.25rem;
  }
}

/* ==========================================================================
   Jurisprudence Classifications Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(20, 26, 21, 0.6);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.show {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  max-width: 760px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 0.9rem;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-family: var(--font-title);
  color: var(--primary);
  font-size: 1.55rem;
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}
.modal-close-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

.ruling-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.15rem;
  margin-bottom: 1rem;
  background: var(--bg-page);
}

.ruling-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ruling-card h4 {
  font-size: 1.2rem;
  color: var(--primary);
  font-family: var(--font-title);
}

.ruling-card p {
  font-size: 0.92rem;
  color: var(--text-main);
  line-height: 1.7;
}

.ruling-card .citation {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.5rem;
  font-style: italic;
  border-top: 1px dashed var(--border-subtle);
  padding-top: 0.4rem;
}

/* ==========================================================================
   Web Table of Contents
   ========================================================================== */
.web-toc {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.toc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.2rem;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}

.toc-search-box {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 260px;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  color: var(--text-light);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.toc-search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(165, 132, 46, 0.18);
  color: var(--primary);
}

.toc-filter-input {
  border: none;
  background: transparent;
  width: 100%;
  font-size: 0.92rem;
  font-family: var(--font-body);
  color: var(--text-main);
  outline: none;
}

.toc-filter-input::placeholder {
  color: var(--text-light);
}

.toc-clear-btn {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
}
.toc-clear-btn:hover {
  color: var(--text-main);
}

.toc-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toc-action-btn {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font-body);
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.toc-action-btn:hover {
  background: var(--primary);
  color: var(--ink-on-primary);
  border-color: var(--primary);
}

.toc-chapters-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.toc-chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.toc-chapter-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.toc-chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.05rem 1.35rem;
  cursor: pointer;
  background: var(--bg-card);
  user-select: none;
  transition: background 0.15s ease;
  gap: 1rem;
}

.toc-chapter-header:hover {
  background: var(--accent-light);
}

.toc-chapter-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  flex: 1;
}

.toc-chapter-num {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.75px;
  color: var(--accent);
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  font-family: var(--font-body);
}

.toc-chapter-title {
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  line-height: 1.3;
}

.toc-chapter-count {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-light);
  background: var(--bg-page);
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
  font-family: var(--font-body);
}

.toc-chapter-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.toc-read-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--primary-subtle);
  color: var(--primary);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-body);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.toc-read-btn:hover {
  background: var(--primary);
  color: var(--ink-on-primary);
  border-color: var(--primary);
}

.toc-chevron-btn {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: transform 0.2s ease, color 0.15s ease;
}

.toc-chevron-icon {
  transition: transform 0.2s ease;
}

.toc-chapter-card.open .toc-chevron-icon {
  transform: rotate(180deg);
}

.toc-chapter-body {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-page);
  padding: 0.85rem 1.25rem 1.25rem;
}

.toc-topic-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc-topic-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.95rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  text-decoration: none;
  gap: 0.85rem;
  transition: all 0.15s ease;
  cursor: pointer;
}

.toc-topic-link:hover {
  border-color: var(--primary);
  transform: translateX(3px);
  box-shadow: var(--shadow-sm);
}

.toc-topic-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
}

.toc-topic-badge {
  background: var(--primary);
  color: var(--ink-on-primary);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.12rem 0.45rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  font-family: var(--font-body);
}

.toc-topic-title {
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-topic-link:hover .toc-topic-title {
  color: var(--primary);
}

.toc-topic-meta {
  flex-shrink: 0;
}

.toc-topic-meta .badge-status {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
}

/* Responsive adjustment for Mobile */
@media (max-width: 680px) {
  .toc-chapter-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
  }
  .toc-chapter-right {
    width: 100%;
    justify-content: space-between;
  }
  .toc-topic-link {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
  }
  .toc-topic-title {
    white-space: normal;
  }
}

/* ==========================================================================
   Terminology (Glossary Dictionary)
   ========================================================================== */
.terminology-page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.term-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.term-search-box {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.95rem;
  color: var(--text-light);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.term-search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(165, 132, 46, 0.18);
  color: var(--primary);
}

.term-search-input {
  border: none;
  background: transparent;
  width: 100%;
  font-size: 0.95rem;
  font-family: var(--font-body);
  color: var(--text-main);
  outline: none;
}

.term-search-input::placeholder {
  color: var(--text-light);
}

.term-clear-btn {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.term-clear-btn:hover {
  color: var(--text-main);
}

.term-alpha-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border-subtle);
}

.term-alpha-btn {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-body);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.term-alpha-btn:hover {
  background: var(--accent-light);
  color: var(--primary);
  border-color: var(--accent-gold);
}

.term-alpha-btn.active {
  background: var(--primary);
  color: var(--ink-on-primary);
  border-color: var(--primary);
}

.term-groups-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.term-group-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.term-letter-header {
  font-family: var(--font-title);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 2px solid var(--accent-gold);
  padding-bottom: 0.25rem;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.term-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.term-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.15rem 1.45rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.term-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.term-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.55rem;
}

.term-word {
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  line-height: 1.3;
}

.term-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.term-action-btn {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-light);
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.term-action-btn:hover {
  background: var(--primary);
  color: var(--ink-on-primary);
  border-color: var(--primary);
}

.term-definition {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text-main);
  margin: 0;
}

.term-footnotes {
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-light);
  font-style: italic;
}

/* ==========================================================================
   Deep-link Highlight Pulse
   ========================================================================== */
@keyframes highlightPulse {
  0% { box-shadow: 0 0 0 0 rgba(165, 132, 46, 0.55); }
  60% { box-shadow: 0 0 0 8px rgba(165, 132, 46, 0.18); }
  100% { box-shadow: 0 0 0 0 rgba(165, 132, 46, 0); }
}

.highlight-pulse {
  animation: highlightPulse 1.6s ease-out 2;
  border-color: var(--accent-gold) !important;
}

/* ==========================================================================
   Mobile / Phone Compatibility (<820px tablets, <480px phones)
   ========================================================================== */
@media (max-width: 820px) {
  /* Header: brand + actions on row 1, search drops to full-width row 2 */
  .header-inner {
    flex-wrap: wrap;
    gap: 0.6rem 0.75rem;
    padding: 0.6rem 1rem;
  }
  .header-actions {
    margin-left: auto;
  }
  .search-container {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
  }
  /* >=16px prevents iOS Safari auto-zoom on input focus */
  .search-input {
    font-size: 16px;
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
  }
  .term-search-input {
    font-size: 16px;
  }

  /* Compact brand */
  .brand-emblem {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }
  .brand-text h1 {
    font-size: 1.1rem;
    letter-spacing: 1px;
  }

  /* Drawer sized to the device */
  .sidebar {
    width: min(300px, 85vw);
  }

  /* Card headers: keep action buttons tidy on narrow cards */
  .card-actions {
    margin-left: auto;
  }

  .banner-stats {
    flex-wrap: wrap;
  }

  .filter-notice {
    flex-wrap: wrap;
  }

  .modal-content {
    padding: 1.25rem;
  }
}

@media (max-width: 480px) {
  /* Icon-only brand: the banner below carries the full title */
  .brand-text {
    display: none;
  }

  .btn-icon {
    width: 34px;
    height: 34px;
  }
  .header-actions {
    gap: 0.3rem;
  }
  .header-inner {
    padding: 0.5rem 0.75rem;
  }

  .site-main {
    padding: 0.75rem;
  }
  .chapter-banner {
    padding: 1rem 0.15rem 0.85rem;
  }
  .banner-title {
    font-size: 1.3rem;
  }

  .topic-card {
    padding: 1rem 0.9rem;
  }
  .topic-title {
    font-size: 1.2rem;
  }
  .arabic-box {
    padding: 0.85rem 0.9rem;
  }
  :root {
    --arabic-size: 22px;
  }

  .page-btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
  }
  .pagination-container {
    justify-content: center;
    text-align: center;
  }

  .modal-content {
    padding: 1rem;
    max-height: 92vh;
  }
  .modal-title {
    font-size: 1.2rem;
  }

  .term-card {
    padding: 0.95rem 1rem;
  }
  .term-alpha-btn {
    padding: 0.3rem 0.6rem;
  }
}

/* Prevent stray horizontal scroll without breaking position:sticky */
body {
  overflow-x: clip;
}

/* ==========================================================================
   Jurisprudence Guide Button — animated attention glow
   ========================================================================== */
@keyframes guideGlow {
  0%, 100% {
    box-shadow: 0 0 1px rgba(212, 173, 86, 0.2);
  }
  50% {
    box-shadow: 0 0 4px 1px rgba(212, 173, 86, 0.45);
  }
}

#rulingsGuideBtn {
  border-color: var(--accent-gold);
  animation: guideGlow 3s ease-in-out infinite;
}

#rulingsGuideBtn:hover {
  animation-play-state: paused;
  border-color: var(--accent-gold);
}

@media (prefers-reduced-motion: reduce) {
  #rulingsGuideBtn {
    animation: none;
  }
}
