:root {
  --paper:      #e8e0ce;   /* newsprint envellit */
  --paper-deep: #ded3ba;   /* panells */
  --ink:        #211e17;   /* tinta ferrogàl·lica */
  --ink-soft:   #6e6553;   /* tinta esvaïda */
  --rule:       #b4a98e;   /* filets */
  --red:        #8c2b1e;   /* tinta roja / llapis de corrector */
  --red-bright: #a6392a;
  --shadow:     rgba(33,30,23,.18);
  --disp: "Old Standard TT", Georgia, "Times New Roman", serif;
  --body: "Spectral", Georgia, serif;
  --mono: "Space Mono", ui-monospace, "Courier New", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(120% 90% at 50% -10%, #efe8d8 0%, var(--paper) 55%, var(--paper-deep) 100%) fixed;
  color: var(--ink);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.5;
  padding: 0 clamp(1rem, 4vw, 4rem);
}

/* --- Capçalera / masthead --- */
.masthead { max-width: 1000px; margin: clamp(1.5rem,4vw,3rem) auto 0; text-align: center; }

.masthead__title {
  font-family: var(--disp);
  font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 6rem);
  line-height: .95;
  letter-spacing: .01em;
  margin: .28em 0;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255,255,255,.35);
}

.masthead__tagline {
  font-family: var(--body);
  font-style: italic;
  font-size: clamp(.85rem, 2.2vw, 1.05rem);
  color: var(--ink-soft);
  margin: .5em auto 0;
  max-width: 40ch;
}

.folio {
  display: flex; justify-content: space-between; gap: 1rem;
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 .2rem .5rem;
}
.folio__mid { color: var(--red); }

.rule--double {
  height: 4px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  background: transparent;
  transform: scaleX(var(--rule-grow, 1));
  transform-origin: center;
}

/* --- Cercador --- */
main { max-width: 1000px; margin: 0 auto; }

.cerca {
  display: grid;
  grid-template-columns: 1fr 11rem 11rem auto;
  gap: 1rem;
  align-items: end;
  margin: clamp(1.5rem, 4vw, 2.5rem) 0 1rem;
}

.lbl {
  display: block;
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: .4rem;
}

.cerca input,
.cerca select {
  width: 100%;
  font-family: var(--body);
  font-size: 1.15rem;
  color: var(--ink);
  background: rgba(255,253,247,.55);
  border: none;
  border-bottom: 2px solid var(--ink);
  padding: .45rem .2rem;
  border-radius: 0;
}
.cerca input:focus,
.cerca select:focus { outline: none; border-bottom-color: var(--red); background: rgba(255,253,247,.85); }

.cerca__btn {
  font-family: var(--mono);
  font-weight: 700;
  font-size: .8rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--ink);
  border: none;
  padding: .7rem 1.6rem;
  cursor: pointer;
  transition: background .15s;
}
.cerca__btn:hover { background: var(--red); }
.cerca__btn:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }

.exacta {
  grid-column: 1 / -1;
  justify-self: start;
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex; align-items: center; gap: .45rem;
  cursor: pointer;
  margin-top: -.4rem;
}
.exacta input { width: auto; accent-color: var(--red); }

.hint {
  font-family: var(--body);
  font-style: italic;
  font-size: .92rem;
  color: var(--ink);
  margin: .8rem 0 0;
}
.hint a {
  color: var(--red); font-style: normal; font-weight: 500;
  text-decoration: underline; text-decoration-color: var(--red-bright);
  cursor: pointer;
}

.status {
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .06em;
  color: var(--ink-soft);
  min-height: 1.2em;
  margin: .4rem 0 1.4rem;
}

/* --- Resultats: retalls de premsa --- */
.results { display: grid; gap: 1px; background: var(--rule); }

