/* =====================================================
   HEMEROTECA — biblioteca, mas nova.
   Tokens → temas por secção → componentes.
   ===================================================== */

:root {
  /* papel & tinta */
  --papel: #f3edde;
  --papel-2: #eae2cd;
  --cartao: #faf6ec;
  --tinta: #241e14;
  --tinta-60: #5c5344;
  --linha: rgba(36, 30, 20, 0.16);

  /* acentos dos corredores */
  --bronze: #8a5a28;   /* átrio */
  --relva: #2b5e45;    /* desporto */
  --azulejo: #2f5a78;  /* portugal */
  --atlas: #57366b;    /* lá fora */
  --corrida: #7e2a1c;  /* finanças (pele oxblood dos livros-razão) */

  --acento: var(--bronze);
  --fundo: var(--papel);

  /* geometria pedida: cantos arredondados */
  --r-tile: 18px;
  --r-btn: 14px;
  --r-chip: 999px;

  --sombra: 0 12px 28px rgba(36, 30, 20, 0.1);
  --sombra-alta: 0 22px 48px rgba(36, 30, 20, 0.18);

  --f-display: 'Fraunces', georgia, serif;
  --f-leitura: 'Newsreader', georgia, serif;
  --f-ui: 'Inter', system-ui, sans-serif;
}

/* fundos diferentes por corredor, mesma família de papel */
body[data-seccao='desporto'] { --acento: var(--relva);   --fundo: #ebefdc; }
body[data-seccao='portugal'] { --acento: var(--azulejo); --fundo: #e8ecdf; }
body[data-seccao='mundo']    { --acento: var(--atlas);   --fundo: #ece8de; }
body[data-seccao='financas'] { --acento: var(--corrida); --fundo: #f2e7d6; }
body[data-seccao='atrio']    { --acento: var(--bronze);  --fundo: var(--papel); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--fundo);
  color: var(--tinta);
  font-family: var(--f-ui);
  font-size: 16px;
  line-height: 1.5;
  transition: background-color 0.45s ease;
}

/* grão de papel, muito subtil */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.55 0 0 0 0 0.5 0 0 0 0 0.42 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23g)'/%3E%3C/svg%3E");
}

#app, .frontao, .sobrepor { position: relative; z-index: 1; }

.sem-scroll { overflow: hidden; }

::selection { background: var(--acento); color: var(--cartao); }

:focus-visible {
  outline: 2.5px solid var(--acento);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- frontão (cabeçalho) ---------- */
.frontao {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 20px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 3px double var(--tinta);
}

.marca {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
}

.marca svg { display: block; }
.marca .marca-fita-1 { fill: var(--relva); }
.marca .marca-fita-2 { fill: var(--corrida); }

.marca-nome {
  font-family: var(--f-display);
  font-weight: 640;
  font-size: 1.45rem;
  letter-spacing: 0.06em;
}

.frontao-espaco { flex: 1; }

/* ---------- botões ---------- */
.btn {
  font-family: var(--f-ui);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--r-btn);
  border: 1.5px solid var(--tinta);
  padding: 10px 16px;
  cursor: pointer;
  background: var(--tinta);
  color: var(--cartao);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--sombra); }
.btn:active { transform: translateY(0); box-shadow: none; }

