/* ==========================================================================
   La línia Guardiola — full d'estil
   Els mapes SVG del document pinten amb var(--land), var(--sea), var(--map-line)…
   Cal conservar aquests noms de variable perquè el mode fosc hi funcioni sol.
   ========================================================================== */

/* ---------- fitxes de color ---------- */

:root {
  color-scheme: light;

  --ground:      #E6E5DF;
  --paper:       #F4F3ED;
  --paper-2:     #DEDDD5;
  --ink:         #15181D;
  --ink-soft:    #4C535C;
  --ink-faint:   #7B828A;
  --rule:        #C6C7BE;
  --rule-soft:   #D8D8D0;
  --accent:      #23425F;
  --accent-soft: #416588;
  --accent-tint: #C9D5E1;
  --seal:        #8A6A3B;
  --seal-tint:   #E6DBC6;

  --land:     #E0DFD6;
  --sea:      #CFDAE3;
  --sea-line: #6F93AD;
  --map-line: #A7ADA4;

  --shadow:    0 1px 2px rgba(21, 24, 29, .06);
  --shadow-lift: 0 6px 18px -6px rgba(21, 24, 29, .18), 0 2px 5px rgba(21, 24, 29, .06);

  --measure: 40rem;
  --wrap: 1180px;

  --dur: 200ms;
  --ease: cubic-bezier(.2, .6, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --ground:      #121419;
    --paper:       #1A1D23;
    --paper-2:     #23272E;
    --ink:         #E8E5DD;
    --ink-soft:    #ABB2BB;
    --ink-faint:   #7C848E;
    --rule:        #333941;
    --rule-soft:   #272C33;
    --accent:      #9CBEE2;
    --accent-soft: #7C9EC2;
    --accent-tint: #2B3B4C;
    --seal:        #C9A567;
    --seal-tint:   #3A331F;

    --land:     #232830;
    --sea:      #1E2C38;
    --sea-line: #4E7891;
    --map-line: #444B54;

    --shadow:      0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lift: 0 8px 24px -8px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --ground:      #121419;
  --paper:       #1A1D23;
  --paper-2:     #23272E;
  --ink:         #E8E5DD;
  --ink-soft:    #ABB2BB;
  --ink-faint:   #7C848E;
  --rule:        #333941;
  --rule-soft:   #272C33;
  --accent:      #9CBEE2;
  --accent-soft: #7C9EC2;
  --accent-tint: #2B3B4C;
  --seal:        #C9A567;
  --seal-tint:   #3A331F;

  --land:     #232830;
  --sea:      #1E2C38;
  --sea-line: #4E7891;
  --map-line: #444B54;

  --shadow:      0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lift: 0 8px 24px -8px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 84px;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: clamp(17px, .55vw + 15.4px, 19px);
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-wrap: break-word;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

h1, h2, h3, h4 {
  font-family: Newsreader, Georgia, serif;
  font-weight: 400;
  text-wrap: balance;
  margin: 0;
}

p { margin: 0; }

a {
  color: var(--accent);
  text-decoration-thickness: .5px;
  text-underline-offset: 3px;
  transition: color var(--dur) var(--ease);
}
a:hover { color: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .74em;
  letter-spacing: .04em;
}

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 28px; }
.col  { max-width: var(--measure); }

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  background: var(--paper);
  color: var(--ink);
  padding: 12px 18px;
  border: 1px solid var(--rule);
  border-radius: 0 0 4px 0;
}
.skip:focus { left: 0; }

/* ---------- barra superior ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 clamp(14px, 3vw, 28px);
  height: 56px;
  background: color-mix(in srgb, var(--ground) 88%, transparent);
  backdrop-filter: saturate(150%) blur(12px);
  -webkit-backdrop-filter: saturate(150%) blur(12px);
  border-bottom: 1px solid transparent;
  transform: translateY(-100%);
  opacity: 0;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
.topbar.is-visible {
  transform: none;
  opacity: 1;
  border-bottom-color: var(--rule-soft);
}

.topbar__title {
  font-family: Newsreader, Georgia, serif;
  font-size: 17px;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  text-decoration: none;
}
.topbar__title em { font-style: italic; color: var(--accent); }

.topbar__now {
  margin-left: auto;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}
@media (max-width: 720px) { .topbar__now { display: none; } }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font: inherit;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: .04em;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              background-color var(--dur) var(--ease);
}
.btn:hover { color: var(--ink); border-color: var(--ink-faint); background: var(--paper); }
.btn svg { width: 15px; height: 15px; flex: none; }

.progress {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 100%;
  transform: scaleX(var(--p, 0));
  transform-origin: 0 50%;
  background: var(--accent);
  will-change: transform;
}

/* ---------- portada ---------- */

