/* ================= Paleta (Tailwind) ================= */
:root {
  --bg: #f3f4f6;          /* gray-100 */
  --surface: #ffffff;
  --head: #e0f2fe;        /* sky-100: capçalera de targeta */
  --head-line: #bae6fd;   /* sky-200 */
  --menu-bg: #f0f9ff;     /* sky-50: columna del menú */
  --ink: #111827;         /* gray-900 */
  --ink-2: #374151;       /* gray-700 */
  --muted: #4b5563;       /* gray-600 */
  --line: #e5e7eb;        /* gray-200 */
  --sep: #d1d5db;         /* gray-300 */
  --link: #0284c7;        /* sky-600 */
  --title: #0284c7;       /* sky-600 */
  --tip-bg: #1f2937;
  --tip-ink: #f9fafb;

  --s-green: #16a34a;  --s-green-soft: #dcfce7;  --s-green-text: #16a34a;
  --s-cyan: #0891b2;   --s-cyan-soft: #cffafe;   --s-cyan-text: #0891b2;
  --s-violet: #7c3aed; --s-violet-soft: #ede9fe; --s-violet-text: #7c3aed;
  --s-orange: #ea580c; --s-orange-soft: #ffedd5; --s-orange-text: #ea580c;
  --s-sky: #0284c7;    --s-sky-soft: #e0f2fe;    --s-sky-text: #0284c7;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #111827;
  --surface: #1f2937;
  --head: #2b3544;
  --head-line: #4b5563;
  --menu-bg: #374151;
  --ink: #f3f4f6;
  --ink-2: #d1d5db;
  --muted: #9ca3af;
  --line: #374151;
  --sep: #4b5563;
  --link: #38bdf8;
  --title: #38bdf8;
  --tip-bg: #e5e7eb;
  --tip-ink: #111827;

  --s-green-soft: #166534;  --s-green-text: #86efac;
  --s-cyan-soft: #155e75;   --s-cyan-text: #67e8f9;
  --s-violet-soft: #5b21b6; --s-violet-text: #c4b5fd;
  --s-orange-soft: #9a3412; --s-orange-text: #fdba74;
  --s-sky-soft: #075985;    --s-sky-text: #7dd3fc;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  transition: background-color .3s, color .3s;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }
.wrap { max-width: 1024px; margin: 0 auto; padding: 0 20px; }

/* ================= Capçalera ================= */
.site-header {
  position: sticky; top: var(--links-h, 0px); z-index: 50;
  background: linear-gradient(to right, #0ea5e9, #6366f1);
  color: #fff; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .1), 0 4px 6px -4px rgba(0, 0, 0, .1);
}
[data-theme="dark"] .site-header { background: linear-gradient(to right, #1f2937, #374151); }
.hdr-row { display: flex; justify-content: space-between; align-items: center; padding-top: 16px; padding-bottom: 16px; }
.hdr-row h1 { font-size: 20px; font-weight: 700; }
.theme-btn { color: #fff; background: rgba(255, 255, 255, .1); padding: 8px 16px; border-radius: 4px; white-space: nowrap; }
.summary-bar { background: #0284c7; color: #fff; padding: 16px 0 0; }
[data-theme="dark"] .summary-bar { background: #1f2937; color: #f3f4f6; }
.summary-bar .wrap { font-size: 14px; font-weight: 600; line-height: 1.375; text-align: justify; }
.summary-bar a { font-weight: 700; color: #fef9c3; text-decoration: none; border-bottom: 1px dotted #fef9c3; }
.summary-bar a:hover { border-bottom: 2px solid #fef08a; color: #fef08a; }
[data-theme="dark"] .summary-bar a { color: #fde68a; border-bottom-color: #fde68a; }
.pills-bar { position: sticky; top: calc(var(--links-h, 0px) + var(--hdr-h, 64px)); z-index: 49; background: #0284c7; color: #fff; }
[data-theme="dark"] .pills-bar { background: #1f2937; color: #f3f4f6; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding-top: 12px; padding-bottom: 12px; }
.pills-label { font-size: 14px; font-weight: 500; align-self: center; }
.pill {
  display: inline-block; padding: 4px 12px; border-radius: 6px;
  font-size: 14px; font-weight: 500; text-decoration: none;
  background: var(--cs); color: var(--ct); transition: background .15s, color .15s;
}
.pill:hover, .pill.is-active { background: var(--c); color: #fff; }

/* ================= Anys (pestanyes) ================= */
.yr {
  flex: none; display: inline-block;
  padding: 4px 12px; border-radius: 6px;
  font-size: 14px; font-weight: 500; line-height: 1.25; text-align: center;
  background: var(--cs); color: var(--ct); transition: background .15s, color .15s;
}
button.yr:hover, .yr.is-active { background: var(--c); color: #fff; }

/* ================= Contingut de les fites ================= */
.evs { color: var(--ink-2); }
.ev-text { text-align: justify; line-height: 1.6; }
.ev-text ul, .card-details ul { list-style: disc; padding-left: 1.5rem; margin: .75rem 0; }
.ev-text li, .card-details li { margin: .25rem 0; }
.ev-text a, .card-details a {
  font-weight: 700; color: var(--link); text-decoration: none;
  border-bottom: 1px dotted var(--link); transition: all .2s;
}
.ev-text a:hover, .card-details a:hover { border-bottom: 2px solid var(--link); }
.ev-sep { border: 0; border-top: 1px solid var(--sep); margin: 16px 0; }
.ev-pic { display: block; width: 100%; height: auto; margin-top: 16px; border-radius: 8px; cursor: pointer; }
.ev-linkwrap { margin-top: 16px; text-align: center; }
.ev-link { display: inline-block; }
.ev-link img { display: block; margin: 0 auto; border-radius: 6px; height: auto; }
.altres-taula td:first-child { background: var(--menu-bg) !important; }
.altres-taula tbody tr + tr td { border-top-color: var(--line) !important; }

/* Llegenda estàtica sota les miniatures d'enllaç (dispositius sense hover) */
.link-caption-static {
  position: relative; display: inline-block; max-width: 300px;
  margin: 10px 0 12px; padding: 8px 12px; border-radius: 6px;
  background: #1f2937; color: #f9fafb;
  font-size: 14px; line-height: 20px; text-align: justify; text-decoration: none;
}
.link-caption-static::before {
  content: ""; position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  border-style: solid; border-width: 0 8px 8px 8px;
  border-color: transparent transparent #1f2937 transparent;
}
[data-theme="dark"] .link-caption-static { background: #e5e7eb; color: #111827; }
[data-theme="dark"] .link-caption-static::before { border-bottom-color: #e5e7eb; }

/* ================= Tooltip i lightbox ================= */
.tip {
  position: fixed; z-index: 150; min-width: 150px; max-width: 300px;
  background: var(--tip-bg); color: var(--tip-ink);
  font-size: 14px; line-height: 1.4; padding: 8px 12px; border-radius: 6px; text-align: justify;
  pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -2px rgba(0, 0, 0, .1);
}
.tip.on { opacity: 1; visibility: visible; }
.tip.pinned { pointer-events: auto; }
.tip a { color: inherit; font-weight: 700; }
.tip-arrow { display: none; position: absolute; width: 0; height: 0; border: 8px solid transparent; transform: translateX(-50%); }
.tip.anchored .tip-arrow { display: block; }
.tip.below .tip-arrow { top: -16px; border-bottom-color: var(--tip-bg); }
.tip.above .tip-arrow { bottom: -16px; border-top-color: var(--tip-bg); }
.tip-x {
  display: none; position: absolute; top: -10px; right: -10px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; color: #333; font: bold 14px/1 Arial, sans-serif;
  align-items: center; justify-content: center; box-shadow: 0 0 10px rgba(0, 0, 0, .35);
}
.tip.pinned .tip-x { display: flex; }

.lb {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(0, 0, 0, .8);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; transition: opacity .35s ease-in-out;
}
.lb.on { opacity: 1; }
.lb-box { position: relative; line-height: 0; }
.lb img { max-width: 90vw; max-height: 90vh; border-radius: 4px; }
.lb iframe { width: min(90vw, 1120px); aspect-ratio: 16 / 9; border: 0; }
.lb-x {
  position: absolute; top: -1.5rem; right: -1.5rem;
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  background: #fff; color: #333; font: bold 2rem/1 Arial, sans-serif;
  box-shadow: 0 0 10px rgba(0, 0, 0, .5);
}
@media (max-width: 767px) { .lb-x { top: 5px; right: 5px; } }

/* ================= Targetes ================= */
.cards { max-width: 1024px; margin: 0 auto; padding: 40px 20px 60px; }

.card {
  margin-bottom: 40px; border-radius: 8px; overflow: clip;
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
  transition: box-shadow .3s;
  scroll-margin-top: var(--sticky, 140px);
}
.card:hover { box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25); }
.card-header {
  background: var(--head); padding: 16px 20px; border-bottom: 2px solid var(--head-line);
  transition: border-color .3s;
}
.card.is-collapsed .card-header { border-bottom: 1px solid transparent; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-header h3 { font-size: 24px; font-weight: 700; color: var(--title); padding-top: 1px; }
.card-details { margin-top: 4px; color: var(--muted); text-align: justify; }
.card-details p { margin: .25rem 0; }
.card-toggle {
  flex: none; width: 2rem; height: 2rem; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #06b6d4; color: #fff; font-size: 20px; font-weight: 500; line-height: 1;
  transition: background-color .2s;
}
.card-toggle:hover { background: #0891b2; }

/* Plegat amb animació sense trencar el sticky del menú (overflow: clip) */
.card-body { display: grid; grid-template-rows: 1fr; grid-template-columns: minmax(0, 1fr); transition: grid-template-rows .4s ease, opacity .3s; }
.card-body-inner { min-height: 0; min-width: 0; overflow: clip; }
.card.is-collapsed .card-body { grid-template-rows: 0fr; opacity: 0; }

.card-main { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.card-main.single { grid-template-columns: minmax(0, 1fr); }

/* Columna esquerra: tota blava; l'opció activa és una pestanya blanca que s'uneix al contingut */
.card-side { background: var(--menu-bg); border-right: 1px solid var(--line); }
.card-menu {
  list-style: none; margin: 0; padding: 16px 0 16px 12px;
  position: sticky; top: var(--sticky, 140px);
}
.card-menu li { margin-bottom: 4px; }
.card-menu button {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 5px;
  width: calc(100% + 1px);
  text-align: left; padding: 10px 14px 10px 12px;
  border: 1px solid transparent; border-right: 0; border-radius: 8px 0 0 8px;
  font-size: 14.5px; line-height: 1.35; color: var(--ink-2);
  transition: background .15s, border-color .15s;
}
.card-menu button:hover { background: color-mix(in srgb, var(--surface) 55%, transparent); }
.card-menu button.is-active { background: var(--surface); border-color: var(--line); color: var(--ink); z-index: 1; }
.card-menu .yr { padding: 2px 10px; font-size: 13px; }

.card-content { padding: 20px 24px 24px; min-width: 0; }
.card-tabs { display: none; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.card-panel-head { display: none; margin-bottom: 12px; }
.card-panel-head h4 { font-size: 18px; font-weight: 700; color: var(--ink); }
.card-main.single .card-panel-head { display: flex; align-items: center; gap: 10px; }

/* Escriptori: només el panell actiu */
.year-panel { display: none; }
.year-panel.is-active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: .35; } to { opacity: 1; } }
.card-bottomnav { display: none; }

@media (max-width: 767px) {
  .cards { padding: 28px 12px 50px; }
  .card { margin-bottom: 28px; }
  .card-header { padding: 14px 16px; }
  .card-header h3 { font-size: 22px; }
  .card-main { display: block; }
  .card-side { display: none; }
  .card-tabs { display: flex; }
  .card-main.single .card-panel-head { display: none; }
  .card-content { padding: 16px 16px 18px; }

  /* Mòbil: carrusel lliscant entre anys, alçada ajustada al panell visible */
  .card-track {
    display: flex; align-items: flex-start;
    overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
    scrollbar-width: none; transition: height .35s ease-in-out;
  }
  .card-track::-webkit-scrollbar { display: none; }
  .year-panel, .year-panel.is-active { display: block; flex: 0 0 100%; min-width: 0; scroll-snap-align: start; animation: none; }
  .card-bottomnav { display: flex; justify-content: center; gap: 4px; margin-top: 16px; }
  .card-bottomnav .yr { background: var(--c); color: #fff; }
}

/* ================= Mode focus (enllaç directe) ================= */
.spot-overlay {
  position: fixed; inset: 0; z-index: 400; background: rgba(0, 0, 0, .62);
  opacity: 0; transition: opacity .35s ease; cursor: pointer;
}
.spot-overlay.on { opacity: 1; }
.card.spot { position: relative; z-index: 500; box-shadow: 0 25px 60px -12px rgba(0, 0, 0, .55); }

/* ================= Mode enllaços (?links=ja2026) ================= */
.links-banner {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 12px 16px;
  padding: 8px 16px; background: #0c4a6e; color: #e0f2fe; font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
[data-theme="dark"] .links-banner { background: #075985; }
.links-banner button {
  flex: none; padding: 3px 10px; border-radius: 6px; font-size: 13px;
  border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .12);
}
.links-banner button:hover { background: rgba(255, 255, 255, .22); }
.copy-link-btn {
  flex: none; align-self: center; font-size: 12px; line-height: 1.2; padding: 4px 8px; border-radius: 6px;
  border: 1px dashed #0284c7; background: #fff; color: #0369a1; cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.copy-link-btn:hover { background: #f8fafc; }
.copy-link-btn.is-done { cursor: default; opacity: .85; }
.copy-link-yr { font-size: 10.5px; padding: 1px 5px; margin-left: 4px; border-style: solid; border-color: currentColor; vertical-align: 1px; }
.card-title-row .copy-link-btn { margin-left: auto; }
.card-title-row .copy-link-btn + .card-toggle { margin-left: 0; }
.copy-toast {
  position: fixed; bottom: 24px; left: 50%; z-index: 700;
  transform: translateX(-50%) translateY(12px);
  padding: 8px 16px; border-radius: 8px; background: #0f172a; color: #f8fafc; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.copy-toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
