/* ============================================================
   FarziPedia — Renaissance codex stylesheet
   ============================================================ */

/* Aged parchment background — multi-layer warm gradients +
   subtle SVG fiber/grain pattern for the "paper" feel. */
body {
  background-color: #f4e8c8;
  background-image:
    /* Vignette (darker corners) */
    radial-gradient(ellipse at 50% 50%, rgba(244, 232, 200, 0) 0%, rgba(120, 80, 30, 0.18) 100%),
    /* Warm tonal variation */
    radial-gradient(at 20% 10%, rgba(212, 176, 92, 0.20) 0, transparent 45%),
    radial-gradient(at 80% 30%, rgba(168, 60, 31, 0.10) 0, transparent 50%),
    radial-gradient(at 15% 85%, rgba(92, 124, 138, 0.10) 0, transparent 55%),
    radial-gradient(at 90% 90%, rgba(139, 90, 43, 0.18) 0, transparent 55%),
    /* Subtle paper fiber via SVG noise */
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.32  0 0 0 0 0.18  0 0 0 0.10 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: cover, cover, cover, cover, cover, 400px 400px;
  background-attachment: fixed, fixed, fixed, fixed, fixed, fixed;
  background-blend-mode: normal, normal, normal, normal, normal, multiply;
}

/* Random "age spots" / foxing. Pseudo elements painted on body. */
body::before, body::after {
  content: "";
  position: fixed;
  pointer-events: none;
  z-index: 0;
}
body::before {
  inset: 0;
  background-image:
    radial-gradient(circle at 12% 22%, rgba(120, 70, 25, 0.10) 0, transparent 1.2%),
    radial-gradient(circle at 88% 14%, rgba(120, 70, 25, 0.07) 0, transparent 1%),
    radial-gradient(circle at 70% 80%, rgba(120, 70, 25, 0.08) 0, transparent 0.9%),
    radial-gradient(circle at 32% 67%, rgba(120, 70, 25, 0.05) 0, transparent 1.1%),
    radial-gradient(circle at 55% 35%, rgba(120, 70, 25, 0.06) 0, transparent 0.7%);
}
/* Soft inner edge — subtle dark border like a worn page */
body::after {
  inset: 0;
  box-shadow: inset 0 0 200px rgba(80, 50, 20, 0.18);
}
main { position: relative; z-index: 1; }

/* Selection: ink on parchment */
::selection {
  background: #2a1f12;
  color: #f4e8c8;
}

/* Typography polish */
.font-roman, .font-codex { font-feature-settings: "liga", "kern", "onum" on, "ss01" on; }
.font-inscription { letter-spacing: 0.06em; }
.tracking-codex   { letter-spacing: 0.18em; }

/* ----- Drop cap (illuminated initial) ----- */
.drop-cap::first-letter {
  float: left;
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 4.5em;
  line-height: 0.9;
  padding: 0.15em 0.12em 0 0;
  color: #a83c1f;     /* rubricated red */
  text-shadow: 1px 1px 0 #c87148, 2px 2px 0 rgba(168, 60, 31, 0.15);
}

/* ----- Hand-drawn ornament line ----- */
.ornament-rule {
  display: flex; align-items: center; gap: 0.75rem;
  color: #8b5a2b;
}
.ornament-rule::before, .ornament-rule::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, #8b5a2b 20%, #8b5a2b 80%, transparent);
}
.ornament-rule .fleuron {
  font-family: 'IM Fell English', serif;
  font-size: 1.5rem; line-height: 1;
}

/* ----- Decorative double rule ----- */
.double-rule {
  border-top: 1px solid #6b4220;
  border-bottom: 1px solid #6b4220;
  padding: 4px 0;
  position: relative;
}
.double-rule::after {
  content: ""; position: absolute; left: 0; right: 0; top: 50%;
  height: 0; border-top: 0.5px solid rgba(107, 66, 32, 0.4);
}

