/* ========================================================
   THE PICTURE OF DORIAN GRAY — E-Book Reader
   Victorian Dark Theme with Gold Accents
   ======================================================== */

/* ---------- Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&display=swap');

/* ---------- Custom Properties ---------- */
:root {
  /* Dark Victorian palette */
  --bg-deep:        #0a0a0f;
  --bg-primary:     #121218;
  --bg-surface:     #1a1a24;
  --bg-page:        #f5f0e8;
  --bg-page-edge:   #e8e0d0;
  
  /* Gold accents */
  --gold-primary:   #c9a84c;
  --gold-light:     #dfc06a;
  --gold-dark:      #8b6914;
  --gold-glow:      rgba(201, 168, 76, 0.15);
  --gold-subtle:    rgba(201, 168, 76, 0.06);
  
  /* Text colors */
  --text-page:      #2a2420;
  --text-light:     #e8e0d0;
  --text-muted:     #8a8490;
  --text-gold:      #c9a84c;
  
  /* Accent */
  --crimson:        #8b2232;
  --crimson-glow:   rgba(139, 34, 50, 0.2);
  
  /* Dimensions — desktop defaults */
  --page-width:     min(620px, 90vw);
  --page-height:    min(820px, 78vh);
  --sidebar-width:  280px;
  
  /* Transitions */
  --ease-out:       cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring:    cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Lora', 'Georgia', serif;
  background: var(--bg-deep);
  color: var(--text-light);
  min-height: 100vh;
  /* overflow:hidden removed — it clips position:fixed children (body::before gradient)
     on Android Chrome / Samsung WebView. Overflow is handled per-element instead. */
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- Ambient Background ---------- */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: 
    radial-gradient(ellipse at 20% 20%, var(--gold-glow) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, var(--crimson-glow) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(201,168,76,0.03) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  /* Force GPU layer so Android Chrome renders fixed pseudo-elements correctly */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  will-change: transform;
}

/* ---------- Header ---------- */
.header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: linear-gradient(180deg, rgba(18,18,24,0.98) 0%, rgba(18,18,24,0.85) 100%);
  border-bottom: 1px solid rgba(201,168,76,0.15);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header__icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--gold-primary), var(--gold-dark));
  border-radius: 8px;
  font-size: 16px;
  box-shadow: 0 2px 12px rgba(201,168,76,0.25);
}

.header__title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-light);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.header__subtitle {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 2px;
}

.header__controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chapter-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 4px;
  border: 1px solid rgba(201,168,76,0.1);
}

