/*
 * Guia Prático da Reforma Tributária — visualizador CF.
 *
 * As cores saíram do logotipo da Contabilidade Facilitada: navy #102850 e
 * laranja #FF9933, amostrados do PNG oficial. A profundidade é literal — o
 * documento é papel branco elevado sobre a tinta navy do poço.
 */

:root {
  --abyss: #061426;
  --navy: #102850;
  --navy-lift: #1b3e6e;
  --orange: #ff9933;
  --paper: #f4f7fb;
  --mist: #a3b9d4;
  --mist-dim: #6d86a6;

  --bar-h: 4rem;
  --dock-h: 3.25rem;
  --gutter: clamp(0.75rem, 3vw, 2.5rem);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --fast: 150ms;
  --base: 260ms;
  --slow: 520ms;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--abyss);
  color: var(--mist);
  font-family: "Archivo", ui-sans-serif, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* O poço. A luz vem de cima, como numa mesa de leitura. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 70% at 50% -14%, rgba(27, 62, 110, 0.6) 0%, transparent 70%),
    linear-gradient(180deg, var(--navy) 0%, var(--abyss) 46%);
}

svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.skip {
  position: fixed;
  top: 0.5rem;
  left: 50%;
  translate: -50% -180%;
  z-index: 60;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: var(--orange);
  color: var(--navy);
  font-weight: 600;
  text-decoration: none;
  transition: translate var(--fast) var(--ease);
}

.skip:focus {
  translate: -50% 0;
}

:where(button, a, [tabindex]):focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

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

.bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 2vw, 1.5rem);
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--gutter) 0;
  background: rgba(9, 25, 48, 0.72);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}

/* A hairline de marca: a única concessão decorativa da interface. */
.bar::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 153, 51, 0.5) 22%,
    rgba(255, 153, 51, 0.5) 78%,
    transparent
  );
}

.bar__brand {
  flex: none;
  display: block;
  line-height: 0;
}

.bar__brand img {
  height: 1.5rem;
  width: auto;
}

.bar__title {
  flex: 1 1 auto;
  min-width: 0;
}

.eyebrow {
  margin: 0;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orange);
}

.bar__title h1 {
  margin: 0;
  font-size: clamp(0.9375rem, 2.2vw, 1.125rem);
  font-weight: 700;
  font-variation-settings: "wdth" 112;
  letter-spacing: -0.012em;
  color: #eef4fb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid rgba(163, 185, 212, 0.22);
  border-radius: 0.625rem;
  background: rgba(255, 255, 255, 0.03);
  color: #dce7f4;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--fast) var(--ease),
    border-color var(--fast) var(--ease),
    transform var(--fast) var(--ease),
    color var(--fast) var(--ease);
}

.ghost:hover {
  background: rgba(255, 153, 51, 0.14);
  border-color: rgba(255, 153, 51, 0.55);
  color: #fff;
  transform: translateY(-1px);
}

.ghost:active {
  transform: translateY(0);
}

/* O botão de ajuste mostra o enquadramento que vai APLICAR, não o atual. */
#fit[aria-pressed="true"] .ic-p,
#fit[aria-pressed="false"] .ic-w {
  display: none;
}

.ghost[aria-pressed="true"] {
  background: rgba(255, 153, 51, 0.18);
  border-color: rgba(255, 153, 51, 0.6);
  color: #fff;
}

/* ------------------------------------------------------------------ palco */

.stage {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow: auto;
  padding-top: calc(var(--bar-h) + env(safe-area-inset-top) + var(--gutter));
  padding-bottom: calc(var(--dock-h) + var(--gutter) * 2 + env(safe-area-inset-bottom));
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
  scrollbar-width: thin;
  scrollbar-color: var(--navy-lift) transparent;
}

.stage::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.stage::-webkit-scrollbar-thumb {
  background: var(--navy-lift);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.reel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gutter);
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
  padding: 0 calc(var(--gutter) + 1.5rem) 0 var(--gutter);
}

/*
 * A folha existe antes do pixel: reserva o espaço pela proporção real da
 * página, então o scroll nunca salta quando o canvas chega.
 */
.sheet {
  position: relative;
  flex: none;
  width: var(--w);
  aspect-ratio: var(--ratio);
  background: var(--paper);
  border-radius: 3px;
  overflow: hidden;
  scroll-margin-top: calc(var(--bar-h) + env(safe-area-inset-top) + var(--gutter));
  scroll-margin-bottom: calc(var(--dock-h) + var(--gutter) * 2 + env(safe-area-inset-bottom));
  box-shadow:
    0 1px 2px rgba(2, 9, 20, 0.6),
    0 2px 6px rgba(2, 9, 20, 0.45),
    0 22px 50px -14px rgba(2, 9, 20, 0.85);
}

