/*
 * GIMUR: full d'estil de les galerades HTML de l'OJS.
 * Tokens de DESIGN.md (gimur-child). La galerada es veu dins d'un iframe i no
 * hereta el tema: el tema registra este fitxer amb el context htmlGalley i l'OJS
 * l'injecta al <head> de cada galerada HTML que no porte cap CSS propi
 * (PKPTemplateManager::loadHtmlGalleyStyles). Font única: ojs-galleys el copia
 * d'ací quan es genera una galerada autònoma ("css": "embedded" al manifest).
 * Les fonts s'agafen del tema de l'OJS (ruta absoluta); si no hi son, cau a serif/sans del sistema.
 */
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/plugins/themes/gimur/fonts/dm-sans-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/plugins/themes/gimur/fonts/dm-sans-latin-ext.woff2") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "DM Sans"; font-style: italic; font-weight: 400 700; font-display: swap;
  src: url("/plugins/themes/gimur/fonts/dm-sans-italic-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "DM Sans"; font-style: italic; font-weight: 400 700; font-display: swap;
  src: url("/plugins/themes/gimur/fonts/dm-sans-italic-latin-ext.woff2") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Libre Baskerville"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/plugins/themes/gimur/fonts/libre-baskerville-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Libre Baskerville"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/plugins/themes/gimur/fonts/libre-baskerville-latin-ext.woff2") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Libre Baskerville"; font-style: italic; font-weight: 400 700; font-display: swap;
  src: url("/plugins/themes/gimur/fonts/libre-baskerville-italic-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --ink: #1a1a2e;
  --ink-muted: #5c5c68;
  --surface: #ffffff;
  --surface-alt: #f0f4f8;
  --primary: #003966;
  --primary-dark: #002744;
  --accent: #d4792a;
  --accent-ink: #a85a17;
  --rule: #e2e2e8;
  --serif: "Libre Baskerville", Georgia, "Times New Roman", serif;
  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --measure: 42.5rem;
  --toc-w: 15rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 16px; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Focus visible: contorn accent de 2px amb separacio (DESIGN.md) */
a:focus-visible, summary:focus-visible, main:focus-visible, figure.table:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
main:focus:not(:focus-visible) { outline: none; }

.skip-link {
  position: absolute; left: 16px; top: -100px; z-index: 10;
  background: var(--primary); color: #fff; padding: 0.6rem 1rem; border-radius: 4px; font-weight: 600;
}
.skip-link:focus { top: 16px; color: #fff; }

/* ---- Disposicio: una columna a mobil; index enganxat a l'esquerra des de 1024px ---- */
.galley {
  display: grid;
  grid-template-columns: minmax(0, var(--measure));
  grid-template-areas: "header" "toc" "text" "footer";
  justify-content: center;
  padding: clamp(1.5rem, 4vw, 3rem) 16px clamp(4rem, 8vw, 5rem);
}
.galley-header { grid-area: header; }
.galley-toc { grid-area: toc; }
.galley-text { grid-area: text; }
.galley-footer { grid-area: footer; }
@media (min-width: 1024px) {
  .galley {
    grid-template-columns: var(--toc-w) minmax(0, var(--measure));
    grid-template-areas: "toc header" "toc text" ". footer";
    column-gap: clamp(2rem, 4vw, 4rem);
  }
  .galley-toc {
    position: sticky; top: 16px; align-self: start;
  }
}

/* ---- Capcalera ---- */
.galley-header { border-bottom: 1px solid var(--rule); padding-bottom: 1.5rem; margin-bottom: 0; }
@media (min-width: 1024px) { .galley-header { margin-bottom: 2rem; } }
.galley-journal {
  margin: 0 0 1rem; font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted);
}
.galley-journal::before {
  content: ""; display: block; width: 2rem; height: 2px; background: var(--accent); margin-bottom: 0.75rem;
}
h1, h2, h3 { font-family: var(--serif); color: var(--primary); font-weight: 700; hyphens: manual; line-height: 1.2; }
h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.5rem); letter-spacing: -0.01em; margin: 0 0 1rem; }
.galley-author { margin: 0; font-weight: 600; }
.galley-affiliation { margin: 0; color: var(--ink-muted); }