/* ----- Marginalia (handwritten note in the margin) ----- */
.marginalia {
  font-family: 'Italianno', cursive;
  color: #6b4220;
  transform: rotate(-3deg);
  font-size: 1.4rem;
  line-height: 1.2;
}

/* ----- Ink-drawn box / card ----- */
.codex-card {
  background:
    linear-gradient(rgba(244, 232, 200, 0.7), rgba(244, 232, 200, 0.7)),
    radial-gradient(at 30% 20%, rgba(212, 176, 92, 0.18) 0, transparent 60%);
  border: 1px solid rgba(107, 66, 32, 0.35);
  box-shadow:
    inset 0 0 30px rgba(80, 50, 20, 0.06),
    0 1px 0 rgba(255, 255, 255, 0.4) inset,
    0 8px 24px -12px rgba(80, 50, 20, 0.25);
  border-radius: 4px;
  position: relative;
}
.codex-card::before, .codex-card::after {
  content: ""; position: absolute; width: 22px; height: 22px;
  border: 1px solid #6b4220;
  pointer-events: none;
}
.codex-card::before { top: 6px; left: 6px; border-right: none; border-bottom: none; }
.codex-card::after  { bottom: 6px; right: 6px; border-left: none; border-top: none; }

/* ----- Wax-seal button ----- */
.wax-seal {
  background: radial-gradient(circle at 35% 30%, #c8401f 0, #8b1f10 65%, #5a1208 100%);
  color: #f4e8c8;
  border: 2px solid #5a1208;
  text-shadow: 0 1px 0 rgba(0,0,0,0.4);
  box-shadow:
    inset 0 4px 8px rgba(255, 255, 255, 0.15),
    inset 0 -6px 12px rgba(0, 0, 0, 0.3),
    0 6px 16px -4px rgba(80, 20, 10, 0.45);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.wax-seal:hover { transform: translateY(-1px) scale(1.02); }
.wax-seal:active { transform: translateY(0) scale(0.99); }

/* ----- Quill input ----- */
.quill-input {
  background: transparent;
  border: 0;
  border-bottom: 2px solid #6b4220;
  border-radius: 0;
  font-family: 'IM Fell English', serif;
  color: #2a1f12;
  padding: 0.6rem 0.25rem;
  outline: none;
}
.quill-input:focus { border-bottom-color: #a83c1f; }
.quill-input::placeholder { color: #9c8a72; font-style: italic; }

/* ----- Sketched border (slight wobble) ----- */
.sketch-border {
  border: 1.5px solid #2a1f12;
  border-radius: 2px;
  position: relative;
}
.sketch-border::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 0.5px solid rgba(42, 31, 18, 0.4);
  pointer-events: none;
}

/* ----- Spinning compass (loading indicator) ----- */
.compass-rose { transform-origin: 50% 50%; }

/* ----- Vitruvian backdrop: visible only at the edges, fades to clear in the centre
   so it never competes with text overlaid on it. */
.vitruvian-mask {
  -webkit-mask-image: radial-gradient(ellipse at center,
    transparent 0%, transparent 28%, rgba(0,0,0,0.4) 55%, rgba(0,0,0,0.85) 100%);
          mask-image: radial-gradient(ellipse at center,
    transparent 0%, transparent 28%, rgba(0,0,0,0.4) 55%, rgba(0,0,0,0.85) 100%);
}

/* ----- "Page within a page": a subtle lighter rectangle that lifts the central
   content above the textured parchment, like a leaf laid on a desk. */
.codex-page {
  background:
    linear-gradient(rgba(250, 243, 224, 0.78), rgba(250, 243, 224, 0.78)),
    radial-gradient(at 50% 0%, rgba(212, 176, 92, 0.10) 0, transparent 60%);
  border: 1px solid rgba(107, 66, 32, 0.12);
  box-shadow:
    inset 0 0 60px rgba(80, 50, 20, 0.05),
    0 30px 80px -30px rgba(80, 50, 20, 0.20),
    0 1px 0 rgba(255, 255, 255, 0.5) inset;
  border-radius: 6px;
}

/* ----- Solid codex card variant — opaque enough that nothing bleeds through ----- */
.codex-card-solid {
  background:
    linear-gradient(rgba(250, 243, 224, 0.96), rgba(250, 243, 224, 0.96)),
    radial-gradient(at 30% 20%, rgba(212, 176, 92, 0.18) 0, transparent 60%);
  border: 1px solid rgba(107, 66, 32, 0.45);
  box-shadow:
    inset 0 0 30px rgba(80, 50, 20, 0.06),
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 14px 36px -14px rgba(80, 50, 20, 0.30);
  border-radius: 4px;
  position: relative;
}
.codex-card-solid::before, .codex-card-solid::after {
  content: ""; position: absolute; width: 22px; height: 22px;
  border: 1px solid #6b4220;
  pointer-events: none;
}
.codex-card-solid::before { top: 6px; left: 6px; border-right: none; border-bottom: none; }
.codex-card-solid::after  { bottom: 6px; right: 6px; border-left: none; border-top: none; }

/* ============================================================
   Folio cards — the PDF library on the home page
   ============================================================ */

.folio-card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.folio-card:hover { transform: translateY(-4px); }
.folio-card:hover .folio-thumb { filter: sepia(0.45) contrast(1.05) brightness(1.0); }
.folio-card:hover .folio-cta   { color: #a83c1f; }

/* ---- The framed cover (thumbnail or engraved illustration) ---- */
.folio-frame {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background:
    linear-gradient(rgba(244, 232, 200, 0.65), rgba(244, 232, 200, 0.65)),
    radial-gradient(at 30% 20%, rgba(212, 176, 92, 0.30) 0, transparent 60%),
    #ebd9a8;
  border: 1px solid rgba(107, 66, 32, 0.55);
  border-radius: 3px;
  box-shadow:
    inset 0 0 30px rgba(80, 50, 20, 0.10),
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 18px 36px -18px rgba(80, 50, 20, 0.40),
    0 4px 10px -4px rgba(80, 50, 20, 0.25);
}

/* Engraved corner brackets on every folio frame */
.folio-frame::before,
.folio-frame::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 1px solid #6b4220;
  pointer-events: none;
  z-index: 3;
}
.folio-frame::before { top: 6px; left: 6px;  border-right: none; border-bottom: none; }
.folio-frame::after  { bottom: 6px; right: 6px; border-left: none;  border-top: none; }

/* ---- Real YouTube thumbnail, sepia-toned ---- */
.folio-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: sepia(0.7) contrast(1.05) brightness(0.92) saturate(0.85);
  transition: filter 0.35s ease, transform 0.6s ease;
}
.folio-card:hover .folio-thumb { transform: scale(1.03); }

/* ---- Parchment overlay that warms the thumbnail toward our palette ---- */
.folio-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(168, 60, 31, 0.10), rgba(244, 232, 200, 0) 45%),
    linear-gradient(0deg, rgba(80, 50, 20, 0.32), rgba(80, 50, 20, 0) 55%),
    radial-gradient(at 50% 50%, rgba(244, 232, 200, 0) 0%, rgba(80, 50, 20, 0.22) 100%);
  z-index: 1;
  pointer-events: none;
}

