/* ── RESET & BASE ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink:        #1a1408;
  --ink-light:  #3d3020;
  --parchment:  #f5f0e8;
  --cream:      #faf7f2;
  --gold:       #8b6914;
  --gold-light: #c4a44a;
  --gold-dim:   #d4b87a22;
  --rust:       #7a3a1e;
  --lapis:      #1e3a5f;
  --lapis-light:#2a5080;
  --blue-star:  #1b3a6b;
  --rule:       #c4a44a55;
  --shadow:     rgba(26,20,8,0.12);
  --sidebar-bg:    #0B1B2E;
  --sidebar-text:  #ffffffcc;
  --sidebar-hover: rgba(255, 255, 255, 0.15);
  --card-bg:      #f5f0e8;
  --card-border:  #c4a44a55;
}

/* ── DARK MODE (Detecció automàtica) ──────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --ink:        #faf7f2;
    --ink-light:  #e8e4d8;
    --parchment:  #2a2419;
    --cream:      #1a1408;
    --gold:       #d4b87a;
    --gold-light: #e8d4a0;
    --gold-dim:   #d4b87a11;
    --rust:       #d4844a;
    --lapis:      #6b9fce;
    --lapis-light:#8fb3d4;
    --blue-star:  #7ba3d4;
    --rule:       #c4a44a55;
    --shadow:     rgba(26,20,8,0.12);
 }
}

html { scroll-behavior: smooth; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 18px;
  line-height: 1.8;
  font-weight: 300;
}

/* ── SCROLLBAR ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--cream); }
::-webkit-scrollbar-thumb { background: var(--gold-light); border-radius: 3px; }

/* ── COVER ────────────────────────────────────────────────────────────── */
.cover {
  min-height: 100vh;
  background: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  position: relative;
  overflow: hidden;
}

.cover::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 30%, #1b3a6b33 0%, transparent 70%),
    radial-gradient(ellipse 60% 80% at 20% 80%, #1e3a5f22 0%, transparent 60%),
    radial-gradient(ellipse 50% 50% at 80% 20%, #8b691411 0%, transparent 60%);
}

/* Menorah decorativa al cover */
.cover-menorah {
  position: absolute;
  font-size: 6rem;
  opacity: 0.04;
  pointer-events: none;
  color: var(--gold-light);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  line-height: 1;
}

.cover-ornament {
  font-family: 'IM Fell English', serif;
  color: var(--gold-light);
  font-size: 1.1rem;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 2.5rem;
  position: relative;
  animation: fadeDown 1.2s ease both;
}

.cover-rule {
  width: 180px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-light), transparent);
  margin: 0 auto 2.5rem;
  position: relative;
  animation: fadeIn 1.4s ease both 0.2s;
}

.cover-hebrew {
  font-family: 'IM Fell English', serif;
  font-size: 2rem;
  color: var(--gold-light);
  opacity: 0.5;
  margin-bottom: 1rem;
  position: relative;
  animation: fadeDown 1.2s ease both 0.1s;
  letter-spacing: 0.2em;
}

.cover-chapter {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(3.5rem, 8vw, 7rem);
  font-weight: 700;
  color: var(--parchment);
  line-height: 1;
  position: relative;
  letter-spacing: -0.02em;
  animation: fadeUp 1.2s ease both 0.3s;
}

.cover-subtitle {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(1.4rem, 3.5vw, 2.4rem);
  font-weight: 300;
  color: var(--gold-light);
  letter-spacing: 0.08em;
  margin-top: 1rem;
  font-style: italic;
  position: relative;
  animation: fadeUp 1.2s ease both 0.5s;
}

.cover-tesi {
  margin-top: 3rem;
  max-width: 620px;
  font-family: 'Crimson Pro', serif;
  font-size: 1.05rem;
  color: #c8b89a;
  font-style: italic;
  line-height: 1.7;
  position: relative;
  border-top: 1px solid #c4a44a33;
  border-bottom: 1px solid #c4a44a33;
  padding: 1.5rem 2rem;
  animation: fadeUp 1.2s ease both 0.7s;
}

