/* Motion layer for the BTB IT website: page transitions, scroll reveals, hover effects, the hero link animation,
   the screenshot lightbox and the link rules demo. Everything is self-hosted. With "reduce motion" turned on in the
   operating system, the page shows the final state without animation. */

/* Page transitions between pages (View Transitions API; browsers without it just load the page). */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: vt-out 0.22s ease-in both;
}

::view-transition-new(root) {
  animation: vt-in 0.32s ease-out both;
}

.site-header {
  view-transition-name: site-header;
}

@keyframes vt-out {
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@keyframes vt-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

/* Sticky header that gains a shadow once the page scrolls. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}

.site-header.is-scrolled {
  box-shadow: 0 6px 24px rgba(11, 16, 32, 0.18);
}

.site-nav a {
  position: relative;
  transition: color 0.2s ease;
}

.site-nav a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 3px;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}

.site-nav a:hover {
  border-bottom-color: transparent;
}

.site-nav a:hover::after,
.site-nav a[aria-current="page"]::after {
  transform: scaleX(1);
}

.site-nav a[aria-current="page"] {
  border-bottom-color: transparent;
}

/* Buttons and cards react to the pointer. */
.btn {
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(11, 16, 32, 0.25);
}

.btn .arrow {
  display: inline-block;
  margin-left: 8px;
  transition: transform 0.2s ease;
}

.btn:hover .arrow {
  transform: translateX(4px);
}

.card {
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--gold);
  box-shadow: 0 14px 32px rgba(11, 16, 32, 0.16);
}

/* Scroll reveal: only when the script runs (the html element gets the "js" class), so content never stays hidden. */
.js .reveal {
  opacity: 0;
  transform: translateY(26px);
  transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
  transition-delay: var(--d, 0ms);
}

.js .reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* Hero with the link animation. */
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
  align-items: center;
}

@media (min-width: 900px) {
  .hero-grid {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  }
}

.hero h1 .word {
  display: inline-block;
}

.js .hero h1 .word {
  opacity: 0;
  transform: translateY(0.5em);
  animation: word-in 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  animation-delay: calc(var(--i) * 70ms + 150ms);
}

@keyframes word-in {
  to {
    opacity: 1;
    transform: none;
  }
}

.js .hero .lead,
.js .hero .actions,
.js .hero .eyebrow {
  opacity: 0;
  animation: fade-up 0.7s ease forwards;
}

.js .hero .eyebrow {
  animation-delay: 0.05s;
}

.js .hero .lead {
  animation-delay: 0.65s;
}