.sheet canvas {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity var(--base) var(--ease);
}

.sheet.is-ready canvas {
  opacity: 1;
}

/* Enquanto o pixel não chega, a folha mostra o próprio número. */
.sheet::after {
  content: attr(data-n);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 2rem;
  color: rgba(16, 40, 80, 0.16);
  transition: opacity var(--base) var(--ease);
}

.sheet.is-ready::after {
  opacity: 0;
}

.colofon {
  margin: calc(var(--gutter) * 1.5) auto 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--mist-dim);
}

.colofon a {
  color: var(--orange);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* ------------------------------------------------------------------ régua */
/*
 * A assinatura da página: o corte lateral do documento. Sessenta traços, um
 * por ilustração; o traço da vez acende e se estende. Cada um sabe a que
 * página do guia impresso pertence.
 */

.rail {
  position: fixed;
  z-index: 25;
  right: max(0.375rem, env(safe-area-inset-right));
  top: calc(var(--bar-h) + env(safe-area-inset-top) + 1.25rem);
  bottom: calc(var(--dock-h) + env(safe-area-inset-bottom) + 2.5rem);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.375rem 0.25rem;
}

.tick {
  position: relative;
  display: block;
  flex: 1 1 auto;
  width: 1.25rem;
  min-height: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  animation: tick-in var(--base) var(--ease) both;
}

.tick::before {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  translate: 0 -50%;
  width: 0.5rem;
  height: 2px;
  border-radius: 1px;
  background: rgba(163, 185, 212, 0.5);
  transition:
    width var(--base) var(--ease),
    background var(--base) var(--ease);
}

.tick:hover::before {
  width: 1.25rem;
  background: var(--mist);
}

.tick[aria-current="page"]::before {
  width: 1.25rem;
  background: var(--orange);
  box-shadow: 0 0 12px rgba(255, 153, 51, 0.55);
}

.tick__say {
  position: absolute;
  right: 1.75rem;
  top: 50%;
  translate: 0 -50%;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid rgba(255, 153, 51, 0.35);
  background: var(--navy);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.6875rem;
  color: #eef4fb;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--fast) var(--ease);
}

.tick:hover .tick__say,
.tick:focus-visible .tick__say {
  opacity: 1;
}

@keyframes tick-in {
  from {
    opacity: 0;
    translate: 8px 0;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

/* ------------------------------------------------------------------- dock */

.dock {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(var(--gutter) * 0.75 + env(safe-area-inset-bottom));
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 0.125rem;
  height: var(--dock-h);
  padding: 0 0.5rem;
  border: 1px solid rgba(163, 185, 212, 0.2);
  border-radius: 999px;
  background: rgba(9, 25, 48, 0.82);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  box-shadow: 0 12px 32px -8px rgba(2, 9, 20, 0.9);
}

.step {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #dce7f4;
  cursor: pointer;
  transition:
    background var(--fast) var(--ease),
    color var(--fast) var(--ease);
}

.step:hover {
  background: rgba(255, 153, 51, 0.16);
  color: #fff;
}

.step:disabled {
  opacity: 0.3;
  cursor: default;
  background: transparent;
}

.dock__count {
  display: flex;
  align-items: baseline;
  gap: 0.3125rem;
  margin: 0;
  padding: 0 0.375rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  white-space: nowrap;
}

.dock__now {
  font-size: 1rem;
  font-weight: 600;
  color: var(--orange);
  font-variant-numeric: tabular-nums;
}

.dock__of {
  font-size: 0.75rem;
  color: var(--mist-dim);
}

.dock__book {
  padding-left: 0.375rem;
  border-left: 1px solid rgba(163, 185, 212, 0.2);
  font-family: "Archivo", sans-serif;
  font-size: 0.6875rem;
  color: var(--mist-dim);
}

.dock__rule {
  width: 1px;
  height: 1.5rem;
  margin: 0 0.375rem;
  background: rgba(163, 185, 212, 0.2);
}

.dock__zoom {
  min-width: 3rem;
  height: 2.25rem;
  padding: 0 0.375rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--mist);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition:
    background var(--fast) var(--ease),
    color var(--fast) var(--ease);
}

.dock__zoom:hover {
  background: rgba(255, 153, 51, 0.16);
  color: #fff;
}

.hint {
  position: fixed;
  z-index: 28;
  left: 50%;
  bottom: calc(var(--dock-h) + var(--gutter) + env(safe-area-inset-bottom) + 0.5rem);
  translate: -50% 0;
  margin: 0;
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 153, 51, 0.25);
  background: rgba(9, 25, 48, 0.92);
  font-size: 0.6875rem;
  white-space: nowrap;
  color: var(--mist);
  animation: rise var(--slow) var(--ease) both;
}

/* -------------------------------------------------------------------- véu */

.veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.875rem;
  background-color: var(--abyss);
  background-image: linear-gradient(180deg, var(--navy) 0%, var(--abyss) 60%);
  transition: opacity var(--slow) var(--ease);
}