.cover-tesi strong { color: var(--gold-light); font-style: normal; font-weight: 600; }

.cover-scroll {
  position: absolute;
  bottom: 2.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: #c4a44a55;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-family: 'Crimson Pro', serif;
  animation: fadeIn 2s ease both 1.5s;
}

.cover-scroll-line {
  width: 1px;
  height: 40px;
  background: linear-gradient(180deg, transparent, var(--gold-light));
  animation: scrollPulse 2s ease-in-out infinite;
}

/* ── SIDEBAR NAV ──────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 290px;
  height: 100vh;
  max-height: 100vh;
  background: var(--sidebar-bg); /* Ara farà servir el blau */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateX(-100%);
  transition: transform 0.4s cubic-bezier(0.4,0,0.2,1);
  z-index: 999; /* Reduït perquè passi per sota del header */
  padding: 2rem 0;
  padding-top: 80px; /* Espai afegit perquè no xoqui amb el header */
  scrollbar-width: thin;
  scrollbar-color: var(--gold) var(--ink);
}

.sidebar.open { transform: translateX(0); }

.sidebar-header {
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid #c4a44a22;
  margin-bottom: 1rem;
}

.sidebar-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.1rem;
  color: var(--gold-light);
  font-weight: 600;
  line-height: 1.3;
}

.sidebar nav { padding: 0 0.5rem; }

.sidebar a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0.6rem 1rem;
  color: var(--sidebar-text); /* Ara farà servir el blanc transparent */
  text-decoration: none;
  font-size: 0.82rem;
  font-family: 'Crimson Pro', serif;
  transition: color 0.2s, background 0.2s;
  border-radius: 3px;
  line-height: 1.4;
  position: relative;
}

.sidebar a:hover { 
  color: var(--gold-light); 
  background: var(--sidebar-hover); /* Ara farà servir el nou blau clar */
}

.sidebar a.active { 
  color: var(--gold-light); 
  background: #c4a44a18;
  font-weight: 600;
}

.sidebar a.active::before {
  content: '';
  position: absolute;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--gold-light);
  border-radius: 0 2px 2px 0;
}

.sidebar a.lvl1 { 
  font-weight: 600; 
  font-size: 0.88rem; 
  color: #c8b89add; 
  margin-top: 0.5rem; 
}

.sidebar a.lvl2 { 
  padding-left: 1.5rem; 
}

.sidebar a.lvl3 { 
  padding-left: 2.2rem; 
  font-size: 0.78rem; 
}

.sidebar a:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: -2px;
}

/* ── HEADER FIXE & NAV TOGGLE ─────────────────────────────────────────── */
header#mainHeader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 70px;
  background: linear-gradient(to bottom, var(--ink) 60%, transparent 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 1000;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.chapter-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--gold-light);
  letter-spacing: 0.05em;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
}

.nav-toggle {
  width: 44px;
  height: 44px;
  background: var(--ink);
  border: 1px solid #c4a44a44;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.2s;
}

.nav-toggle:hover { 
  background: #2a2010; 
}

.nav-toggle:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 1.5px;
  background: var(--gold-light);
  transition: transform 0.3s, opacity 0.3s;
}

.nav-toggle.open span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}
.overlay.active { display: block; }

/* ── MAIN CONTENT ─────────────────────────────────────────────────────── */
.content {
  max-width: 780px;
  margin: 0 auto;
  padding: 5rem 2.5rem 8rem;
}

/* ── SECTIONS ─────────────────────────────────────────────────────────── */
section { margin-bottom: 5rem; }

/* ── HEADINGS ─────────────────────────────────────────────────────────── */
h1.chapter-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
  margin: 4rem 0 0.5rem;
  letter-spacing: -0.02em;
}

h1.chapter-title .ch-num {
  display: block;
  font-size: 0.75em;
  font-weight: 300;
  color: var(--gold);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-style: italic;
  margin-bottom: 0.3rem;
}

