/* ==========================================================================
   Atlas Biblioteca — identidade de movimento do site público
   Fontes (SIL OFL 1.1, servidas localmente), tokens de movimento, View Transitions
   nativas, abertura da marca, fundo ambiente + grão, cursor próprio, tipografia
   cinética, faixa infinita, galeria horizontal, palavra-marca do rodapé e
   micro-interações. Só é carregada pelo site público (templates/base.html):
   o painel de gestão não tem nenhuma destas regras.
   O JavaScript correspondente está em frontend/src/motion/ (motion.bundle.js).
   ========================================================================== */

/* ---------- Fontes (latin; cobre o português europeu) ---------- */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin-wght.260c81a4759b.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk"; font-style: normal; font-weight: 300 700; font-display: swap;
  src: url("../fonts/space-grotesk-latin-wght.87c506d88b9f.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("../fonts/jetbrains-mono-latin-wght.b058178d7f30.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Tokens de movimento (iguais aos de frontend/src/motion/tokens.js) ---------- */
:root {
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in-out: cubic-bezier(.76, 0, .24, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --dur-xs: .18s;
  --dur-s: .35s;
  --dur-m: .6s;
  --dur-l: .9s;
  --dur-xl: 1.3s;
}

/* ---------- View Transitions entre páginas (nativas; sem JavaScript a intercetar) ---------- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
::view-transition-group(*) { animation-duration: var(--dur-l); animation-timing-function: var(--ease-out); }
::view-transition-old(root) { animation: vt-out var(--dur-m) var(--ease-in-out) both; }
::view-transition-new(root) { animation: vt-in var(--dur-l) var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-3vh) scale(.985); } }
@keyframes vt-in { from { clip-path: inset(100% 0 0 0); transform: translateY(8vh); } to { clip-path: inset(0 0 0 0); transform: none; } }
@media (min-width: 861px) {
  .site-header { view-transition-name: site-header; }
  .main-nav { view-transition-name: main-nav; }
}
/* Capa do livro: o cartão clicado recebe o mesmo nome no momento da navegação (motion.js). */
.product-detail-cover .book-3d-front { view-transition-name: product-cover; }
::view-transition-group(product-cover) { animation-duration: var(--dur-xl); z-index: 2; }

/* ---------- Abertura da marca (primeira página da sessão; ver static/js/motion-gate.js) ---------- */
.preloader { display: none; }
html.is-preloading .preloader {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: radial-gradient(80% 60% at 50% 38%, #0d1640, #050816 72%);
  color: var(--heading); clip-path: inset(0 0 0 0);
  animation: preloader-failsafe .5s ease 3.6s forwards; /* nunca prende a página se o JS falhar */
}
.preloader-inner { display: grid; justify-items: center; gap: 22px; }
.preloader-logo { width: 64px; height: 64px; border-radius: 14px; box-shadow: 0 0 40px rgba(56, 189, 248, .5); animation: preloader-pop var(--dur-l) var(--ease-out) both; }
.preloader-word { display: flex; gap: .28em; overflow: hidden; padding: 0 .05em .1em; font-family: var(--font-display); font-weight: 700; font-size: clamp(2.2rem, 6.4vw, 5rem); line-height: 1; letter-spacing: -.035em; text-transform: uppercase; }
.preloader-word > span { display: block; animation: preloader-rise 1s var(--ease-out) .1s both; }
.preloader-word > span + span { animation-delay: .18s; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.preloader-meta { display: flex; justify-content: space-between; width: min(440px, 72vw); font-family: var(--mono); font-size: .72rem; letter-spacing: .24em; text-transform: uppercase; color: var(--muted); }
.preloader-count { color: var(--heading); font-variant-numeric: tabular-nums; }
.preloader-bar { position: relative; width: min(440px, 72vw); height: 1px; overflow: hidden; background: var(--border); }
.preloader-bar::after { content: ""; position: absolute; inset: 0; background: var(--grad); transform-origin: left; transform: scaleX(var(--p, 0)); box-shadow: 0 0 12px rgba(56, 189, 248, .8); }
.preloader-skip { position: absolute; bottom: 28px; left: 50%; translate: -50% 0; white-space: nowrap; font-family: var(--mono); font-size: .7rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.preloader-skip .on-touch { display: none; }
@media (hover: none), (pointer: coarse) {
  .preloader-skip .on-fine { display: none; }
  .preloader-skip .on-touch { display: inline; }
}
@keyframes preloader-rise { from { transform: translateY(110%); } to { transform: none; } }
@keyframes preloader-pop { from { opacity: 0; transform: scale(.6) rotate(-12deg); } to { opacity: 1; transform: none; } }
@keyframes preloader-failsafe { to { opacity: 0; visibility: hidden; } }

/* Topo da página inicial: escondido até a entrada estar montada (nunca mais de 3 s). */
html.motion-ok .hero:not(.is-ready) .hero-text,
html.motion-ok .hero:not(.is-ready) .hero-aside { visibility: hidden; animation: reveal-late 0s linear 3s forwards; }
@keyframes reveal-late { to { visibility: visible; } }

/* ---------- Fundo ambiente WebGL + grão de filme ---------- */
.fx-ambient { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; display: block; pointer-events: none; opacity: 0; transition: opacity 1.6s var(--ease-out); }
.fx-ambient.is-ready { opacity: 1; }
.fx-grain {
  position: fixed; inset: -96px; z-index: 95; pointer-events: none;
  background: url("../img/grain.45f492b516d6.svg") repeat; background-size: 200px 200px; opacity: .07;
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 17% { transform: translate(-48px, 32px); } 33% { transform: translate(40px, -56px); }
  50% { transform: translate(-24px, 72px); } 67% { transform: translate(64px, 16px); } 83% { transform: translate(-72px, -40px); }
  100% { transform: translate(0, 0); }
}

/* ---------- Cursor próprio (só "pointer: fine"; criado em JS) ---------- */
html.has-cursor, html.has-cursor * { cursor: none; }
html.has-cursor :is(input, textarea, select, label, [contenteditable], .cookie-banner, .cookie-banner *) { cursor: auto; }
.cursor { position: fixed; left: 0; top: 0; z-index: 1001; pointer-events: none; opacity: 0; mix-blend-mode: difference; transition: opacity var(--dur-s); }
.cursor.is-visible { opacity: 1; }
.cursor.is-native { opacity: 0; }
.cursor-dot { position: absolute; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%; background: #fff; transition: opacity var(--dur-xs); }
.cursor-ring { position: absolute; left: 0; top: 0; }
.cursor-ring::before { content: ""; position: absolute; left: -18px; top: -18px; width: 36px; height: 36px; border: 1px solid rgba(255, 255, 255, .85); border-radius: 50%; transition: transform var(--dur-m) var(--ease-out), background-color var(--dur-s), border-color var(--dur-s); }
.cursor.is-link .cursor-ring::before { transform: scale(1.65); background: rgba(255, 255, 255, .14); }
.cursor.is-down .cursor-ring::before { transform: scale(.75); }
.cursor.is-link.is-down .cursor-ring::before { transform: scale(1.35); }
.cursor.is-view { mix-blend-mode: normal; }
.cursor.is-view .cursor-ring::before { transform: scale(2.5); background: var(--grad); border-color: transparent; box-shadow: 0 10px 30px -8px rgba(139, 92, 246, .8); }
.cursor.is-view .cursor-dot { opacity: 0; }
.cursor-label { position: absolute; left: 0; top: 0; translate: -50% -50%; scale: .4; opacity: 0; font-family: var(--mono); font-size: .74rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: #fff; transition: opacity var(--dur-s), scale var(--dur-m) var(--ease-out); }
.cursor.is-view .cursor-label { opacity: 1; scale: 1; }

/* ---------- Tipografia cinética ---------- */
.split-line-mask { padding-bottom: .1em; margin-bottom: -.1em; }
.section-title small.is-kicker { font-variant-numeric: tabular-nums; }
.hero-kicker { font-variant-numeric: tabular-nums; }

/* Palavra-marca gigante do rodapé (decorativa; o nome existe no cabeçalho e no rodapé). */
.footer-wordmark {
  --fill: 1;
  position: relative; overflow: hidden; padding: 18px 0 6px; margin: 0 auto;
  font-family: var(--font-display); font-weight: 700; font-size: 10.4vw; line-height: .86; letter-spacing: -.05em;
  text-transform: uppercase; white-space: nowrap; text-align: center; user-select: none; pointer-events: none;
}
.footer-wordmark-outline { display: block; color: transparent; -webkit-text-stroke: 1px rgba(129, 161, 255, .32); }
.footer-wordmark-fill {
  position: absolute; inset: 18px 0 6px; display: block;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  clip-path: inset(0 calc(100% - var(--fill) * 100%) 0 0); opacity: .85;
}
.footer-wordmark .wm-char { will-change: transform; }

/* ---------- Faixa infinita das áreas (só com movimento; o conteúdo está na lista abaixo) ---------- */
.marquee { display: none; }
.marquee.is-running {
  display: block; position: relative; overflow: hidden; margin: -20px 0 56px; padding: 22px 0 10px;
  border-block: 1px solid var(--border);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
}
.marquee-track { display: flex; width: max-content; will-change: transform; }
.marquee-group { display: flex; flex-shrink: 0; margin: 0; padding: 0; list-style: none; }
.marquee-group li {
  display: flex; align-items: center; gap: .55em; padding-right: .55em; white-space: nowrap;
  font-family: var(--font-display); font-weight: 700; font-size: clamp(2rem, 4.8vw, 4.4rem); line-height: 1.15; letter-spacing: -.035em;
  color: transparent; -webkit-text-stroke: 1px rgba(196, 181, 253, .45); transition: color var(--dur-m) var(--ease-out);
}
.marquee-group li:nth-child(3n + 2) { color: var(--heading); -webkit-text-stroke: 0; }
.marquee-group li::after { content: ""; flex: 0 0 auto; width: .26em; height: .26em; border-radius: 3px; background: var(--grad); transform: rotate(45deg); box-shadow: 0 0 18px rgba(56, 189, 248, .6); }
.marquee-group li:hover { color: var(--accent); }
.marquee-toggle {
  display: block; margin: 8px 8% 0 auto; padding: 3px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: rgba(5, 8, 22, .6); color: var(--muted); font-family: var(--mono); font-size: .66rem; letter-spacing: .16em; text-transform: uppercase; cursor: pointer;
}
.marquee-toggle:hover, .marquee-toggle:focus-visible { color: var(--heading); border-color: var(--accent); }

/* ---------- Galeria horizontal do catálogo em destaque (desktop, com movimento) ---------- */
[data-gallery].is-horizontal { overflow: hidden; min-height: var(--gallery-h, 100vh); display: flex; align-items: center; padding: 28px 0; }
[data-gallery].is-horizontal > .container { max-width: none; padding-left: max(20px, calc((100vw - 1200px) / 2 + 20px)); padding-right: 0; }
[data-gallery].is-horizontal .section-title { margin-bottom: 20px; }
[data-gallery].is-horizontal .product-grid { display: flex; gap: 28px; width: max-content; perspective: none; will-change: transform; }
/* Em galeria, cada cartão fica "deitado": capa à esquerda, informação à direita (cabe num ecrã). */
[data-gallery].is-horizontal .product-card { flex: 0 0 auto; width: clamp(480px, 38vw, 560px); display: grid; grid-template-columns: 190px 1fr; grid-template-rows: 1fr auto auto; }
[data-gallery].is-horizontal .product-card-cover { grid-row: 1 / span 3; display: flex; align-items: center; justify-content: center; padding: 20px 10px; border-bottom: 0; border-right: 1px solid var(--border); }
[data-gallery].is-horizontal .product-card-body p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
.gallery-progress { display: flex; align-items: center; gap: 18px; max-width: 1160px; margin-top: 24px; font-family: var(--mono); font-size: .72rem; letter-spacing: .22em; color: var(--muted); }
.gallery-progress-bar { position: relative; flex: 0 1 360px; height: 1px; overflow: hidden; background: var(--border); }
.gallery-progress-bar::after { content: ""; position: absolute; inset: 0; background: var(--grad); transform-origin: left; transform: scaleX(var(--p, 0)); }
.gallery-progress-count { color: var(--heading); font-variant-numeric: tabular-nums; }
[data-gallery].is-horizontal .gallery-progress + p { margin-top: 14px !important; }

/* Capas: distorção RGB momentânea ao passar o rato (filtro SVG criado em motion.js). */
.fx-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.fx-glitch { filter: url(#fx-rgb); }

/* ---------- Micro-interações (todas com os mesmos tokens) ---------- */
.btn { isolation: isolate; transition: transform var(--dur-s) var(--ease-out), box-shadow var(--dur-s), background var(--dur-s), border-color var(--dur-s), color var(--dur-s); }
.btn-default::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background: linear-gradient(120deg, rgba(56, 189, 248, .28), rgba(139, 92, 246, .32) 60%, rgba(244, 114, 182, .24));
  transform: translateY(102%); transition: transform var(--dur-m) var(--ease-out);
}
.btn-default:hover::before, .btn-default:focus-visible::before { transform: translateY(0); }
.btn-primary::after, .btn-navy::after { transition: left var(--dur-l) var(--ease-out); }

/* Sublinhados desenhados da esquerda para a direita (e recolhidos para a direita). */
:is(.site-footer, .topbar-links, .breadcrumb, .product-card h3, .area-list h3, .dropdown) a:not(.btn) {
  text-decoration: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-3)) no-repeat 100% 100% / 0 1px;
  transition: background-size var(--dur-m) var(--ease-out), color var(--dur-s);
}
:is(.site-footer, .topbar-links, .breadcrumb, .product-card h3, .area-list h3, .dropdown) a:not(.btn):is(:hover, :focus-visible) {
  text-decoration: none; background-size: 100% 1px; background-position: 0 100%;
}
.nav-menu > li > a::after { transition: transform var(--dur-m) var(--ease-out); }

/* Etiquetas de nível de preço: preenchimento com o gradiente. */
.price-tier { position: relative; overflow: hidden; isolation: isolate; transition: color var(--dur-s), border-color var(--dur-s), transform var(--dur-s) var(--ease-out); }
.price-tier::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--grad); transform: scaleX(0); transform-origin: left; transition: transform var(--dur-m) var(--ease-out); }
.price-tier:is(:hover, :focus-visible) { color: #fff; border-color: transparent; text-decoration: none; transform: translateY(-1px); }
.price-tier:is(:hover, :focus-visible)::before { transform: scaleX(1); }

/* Contador do carrinho: anel que se expande quando aumenta (motion.js). */
.badge { position: relative; }
.badge.is-bumped::after { content: ""; position: absolute; inset: -2px; border-radius: inherit; border: 2px solid var(--accent); animation: badge-ring 1s var(--ease-out) .35s both; }
@keyframes badge-ring { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(2.4); } }

/* ---------- Menos movimento / impressão ---------- */
@media (prefers-reduced-motion: reduce) {
  .fx-grain { animation: none; }
  .cursor, .fx-ambient, .preloader { display: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
@media print {
  .fx-grain, .fx-ambient, .cursor, .preloader, .marquee, .footer-wordmark { display: none !important; }
}