.js .hero .actions {
  animation-delay: 0.85s;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.link-graph {
  width: 100%;
  max-width: 520px;
  height: auto;
  margin: 0 auto;
  display: block;
}

.link-graph .node rect {
  fill: #24305a;
  stroke: #3a4777;
  stroke-width: 1.5;
}

.link-graph .node .key {
  fill: var(--gold);
  font: 700 12px system-ui, sans-serif;
  letter-spacing: 0.04em;
}

.link-graph .node .name {
  fill: #ffffff;
  font: 600 13px system-ui, sans-serif;
}

.link-graph .edge {
  fill: none;
  stroke: var(--gold);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.link-graph .edge-blocked {
  stroke: #ff7a7a;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.link-graph .badge circle {
  fill: var(--gold);
}

.link-graph .badge path {
  fill: none;
  stroke: #1b2440;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.link-graph .badge-blocked circle {
  fill: #ff7a7a;
}

.link-graph .badge,
.link-graph .badge-blocked,
.link-graph .rule-note {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.link-graph .rule-note rect {
  fill: #0b1020;
  stroke: #ff7a7a;
  stroke-width: 1.2;
}

.link-graph .rule-note text {
  fill: #ffd0d0;
  font: 600 12px system-ui, sans-serif;
}

.js .link-graph .node {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.link-graph.is-playing .node {
  animation: node-in 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  animation-delay: calc(var(--i) * 120ms);
}

/* After the first run the cards stay put; only the links replay. */
.js .link-graph.has-played .node {
  opacity: 1;
  animation: none;
}

.link-graph.is-playing .edge {
  animation: draw 0.7s ease-out forwards, fade-out 0.5s ease-in forwards;
  animation-delay: var(--t), 8.3s;
}

.link-graph.is-playing .badge {
  animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) forwards, fade-out 0.5s ease-in forwards;
  animation-delay: calc(var(--t) + 0.6s), 8.3s;
}

.link-graph.is-playing .edge-blocked {
  animation: draw-half 0.8s ease-out forwards, fade-out 0.6s ease-in 3.4s forwards;
  animation-delay: var(--t), calc(var(--t) + 3.9s);
}

.link-graph.is-playing .badge-blocked {
  animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) forwards, fade-out 0.6s ease-in forwards;
  animation-delay: calc(var(--t) + 0.75s), calc(var(--t) + 3.9s);
}

.link-graph.is-playing .rule-note {
  animation: fade-up-svg 0.4s ease-out forwards, fade-out 0.6s ease-in forwards;
  animation-delay: calc(var(--t) + 0.95s), calc(var(--t) + 3.9s);
}

@keyframes node-in {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes draw-half {
  to {
    stroke-dashoffset: 0.45;
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fade-up-svg {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade-out {
  to {
    opacity: 0;
  }
}

/* Screenshot lightbox. */
.shot button.zoom {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  border-radius: 12px;
  overflow: hidden;
}

.shot button.zoom img {
  transition: transform 0.4s ease;
}

.shot button.zoom:hover img {
  transform: scale(1.04);
}

dialog.lightbox {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(1200px, 94vw);
  width: 100%;
}

dialog.lightbox::backdrop {
  background: rgba(8, 12, 24, 0.82);
  backdrop-filter: blur(4px);
}

dialog.lightbox[open] {
  animation: zoom-in 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}

dialog.lightbox img {
  border-radius: 12px;
  width: 100%;
}

dialog.lightbox p {
  color: #ffffff;
  margin: 12px 0 0;
}

dialog.lightbox .close {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: 0;
  background: var(--gold);
  color: var(--navy);
  font-weight: 800;
  font-size: 1.2rem;
  cursor: pointer;
}

@keyframes zoom-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}

/* Link rules demo. */
.demo {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

@media (min-width: 820px) {
  .demo {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.demo fieldset {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px 18px;
  margin: 0 0 16px;
}

.demo legend {
  font-weight: 700;
  padding: 0 6px;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice {
  position: relative;
}

.choice input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.choice span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--border);
  font-weight: 600;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.choice input:checked + span {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--navy);
}

.choice input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.choice:active span {
  transform: scale(0.96);
}

.verdict {
  border-radius: 16px;
  padding: 24px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  border: 2px solid var(--border);
  background: var(--card);
  transition: border-color 0.3s ease, background-color 0.3s ease;
}

.verdict.allowed {
  border-color: var(--gold);
}

.verdict.blocked {
  border-color: #e05252;
}

.verdict .icon {
  width: 56px;
  height: 56px;
}

.verdict .icon[hidden] {
  display: none;
}

.verdict.is-changing .icon,
.verdict.is-changing .verdict-text {
  animation: verdict-in 0.45s cubic-bezier(0.3, 1.4, 0.5, 1);
}

@keyframes verdict-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.92);
  }
}

.verdict-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0;
}

.verdict-text {
  margin: 0;
  color: var(--muted);
}

.rule-table {
  font-size: 0.95rem;
}

.rule-table tr {
  transition: background-color 0.3s ease;
}

.rule-table tr.is-active {
  background: color-mix(in srgb, var(--gold) 22%, transparent);
}

/* Hero graph played once (visitors with "reduce motion" turned on): no fade-out at the end, so the graph stops on its
   final picture - the allowed links in gold and the blocked bug-to-epic link with its note. */
.link-graph.is-playing.play-once .edge {
  animation: draw 0.7s ease-out forwards;
  animation-delay: var(--t);
}

.link-graph.is-playing.play-once .badge {
  animation: fade-in 0.45s ease-out forwards;
  animation-delay: calc(var(--t) + 0.6s);
}

.link-graph.is-playing.play-once .edge-blocked {
  animation: draw-half 0.8s ease-out forwards;
  animation-delay: var(--t);
}

.link-graph.is-playing.play-once .badge-blocked,
.link-graph.is-playing.play-once .rule-note {
  animation: fade-in 0.45s ease-out forwards;
  animation-delay: calc(var(--t) + 0.8s);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Pause button for the looping graph (WCAG 2.2.2: moving content that repeats must be possible to pause). */
.graph-wrap {
  position: relative;
}

.graph-toggle {
  position: absolute;
  right: 0;
  bottom: -6px;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(11, 16, 32, 0.6);
  color: #ffffff;
  font: 600 0.85rem system-ui, sans-serif;
  cursor: pointer;
}

.graph-toggle:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.link-graph.is-paused,
.link-graph.is-paused * {
  animation-play-state: paused !important;
}

/* "Reduce motion" in the operating system: the page still comes alive, but without movement - elements fade in
   instead of sliding, nothing lifts on hover, page transitions only cross-fade, and the hero graph plays once
   (script: play-once) instead of looping. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-name: fade-in;
  }

  ::view-transition-old(root) {
    animation-direction: reverse;
  }

  .js .reveal,
  .js .reveal.is-visible {
    transform: none;
  }

  .js .hero h1 .word,
  .js .hero .lead,
  .js .hero .actions,
  .js .hero .eyebrow,
  .js .link-graph .node {
    transform: none;
    animation-name: fade-in;
  }

  .link-graph.is-playing .node {
    animation-name: fade-in;
  }

  .btn:hover,
  .card:hover,
  .shot button.zoom:hover img,
  .choice:active span {
    transform: none;
  }

  dialog.lightbox[open] {
    animation-name: fade-in;
  }

  .verdict.is-changing .icon,
  .verdict.is-changing .verdict-text {
    animation-name: fade-in;
  }
}