.btn--cheio { background: var(--acento); border-color: var(--acento); color: #fdfaf2; }

.btn--ghost {
  background: transparent;
  color: var(--tinta);
  border-color: var(--linha);
}
.btn--ghost:hover { border-color: var(--tinta); }

.btn--icone {
  padding: 10px 12px;
  font-size: 1.05rem;
  background: var(--cartao);
  color: var(--tinta);
  border-color: var(--linha);
}
.btn--icone:hover { border-color: var(--tinta); }

.btn--mini { padding: 4px 10px; font-size: 0.78rem; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }

.chip {
  font-family: var(--f-ui);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--r-chip);
  border: 1.5px solid var(--tinta-60);
  background: var(--cartao);
  color: var(--tinta);
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.chip:hover { transform: translateY(-1px); border-color: var(--tinta); }

.chip--on {
  background: var(--acento);
  border-color: var(--acento);
  color: #fdfaf2;
}

.chip--x { padding-right: 12px; }

/* ---------- layout base das páginas ---------- */
#app { max-width: 1120px; margin: 0 auto; padding: 22px 20px 80px; }

.cabecalho-pagina {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.titulo-seccao {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 4.5vw, 2.1rem);
  margin: 0;
  flex: 1;
}

.acoes { display: flex; gap: 8px; }

.instrucao, .lema {
  color: var(--tinta-60);
  font-size: 1rem;
  max-width: 62ch;
}

/* ---------- átrio ---------- */
.atrio { padding-top: 8px; }

.atrio .lema {
  font-family: var(--f-display);
  font-style: italic;
  font-weight: 420;
  font-size: clamp(1.15rem, 3.6vw, 1.5rem);
  color: var(--tinta);
  margin: 10px 0 26px;
}

.alas { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 700px) { .alas { grid-template-columns: 1fr 1fr; } }

.ala {
  position: relative;
  text-align: left;
  border: 1.5px solid var(--linha);
  border-radius: var(--r-tile);
  background: var(--cartao);
  padding: 20px 20px 22px;
  cursor: pointer;
  overflow: hidden;
  display: grid;
  gap: 6px;
  color: var(--tinta);
  box-shadow: var(--sombra);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.ala:hover { transform: translateY(-3px); box-shadow: var(--sombra-alta); border-color: var(--ala-cor); }

.ala--desporto { --ala-cor: var(--relva);   --ala-fundo: #e5ecd9; }
.ala--portugal { --ala-cor: var(--azulejo); --ala-fundo: #e1e7de; }
.ala--mundo    { --ala-cor: var(--atlas);   --ala-fundo: #e8e1d8; }
.ala--financas { --ala-cor: var(--corrida); --ala-fundo: #f0e2cf; }

.ala-titulo {
  font-family: var(--f-display);
  font-weight: 640;
  font-size: 1.55rem;
  margin-top: 6px;
}

.ala-lema { color: var(--tinta-60); font-size: 0.95rem; max-width: 40ch; }

.ala-seta {
  margin-top: 10px;
  justify-self: start;
  font-weight: 700;
  font-size: 0.92rem;
  color: #fdfaf2;
  background: var(--ala-cor);
  border-radius: var(--r-btn);
  padding: 8px 14px;
  transition: transform 0.15s ease;
}
.ala:hover .ala-seta { transform: translateX(3px); }

/* lombadas de livros — a estante de cada ala */
.lombadas {
  height: 96px;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 10px 10px 0;
  border-radius: 12px;
  background: linear-gradient(var(--ala-fundo), var(--ala-fundo)) padding-box;
  border-bottom: 6px solid var(--tinta);
}

.lombada {
  flex: 1;
  height: var(--h);
  max-width: 44px;
  border-radius: 6px 6px 2px 2px;
  border: 1.5px solid var(--tinta);
  background: var(--cartao);
  position: relative;
  transition: transform 0.25s ease;
  transition-delay: calc(var(--i) * 30ms);
}

.lombada--cheia { background: var(--ala-cor); }

.lombada::after {          /* cota na lombada */
  content: '';
  position: absolute;
  left: 15%;
  right: 15%;
  bottom: 8px;
  height: 9px;
  border-radius: 3px;
  background: var(--papel);
  border: 1px solid var(--tinta);
}

.ala:hover .lombada { transform: translateY(-4px); }

.retomar {
  margin-top: 22px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border: 1.5px dashed var(--tinta-60);
  border-radius: var(--r-btn);
  background: transparent;
  color: var(--tinta);
  padding: 14px 16px;
  font-size: 0.98rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.retomar:hover { border-color: var(--tinta); background: var(--cartao); }

.retomar-rotulo {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--acento);
}

/* ---------- página de filtros ---------- */
.estante { margin-top: 22px; }

.estante-rotulo {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--acento);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.estante-rotulo::after { content: ''; flex: 1; border-top: 1px solid var(--linha); }

.barra-abrir {
  position: sticky;
  bottom: 14px;
  margin-top: 30px;
  display: flex;
  gap: 10px;
  align-items: center;
  background: color-mix(in srgb, var(--fundo) 82%, transparent);
  backdrop-filter: blur(6px);
  padding: 10px;
  border-radius: var(--r-tile);
  border: 1.5px solid var(--linha);
  box-shadow: var(--sombra);
}
.barra-abrir .btn--cheio { flex: 1; justify-content: center; font-size: 1rem; padding: 13px 16px; }

/* ---------- banca (tiles) ---------- */
.chips--ativos { margin: 8px 0 4px; }

.barra-estado {
  font-size: 0.85rem;
  color: var(--tinta-60);
  margin: 8px 0 14px;
  min-height: 1.2em;
}

.grelha {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 16px;
  transition: opacity 0.2s ease;
}
.grelha--ocupada { opacity: 0.75; }

.tile {
  background: var(--cartao);
  border: 1.5px solid var(--linha);
  border-radius: var(--r-tile);
  padding: 10px 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(36, 30, 20, 0.06);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.tile:hover { transform: translateY(-3px); box-shadow: var(--sombra); border-color: var(--acento); }

.tile-figura {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: calc(var(--r-tile) - 8px);
  overflow: hidden;
  background: var(--papel-2);
}
.tile-figura img { width: 100%; height: 100%; object-fit: cover; display: block; }

.tile-figura--vazia {
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 20% 0%, color-mix(in srgb, var(--acento) 22%, transparent), transparent 70%),
    var(--papel-2);
}
.tile-glifo { font-size: 2rem; color: var(--acento); }

/* a assinatura: cota de biblioteca no canto de cada tile */
.cota {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--papel);
  color: var(--tinta);
  border: 1.5px solid var(--tinta);
  border-radius: 8px;
  padding: 4px 9px;
  box-shadow: 0 3px 8px rgba(36, 30, 20, 0.22);
}
.cota b { font-weight: 800; }
.cota i {
  width: 4px;
  height: 14px;
  border-radius: 2px;
  background: var(--acento);
}
.cota--solta { position: static; box-shadow: none; }

.tile-titulo {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 1.06rem;
  line-height: 1.32;
  margin: 2px 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-meta { font-size: 0.82rem; color: var(--tinta-60); margin: 0; }

@media (min-width: 740px) {
  .tile--lead { grid-column: span 2; }
  .tile--lead .tile-titulo { font-size: 1.42rem; -webkit-line-clamp: 3; }
}

/* esqueleto de carregamento */
.tile--esqueleto { pointer-events: none; }
.tile--esqueleto .tile-figura,
.linha-fantasma {
  background: linear-gradient(100deg, var(--papel-2) 40%, var(--cartao) 50%, var(--papel-2) 60%);
  background-size: 220% 100%;
  animation: brilhar 1.4s infinite linear;
}
.linha-fantasma { height: 15px; border-radius: 7px; }
.linha-fantasma.curta { width: 55%; }
@keyframes brilhar { to { background-position: -120% 0; } }

.vazio {
  grid-column: 1 / -1;
  text-align: center;
  padding: 46px 16px;
  border: 1.5px dashed var(--tinta-60);
  border-radius: var(--r-tile);
  display: grid;
  gap: 12px;
  justify-items: center;
  color: var(--tinta-60);
}

.mais-antigas {
  grid-column: 1 / -1;
  justify-self: center;
  margin: 10px 0 4px;
  padding: 12px 22px;
}

.fim-estante {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--tinta-60);
  font-size: 0.9rem;
  padding: 20px 10px 6px;
  border-top: 3px double var(--tinta);
  margin-top: 8px;
}

/* ---------- artigo em ecrã inteiro ---------- */
.sobrepor {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
}
.sobrepor.aberto { display: block; }

#artigo { background: var(--fundo); }

#artigo.aberto .artigo-pele { animation: subir 0.28s ease both; }
@keyframes subir { from { transform: translateY(26px); opacity: 0; } }

.artigo-pele { height: 100dvh; overflow-y: auto; overflow-x: hidden; }

.artigo-topo {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--fundo) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 3px double var(--tinta);
}

.artigo-corpo { max-width: 720px; margin: 0 auto; padding: 22px 20px 90px; overflow-wrap: break-word; }

.artigo-hero {
  width: 100%;
  border-radius: var(--r-tile);
  border: 1.5px solid var(--linha);
  margin-bottom: 18px;
  box-shadow: var(--sombra);
}

.artigo-titulo {
  font-family: var(--f-display);
  font-weight: 640;
  font-size: clamp(1.6rem, 5vw, 2.35rem);
  line-height: 1.18;
  margin: 0 0 8px;
}

.artigo-meta {
  font-size: 0.88rem;
  color: var(--tinta-60);
  margin: 0 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--linha);
}

.prosa {
  font-family: var(--f-leitura);
  font-size: 1.14rem;
  line-height: 1.72;
}
.prosa p { margin: 0 0 1em; }
.prosa img {
  max-width: 100%;
  height: auto;
  border-radius: calc(var(--r-tile) - 6px);
  border: 1.5px solid var(--linha);
  margin: 6px 0;
}
/* nada da extração pode ser mais largo que o ecrã (bug Android) */
.prosa :where(figure, video, table, blockquote, div, section, picture) { max-width: 100%; }
.prosa figure { margin: 0 0 1em; }
.prosa video { height: auto; }
.prosa table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; }
.prosa pre { white-space: pre-wrap; word-break: break-word; max-width: 100%; }
.prosa a { color: var(--acento); text-decoration-thickness: 1.5px; }
.prosa h2, .prosa h3 { font-family: var(--f-display); line-height: 1.25; }
.prosa blockquote {
  margin: 1em 0;
  padding: 4px 18px;
  border-left: 4px solid var(--acento);
  color: var(--tinta-60);
  font-style: italic;
}

.nota-prosa { font-family: var(--f-ui); font-size: 0.88rem; color: var(--tinta-60); }

.artigo-rodape {
  margin-top: 30px;
  padding-top: 14px;
  border-top: 3px double var(--tinta);
  font-size: 0.9rem;
  color: var(--tinta-60);
}
.artigo-rodape a { color: var(--acento); font-weight: 600; }

/* ---------- painel de fontes ---------- */
#painel {
  background: rgba(36, 30, 20, 0.45);
}
#painel.aberto { display: grid; place-items: end center; }
@media (min-width: 700px) { #painel.aberto { place-items: center; } }

.painel-pele {
  width: min(560px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--fundo);
  border: 1.5px solid var(--tinta);
  border-radius: var(--r-tile) var(--r-tile) 0 0;
  padding: 16px 18px 22px;
  box-shadow: var(--sombra-alta);
}
@media (min-width: 700px) { .painel-pele { border-radius: var(--r-tile); } }

.painel-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 3px double var(--tinta);
  padding-bottom: 10px;
  margin-bottom: 12px;
}
.painel-topo h2 { font-family: var(--f-display); font-size: 1.25rem; margin: 0; }

.lista-fontes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.fonte {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--cartao);
  border: 1.5px solid var(--linha);
  border-radius: var(--r-btn);
  padding: 10px 12px;
}
.fonte-nome { flex: 1; font-size: 0.95rem; font-weight: 600; }
.fonte-nome em { color: var(--tinta-60); font-weight: 500; font-size: 0.82rem; }
.fonte-erro {
  display: block;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--corrida);
}