/* Make header responsive so elements don't wrap and overlap */
@media (max-width: 768px) {
  .header {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    padding: 10px 12px;
    gap: 8px;
    overflow: hidden;
  }
  .header__brand {
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
  }
  .header__brand > div {
    min-width: 0;
  }
  .header__icon {
    width: 24px;
    height: 24px;
    font-size: 12px;
    flex-shrink: 0;
  }
  .header__title {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header__subtitle {
    font-size: 0.75rem;
    display: block; /* Restore author name */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header__controls {
    flex-shrink: 0;
  }
  .page-controls {
    gap: 8px;
  }
  .page-nav-btn {
    width: 32px;
    height: 32px;
  }
  .page-nav-btn svg {
    width: 16px;
    height: 16px;
  }
  .page-indicator {
    min-width: 60px;
  }
  .page-indicator__number {
    font-size: 0.9rem;
  }
  .page-indicator__range {
    font-size: 0.7rem;
  }
}

.chapter-tab {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.35s var(--ease-out);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.chapter-tab:hover {
  color: var(--text-light);
  background: rgba(201,168,76,0.06);
}

.chapter-tab.active {
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--gold-primary), var(--gold-light));
  box-shadow: 0 2px 12px rgba(201,168,76,0.3);
}

/* ---------- Main Layout ---------- */
.main {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 24px;
}

/* ---------- Book Container ---------- */
.book-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* ---------- The Book / Page ---------- */
.book {
  position: relative;
  width: var(--page-width);
  height: var(--page-height);
  perspective: 1800px;
}

.page-wrapper {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.page {
  position: absolute;
  inset: 0;
  background: var(--bg-page);
  border-radius: 4px 12px 12px 4px;
  padding: 48px 48px 60px 52px;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow:
    -4px 0 8px rgba(0,0,0,0.15),
    4px 0 20px rgba(0,0,0,0.3),
    0 0 60px rgba(0,0,0,0.2),
    inset -2px 0 4px rgba(0,0,0,0.05);
  transition: transform 0.6s var(--ease-out), opacity 0.4s ease;
  will-change: transform, opacity;
}

/* Paper texture effect */
.page::before {
  content: '';
  position: absolute;
  inset: 0;
  background: 
    url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;
}

/* Book spine shadow */
.page::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 100%;
  background: linear-gradient(90deg, 
    rgba(0,0,0,0.08) 0%, 
    rgba(0,0,0,0.03) 40%, 
    transparent 100%);
  pointer-events: none;
  border-radius: 4px 0 0 4px;
  z-index: 1;
}

/* Page content */
.page__content {
  position: relative;
  z-index: 2;
}

.page__chapter-heading {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-page);
  text-align: center;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(42,36,32,0.15);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page__chapter-heading::after {
  content: '❧';
  display: block;
  font-size: 1rem;
  color: var(--gold-dark);
  margin-top: 8px;
  letter-spacing: 0;
}

.page__text p {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.08rem;
  line-height: 1.72;
  color: var(--text-page);
  text-align: justify;
  text-indent: 1.5em;
  margin-bottom: 0.6em;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.page__text p:first-child {
  text-indent: 0;
}

.page__text p.no-indent {
  text-indent: 0;
}

/* Inquest block styling */
.page__text p.inquest {
  font-size: 0.95rem;
  text-indent: 0;
  padding: 12px 16px;
  background: rgba(42,36,32,0.04);
  border-left: 2px solid rgba(42,36,32,0.15);
  margin: 12px 0;
}

/* Page number */
.page__number {
  display: block;
  text-align: center;
  margin-top: 32px;
  padding-bottom: 8px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.85rem;
  color: rgba(42,36,32,0.5);
  letter-spacing: 0.1em;
}

/* Page scrollbar */
.page::-webkit-scrollbar {
  width: 4px;
}

.page::-webkit-scrollbar-track {
  background: transparent;
}

.page::-webkit-scrollbar-thumb {
  background: rgba(42,36,32,0.15);
  border-radius: 4px;
}

.page::-webkit-scrollbar-thumb:hover {
  background: rgba(42,36,32,0.25);
}

/* ---------- Page Animations ---------- */
.page.turning-out {
  animation: pageTurnOut 0.55s var(--ease-out) forwards;
}

.page.turning-in {
  animation: pageTurnIn 0.55s var(--ease-out) forwards;
}

.page.turning-back-out {
  animation: pageTurnBackOut 0.55s var(--ease-out) forwards;
}

.page.turning-back-in {
  animation: pageTurnBackIn 0.55s var(--ease-out) forwards;
}

@keyframes pageTurnOut {
  0%   { transform: rotateY(0deg); opacity: 1; }
  100% { transform: rotateY(-30deg) translateX(-8%); opacity: 0; }
}

@keyframes pageTurnIn {
  0%   { transform: rotateY(30deg) translateX(8%); opacity: 0; }
  100% { transform: rotateY(0deg); opacity: 1; }
}

@keyframes pageTurnBackOut {
  0%   { transform: rotateY(0deg); opacity: 1; }
  100% { transform: rotateY(30deg) translateX(8%); opacity: 0; }
}

@keyframes pageTurnBackIn {
  0%   { transform: rotateY(-30deg) translateX(-8%); opacity: 0; }
  100% { transform: rotateY(0deg); opacity: 1; }
}

/* ---------- Page Navigation Controls ---------- */
.page-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(201,168,76,0.25);
  border-radius: 50%;
  background: rgba(26,26,36,0.8);
  color: var(--gold-primary);
  cursor: pointer;
  transition: all 0.3s var(--ease-out);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.page-nav-btn:hover:not(:disabled) {
  background: rgba(201,168,76,0.12);
  border-color: var(--gold-primary);
  box-shadow: 0 0 20px rgba(201,168,76,0.15);
  transform: scale(1.08);
}

.page-nav-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.page-nav-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.page-nav-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Page indicator */
.page-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 80px;
}

.page-indicator__number {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold-primary);
  letter-spacing: 0.05em;
}