/* ---- Folio number ribbon (top-left) ---- */
.folio-folionum {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 4;
  font-family: 'Cinzel', serif;
  font-size: 0.65rem;
  letter-spacing: 0.22em;
  color: #f4e8c8;
  background: rgba(42, 31, 18, 0.78);
  padding: 4px 9px;
  border: 0.5px solid #c9a449;
  border-radius: 1px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.5);
}

/* ---- "PDF" wax-seal badge (bottom-right of the cover) ---- */
.folio-pdf-badge {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 4;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  color: #f4e8c8;
  background: radial-gradient(circle at 35% 30%, #c8401f 0, #8b1f10 65%, #5a1208 100%);
  border: 1.5px solid #5a1208;
  text-shadow: 0 1px 0 rgba(0,0,0,0.4);
  box-shadow:
    inset 0 3px 6px rgba(255, 255, 255, 0.15),
    inset 0 -4px 8px rgba(0, 0, 0, 0.3),
    0 4px 10px -3px rgba(80, 20, 10, 0.5);
  transform: rotate(-6deg);
}

/* ---- Engraved cover variant (CSS-only, no thumbnail) ---- */
.folio-engraved {
  background:
    linear-gradient(rgba(250, 243, 224, 0.95), rgba(250, 243, 224, 0.95)),
    radial-gradient(at 30% 20%, rgba(212, 176, 92, 0.28) 0, transparent 60%),
    #ebd9a8;
}
.folio-engraved-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

/* ---- Fallback if a thumbnail fails to load: turn the frame into an engraved style ---- */
.folio-frame-fallback {
  background:
    linear-gradient(rgba(250, 243, 224, 0.95), rgba(250, 243, 224, 0.95)),
    radial-gradient(at 30% 20%, rgba(212, 176, 92, 0.28) 0, transparent 60%),
    #ebd9a8;
}
.folio-frame-fallback .folio-overlay { display: none; }
.folio-frame-fallback::after {
  /* keep the corner bracket */
}

/* ---- Metadata block below the cover ---- */
.folio-meta {
  padding: 18px 4px 0;
}
.folio-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed rgba(107, 66, 32, 0.35);
}
.folio-cta {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 0.8rem;
  color: #6b4220;
  transition: color 0.25s ease;
}

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

