/* ==========================================================================
   📜 UGC NET PAPER ONE — LAYOUT & COMPONENTS (components.css)
   ========================================================================== */

/* ── App Shell ────────────────────────────────────────────────── */
.app-container {
  display: flex;
  /* Do NOT use min-height:100vh here — it traps content inside the viewport
     and prevents the page from scrolling on mobile */
  position: relative;
}

/* ── Mobile Top Nav Bar ───────────────────────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background-color: var(--parchment-dark);
  border-bottom: 2px solid var(--accent-gold);
  z-index: 300;
  padding: 0 1rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.mobile-topbar-brand {
  font-family: var(--font-serif-display);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent-crimson);
  text-decoration: none;
  border-bottom: none;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-topbar-brand:hover {
  background-color: transparent;
  color: var(--accent-gold);
}

.topbar-btn-group {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-shrink: 0;
}

.topbar-icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--ink);
  font-size: 1.1rem;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;
  flex-shrink: 0;
}

.topbar-icon-btn:hover,
.topbar-icon-btn:focus-visible {
  border-color: var(--accent-gold);
  background-color: rgba(184, 134, 11, 0.12);
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 6px;
  background: none;
  border: 1px solid var(--accent-gold);
  border-radius: 6px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background-color: var(--ink);
  border-radius: 2px;
  transition: all 0.3s ease;
  transform-origin: center;
}

.hamburger-btn.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger-btn.open span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.hamburger-btn.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── Sidebar Overlay (mobile backdrop) ───────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(10, 6, 3, 0.65);
  z-index: 190;
  opacity: 0;
  transition: opacity var(--transition-speed) ease;
  backdrop-filter: blur(2px);
}

/* ── Sidebar TOC ──────────────────────────────────────────────── */
.sidebar-toc {
  width: 300px;
  background-color: var(--parchment-dark);
  border-right: 3px double var(--accent-gold);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.sidebar-header {
  border-bottom: 2px solid var(--accent-gold);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.sidebar-header h2 {
  font-family: var(--font-serif-display);
  font-size: 1.3rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 3px;
  border-bottom: none;
  margin-top: 0;
  margin-bottom: 0.4rem;
  color: var(--accent-crimson);
}

.sidebar-header p {
  font-size: 0.82rem;
  text-align: center;
  font-style: italic;
  margin-bottom: 0;
  color: var(--ink-light);
}

/* Progress bar in sidebar */
.sidebar-progress {
  margin-bottom: 1.2rem;
  padding: 0.7rem 0.8rem;
  background-color: var(--vellum);
  border: var(--border-gold);
  border-radius: 4px;
}

.sidebar-progress-label {
  font-size: 0.78rem;
  color: var(--ink-light);
  margin-bottom: 0.4rem;
  display: flex;
  justify-content: space-between;
}

.sidebar-progress-bar-track {
  height: 6px;
  background-color: var(--parchment-dark);
  border-radius: 3px;
  overflow: hidden;
}

.sidebar-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-gold), var(--accent-crimson));
  border-radius: 3px;
  transition: width 0.6s ease;
  width: 0%;
}

.toc-nav ul {
  list-style: none;
  padding-left: 0;
}

.toc-nav > ul > li {
  margin-bottom: 0.3rem;
}

.toc-chapter {
  font-family: var(--font-serif-display);
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  padding: 0.45rem 0.6rem;
  color: var(--ink);
  border-radius: 4px;
  border-bottom: none;
  position: relative;
  transition: all var(--transition-speed) ease;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
  gap: 0.4rem;
}

.toc-chapter:hover {
  color: var(--accent-crimson);
  background-color: rgba(139, 26, 26, 0.07);
}

.toc-indicator {
  font-size: 0.55rem;
  color: var(--accent-gold);
  transition: transform var(--transition-speed) ease;
  display: inline-block;
  flex-shrink: 0;
}

.toc-indicator.open {
  transform: rotate(90deg);
}

.active-chapter .toc-indicator {
  color: var(--accent-crimson);
}

.toc-subsections {
  margin-top: 0.2rem;
  margin-bottom: 0.5rem;
  padding-left: 1.2rem;
  border-left: 2px solid rgba(184, 134, 11, 0.4);
  display: none;
  overflow: hidden;
}

.toc-subsections.open {
  display: block;
  animation: slideDown 0.2s ease;
}

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

.toc-subsections li {
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
}

.toc-subsections a {
  color: var(--ink-light);
  border-bottom: none;
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: 3px;
  transition: all var(--transition-speed) ease;
  line-height: 1.3;
}

.toc-subsections a:hover {
  color: var(--accent-crimson);
  background-color: rgba(139, 26, 26, 0.06);
}

.active-item {
  color: var(--accent-crimson) !important;
  font-weight: bold;
  background-color: rgba(139, 26, 26, 0.08) !important;
}

/* ── Main Content Area ────────────────────────────────────────── */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1.5rem;
  /* NO overflow-y:auto — let the page (body) scroll naturally */
  min-width: 0;
  /* Prevent content from overflowing on narrow screens */
  overflow-x: hidden;
}