.vazio-detalhe { font-size: 0.88rem; max-width: 52ch; margin: 0; }

.fonte-luz {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--tinta-60);
  opacity: 0.4;
  flex: none;
}
.fonte-luz.ok { background: var(--relva); opacity: 1; }
.fonte-luz.erro { background: var(--corrida); opacity: 1; }

.interruptor {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  border: 1.5px solid var(--tinta-60);
  background: var(--papel-2);
  cursor: pointer;
  position: relative;
  flex: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.interruptor i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--cartao);
  border: 1.5px solid var(--tinta-60);
  transition: transform 0.15s ease;
}
.interruptor.on { background: var(--acento); border-color: var(--acento); }
.interruptor.on i { transform: translateX(19px); border-color: #fdfaf2; }

.nova-fonte { margin-top: 20px; display: grid; gap: 10px; }
.nova-fonte input {
  font: inherit;
  padding: 11px 14px;
  border-radius: var(--r-btn);
  border: 1.5px solid var(--tinta-60);
  background: var(--cartao);
  color: var(--tinta);
}
.nova-fonte input:focus { outline: 2.5px solid var(--acento); outline-offset: 1px; }

.painel-nota { font-size: 0.82rem; color: var(--tinta-60); margin: 14px 0 0; }

/* ---------- diversos ---------- */
noscript { display: block; padding: 30px 20px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