.cover {
  padding: clamp(80px, 16vh, 168px) 0 clamp(52px, 8vh, 96px);
  max-width: 46rem;
}

.cover .eyebrow {
  display: block;
  color: var(--ink-faint);
  letter-spacing: .1em;
  text-transform: uppercase;
  font-size: .68rem;
  line-height: 1.9;
  margin-bottom: clamp(24px, 5vh, 44px);
}

.cover h1 {
  font-size: clamp(3rem, 9.5vw, 6.6rem);
  line-height: .94;
  letter-spacing: -.022em;
  margin-bottom: clamp(20px, 3.5vh, 34px);
}
.cover h1 em {
  font-style: italic;
  color: var(--accent);
  display: inline-block;
}

.cover .sub {
  font-size: clamp(1.15rem, 2.3vw, 1.5rem);
  line-height: 1.42;
  color: var(--ink-soft);
  font-style: italic;
  max-width: 30rem;
  margin-bottom: clamp(32px, 6vh, 54px);
}

.cover .lede {
  max-width: var(--measure);
  padding-top: clamp(26px, 4vh, 38px);
  border-top: 1px solid var(--rule);
  position: relative;
}
.cover .lede::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 68px;
  height: 2px;
  background: var(--seal);
}
.cover .lede p { color: var(--ink-soft); }
.cover .lede strong { color: var(--ink); font-weight: 600; }

/* ---------- índex ---------- */

.index {
  padding: clamp(40px, 7vh, 72px) 0 clamp(48px, 8vh, 84px);
  border-top: 1px solid var(--rule-soft);
}

.index-head { max-width: var(--measure); margin-bottom: clamp(26px, 4vh, 40px); }
.index-head h2 {
  font-size: clamp(1.6rem, 3.4vw, 2.15rem);
  letter-spacing: -.012em;
  margin-bottom: 10px;
}
.index-head .note { color: var(--ink-faint); font-size: .94rem; line-height: 1.55; }

ol.toc {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 1px;
  background: var(--rule-soft);
  border: 1px solid var(--rule-soft);
}

ol.toc li { background: var(--ground); }

ol.toc a {
  display: grid;
  grid-template-columns: 3.1rem 1fr;
  grid-template-areas: "rn nm" "rn yr";
  align-items: baseline;
  gap: 0 6px;
  padding: 15px 18px;
  text-decoration: none;
  color: inherit;
  background: var(--ground);
  transition: background-color var(--dur) var(--ease);
}
ol.toc a:hover { background: var(--paper); }

ol.toc .rn {
  grid-area: rn;
  align-self: center;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .78rem;
  letter-spacing: .06em;
  color: var(--seal);
}
ol.toc .nm {
  grid-area: nm;
  font-size: 1.02rem;
  line-height: 1.3;
  transition: color var(--dur) var(--ease);
}
ol.toc a:hover .nm { color: var(--accent); }
ol.toc .yr {
  grid-area: yr;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .72rem;
  letter-spacing: .03em;
  color: var(--ink-faint);
  margin-top: 3px;
}

/* ---------- carril lateral de generacions ---------- */