/* ── Top Toolbar ──────────────────────────────────────────────── */
.top-toolbar {
  width: 100%;
  max-width: 860px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  margin-bottom: 1.5rem;
  background-color: var(--parchment-dark);
  border: var(--border-gold);
  border-radius: 6px;
  font-size: 0.88rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar-group {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--ink);
  font-family: var(--font-serif-body);
  font-size: 0.84rem;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  transition: all var(--transition-speed) ease;
  white-space: nowrap;
}

.toolbar-btn:hover {
  border-color: var(--accent-gold);
  background-color: rgba(184, 134, 11, 0.1);
}

/* ── Manuscript Page Wrapper ──────────────────────────────────── */
.manuscript-wrapper {
  width: 100%;
  max-width: 860px;
  background-color: var(--vellum);
  border: 1px solid var(--parchment-dark);
  box-shadow: var(--shadow-deep);
  padding: 3rem 3.5rem;
  position: relative;
  border-radius: 4px;
}

/* Double border page frame — desktop only */
.manuscript-wrapper::before {
  content: "";
  position: absolute;
  top: 14px; bottom: 14px;
  left: 14px; right: 14px;
  border: 1px solid rgba(184, 134, 11, 0.2);
  pointer-events: none;
}

.manuscript-wrapper::after {
  content: "";
  position: absolute;
  top: 20px; bottom: 20px;
  left: 20px; right: 20px;
  border: 1px dashed rgba(184, 134, 11, 0.15);
  pointer-events: none;
}

/* ── Ornamental Dividers ──────────────────────────────────────── */
.ornamental-divider {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 2rem 0;
  position: relative;
  width: 100%;
}

.ornamental-divider::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-gold) 30%, var(--accent-gold) 70%, transparent);
}

.divider-glyph {
  font-family: var(--font-gothic);
  font-size: 1.8rem;
  color: var(--accent-gold);
  background-color: var(--vellum);
  padding: 0 1rem;
  z-index: 2;
  position: relative;
}

/* ── Marginalia / Exam Tips ───────────────────────────────────── */
.marginalia {
  background-color: var(--parchment-dark);
  border-left: 4px solid var(--accent-crimson);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  box-shadow: var(--shadow-light);
  border-radius: 0 4px 4px 0;
  position: relative;
}

.marginalia h4 {
  font-family: var(--font-serif-display);
  color: var(--accent-crimson);
  font-size: 1rem;
  margin-top: 0;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.marginalia p {
  font-size: 0.93rem;
  font-style: italic;
  margin-bottom: 0;
  text-align: left;
}

/* ── Page Navigation ──────────────────────────────────────────── */
.page-navigation {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--accent-gold);
}

.nav-link {
  font-family: var(--font-serif-display);
  font-size: 1rem;
  font-weight: bold;
  display: flex;
  flex-direction: column;
  border-bottom: none;
  padding: 0.6rem 1rem;
  border: 1px solid var(--parchment-dark);
  border-radius: 4px;
  transition: all var(--transition-speed) ease;
  min-width: 0;
  flex: 1;
  max-width: 48%;
}

.nav-link span {
  font-family: var(--font-serif-body);
  font-size: 0.78rem;
  font-weight: normal;
  color: var(--ink-light);
  margin-bottom: 0.2rem;
}

.nav-link.next {
  text-align: right;
  align-items: flex-end;
}

.nav-link:hover {
  background-color: rgba(184, 134, 11, 0.07);
  border-color: var(--accent-gold);
  color: var(--accent-crimson);
}

/* ── References Section ───────────────────────────────────────── */
.references-section {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--accent-gold);
}

.references-section h2 {
  font-size: 1.2rem;
  border-bottom: none;
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--ink-light);
  font-family: var(--font-serif-display);
  text-align: left;
}

/* ── Quiz Elements ────────────────────────────────────────────── */
.quiz-container { margin-top: 2rem; }

.quiz-question {
  background-color: var(--parchment-dark);
  border: var(--border-gold);
  border-radius: 6px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-light);
}

.question-text {
  font-family: var(--font-serif-display);
  font-size: 1.1rem;
  font-weight: bold;
  margin-bottom: 1rem;
  text-align: left;
  line-height: 1.5;
}

.q-number {
  color: var(--accent-crimson);
  margin-right: 0.4rem;
}

.options-list {
  list-style: none;
  padding-left: 0;
}

.option-item {
  padding: 0.75rem 1rem;
  border: 1px solid rgba(59, 47, 30, 0.2);
  margin-bottom: 0.5rem;
  border-radius: 5px;
  transition: all var(--transition-speed) ease;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background-color: var(--vellum);
  cursor: pointer;
  line-height: 1.4;
  /* Touch target */
  min-height: 48px;
}

.option-item:hover {
  border-color: var(--accent-gold);
  background-color: rgba(184, 134, 11, 0.06);
}

