/* 10 · Territórios — seis cartas holográficas distribuídas por um emissor de luz */
#territorios {
  --tr-gap: clamp(12px, 1.1vw, 18px);
  --tr-radius: 16px;
  background: radial-gradient(90% 70% at 70% 55%, rgba(18, 197, 181, 0.07), transparent 70%);
}
#territorios .tr-pin { position: relative; min-height: 100vh; min-height: 100svh; padding-block: clamp(96px, 13vh, 160px) clamp(64px, 10vh, 120px); }
#territorios .tr-bg { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#territorios .tr-bg__grid { opacity: 0.4; background-size: 56px 56px; }
#territorios .tr-bg__glow { position: absolute; left: 50%; top: 56%; width: 90vmax; height: 60vmax; transform: translate(-50%, -50%); background: radial-gradient(closest-side, rgba(29, 159, 208, 0.12), rgba(18, 197, 181, 0.05) 50%, transparent 72%); }

/* ---------- Cabeçalho ---------- */
#territorios .tr-head { position: relative; z-index: 2; }
#territorios .tr-h2 { max-width: 20ch; }
#territorios .tr-ring, #territorios .tr-status { display: none; }

/* ---------- Grade de cartas ---------- */
#territorios .tr-board { position: relative; margin-top: clamp(36px, 6vh, 64px); }
#territorios .tr-scroller { position: relative; outline-offset: 6px; }
#territorios .tr-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--tr-gap);
  perspective: 1700px; perspective-origin: 50% 50%; transform-style: preserve-3d;
}
#territorios .tr-slot { --acc: var(--teal-hi); --acc-rgb: 79, 240, 220; position: relative; aspect-ratio: 4 / 5; transform-style: preserve-3d; }
#territorios .tr-slot:nth-child(even) { --acc: var(--cyan-hi); --acc-rgb: 111, 211, 255; }
#territorios .tr-card, #territorios .tr-tilt { position: absolute; inset: 0; transform-style: preserve-3d; }
#territorios .tr-face {
  position: absolute; inset: 0; overflow: hidden; border-radius: var(--tr-radius);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
#territorios .tr-face::after {
  content: ''; position: absolute; inset: 0; z-index: 6; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(150deg, rgba(var(--acc-rgb), 0.75), rgba(29, 159, 208, 0.14) 36%, rgba(126, 170, 232, 0.08) 64%, rgba(var(--acc-rgb), 0.5));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}