h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 600;
  color: var(--lapis);
  margin: 3rem 0 1rem;
  line-height: 1.25;
}

h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--rust);
  margin: 2rem 0 0.75rem;
  font-style: italic;
}

h4 {
  font-family: 'Crimson Pro', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  margin: 1.75rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-style: normal;
}

/* ── RULE DIVIDER ─────────────────────────────────────────────────────── */
.rule {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-light) 20%, var(--gold-light) 80%, transparent);
  margin: 4rem 0;
  opacity: 0.5;
}

.rule-ornament {
  text-align: center;
  margin: 3rem 0;
  color: var(--gold);
  font-size: 1.5rem;
  letter-spacing: 0.8em;
  opacity: 0.6;
}
/* ── PARAGRAPHS ───────────────────────────────────────────────────────── */
p {
  margin-bottom: 1.3rem;
  text-align: justify;
  hyphens: auto;
}

p.drop-cap::first-letter {
  font-family: 'Cormorant Garamond', serif;
  font-size: 4.2em;
  font-weight: 700;
  float: left;
  line-height: 0.75;
  margin: 0.1em 0.1em 0 0;
  color: var(--gold);
}

/* ── TESI BOX ─────────────────────────────────────────────────────────── */
.tesi {
  background: var(--ink);
  color: var(--parchment);
  padding: 2.5rem;
  margin: 3rem 0;
  border-left: 4px solid var(--gold-light);
  border-radius: 0 4px 4px 0; /* Arrodoniment suau només a la dreta */
  position: relative;
  background: linear-gradient(135deg, var(--ink) 0%, #2a2419 100%); /* Gradient molt subtil */
}

.tesi::before {
  content: 'TESI';
  position: absolute;
  top: -0.8rem;
  left: 2rem;
  background: var(--ink);
  padding: 0 0.75rem;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.8rem;
  color: var(--gold-light);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* ── HIGHLIGHT / CITA ─────────────────────────────────────────────────── */
.highlight {
  background: var(--gold-dim);
  border-left: 3px solid var(--gold-light);
  padding: 1.5rem 2rem;
  margin: 2rem 0;
  font-style: italic;
  color: var(--ink-light);
  border-radius: 0 4px 4px 0;
}
.cita-autor {
  display: block;
  text-align: right;
  font-style: normal;
  font-size: 0.88rem;
  color: var(--gold);
  margin-top: 0.5rem;
  font-family: 'Crimson Pro', serif;
  letter-spacing: 0.03em;
}

/* ── COMPONENTS EDITORIALS: INDEX, CARDS & LISTS ───────────────────────── */

/* 1. Caixes d'Índex */
.index-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 1.5rem;
  margin: 2rem 0;
  border-radius: 2px;
}
.index-section h3 {
  font-family: 'Cormorant Garamond', serif;
  color: var(--lapis);
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.3rem;
  font-weight: 600;
}
.index-list { list-style: none; column-count: 1; gap: 1.5rem; }
@media (min-width: 600px) { .index-list { column-count: 2; } }
.index-list li {
  margin-bottom: 0.8rem;
  padding-left: 1.5rem;
  position: relative;
  break-inside: avoid;
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 0.95rem;
}
.index-list li::before {
  content: '◆';
  position: absolute;
  left: 0;
  color: var(--gold-light);
  font-size: 0.7rem;
  top: 4px;
}

/* 2. Graelles de Conceptes (Triple i Corrents) */
.triple-path { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; margin: 2rem 0; }
.triple-card {
  background: var(--ink);
  color: var(--parchment);
  padding: 1.5rem;
  text-align: center;
  font-family: 'Crimson Pro', Georgia, serif;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.triple-card:hover { transform: translateY(-5px); box-shadow: 0 10px 20px var(--shadow); }
.triple-card .term { 
  font-family: 'Cormorant Garamond', serif; 
  font-size: 1.4rem; 
  font-weight: 700; 
  color: var(--gold-light); 
  display: block; 
  margin-bottom: 0.3rem; 
}
.triple-card .meaning { font-size: 0.85rem; color: #c8b89a; font-style: italic; }

.corrents-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; margin: 2rem 0; }
.corrent-card { 
  border: 1px solid var(--card-border); 
  padding: 1.5rem; 
  background: var(--card-bg); 
  transition: 0.3s; 
}
.corrent-card:hover { border-color: var(--gold-light); }
.corrent-card .corrent-nom { 
  font-family: 'Cormorant Garamond', serif; 
  font-size: 1.2rem; 
  font-weight: 700; 
  color: var(--lapis); 
  margin-bottom: 0.5rem; 
}
.corrent-card p { font-family: 'Crimson Pro', Georgia, serif; font-size: 0.92rem; margin-bottom: 0; }

/* ── SECTION LEAD ─────────────────────────────────────────────────────── */
.section-lead {
  font-style: italic;
  color: var(--ink-light);
  margin-bottom: 2rem;
  font-size: 1.02rem;
}

/* ── FOOTNOTE / NOTE ──────────────────────────────────────────────────── */
.note {
  font-size: 0.85rem;
  color: var(--ink-light);
  font-style: italic;
  border-top: 1px solid var(--rule);
  margin-top: 3rem;
  padding-top: 1rem;
  opacity: 0.8;
}

/* ── BIBLIOGRAPHY ─────────────────────────────────────────────────────── */
.bib-section { margin-bottom: 2rem; }
.bib-section h3 { font-style: normal; color: var(--lapis); font-size: 1rem; letter-spacing: 0.05em; margin-bottom: 0.75rem; }
.bib-entry {
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
  padding-left: 1.5rem;
  text-indent: -1.5rem;
  line-height: 1.55;
  color: var(--ink-light);
  text-align: left;
}

/* ── PROGRESS BAR ─────────────────────────────────────────────────────── */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  z-index: 2000;
  transition: width 0.1s;
}

/* ── BACK TO TOP ──────────────────────────────────────────────────────── */
.back-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 44px;
  height: 44px;
  background: var(--ink);
  border: 1px solid #c4a44a44;
  color: var(--gold-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  opacity: 0;
  transition: opacity 0.3s, background 0.2s, border-color 0.2s;
  text-decoration: none;
  border-radius: 2px;
  pointer-events: none;
}

.back-top.visible { 
  opacity: 1;
  pointer-events: auto;
}

.back-top:hover {
  background: #2a2010;
  border-color: #c4a44a;
}

.back-top:focus {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
}

/* ── ANIMATIONS ───────────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes scrollPulse {
  0%, 100% { opacity: 0.3; transform: scaleY(1); }
  50%       { opacity: 0.8; transform: scaleY(1.1); }
}

/* ── ACCESSIBILITY: Respectar preferències de moviment reducit ─────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── SECTION START ────────────────────────────────────────────────────── */
.section-start { padding-top: 3rem; }

/* ── RESPONSIVE ───────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .content { padding: 4rem 1.25rem 6rem; }
  .triple-path { grid-template-columns: 1fr; }
  .corrents-grid { grid-template-columns: 1fr; }
  .cover-tesi { padding: 1rem 1.25rem; }
}
/* ── CORRECCIÓ DE SEGURETAT PER AL REVEAL ────────────────────────────── */
.reveal {
  opacity: 1 !important; 
  transform: translateY(0) !important;
}
/* Botó "Tornar al índex" dins del sidebar */
.sidebar-back {
  color: var(--gold-light);
  font-weight: 600;
  margin-bottom: 1rem;
  border: 1px solid #c4a44a33;
  border-radius: 4px;
  padding: 0.6rem 1rem;
  background: rgba(255,255,255,0.05);
  transition: background 0.2s, color 0.2s;
}

.sidebar-back:hover {
  background: var(--sidebar-hover);
  color: var(--gold-light);
}