.galley-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem; margin-top: 1.25rem; }
.galley-btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 1.1rem;
  background: var(--primary); color: #fff; border-radius: 4px; font-weight: 600; font-size: 1rem; text-decoration: none;
}
.galley-btn:hover { background: var(--primary-dark); color: #fff; }
.galley-link { display: inline-flex; align-items: center; min-height: 44px; font-size: 1rem; }

/* ---- Index (details: obert sense JS; el JS el plega a mobil) ----
 * Nomes es veuen els H2; els H3 de la seccio activa es despleguen (amb JS).
 * Titols retallats a 2 linies (el sencer, al title). Sense scroll intern. */
.galley-toc { margin: 1.25rem 0 2rem; font-size: 0.9375rem; }
.galley-toc summary {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  min-height: 44px; padding: 0 1rem; cursor: pointer; list-style: none;
  border: 1px solid var(--rule); border-radius: 4px;
  font-weight: 600; color: var(--primary); font-size: 1rem;
}
.galley-toc summary::-webkit-details-marker { display: none; }
.galley-toc summary::after {
  content: ""; width: 0.5rem; height: 0.5rem; margin-right: 0.25rem;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(45deg) translateY(-2px);
}
.galley-toc details[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.galley-toc details[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.galley-toc ol { list-style: none; margin: 0; padding: 0.25rem 0 0.5rem; }
.galley-toc details > ol { border: 1px solid var(--rule); border-top: 0; border-radius: 0 0 4px 4px; padding: 0.25rem 0.5rem 0.5rem; }
.galley-toc ol ol { padding: 0 0 0.25rem 0.9rem; }
.js .galley-toc ol ol { display: none; }
.js .galley-toc li:has(a[aria-current]) > ol { display: block; }
.galley-toc li { margin: 0; }
.galley-toc a {
  display: block; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border-left: 2px solid transparent;
  color: var(--ink-muted); text-decoration: none; line-height: 1.35;
}
.galley-toc .toc-text {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.galley-toc a:hover { color: var(--primary); text-decoration: none; }
.galley-toc a[aria-current="true"] { color: var(--primary); border-left-color: var(--accent); font-weight: 600; }
.galley-toc li:has(ol a[aria-current]) > a { color: var(--primary); font-weight: 600; }
@media (min-width: 1024px) {
  .galley-toc { margin: 0; padding-top: 0.4rem; }
  .galley-toc summary {
    cursor: default; min-height: 0; padding: 0 0 0.6rem; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0;
    font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted);
  }
  .galley-toc summary::after { display: none; }
  .galley-toc details > ol { border: 0; padding: 0.5rem 0 0; }
  .galley-toc a { padding: 0.35rem 0 0.35rem 0.75rem; }
}
/* Pantalles baixes: mes compacte perque l'index hi capia */
@media (min-width: 1024px) and (max-height: 820px) {
  .galley-toc { font-size: 0.875rem; }
  .galley-toc a { padding-top: 0.2rem; padding-bottom: 0.2rem; }
}

/* ---- Text ---- */
.galley-text section { margin-top: clamp(2rem, 4vw, 2.75rem); }
.galley-text section:first-child { margin-top: 0; }
h2 { font-size: clamp(1.25rem, 1rem + 1vw, 1.5rem); margin: 0 0 0.75rem; }
h3 { font-size: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem); margin: 1.75rem 0 0.5rem; }
p { margin: 0 0 1rem; }
/* URL llargues sense enllac (p. ex. "www...") no han de fer scroll horitzontal */
.galley-text :is(p, li, td, th) { overflow-wrap: anywhere; }
ul, ol { padding-left: 1.25rem; }
li { margin-bottom: 0.4rem; }
a { color: var(--primary); text-decoration: underline; text-underline-offset: 0.15em; overflow-wrap: anywhere; }
a:hover { color: var(--primary-dark); }

/* Ancoratge dels titols: discret, visible en passar-hi o amb focus */
.heading-anchor {
  font-family: var(--sans); font-weight: 400; font-size: 0.8em; color: var(--accent-ink);
  text-decoration: none; opacity: 0; padding: 0 0.2em;
}
:is(h2, h3, caption):hover .heading-anchor, .heading-anchor:focus-visible { opacity: 1; }
@media (hover: none) { .heading-anchor { opacity: 0.6; } }

/* Element apuntat per un enllac intern */
:target { scroll-margin-top: 16px; }
li:target, figure:target, p:target { background: var(--surface-alt); box-shadow: -8px 0 0 var(--surface-alt), 8px 0 0 var(--surface-alt); }

/* Taules */
figure.table { margin: 1.5rem 0 2rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; line-height: 1.45; }
caption { caption-side: top; text-align: left; font-family: var(--serif); color: var(--primary); font-size: 1rem; padding-bottom: 0.75rem; }
th, td { text-align: left; vertical-align: top; padding: 0.5rem 0.75rem 0.5rem 0; border-bottom: 1px solid var(--rule); }
thead th { border-bottom: 2px solid var(--primary); font-weight: 600; }
tbody th { font-weight: 600; }
@media (max-width: 639px) { table { font-size: 0.875rem; } th, td { padding-right: 0.5rem; } }

/* Figures */
figure.figure { margin: 1.5rem 0 2rem; }
figure.figure img { max-width: 100%; height: auto; display: block; }
figcaption { font-size: 0.9375rem; color: var(--ink-muted); margin-top: 0.5rem; }

/* Notes al peu */
.footnote-ref { text-decoration: none; padding: 0 0.1em; }
.footnote-ref sup { font-size: 0.75em; font-weight: 600; }
.footnotes { font-size: 0.9375rem; }
.footnotes ol { padding-left: 1.5rem; }
.footnote-back { text-decoration: none; padding: 0 0.25rem; }

/* Referencies: sagnat frances, sense vinyetes */
ul.references { list-style: none; padding: 0; font-size: 1rem; }
ul.references li { padding-left: 2rem; text-indent: -2rem; margin-bottom: 0.75rem; }

.galley-footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-size: 0.875rem; color: var(--ink-muted); }

/* Tornar a dalt: discret, a baix a la dreta; el JS l'amaga fins que s'ha baixat */
.to-top {
  position: fixed; right: 16px; bottom: 16px; z-index: 5;
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.9rem;
  background: var(--surface); color: var(--primary); border: 1px solid var(--rule); border-radius: 4px;
  font-size: 0.875rem; font-weight: 600; text-decoration: none;
}
.to-top:hover { border-color: var(--primary); }
.js .to-top { opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.js.is-scrolled .to-top { opacity: 1; pointer-events: auto; }
.js .to-top:focus-visible { opacity: 1; pointer-events: auto; }
@media (prefers-reduced-motion: reduce) { .js .to-top { transition: none; } }

@media print {
  .galley-toc, .galley-actions, .to-top, .skip-link, .heading-anchor { display: none !important; }
  .galley { display: block; }
  a { color: inherit; }
}