/* Frente */
#territorios .tr-front { --mx: 0.5; --my: 0.35; --hov: 0; background: var(--navy-900); isolation: isolate; box-shadow: 0 34px 70px -34px rgba(0, 0, 0, 0.85); }
#territorios .tr-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transform: translate3d(calc((var(--mx) - 0.5) * -14px), calc((var(--my) - 0.5) * -14px + var(--sy, 0%)), 0) scale(1.07);
}
/* Imagens com o assunto baixo sobem para ficar acima do texto; a borda de baixo some no degradê */
#territorios .tr-img--lift { -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent 98%); mask-image: linear-gradient(180deg, #000 70%, transparent 98%); }
#territorios .tr-shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(0deg, rgba(2, 8, 22, 0.97) 0%, rgba(2, 8, 22, 0.86) 26%, rgba(2, 8, 22, 0.35) 50%, rgba(2, 8, 22, 0) 64%),
    linear-gradient(180deg, rgba(2, 8, 22, 0.55) 0%, rgba(2, 8, 22, 0) 22%);
}
#territorios .tr-holo {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(115deg, rgba(79, 240, 220, 0) 0%, rgba(79, 240, 220, 0.5) 5%, rgba(111, 211, 255, 0.45) 10%, rgba(150, 120, 255, 0.4) 15%, rgba(255, 130, 210, 0.32) 20%, rgba(255, 226, 140, 0.3) 25%, rgba(79, 240, 220, 0) 31%);
  background-size: 240% 240%;
  background-position: calc(var(--mx) * 100%) calc(var(--my) * 100%);
  mix-blend-mode: color-dodge; opacity: calc(0.07 + var(--hov) * 0.55);
  transition: opacity 0.4s;
}
#territorios .tr-glare {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(circle at calc(var(--mx) * 100%) calc(var(--my) * 100%), rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 46%);
  mix-blend-mode: overlay; opacity: var(--hov); transition: opacity 0.4s;
}
/* Brilho de folha que atravessa a carta periodicamente (projetor, sem mouse) */
#territorios .tr-front::before {
  content: ''; position: absolute; z-index: 3; top: -20%; bottom: -20%; left: -70%; width: 45%; pointer-events: none;
  background: linear-gradient(100deg, transparent 0%, rgba(var(--acc-rgb), 0.08) 35%, rgba(220, 255, 250, 0.2) 50%, rgba(var(--acc-rgb), 0.08) 65%, transparent 100%);
  transform: translateX(0) skewX(-14deg); mix-blend-mode: screen;
  animation: tr-sheen 8s var(--ease-io) infinite; animation-delay: calc(var(--i) * 1.1s + 2s);
}
@keyframes tr-sheen { 0%, 70% { transform: translateX(0) skewX(-14deg); } 100% { transform: translateX(460%) skewX(-14deg); } }
/* Clarão de assentamento (animado pelo scroll) */
#territorios .tr-sweep {
  position: absolute; z-index: 4; top: -10%; bottom: -10%; left: 0; width: 100%; pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgba(var(--acc-rgb), 0.35) 46%, rgba(255, 255, 255, 0.55) 50%, rgba(var(--acc-rgb), 0.35) 54%, transparent 70%);
  mix-blend-mode: screen; opacity: 0;
}
#territorios .tr-front > .hud-c { z-index: 5; width: 14px; height: 14px; border-color: var(--acc); opacity: 0.85; }
#territorios .tr-front > .hud-c.tl { top: 10px; left: 10px; }
#territorios .tr-front > .hud-c.tr { top: 10px; right: 10px; }
#territorios .tr-front > .hud-c.bl { bottom: 10px; left: 10px; }
#territorios .tr-front > .hud-c.br { bottom: 10px; right: 10px; }
#territorios .tr-num {
  position: absolute; z-index: 5; top: clamp(14px, 1.5vw, 22px); left: clamp(16px, 1.5vw, 24px);
  font-family: var(--font-display); font-style: italic; font-weight: 850; font-stretch: 118%;
  font-size: clamp(34px, 3vw, 56px); line-height: 0.9; letter-spacing: -0.02em;
  color: transparent; -webkit-text-stroke: 1.2px var(--acc);
  filter: drop-shadow(0 0 10px rgba(var(--acc-rgb), 0.55));
}
#territorios .concept-tag { top: 38px; right: 7px; bottom: auto; z-index: 6; writing-mode: vertical-rl; font-size: 10px; letter-spacing: 0.12em; line-height: 1; padding: 7px 4px; border-radius: 4px; color: rgba(230, 247, 255, 0.78); background: rgba(3, 11, 28, 0.62); -webkit-backdrop-filter: none; backdrop-filter: none; white-space: nowrap; }
#territorios .tr-copy { position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; padding: 0 30px clamp(16px, 1.6vw, 24px) clamp(14px, 1.5vw, 24px); container-type: inline-size; }
#territorios .tr-copy::before { content: ''; display: block; width: 30px; height: 2px; margin-bottom: 12px; background: var(--acc); box-shadow: 0 0 12px var(--acc); }
#territorios .tr-idx { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#territorios .tr-name {
  margin: 0; font-family: var(--font-display); font-style: italic; font-weight: 850; font-stretch: 112%;
  font-size: clamp(15px, 1.2vw, 21px); font-size: clamp(13px, 8.1cqi, 21px); line-height: 1.06; letter-spacing: -0.005em; text-transform: uppercase;
  text-wrap: balance; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6);
}
#territorios .tr-desc { margin: 8px 0 0; font-size: clamp(14px, 0.98vw, 15.5px); line-height: 1.42; color: #c9d6ea; text-wrap: pretty; }