/* ============================================================
   Print stylesheet (used for "Save as PDF" on the blog page)
   ============================================================ */
@media print {
  .no-print { display: none !important; }
  .print-block { display: block !important; }
  body {
    background: #fff !important;
    background-image: none !important;
    color: #1a1108 !important;
  }
  body::before, body::after { display: none !important; }
  article { background: #fff !important; }
  .print-mb-8 { margin-bottom: 2rem !important; }
  .print-mb-6 { margin-bottom: 1.5rem !important; }
  .print-my-4 { margin-top: 1rem !important; margin-bottom: 1rem !important; }
  .print-mt-6 { margin-top: 1.5rem !important; }
  .print-shadow-none { box-shadow: none !important; }
  figure, aside, pre, blockquote, .print-keep-together {
    break-inside: avoid; page-break-inside: avoid;
  }
  @page { size: A4; margin: 18mm 16mm; }
  header.relative > div.max-w-3xl {
    margin-top: 0 !important; padding-top: 0 !important;
  }
  p, figcaption, li { font-size: 11pt !important; line-height: 1.55 !important; }
  h1 { font-size: 24pt !important; line-height: 1.1 !important; }
  h2 { font-size: 16pt !important; line-height: 1.2 !important; }
  figure img {
    box-shadow: none !important;
    max-height: 70vh; object-fit: contain;
  }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ============================================================
   Tomes — folio filing controls, commission button, dialog
   ============================================================ */

/* A quiet colophon line, not a form: inline italic binding selector on the
   left, a whisper of a burn link on the right. */
.folio-controls {
  margin-top: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.folio-shelf-select {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 1 auto;
  min-width: 0;
  font-family: 'IM Fell English', Garamond, serif;
  font-style: italic;
  font-size: 12.5px;
  color: #8b5a2b;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a87844' fill='none' stroke-width='1.1'/%3E%3C/svg%3E")
    no-repeat right 2px center / 8px 5px transparent;
  border: none;
  border-bottom: 1px dotted rgba(139, 90, 43, 0.4);
  border-radius: 0;
  padding: 2px 16px 2px 1px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.folio-shelf-select:hover,
.folio-shelf-select:focus {
  color: #a83c1f;
  border-bottom-color: rgba(168, 60, 31, 0.55);
  outline: none;
}

.folio-burn {
  font-family: 'Cinzel', 'Trajan Pro', serif;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: rgba(168, 60, 31, 0.55);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  border-radius: 2px;
  padding: 3px 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.folio-burn:hover {
  color: #a83c1f;
  border-color: rgba(168, 60, 31, 0.35);
}

.tome-found-btn {
  font-family: 'Cinzel', 'Trajan Pro', serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: #6b4220;
  background: rgba(250, 243, 224, 0.65);
  border: 1px solid rgba(139, 90, 43, 0.5);
  outline: 3px double rgba(139, 90, 43, 0.3);
  outline-offset: 3px;
  border-radius: 2px;
  padding: 11px 26px;
  cursor: pointer;
  transition: all 0.2s;
}
.tome-found-btn:hover {
  color: #a83c1f;
  border-color: rgba(168, 60, 31, 0.6);
  outline-color: rgba(168, 60, 31, 0.35);
  transform: translateY(-1px);
}

.tome-dissolve {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.tome-dissolve:hover { color: #a83c1f; }

/* ---------- the codex dialog ---------- */

.codex-dialog {
  background: #faf3e0;
  color: #2a1f12;
  border: 1px solid rgba(107, 66, 32, 0.55);
  outline: 4px double rgba(139, 90, 43, 0.35);
  outline-offset: 4px;
  border-radius: 3px;
  padding: 28px 32px 24px;
  max-width: 420px;
  width: calc(100vw - 48px);
  box-shadow: 0 24px 64px rgba(26, 17, 8, 0.4);
}
.codex-dialog::backdrop {
  background: rgba(26, 17, 8, 0.45);
  backdrop-filter: blur(1.5px);
}

.cd-eyebrow {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 0.22em;
  color: #8b5a2b;
  text-align: center;
  margin-bottom: 6px;
}
.cd-title {
  font-family: 'Cormorant Garamond', Garamond, serif;
  font-size: 24px;
  font-weight: 600;
  color: #1a1108;
  text-align: center;
  line-height: 1.2;
  margin-bottom: 10px;
}
.cd-msg {
  font-family: 'IM Fell English', Garamond, serif;
  font-style: italic;
  font-size: 14px;
  color: #5a4530;
  text-align: center;
  line-height: 1.5;
  margin-bottom: 14px;
}
.cd-input {
  display: block;
  width: 100%;
  font-family: 'Cormorant Garamond', Garamond, serif;
  font-size: 16px;
  color: #1a1108;
  background: rgba(255, 252, 240, 0.9);
  border: 1px solid rgba(139, 90, 43, 0.45);
  border-radius: 2px;
  padding: 8px 12px;
  margin-bottom: 16px;
}
.cd-input:focus {
  outline: none;
  border-color: #a83c1f;
  box-shadow: 0 0 0 3px rgba(168, 60, 31, 0.12);
}
.cd-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}
.cd-cancel,
.cd-confirm {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  border-radius: 2px;
  padding: 9px 18px;
  cursor: pointer;
  transition: all 0.15s;
}
.cd-cancel {
  color: #8b5a2b;
  background: transparent;
  border: 1px solid rgba(139, 90, 43, 0.4);
}
.cd-cancel:hover { border-color: #6b4220; color: #6b4220; }
.cd-confirm {
  color: #faf3e0;
  background: #6b4220;
  border: 1px solid #6b4220;
}
.cd-confirm:hover { background: #8b5a2b; border-color: #8b5a2b; }
.cd-confirm.cd-danger {
  background: #a83c1f;
  border-color: #a83c1f;
}
.cd-confirm.cd-danger:hover {
  background: #7d2d18;
  border-color: #7d2d18;
}

/* ---------- Compendium · Tomes · Folios view switcher ---------- */

.codex-tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 44px;
}
.codex-tab {
  font-family: 'Cinzel', 'Trajan Pro', serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #8b5a2b;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 2px 7px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.codex-tab:hover { color: #6b4220; }
.codex-tab.active {
  color: #1a1108;
  border-bottom-color: #a83c1f;
}
.codex-tab-sep {
  color: #a87844;
  font-size: 12px;
  opacity: 0.65;
  user-select: none;
}