.rail {
  position: fixed;
  left: max(16px, calc(50vw - var(--wrap) / 2 - 74px));
  top: 50%;
  transform: translateY(-50%);
  z-index: 60;
  display: none;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.rail.is-visible { opacity: 1; }

.rail a {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 46px;
  height: 19px;
  padding-right: 8px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--ink-faint);
  text-decoration: none;
  border-right: 2px solid var(--rule);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.rail a:hover { color: var(--ink); border-right-color: var(--ink-faint); }
.rail a[aria-current="true"] {
  color: var(--accent);
  border-right-color: var(--accent);
}

@media (min-width: 1340px) { .rail { display: flex; } }

/* ---------- generació ---------- */

.era {
  margin: clamp(40px, 7vh, 72px) 0 clamp(28px, 4vh, 44px);
  color: var(--ink-faint);
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .68rem;
  position: relative;
}
.era::after {
  content: "";
  display: block;
  margin-top: 12px;
  height: 1px;
  background: var(--rule);
}

.gen {
  padding: clamp(44px, 7vh, 78px) 0;
  border-top: 1px solid var(--rule-soft);
  position: relative;
  scroll-margin-top: 76px;
}
.gen:first-of-type { border-top: 0; }

.gen-num {
  display: block;
  color: var(--seal);
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .68rem;
  margin-bottom: 14px;
}

.gen h2 {
  font-size: clamp(1.95rem, 4.6vw, 3.1rem);
  line-height: 1.06;
  letter-spacing: -.02em;
  max-width: 22ch;
  margin-bottom: 10px;
}

.gen .life {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .78rem;
  letter-spacing: .04em;
  color: var(--ink-faint);
  margin-bottom: clamp(22px, 3.5vh, 34px);
}

.gen .body { max-width: var(--measure); }
.gen .body p + p { margin-top: 1.05em; }

.gen .body p:first-child::first-letter {
  float: left;
  font-family: Newsreader, Georgia, serif;
  font-size: 3.5em;
  line-height: .82;
  padding: .06em .1em 0 0;
  color: var(--accent);
}
.gen .body.cont p:first-child::first-letter,
.aside-branch .body p:first-child::first-letter {
  float: none;
  font-size: inherit;
  line-height: inherit;
  padding: 0;
  color: inherit;
}

/* ---------- fitxa ---------- */

.fitxa {
  margin: clamp(28px, 4.5vh, 42px) 0 0;
  max-width: var(--measure);
  border: 1px solid var(--rule-soft);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.fitxa div {
  display: grid;
  grid-template-columns: 9.5rem 1fr;
  gap: 4px 18px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--rule-soft);
}
.fitxa div:last-child { border-bottom: 0; }
.fitxa dt {
  color: var(--ink-faint);
  letter-spacing: .07em;
  text-transform: uppercase;
  font-size: .64rem;
  padding-top: .34em;
}
.fitxa dd { margin: 0; font-size: .97rem; line-height: 1.5; }
.fitxa dd b { font-weight: 600; }

/* ---------- document citat ---------- */

.doc {
  margin: clamp(26px, 4vh, 38px) 0;
  max-width: var(--measure);
  padding: 22px 24px;
  background: var(--seal-tint);
  border-left: 2px solid var(--seal);
}
.doc .lbl {
  display: block;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--seal);
  margin-bottom: 10px;
}
.doc q {
  display: block;
  font-style: italic;
  font-size: 1.06rem;
  line-height: 1.55;
  quotes: "«" "»";
}
.doc .src {
  display: block;
  margin-top: 12px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .7rem;
  color: var(--ink-faint);
}

/* ---------- on veure-ho ---------- */

.seealso { margin: clamp(28px, 4.5vh, 42px) 0 0; }
.seealso > .lbl {
  display: block;
  color: var(--ink-faint);
  letter-spacing: .1em;
  text-transform: uppercase;
  font-size: .64rem;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule-soft);
}

.lcgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
  gap: 14px;
}

a.linkcard {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
a.linkcard:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  border-color: var(--rule);
}