.option-item.selected  { border-color: var(--accent-crimson); background-color: rgba(139, 26, 26, 0.05); }
.option-item.correct   { border-color: #2e7d32; background-color: rgba(46, 125, 50, 0.08); }
.option-item.incorrect { border-color: var(--accent-crimson); background-color: rgba(139, 26, 26, 0.08); }

.option-marker {
  font-weight: bold;
  color: var(--accent-gold);
  flex-shrink: 0;
}

.option-item.selected .option-marker { color: var(--accent-crimson); }

.explanation-box {
  background-color: var(--vellum);
  border-left: 3px solid #2e7d32;
  padding: 0.9rem 1rem;
  margin-top: 1rem;
  font-size: 0.93rem;
  display: none;
  border-radius: 0 4px 4px 0;
}

.explanation-box p { text-align: left; margin-bottom: 0.5rem; }
.explanation-box p:last-child { margin-bottom: 0; }
.show-explanation { display: block !important; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn-primary {
  background-color: var(--ink);
  color: var(--parchment);
  border: 1px solid var(--accent-gold);
  padding: 0.55rem 1.3rem;
  font-family: var(--font-serif-display);
  font-weight: bold;
  border-radius: 4px;
  transition: all var(--transition-speed) ease;
  font-size: 0.95rem;
  min-height: 44px;
}

.btn-primary:hover {
  background-color: var(--accent-crimson);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 26, 26, 0.3);
}

/* ── Breadcrumb ───────────────────────────────────────────────── */
.breadcrumb {
  font-size: 0.82rem;
  color: var(--ink-light);
  margin-bottom: 1.5rem;
  font-style: italic;
  display: flex;
  gap: 0.3rem;
  align-items: center;
  flex-wrap: wrap;
  border-bottom: 1px dotted var(--parchment-dark);
  padding-bottom: 0.5rem;
}

.breadcrumb a { color: var(--ink-light); border-bottom: none; }
.breadcrumb a:hover { color: var(--accent-crimson); background-color: transparent; }

/* ── Chapter Header ───────────────────────────────────────────── */
.chapter-header {
  text-align: center;
  margin-bottom: 2rem;
}

.chapter-number {
  font-family: var(--font-serif-display);
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent-crimson);
  display: block;
  margin-bottom: 0.5rem;
}

.chapter-header h1 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  text-align: center;
}

/* ── Key Takeaways Box ────────────────────────────────────────── */
.key-takeaways {
  background-color: var(--parchment-dark);
  border: 2px solid var(--accent-gold);
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
}

.key-takeaways h4 {
  font-family: var(--font-serif-display);
  color: var(--accent-gold);
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.key-takeaways ul {
  padding-left: 1.4rem;
  margin-bottom: 0;
}

.key-takeaways li {
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}

/* ── Scroll-to-top button ─────────────────────────────────────── */
.scroll-top-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 44px;
  height: 44px;
  background-color: var(--ink);
  color: var(--parchment);
  border: 2px solid var(--accent-gold);
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: all 0.3s ease;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  z-index: 100;
}

.scroll-top-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.scroll-top-btn:hover {
  background-color: var(--accent-crimson);
  transform: translateY(-3px);
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════ */

/* ── Tablet / Mobile (≤ 1024px) ───────────────────────────────── */
@media (max-width: 1024px) {
  .mobile-topbar {
    display: flex;
  }

  /* Push page content down so fixed topbar doesn't overlap it.
     We use padding-top on the BODY (via app-container which is the first
     element after body's flow), not on body itself, to avoid
     double-shifting issues. */
  body {
    padding-top: 56px;
  }
  /* Reset padding on app-container to avoid double shift */
  .app-container {
    padding-top: 0;
  }

  /* Sidebar becomes off-canvas drawer */
  .sidebar-toc {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    height: auto;
    transform: translateX(-100%);
    z-index: 200;
    width: min(300px, 85vw);
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    padding-top: 1rem;
    /* Allow sidebar itself to scroll internally */
    overflow-y: auto;
    overflow-x: hidden;
  }

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

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    top: 56px;
  }

  .sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Toolbar becomes slimmer */
  .top-toolbar {
    display: none; /* Hidden on mobile — toolbar moves to topbar */
  }

  .main-content {
    padding: 1.25rem 1rem;
  }

  .manuscript-wrapper {
    padding: 1.75rem 1.5rem;
  }

  .manuscript-wrapper::before,
  .manuscript-wrapper::after {
    display: none;
  }
}

/* ── Mobile (≤ 640px) ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .manuscript-wrapper {
    padding: 1.25rem 1rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  }

  .page-navigation {
    flex-direction: column;
    gap: 0.75rem;
  }

  .nav-link {
    max-width: 100%;
    padding: 0.75rem 1rem;
  }

  .nav-link.next {
    text-align: left;
    align-items: flex-start;
  }

  .quiz-question {
    padding: 1rem;
  }

  .scroll-top-btn {
    bottom: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  .marginalia {
    margin: 1rem 0;
  }

  .chapter-number {
    font-size: 1.3rem;
  }
}