.page-indicator__range {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Progress bar */
.progress-bar {
  width: var(--page-width);
  height: 3px;
  background: rgba(201,168,76,0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold-primary), var(--gold-light));
  border-radius: 3px;
  transition: width 0.5s var(--ease-out);
}

/* ---------- Side Annotations (page edge effect) ---------- */
.book-edge {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: -6px;
  width: 6px;
  background: linear-gradient(180deg,
    var(--bg-page-edge) 0%,
    #d4ccc0 20%,
    var(--bg-page-edge) 40%,
    #d4ccc0 60%,
    var(--bg-page-edge) 80%,
    #d4ccc0 100%
  );
  border-radius: 2px 0 0 2px;
  box-shadow: -2px 0 4px rgba(0,0,0,0.1);
}

/* ---------- Loading State ---------- */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  height: 100%;
  color: var(--text-muted);
}

.loading__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(201,168,76,0.15);
  border-top-color: var(--gold-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading__text {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  font-style: italic;
}

/* ---------- Chapter Info Card ---------- */
.chapter-info {
  position: absolute;
  top: 50%;
  right: -300px;
  transform: translateY(-50%);
  width: 260px;
  background: rgba(26,26,36,0.85);
  border: 1px solid rgba(201,168,76,0.12);
  border-radius: 12px;
  padding: 24px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0;
  transition: all 0.5s var(--ease-out);
}

.chapter-info.visible {
  right: -280px;
  opacity: 1;
}

.chapter-info__label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.75rem;
  color: var(--gold-primary);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 8px;
}

.chapter-info__title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 12px;
}

.chapter-info__meta {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ---------- Keyboard Hint ---------- */
.keyboard-hint {
  position: fixed;
  bottom: 20px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.5;
  transition: opacity 0.3s ease;
  z-index: 5;
}

.keyboard-hint:hover {
  opacity: 0.9;
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  background: rgba(26,26,36,0.8);
  border: 1px solid rgba(201,168,76,0.2);
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--gold-primary);
  font-family: inherit;
}

/* ---------- Responsive ---------- */

/* ── Tablet (601px–1024px): shift book left so annotation cards have right-side room ── */
@media (min-width: 601px) and (max-width: 1024px) {
  :root {
    /* Narrower page leaves ~200px for annotation cards on the right */
    --page-width:  min(500px, 68vw);
    --page-height: min(740px, 72vh);
  }

  .header {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .header__controls {
    order: -1;
    width: 100%;
    justify-content: center;
  }

  .chapter-info {
    /* Hidden — not enough room even with offset book */
    display: none;
  }

  /* Shift book to the left third of the screen to free the right ~30% for cards */
  .main {
    justify-content: flex-start;
    padding: 16px 16px 16px 24px;
    align-items: center;
  }

  .book-container {
    margin-left: max(16px, 3vw);
  }

  .page {
    padding: 36px 32px 56px 36px;
  }

  .page__text p {
    font-size: 1rem;
    line-height: 1.68;
  }

  .progress-bar {
    width: var(--page-width);
  }

  .keyboard-hint {
    display: none;
  }
}

/* ── Tablet landscape (768px–1024px wide): slightly more page width ── */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
  :root {
    --page-width:  min(560px, 60vw);
    --page-height: min(640px, 80vh);
  }
}