.lc-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule-soft);
}
.lc-dots {
  flex: none;
  width: 26px;
  height: 6px;
  background-image: radial-gradient(circle, var(--ink-faint) 46%, transparent 48%);
  background-size: 10px 6px;
  background-repeat: repeat-x;
  opacity: .55;
}
.lc-url {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .63rem;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lc-body { display: flex; flex-direction: column; gap: 6px; padding: 14px 15px 15px; flex: 1; }
.lc-title { font-family: Newsreader, Georgia, serif; font-size: 1.03rem; line-height: 1.26; }
.lc-desc  { font-size: .84rem; line-height: 1.5; color: var(--ink-soft); }
.lc-go {
  margin-top: auto;
  padding-top: 10px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .68rem;
  letter-spacing: .03em;
  color: var(--accent);
}

/* ---------- mapes ---------- */

figure.mapfig { margin: clamp(32px, 5vh, 52px) 0; max-width: var(--measure); }
figure.mapfig.wide { max-width: 100%; }

.mapwrap {
  background: var(--paper);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  padding: 14px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
svg.map { display: block; width: 100%; height: auto; }
svg.map text {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  fill: var(--ink-soft);
}
.t-key   { font-size: 11px; fill: var(--ink); letter-spacing: .04em; }
.t-ctx   { font-size: 9.5px; fill: var(--ink-faint); }
.t-min   { font-size: 9px;  fill: var(--ink-faint); }
.t-sea   { font-size: 10px; fill: var(--sea-line); font-style: italic; }
.t-route { font-size: 9px;  fill: var(--accent-soft); letter-spacing: .06em; }
.t-km    { font-size: 8.5px; fill: var(--ink-faint); }
.t-num   { font-size: 9px;  fill: var(--accent); }
.t-pin   { font-size: 10px; fill: var(--accent); }
.t-road  { font-size: 8.5px; fill: var(--ink-faint); letter-spacing: .05em; }
.t-place { font-size: 10.5px; fill: var(--ink); }
.t-guard { font-size: 11px; fill: var(--seal); }

figure.mapfig figcaption {
  margin-top: 12px;
  font-size: .86rem;
  line-height: 1.5;
  color: var(--ink-soft);
}
figure.mapfig figcaption b { color: var(--ink); font-weight: 600; }
figure.mapfig figcaption .tag {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
  margin-bottom: 5px;
}

ol.mapkey {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 7px 18px;
}
ol.mapkey li {
  display: grid;
  grid-template-columns: 1.6rem 1fr;
  gap: 8px;
  font-size: .83rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
ol.mapkey .k {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .7rem;
  color: var(--accent);
  padding-top: .18em;
}
ol.mapkey .k.s { color: var(--seal); }
ol.mapkey b { color: var(--ink); font-weight: 600; }

.scrollhint {
  display: none;
  margin-top: 9px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .64rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------- branca lateral ---------- */

.aside-branch {
  margin: clamp(30px, 5vh, 46px) 0;
  max-width: var(--measure);
  padding: clamp(22px, 3.5vh, 30px) clamp(22px, 3.5vw, 28px);
  background: var(--paper);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
}
.aside-branch .kicker {
  display: block;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 9px;
}
.aside-branch h3 {
  font-size: clamp(1.25rem, 2.6vw, 1.6rem);
  line-height: 1.2;
  margin-bottom: 14px;
}
.aside-branch .body { font-size: .96rem; }
.aside-branch .body p + p { margin-top: .9em; }

.fork {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--rule-soft);
}
.fork h4 {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--accent);
}
.fork ul { list-style: none; margin: 0; padding: 0; }
.fork li {
  position: relative;
  padding-left: 17px;
  font-size: .9rem;
  line-height: 1.5;
  margin-bottom: 7px;
}
.fork li::before {
  content: "";
  position: absolute;
  left: 3px;
  top: -4px;
  bottom: 50%;
  width: 1px;
  background: var(--rule);
}
.fork li::after {
  content: "";
  position: absolute;
  left: 3px;
  top: calc(.75em - 1px);
  width: 8px;
  height: 1px;
  background: var(--rule);
}
.fork li:first-child::before { top: .3em; }

/* ---------- epíleg i notes ---------- */

.closing {
  padding: clamp(52px, 9vh, 92px) 0 clamp(30px, 5vh, 48px);
  border-top: 1px solid var(--rule);
  scroll-margin-top: 76px;
}
.closing h2 {
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.1;
  letter-spacing: -.018em;
  margin-bottom: clamp(20px, 3vh, 30px);
  max-width: 24ch;
}
.closing .body { max-width: var(--measure); }
.closing .body p + p { margin-top: 1.05em; }

.desc {
  margin: clamp(30px, 5vh, 46px) 0;
  max-width: var(--measure);
  border-top: 1px solid var(--rule-soft);
}
.desc-row {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--rule-soft);
}
.desc-row .g {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-top: .3em;
}
.desc-row .n { font-size: .98rem; line-height: 1.45; }
.desc-row .n span { display: block; color: var(--ink-faint); font-size: .84rem; margin-top: 2px; }

.notes {
  padding: clamp(34px, 5vh, 54px) 0 clamp(52px, 9vh, 92px);
  border-top: 1px solid var(--rule-soft);
  max-width: var(--measure);
}
.notes h3 { font-size: 1.24rem; margin-bottom: 14px; }
.notes p, .notes li { font-size: .92rem; line-height: 1.6; color: var(--ink-soft); }
.notes p + p { margin-top: .85em; }
.notes ul { margin: 14px 0 0; padding-left: 18px; }
.notes li { margin-bottom: 7px; }

.colofon {
  margin-top: clamp(30px, 5vh, 46px);
  padding-top: 20px;
  border-top: 1px solid var(--rule-soft);
  color: var(--ink-faint);
  letter-spacing: .06em;
  font-size: .68rem;
}

/* ---------- tornar amunt ---------- */

.totop {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: clamp(14px, 3vw, 28px);
  z-index: 90;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--ink-soft);
  box-shadow: var(--shadow-lift);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease),
              color var(--dur) var(--ease);
}
.totop.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.totop:hover { color: var(--accent); }
.totop svg { width: 17px; height: 17px; }