/* Verso */
#territorios .tr-back {
  transform: rotateY(180deg);
  display: grid; place-content: center; justify-items: center; gap: 8px;
  background:
    radial-gradient(90% 60% at 50% 38%, rgba(18, 197, 181, 0.28), transparent 70%),
    linear-gradient(160deg, #0f3b62 0%, var(--navy-900) 48%, var(--navy-950) 100%);
  box-shadow: 0 34px 70px -34px rgba(0, 0, 0, 0.85);
}
#territorios .tr-back::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; mix-blend-mode: screen; opacity: 0.35;
  background: conic-gradient(from 210deg at 50% 40%, rgba(79, 240, 220, 0), rgba(79, 240, 220, 0.45), rgba(111, 211, 255, 0.3), rgba(150, 120, 255, 0.25), rgba(79, 240, 220, 0));
}
#territorios .tr-back__grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(45deg, rgba(79, 240, 220, 0.08) 0 1px, transparent 1px 16px), repeating-linear-gradient(-45deg, rgba(79, 240, 220, 0.08) 0 1px, transparent 1px 16px);
  -webkit-mask-image: radial-gradient(70% 60% at 50% 45%, #000 20%, transparent 85%); mask-image: radial-gradient(70% 60% at 50% 45%, #000 20%, transparent 85%);
}
#territorios .tr-back__mark { position: relative; width: 34%; aspect-ratio: 1; height: auto; overflow: visible; filter: drop-shadow(0 0 16px rgba(18, 197, 181, 0.6)); }
#territorios .tr-back__k { position: relative; margin-top: 10px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.34em; text-transform: uppercase; color: var(--ink-2); }
#territorios .tr-back__n { position: relative; font-family: var(--font-display); font-style: italic; font-weight: 850; font-stretch: 120%; font-size: clamp(34px, 3.4vw, 60px); line-height: 0.9; background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: 0.06em; }
#territorios .tr-back__foot { position: absolute; left: 0; right: 0; bottom: 16px; text-align: center; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-3); }

/* Clarão de encaixe na posição */
#territorios .tr-flash {
  position: absolute; inset: -7px; border-radius: calc(var(--tr-radius) + 6px); pointer-events: none; opacity: 0;
  border: 1px solid rgba(var(--acc-rgb), 0.9);
  box-shadow: 0 0 34px rgba(var(--acc-rgb), 0.55), inset 0 0 34px rgba(var(--acc-rgb), 0.25);
}

/* ---------- Emissor holográfico (só no modo com pin) ---------- */
#territorios .tr-portal { display: none; }
#territorios.tr-pinned .tr-portal { display: block; position: absolute; left: 12%; right: 12%; top: -4%; bottom: -2%; z-index: 0; pointer-events: none; perspective: 700px; opacity: 0; }
#territorios .tr-portal__beam {
  position: absolute; left: 6%; right: 6%; top: 10%; height: 64%;
  background: linear-gradient(0deg, rgba(79, 240, 220, 0.34) 0%, rgba(29, 159, 208, 0.12) 55%, rgba(29, 159, 208, 0) 100%);
  clip-path: polygon(0 0, 100% 0, 64% 100%, 36% 100%);
  filter: blur(6px);
}
#territorios .tr-portal__disc { position: absolute; left: 50%; top: 76%; width: 48%; aspect-ratio: 1; margin-left: -24%; transform: translateY(-50%) rotateX(76deg); transform-style: preserve-3d; }
#territorios .tr-portal__disc i { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(79, 240, 220, 0.7); box-shadow: 0 0 40px rgba(18, 197, 181, 0.55), inset 0 0 40px rgba(18, 197, 181, 0.35); }
#territorios .tr-portal__disc i:nth-child(2) { inset: 12%; border: 2px dashed rgba(111, 211, 255, 0.75); box-shadow: none; animation: tr-spin 9s linear infinite; }
#territorios .tr-portal__disc i:nth-child(3) { inset: 28%; border: 1px solid rgba(79, 240, 220, 0.5); background: radial-gradient(circle, rgba(79, 240, 220, 0.55), rgba(18, 197, 181, 0.1) 60%, transparent 70%); box-shadow: none; }
/* Varredura que atravessa o baralho */
#territorios .tr-scanfx { display: none; }
#territorios.tr-pinned .tr-scanfx {
  display: block; position: absolute; z-index: 3; left: 31%; right: 31%; top: 25%; height: 50%; overflow: hidden; pointer-events: none; opacity: 0;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent); mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent);
  mix-blend-mode: screen;
}
#territorios .tr-scanfx i { position: absolute; left: 0; right: 0; top: 0; height: 100%; transform: translateY(-100%); animation: tr-scan 2.2s linear infinite;
  background: linear-gradient(180deg, rgba(79, 240, 220, 0) 0%, rgba(79, 240, 220, 0) 86%, rgba(79, 240, 220, 0.2) 98.4%, rgba(170, 255, 245, 0.95) 99.7%, rgba(79, 240, 220, 0) 100%); }