/* ── Mobile portrait (≤600px): book centred, annotations as bottom sheet ── */
@media (max-width: 600px) {
  .header {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  
  .header__controls {
    order: -1;
    width: 100%;
    justify-content: center;
  }
  
  .chapter-info {
    display: none;
  }
  
  .main {
    padding: 10px;
    justify-content: center;
  }
  
  :root {
    --page-width:  min(92vw, 480px);
    --page-height: 66vh;
  }
  
  .page {
    padding: 28px 22px 52px 28px;
  }
  
  .page__text p {
    font-size: 0.97rem;
    line-height: 1.65;
  }
  
  .keyboard-hint {
    display: none;
  }
}

/* ── Very small phones (≤420px) ── */
@media (max-width: 420px) {
  .header__brand {
    gap: 10px;
  }
  
  .header__title {
    font-size: 1rem;
  }
  
  .header__subtitle {
    font-size: 0.75rem;
  }
  
  .chapter-tab {
    font-size: 0.85rem;
    padding: 6px 14px;
  }
  
  .page {
    padding: 22px 18px 46px 22px;
    border-radius: 2px 8px 8px 2px;
  }
  
  .page__chapter-heading {
    font-size: 1.2rem;
  }
  
  .page__text p {
    font-size: 0.93rem;
    line-height: 1.62;
  }
  
  .page-nav-btn {
    width: 44px;
    height: 44px;
  }
  
  .book-edge {
    display: none;
  }
  
  :root {
    --page-height: 63vh;
  }
}

/* ---------- Print Styles ---------- */
@media print {
  body {
    background: white;
  }
  
  .header, .page-controls, .progress-bar, .keyboard-hint, .chapter-info {
    display: none;
  }
  
  .page {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* ========================================================
   INTERACTIVE ANNOTATIONS
   ======================================================== */

/* ---------- Annotated Text Spans ---------- */
.annotated-text {
  position: relative;
  border-bottom: 2px solid var(--gold-primary);
  background: rgba(201, 168, 76, 0.06);
  cursor: pointer;
  transition:
    background 0.25s ease,
    border-color 0.25s ease;
  border-radius: 1px;
  /* Prevent text selection on click */
  -webkit-user-select: none;
  user-select: none;
}

.annotated-text:hover,
.annotated-text.annotation-active {
  background: rgba(201, 168, 76, 0.16);
  border-bottom-color: var(--gold-light);
}

/* Small pulse dot at start of annotation to hint interactivity */
.annotated-text::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 0;
  width: 5px;
  height: 5px;
  background: var(--gold-primary);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.annotated-text:hover::before,
.annotated-text.annotation-active::before {
  opacity: 1;
  transform: scale(1);
}

/* ---------- Annotation Card ---------- */
.annotation-card {
  position: fixed;
  z-index: 9999;
  /* width and max-height set dynamically by JS */
  max-width: 320px;
  overflow-y: auto;
  background: rgba(16, 16, 22, 0.96);
  border: 1px solid rgba(201, 168, 76, 0.25);
  border-radius: 14px;
  padding: 0;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(201, 168, 76, 0.08),
    0 0 60px rgba(201, 168, 76, 0.06);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  pointer-events: auto;
}

/* Slide in from the left when card is on the right side of the page */
.annotation-card.annotation-card--right {
  animation: annotationSlideFromLeft 0.24s var(--ease-out) forwards;
  transform-origin: left center;
}

/* Slide in from the right when card is on the left side of the page */
.annotation-card.annotation-card--left {
  animation: annotationSlideFromRight 0.24s var(--ease-out) forwards;
  transform-origin: right center;
}

@keyframes annotationSlideFromLeft {
  from { opacity: 0; transform: translateX(-10px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0)     scale(1); }
}

@keyframes annotationSlideFromRight {
  from { opacity: 0; transform: translateX(10px)  scale(0.97); }
  to   { opacity: 1; transform: translateX(0)     scale(1); }
}

@keyframes annotationFadeOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.96); }
}

.annotation-card.is-hiding {
  animation: annotationFadeOut 0.18s var(--ease-out) forwards;
  pointer-events: none;
}