.veil.is-gone {
  opacity: 0;
  pointer-events: none;
}

/* Deu errado: o medidor não tem mais o que medir e o selo para de respirar. */
.veil.is-broken .veil__meter,
.veil.is-broken .veil__pct {
  display: none;
}

.veil.is-broken .veil__seal::after {
  animation: none;
  opacity: 0.35;
}

.veil__seal {
  position: relative;
}

.veil__seal img {
  display: block;
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 1rem;
  box-shadow:
    0 18px 40px -12px rgba(2, 9, 20, 0.9),
    0 0 0 1px rgba(255, 153, 51, 0.25);
}

/* O anel respira enquanto o arquivo desce. */
.veil__seal::after {
  content: "";
  position: absolute;
  inset: -0.5rem;
  border-radius: 1.5rem;
  border: 1px solid rgba(255, 153, 51, 0.3);
  animation: breathe 2.4s ease-in-out infinite;
}

.veil__say {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  font-variation-settings: "wdth" 108;
  color: #eef4fb;
}

.veil__meter {
  width: min(15rem, 60vw);
  height: 2px;
  border-radius: 2px;
  background: rgba(163, 185, 212, 0.18);
  overflow: hidden;
}

.veil__meter i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--orange);
  box-shadow: 0 0 10px rgba(255, 153, 51, 0.7);
  transition: width 200ms linear;
}

.veil__pct {
  margin: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--mist-dim);
  font-variant-numeric: tabular-nums;
}

.veil__out {
  max-width: 20rem;
  text-align: center;
}

.veil__out p {
  margin: 0 0 0.875rem;
  font-size: 0.8125rem;
  color: var(--mist);
}

.veil__out button {
  height: 2.5rem;
  padding: 0 1.25rem;
  border: 0;
  border-radius: 0.625rem;
  background: var(--orange);
  color: var(--navy);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}

.veil__out button:hover {
  background: #ffad5c;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.35;
    scale: 1;
  }
  50% {
    opacity: 1;
    scale: 1.04;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    translate: -50% 12px;
  }
  to {
    opacity: 1;
    translate: -50% 0;
  }
}

/* A entrada: as duas primeiras folhas assentam. Uma vez, na abertura. */
.reel.is-arriving .sheet:nth-child(1) {
  animation: settle var(--slow) var(--ease) both;
}

.reel.is-arriving .sheet:nth-child(2) {
  animation: settle var(--slow) var(--ease) 60ms both;
}

@keyframes settle {
  from {
    opacity: 0;
    translate: 0 18px;
    scale: 0.985;
  }
  to {
    opacity: 1;
    translate: 0 0;
    scale: 1;
  }
}

/* --------------------------------------------------------------- estreito */

@media (max-width: 640px) {
  :root {
    --bar-h: 3.5rem;
  }

  .bar__title {
    display: none;
  }

  .bar__brand {
    flex: 1 1 auto;
  }

  .ghost {
    padding: 0 0.625rem;
  }

  .ghost .lbl {
    display: none;
  }

  .dock__book {
    display: none;
  }

  .tick {
    width: 0.875rem;
  }

  .tick::before {
    width: 0.375rem;
  }

  .tick:hover::before,
  .tick[aria-current="page"]::before {
    width: 0.875rem;
  }
}

@media (max-height: 460px) {
  :root {
    --bar-h: 2.75rem;
    --dock-h: 2.5rem;
    --gutter: 0.5rem;
  }

  .rail {
    display: none;
  }

  .bar__brand img {
    height: 1.125rem;
  }

  .ghost,
  .step {
    height: 2rem;
  }

  .step {
    width: 2rem;
  }

  .hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }

  .stage {
    scroll-behavior: auto;
  }
}