#territorios .tr-portal__lbl { position: absolute; left: 0; right: 0; top: 88%; margin: 0; text-align: center; font-size: 11px; color: var(--teal-hi); letter-spacing: 0.28em; text-shadow: 0 0 12px rgba(18, 197, 181, 0.7); }
@keyframes tr-spin { to { transform: rotate(360deg); } }
@keyframes tr-scan { 0% { transform: translateY(-100%); opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { transform: translateY(0); opacity: 0; } }

/* ---------- Carrossel (celular) ---------- */
#territorios .tr-nav { display: none; }

/* ---------- Palco com pin: cabeçalho à esquerda, cartas 4:5 em 3×2 à direita ---------- */
@media (min-width: 1180px) and (min-height: 620px) {
  #territorios .tr-pin { padding-block: 0; }
  #territorios .tr-stage {
    --tr-py-t: calc(var(--hud-h) + clamp(10px, 2.4vh, 28px));
    --tr-py-b: clamp(18px, 3.6vh, 40px);
    --tr-rowh: calc((100svh - var(--tr-py-t) - var(--tr-py-b) - var(--tr-gap)) / 2);
    --tr-content: calc(min(100vw, var(--maxw)) - 2 * var(--gutter));
    /* largura da grade: cartas 4:5 pela altura, nunca menores que 240px, e no máximo 68% do palco */
    --tr-gw: min(calc(var(--tr-content) * 0.68), calc(max(var(--tr-rowh) * 0.8, 256px) * 3 + var(--tr-gap) * 2));
    min-height: 100vh; min-height: 100svh;
    display: grid; align-items: center;
    grid-template-columns: minmax(0, 1fr) var(--tr-gw);
    column-gap: clamp(32px, 3.6vw, 72px);
    padding-top: var(--tr-py-t); padding-bottom: var(--tr-py-b);
  }
  #territorios .tr-h2 { font-size: clamp(28px, min(2.75vw, 5vh), 50px); line-height: 1.04; max-width: 15ch; }
  #territorios .tr-board { margin-top: 0; }
  #territorios .tr-slot { aspect-ratio: auto; height: min(var(--tr-rowh), calc((var(--tr-gw) - 2 * var(--tr-gap)) / 3 * 1.25)); }
  /* leitura no projetor: descrição a 16px e nome nunca abaixo de 16px; sombra mais alta para o texto maior */
  #territorios .tr-name { font-size: clamp(16px, 8.1cqi, 21px); }
  #territorios .tr-desc { font-size: 16px; line-height: 1.34; }
  #territorios .tr-shade { background: linear-gradient(0deg, rgba(2, 8, 22, 0.97) 0%, rgba(2, 8, 22, 0.9) 32%, rgba(2, 8, 22, 0.5) 54%, rgba(2, 8, 22, 0) 70%), linear-gradient(180deg, rgba(2, 8, 22, 0.55) 0%, rgba(2, 8, 22, 0) 22%); }
  #territorios .tr-ring { display: block; position: relative; width: clamp(140px, min(14vw, 24vh), 236px); aspect-ratio: 1; margin-top: clamp(22px, 4.4vh, 52px); }
  #territorios .tr-status { display: flex; align-items: center; gap: 10px; margin: clamp(14px, 2.4vh, 26px) 0 0; font-size: 11px; color: var(--ink-2); }
}
#territorios .tr-ring svg { width: 100%; height: 100%; overflow: visible; }
#territorios .tr-ring__track { fill: none; stroke: var(--line-2); stroke-width: 1; }
#territorios .tr-ring__dash { fill: none; stroke: rgba(79, 240, 220, 0.4); stroke-width: 1; stroke-dasharray: 2 6; transform-origin: 120px 120px; animation: tr-spin 48s linear infinite; }
#territorios .tr-ring__inner { fill: rgba(5, 20, 46, 0.55); stroke: var(--line); }
#territorios .tr-seg { fill: none; stroke: var(--teal-hi); stroke-width: 4; stroke-linecap: round; filter: drop-shadow(0 0 5px rgba(18, 197, 181, 0.9)); }
#territorios .tr-seg:nth-child(even) { stroke: var(--cyan-hi); filter: drop-shadow(0 0 5px rgba(29, 159, 208, 0.9)); }
#territorios .tr-node { fill: var(--teal-hi); stroke: var(--navy-950); stroke-width: 2; }
#territorios .tr-node:nth-child(even) { fill: var(--cyan-hi); }
#territorios .tr-labels text { font-family: var(--font-mono); font-size: 15px; letter-spacing: 0.08em; fill: var(--ink-2); text-anchor: middle; }
#territorios .tr-orbit { transform-origin: 120px 120px; animation: tr-spin 7s linear infinite; }
#territorios .tr-orbit circle { fill: #fff; filter: drop-shadow(0 0 6px var(--teal-hi)); }
#territorios .tr-ring__c { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; gap: 4px; }
#territorios .tr-count { font-family: var(--font-display); font-style: italic; font-weight: 850; font-stretch: 118%; font-size: clamp(32px, min(3.2vw, 5.4vh), 54px); line-height: 0.9; font-variant-numeric: tabular-nums; background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: 0.06em; }
#territorios .tr-ring__c span { font-family: var(--font-mono); font-size: 10px; line-height: 1.35; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-3); }
#territorios .tr-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--teal-hi); box-shadow: 0 0 10px var(--teal-hi); animation: tr-blink 1.6s steps(2) infinite; }
@keyframes tr-blink { 50% { opacity: 0.25; } }
/* Jornada completa: a sexta carta assenta, o anel dispara uma onda e o contador pulsa */
#territorios .tr-ring::after { content: ''; position: absolute; inset: 16%; border-radius: 50%; border: 1.5px solid var(--teal-hi); box-shadow: 0 0 24px rgba(79, 240, 220, 0.6), inset 0 0 18px rgba(79, 240, 220, 0.35); opacity: 0; pointer-events: none; }
#territorios.tr-complete .tr-ring::after { animation: tr-wave 1.3s var(--ease-out) both; }
#territorios.tr-complete .tr-count { animation: tr-pop 0.8s var(--ease-out) both; }
#territorios.tr-complete .tr-status { color: var(--teal-hi); transition: color 0.5s; }
@keyframes tr-wave { 0% { opacity: 0.95; transform: scale(0.72); } 100% { opacity: 0; transform: scale(1.6); } }
@keyframes tr-pop { 0% { transform: scale(1.4); filter: brightness(1.9) drop-shadow(0 0 14px rgba(79, 240, 220, 0.9)); } 100% { transform: none; filter: none; } }