/* ---------- Annotation Card — Header ---------- */
.annotation-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(201, 168, 76, 0.12);
  background: linear-gradient(135deg,
    rgba(201, 168, 76, 0.08) 0%,
    rgba(201, 168, 76, 0.02) 100%);
  border-radius: 14px 14px 0 0;
}

.annotation-card__header-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gold-primary);
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.annotation-card__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1;
  transition: all 0.2s ease;
}

.annotation-card__close:hover {
  background: rgba(201,168,76,0.15);
  border-color: rgba(201,168,76,0.3);
  color: var(--gold-light);
}

/* ---------- Annotation Card — Sections ---------- */
.annotation-card__body {
  padding: 4px 0 8px;
}

.annotation-card__section {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.annotation-card__section:last-child {
  border-bottom: none;
}

.annotation-card__section-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold-primary);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.annotation-card__section-title .section-icon {
  font-size: 0.85rem;
  line-height: 1;
}

.annotation-card__section-text {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.92rem;
  line-height: 1.6;
  color: rgba(232, 224, 208, 0.85);
}

/* ---------- Exam Terms (Pill Tags) ---------- */
.annotation-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.annotation-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: rgba(201, 168, 76, 0.1);
  border: 1px solid rgba(201, 168, 76, 0.28);
  border-radius: 20px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gold-light);
  letter-spacing: 0.02em;
  transition: background 0.2s ease;
}

.annotation-tag:hover {
  background: rgba(201, 168, 76, 0.2);
}

.annotation-card__section--no-terms .annotation-card__section-text {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- Vocabulary List ---------- */
.annotation-vocab {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 2px;
}

.annotation-vocab__item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.annotation-vocab__word {
  font-family: 'Playfair Display', serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gold-light);
  letter-spacing: 0.01em;
}

.annotation-vocab__def {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.88rem;
  color: rgba(232, 224, 208, 0.7);
  line-height: 1.4;
}

/* ---------- SVG Leader Line ---------- */
.annotation-leader {
  position: fixed;
  pointer-events: none;
  z-index: 9998;
  overflow: visible;
}

.annotation-leader line {
  stroke: var(--gold-primary);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  opacity: 0.55;
  animation: leaderFadeIn 0.3s ease forwards;
}

.annotation-leader circle {
  fill: var(--gold-primary);
  opacity: 0.7;
  animation: leaderFadeIn 0.3s ease forwards;
}

@keyframes leaderFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- Annotations Scrollbar ---------- */
.annotation-card::-webkit-scrollbar {
  width: 3px;
}
.annotation-card::-webkit-scrollbar-track {
  background: transparent;
}
.annotation-card::-webkit-scrollbar-thumb {
  background: rgba(201, 168, 76, 0.2);
  border-radius: 3px;
}

/* ---------- Annotations Legend (page indicator) ---------- */
.annotation-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.annotation-legend.visible {
  opacity: 1;
}

.annotation-legend__dot {
  width: 8px;
  height: 2px;
  background: var(--gold-primary);
  border-radius: 1px;
  flex-shrink: 0;
}

/* ---------- Responsive: Mobile annotation card ---------- */
/* ── On tablet (≤1024px) and phone (≤600px): annotation cards use bottom-sheet layout ── */
@media (max-width: 1024px) {
  .annotation-card {
    position: fixed;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 50vh;
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transform: none !important;
    animation: annotationSlideUp 0.28s var(--ease-out) forwards;
  }

  .annotation-card.is-hiding {
    animation: annotationSlideDown 0.2s var(--ease-out) forwards;
  }

  @keyframes annotationSlideUp {
    from { transform: translateY(100%); opacity: 0.6; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  @keyframes annotationSlideDown {
    from { transform: translateY(0);    opacity: 1; }
    to   { transform: translateY(100%); opacity: 0; }
  }

  .annotation-leader {
    display: none;
  }

  /* Drag handle hint */
  .annotation-card::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.18);
    border-radius: 2px;
    margin: 10px auto 0;
  }
}