/* ---------- tauleta ---------- */

@media (max-width: 1000px) {
  :root { --wrap: 100%; }
  .wrap { padding: 0 24px; }
  figure.mapfig, figure.mapfig.wide { max-width: 100%; }
}

@media (max-width: 820px) {
  .fitxa div { grid-template-columns: 8rem 1fr; }
}

/* ---------- mòbil ---------- */

@media (max-width: 640px) {
  html { scroll-padding-top: 68px; }
  .wrap { padding: 0 18px; }

  .cover { padding-top: clamp(64px, 12vh, 96px); }
  .cover h1 { font-size: clamp(2.6rem, 13vw, 3.6rem); }
  .cover .eyebrow { font-size: .62rem; letter-spacing: .08em; }

  .index-head h2 { font-size: 1.5rem; }
  ol.toc { grid-template-columns: 1fr; }

  .gen h2 { font-size: clamp(1.7rem, 8vw, 2.1rem); }
  .gen .body p:first-child::first-letter { font-size: 3em; }

  .fitxa div { grid-template-columns: 1fr; gap: 3px; padding: 12px 15px; }
  .fitxa div:nth-child(odd) { background: color-mix(in srgb, var(--paper-2) 45%, transparent); }

  .fork { grid-template-columns: 1fr; gap: 16px; }
  .desc-row { grid-template-columns: 1fr; gap: 3px; }

  .doc { padding: 18px 18px; }
  .doc q { font-size: 1rem; }

  .lcgrid { grid-template-columns: 1fr; }

  /* els mapes surten del marge i es desplacen a dit */
  .mapwrap { margin: 0 -18px; border-left: 0; border-right: 0; border-radius: 0; padding: 12px 18px; }
  .scrollhint { display: block; }
}

@media (max-width: 400px) {
  .cover h1 { font-size: 2.4rem; }
}

/* ---------- moviment reduït ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  a.linkcard:hover { transform: none; }
}

/* ---------- impressió ---------- */

@media print {
  :root {
    --ground: #fff; --paper: #fff; --paper-2: #fff;
    --ink: #000; --ink-soft: #333; --ink-faint: #666;
    --rule: #bbb; --rule-soft: #ddd;
    --accent: #1a3550; --seal: #6a5228;
    --shadow: none; --shadow-lift: none;
  }
  .topbar, .rail, .totop, .skip, .scrollhint { display: none !important; }
  body { font-size: 11pt; background: #fff; }
  .wrap { max-width: 100%; padding: 0; }
  .gen, .closing { page-break-inside: auto; break-inside: auto; }
  .gen h2, .closing h2 { page-break-after: avoid; break-after: avoid; }
  .fitxa, .doc, a.linkcard, figure.mapfig { page-break-inside: avoid; break-inside: avoid; }
  a.linkcard { box-shadow: none; }
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: .7em;
    color: #666;
    word-break: break-all;
  }
  .lc-go { display: none; }
}