#territorios.tr-pinned .tr-pin { height: 100vh; height: 100svh; overflow: hidden; }

/* ---------- Tablet / telas baixas: grade em fluxo ---------- */
@media (min-width: 821px) and (max-width: 1179.98px) {
  #territorios .tr-grid { gap: 14px; }
  #territorios .tr-name { font-size: clamp(15px, 1.9vw, 20px); }
}

/* ---------- Celular: carrossel com scroll-snap ---------- */
@media (max-width: 820px) {
  #territorios .tr-pin { padding-block: clamp(84px, 12vh, 120px) clamp(56px, 9vh, 96px); }
  #territorios .tr-h2 { max-width: 16ch; }
  #territorios .tr-board { margin-top: 28px; }
  #territorios .tr-scroller {
    margin-inline: calc(var(--gutter) * -1); padding: 10px var(--gutter) 18px;
    overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-padding-inline: var(--gutter);
    overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  #territorios .tr-scroller::-webkit-scrollbar { display: none; }
  #territorios .tr-grid { display: flex; gap: 14px; width: max-content; perspective: none; transform-style: flat; }
  #territorios .tr-slot { flex: 0 0 min(78vw, 330px); scroll-snap-align: start; perspective: 1100px; transform-style: flat; }
  #territorios .tr-name { font-size: 19px; }
  #territorios .tr-desc { font-size: 15px; }
  #territorios .tr-num { font-size: 42px; }
  #territorios .tr-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 8px; }
  #territorios .tr-nav__btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-2); background: rgba(5, 20, 46, 0.6); transition: border-color 0.3s, opacity 0.3s; }
  #territorios .tr-nav__btn:disabled { opacity: 0.35; cursor: default; }
  #territorios .tr-nav__btn svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  #territorios .tr-nav__pos { margin: 0; min-width: 64px; text-align: center; font-size: 12px; color: var(--ink-3); }
  #territorios .tr-nav__pos b { color: var(--teal-hi); font-weight: 700; }
  .no-js #territorios .tr-nav { display: none; }
}

/* Loops decorativos só rodam com o capítulo na tela */
#territorios:not(.tr-inview) .tr-front::before, #territorios:not(.tr-inview) .tr-ring__dash, #territorios:not(.tr-inview) .tr-orbit,
#territorios:not(.tr-inview) .tr-portal__disc i, #territorios:not(.tr-inview) .tr-scanfx i, #territorios:not(.tr-inview) .tr-status i { animation-play-state: paused; }

/* ---------- Movimento reduzido ---------- */
.reduced #territorios .tr-front::before, .reduced #territorios .tr-portal { display: none; }
.reduced #territorios .tr-card, .reduced #territorios .tr-tilt { transform: none !important; }
.reduced #territorios .tr-ring__dash, .reduced #territorios .tr-orbit, .reduced #territorios .tr-status i { animation: none; }