/* ── On tablet portrait in the shifted-left layout, prefer side card ── */
/* (Tablets 601px–1024px where book is shifted left — use right-side card instead) */
@media (min-width: 601px) and (max-width: 1024px) {
  .annotation-card {
    /* Override the bottom-sheet for tablets with side-card layout.
       The book is shifted left, so we place the card to the right of the book. */
    position: fixed !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    top: auto !important;
    width: auto !important;
    max-width: 280px !important;
    max-height: 60vh;
    border-radius: 14px;
    border: 1px solid rgba(201, 168, 76, 0.25);
    transform: none !important;
    animation: annotationSlideFromLeft 0.24s var(--ease-out) forwards;
  }

  .annotation-card.is-hiding {
    animation: annotationFadeOut 0.18s var(--ease-out) forwards;
  }

  .annotation-card::before {
    display: none; /* No drag handle for side-card */
  }

  .annotation-leader {
    display: block; /* Show leader line on tablet in side-card mode */
  }
}

/* ========================================================
   3-TIER ANNOTATION HIERARCHY (Chapter 11+)
   ======================================================== */

/* ---------- Layer 1 & 2: Macro & Micro — unified highlight ---------- */
.anno-macro,
.anno-micro {
  background: rgba(201, 168, 76, 0.15);
  border-bottom: 1px dotted rgba(201, 168, 76, 0.5);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.anno-macro:hover,
.anno-macro.annotation-active,
.anno-micro:hover,
.anno-micro.annotation-active {
  background: rgba(201, 168, 76, 0.25);
  border-bottom-color: var(--gold-light);
}

/* ---------- Layer 3: Nano / Vocabulary — dotted underline ---------- */
.anno-nano {
  background: rgba(201, 168, 76, 0.35);
  border-bottom: 2px solid var(--gold-primary);
  border-radius: 2px;
  cursor: help;
  transition: background 0.2s ease, border-color 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
}

.anno-nano:hover,
.anno-nano.annotation-active {
  background: rgba(201, 168, 76, 0.5);
  border-bottom-color: var(--gold-light);
}

/* ---------- Micro card — amber accent header ---------- */
.annotation-card--micro .annotation-card__header {
  background: linear-gradient(135deg,
    rgba(201, 140, 30, 0.14) 0%,
    rgba(201, 140, 30, 0.04) 100%);
  border-bottom-color: rgba(201, 140, 30, 0.18);
}

.annotation-card--micro .annotation-card__header-label {
  color: #d4a332;
}

/* ---------- Nano card — compact vocabulary card ---------- */
.annotation-card--nano {
  max-width: 260px;
}

.annotation-card__header--nano {
  background: linear-gradient(135deg,
    rgba(80, 160, 100, 0.12) 0%,
    rgba(80, 160, 100, 0.04) 100%);
  border-bottom-color: rgba(80, 160, 100, 0.15);
  border-radius: 14px 14px 0 0;
}

.annotation-card--nano .annotation-card__header-label {
  color: #7bc99a;
}

/* Legend hint update for 3 tiers */
.annotation-legend__dot--micro {
  background: var(--gold-primary);
}
.annotation-legend__dot--nano {
  background: transparent;
  border-bottom: 2px dotted var(--gold-primary);
  height: auto;
  width: 10px;
}

/* ---------- Sidebar-triggered Pulse Highlight ---------- */
@keyframes sidebarPulse {
  0%   { background: rgba(201,168,76,0.08);  outline: 2px solid rgba(201,168,76,0); }
  25%  { background: rgba(201,168,76,0.42);  outline: 2px solid rgba(201,168,76,0.7); }
  65%  { background: rgba(201,168,76,0.28);  outline: 2px solid rgba(201,168,76,0.4); }
  100% { background: rgba(201,168,76,0.08);  outline: 2px solid rgba(201,168,76,0); }
}

.sidebar-pulse {
  animation: sidebarPulse 1.8s var(--ease-out) forwards;
  outline-offset: 3px;
  border-radius: 3px;
}