.clip {
  background: var(--paper);
  padding: 1.1rem 1.2rem;
  cursor: pointer;
  display: grid;
  gap: .5rem;
  transition: background .12s;
  border-left: 3px solid transparent;
}
.clip:hover { background: #efe8d8; border-left-color: var(--red); }
.clip:focus-visible { outline: none; border-left-color: var(--red); background: #efe8d8; }

.clip__head {
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; align-items: baseline;
}
.clip__num { color: var(--ink); font-weight: 700; }
.clip__date { color: var(--red); }

.clip__snippet {
  font-family: var(--body);
  font-size: 1.02rem;
  line-height: 1.55;
  color: var(--ink);
}
.clip__snippet mark {
  background: none;
  color: var(--red);
  font-weight: 500;
  /* llapis de corrector */
  text-decoration: underline;
  text-decoration-color: var(--red-bright);
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

/* --- Paginació --- */
.pager {
  display: flex; align-items: center; justify-content: center; gap: 1.5rem;
  margin: 2rem 0;
}
.pager button {
  font-family: var(--mono); font-size: .78rem; letter-spacing: .08em;
  background: none; border: 1px solid var(--ink); color: var(--ink);
  padding: .5rem 1rem; cursor: pointer;
}
.pager button:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.pager button:disabled { opacity: .3; cursor: default; }
.mono { font-family: var(--mono); font-size: .78rem; color: var(--ink-soft); }

/* --- Colofó --- */
.colophon {
  max-width: 1000px; margin: 3rem auto 2rem;
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  font-family: var(--body); font-style: italic; font-size: .82rem; color: var(--ink-soft);
}

/* --- Visor --- */
.viewer {
  position: fixed; inset: 0;
  background: rgba(20,18,12,.72);
  display: flex; align-items: stretch; justify-content: center;
  z-index: 50;
  padding: clamp(.5rem, 2vw, 2rem);
}
.viewer[hidden] { display: none; }
.viewer__panel {
  background: var(--paper);
  width: min(900px, 100%);
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.viewer__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1rem; border-bottom: 2px solid var(--ink);
}
.viewer__meta { color: var(--ink); }
.viewer__actions { display: flex; align-items: center; gap: 1rem; }
.viewer__actions a { color: var(--red); text-decoration: none; }
.viewer__actions a:hover { text-decoration: underline; }
#viewer-close {
  background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--ink);
  line-height: 1;
}
.pgnav {
  background: none; border: 1px solid var(--ink); color: var(--ink);
  font-size: 1.1rem; line-height: 1; width: 1.9rem; height: 1.9rem; cursor: pointer;
  border-radius: 0;
}
.pgnav:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.pgnav:disabled { opacity: .3; cursor: default; }
.viewer__sep { width: 1px; height: 1.4rem; background: var(--rule); margin: 0 .2rem; }

.viewer__stage {
  flex: 1; position: relative; overflow: hidden; background: #2a2622;
  touch-action: none; cursor: grab;
}
.viewer__stage:active { cursor: grabbing; }
.viewer__canvas {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
}
#viewer-img {
  display: block; width: 100%; height: auto; background: var(--paper);
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  user-select: none; -webkit-user-drag: none;
}
.viewer__marks { position: absolute; inset: 0; pointer-events: none; }
.mark {
  position: absolute;
  background: rgba(230,70,50,.22);
  outline: 2px solid var(--red-bright);
  border-radius: 2px;
  box-shadow: 0 0 0 3px rgba(230,70,50,.12);
}
@media (prefers-reduced-motion: no-preference) {
  .mark { animation: markpulse 1.1s ease-in-out 2; }
  @keyframes markpulse {
    0%,100% { background: rgba(230,70,50,.18); }
    50% { background: rgba(230,70,50,.42); }
  }
}

/* --- Responsiu --- */
@media (max-width: 680px) {
  .cerca { grid-template-columns: 1fr; }
  .folio { font-size: .58rem; letter-spacing: .1em; }
}

@media (prefers-reduced-motion: no-preference) {
  .rule--double { animation: grow .7s cubic-bezier(.2,.8,.2,1) both; }
  @keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
  .clip { animation: fade .35s ease both; }
  @keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}

/* --- Login de Lumen --- */
.login { max-width: 26rem; margin: 2.5rem auto 3rem; }
.login__form { display: flex; flex-direction: column; gap: .35rem; }
.login__intro { font-style: italic; color: var(--ink-soft); margin: 0 0 1rem; text-align: center; }
.login__intro a { color: var(--red); }
.login input {
  font-family: var(--body); font-size: 1.05rem; color: var(--ink);
  background: rgba(255,253,247,.55); border: 0; border-bottom: 2px solid var(--ink);
  padding: .45rem .5rem; margin-bottom: .8rem; width: 100%;
}
.login input:focus { outline: none; border-bottom-color: var(--red); background: rgba(255,253,247,.85); }
.login .cerca__btn { margin-top: .5rem; }
.login__error { color: var(--red); font-size: .95rem; margin: .6rem 0 0; text-align: center; }
.linkbtn {
  font: inherit; color: var(--red); background: none; border: 0; padding: 0;
  cursor: pointer; text-decoration: underline;
}
