/* ============================================================
   CALEXFIN — 3D MOTION & CORPORATE ARCHITECTURE ENGINE
   ============================================================ */

/* 1. Perspective Viewports */
.perspective-viewport {
  perspective: var(--perspective);
  perspective-origin: center center;
  transform-style: preserve-3d;
}

.perspective-deep {
  perspective: var(--perspective-deep);
}

.preserve-3d {
  transform-style: preserve-3d;
}

/* 2. 3D Interactive Tilt Cards (Max 3deg - 5deg rotation) */
.tilt-card-3d {
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--duration-fast) var(--ease-corporate), 
              box-shadow var(--duration-normal) var(--ease-corporate),
              border-color var(--duration-fast) ease;
  will-change: transform;
}

/* Subtle corporate blue-tinted specular highlight layer */
.tilt-card-3d::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
    circle 320px at var(--mouse-x-px, 50%) var(--mouse-y-px, 50%),
    rgba(29, 78, 216, 0.06),
    transparent 70%
  );
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast) ease;
}

.tilt-card-3d:hover::after {
  opacity: 1;
}

.tilt-card-3d.tilting {
  transform: perspective(var(--perspective)) 
             rotateX(var(--tilt-x, 0deg)) 
             rotateY(var(--tilt-y, 0deg)) 
             translateZ(6px);
}

/* 3. Hover Depth States */
.btn-elevated {
  position: relative;
  transform: translate3d(0, 0, 0);
  transition: transform var(--duration-fast) var(--ease-corporate),
              box-shadow var(--duration-fast) var(--ease-corporate),
              background-color var(--duration-fast) ease;
}

.btn-elevated:hover {
  transform: translate3d(0, -2px, 4px);
  box-shadow: 0 8px 20px rgba(29, 78, 216, 0.28);
}

.btn-elevated:active {
  transform: translate3d(0, 0, 0);
}

.card-depth {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-md);
  transform: translate3d(0, 0, 0);
  transition: transform var(--duration-normal) var(--ease-corporate),
              box-shadow var(--duration-normal) var(--ease-corporate),
              border-color var(--duration-fast) ease;
}

.card-depth:hover {
  transform: translate3d(0, -4px, 8px);
  border-color: var(--calexfin-blue-border);
  box-shadow: var(--shadow-lg);
}

/* ============================================================
   4. APPROVED GENUINE MECHANICAL SPLIT-FLAP COUNTDOWN
   (Retained with mechanical precision & refined luxury styling)
   ============================================================ */
.flip-clock-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  perspective: 1000px;
}

.flip-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flip-card {
  position: relative;
  width: 82px;
  height: 90px;
  perspective: 500px;
  transform-style: preserve-3d;
  font-family: var(--font-mono);
  font-size: 2.75rem;
  font-weight: 800;
  line-height: 1;
  color: #FFFFFF;
  box-shadow: 0 12px 30px rgba(16, 36, 79, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  background: #0E1E42;
  user-select: none;
}

/* Top & Bottom static halves */
.card-half {
  position: absolute;
  left: 0;
  right: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(180deg, #1B356B 0%, #10244F 100%);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.card-half.top {
  top: 0;
  height: 50%;
  align-items: flex-end;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  border-bottom: 1px solid rgba(10, 22, 51, 0.9);
}

.card-half.top span {
  transform: translateY(50%);
}

.card-half.bottom {
  bottom: 0;
  height: 50%;
  align-items: flex-start;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(180deg, #10244F 0%, #0B1938 100%);
}

.card-half.bottom span {
  transform: translateY(-50%);
}

/* Mechanical divider crease and rivets */
.flip-card::before {
  content: '';
  position: absolute;
  top: calc(50% - 1px);
  left: 0;
  right: 0;
  height: 2px;
  background: #0A1633;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15), 0 -1px 0 rgba(0, 0, 0, 0.8);
  z-index: 10;
}

.flip-card::after {
  content: '';
  position: absolute;
  top: calc(50% - 3px);
  left: 4px;
  width: 6px;
  height: 6px;
  background: #334155;
  border-radius: 50%;
  box-shadow: calc(82px - 14px) 0 0 #334155;
  z-index: 11;
}

/* Dynamic Flap that animates downward in 3D perspective */
.flap {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.flap.top-flip {
  top: 0;
  align-items: flex-end;
  transform-origin: bottom center;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  background: linear-gradient(180deg, #224285 0%, #152D61 100%);
  z-index: 5;
  animation: flipTop 500ms var(--ease-corporate) forwards;
}

.flap.top-flip span {
  transform: translateY(50%);
}

.flap.bottom-flip {
  bottom: 0;
  align-items: flex-start;
  transform-origin: top center;
  transform: rotateX(90deg);
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  background: linear-gradient(180deg, #152D61 0%, #0D1D40 100%);
  z-index: 5;
  animation: flipBottom 500ms var(--ease-corporate) forwards;
}

.flap.bottom-flip span {
  transform: translateY(-50%);
}

@keyframes flipTop {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(-90deg); }
}

@keyframes flipBottom {
  0% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

.flip-label {
  margin-top: 10px;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--slate-600);
}

/* Hero Section white text label for countdown */
.hero-countdown-wrap .flip-label {
  color: #CBD5E1;
}

/* Responsive Split-Flap Countdown for Mobile (320px - 560px) */
@media (max-width: 560px) {
  .flip-clock-container {
    gap: clamp(5px, 1.8vw, 10px);
    width: 100%;
    max-width: 100%;
    justify-content: center;
  }
  .flip-card {
    width: clamp(54px, 15vw, 68px);
    height: clamp(62px, 17vw, 76px);
    font-size: clamp(1.75rem, 5.2vw, 2.2rem);
  }
  .flip-label {
    font-size: 0.62rem;
    margin-top: 5px;
    letter-spacing: 0.08em;
  }
}

@media (max-width: 360px) {
  .flip-clock-container {
    gap: 4px;
  }
  .flip-card {
    width: 50px;
    height: 58px;
    font-size: 1.55rem;
  }
  .flip-label {
    font-size: 0.55rem;
    letter-spacing: 0.05em;
  }
}

/* ============================================================
   5. FLOATING ARCHITECTURE (Spec Section 12)
   ============================================================ */
@keyframes slowFloatA {
  0%, 100% { transform: translate3d(0, 0px, 0); }
  50% { transform: translate3d(0, -6px, 0); }
}

@keyframes slowFloatB {
  0%, 100% { transform: translate3d(0, -5px, 0); }
  50% { transform: translate3d(0, 3px, 0); }
}

.float-slow-a {
  animation: slowFloatA 7s ease-in-out infinite;
  will-change: transform;
}

.float-slow-b {
  animation: slowFloatB 8.5s ease-in-out infinite;
  animation-delay: 1.5s;
  will-change: transform;
}

/* ============================================================
   6. LIGHT REFINED 3D LEGAL & ACCOUNTING ARCHITECTURE
   (White, silver, soft blue, CALEXFIN blue, light slate)
   ============================================================ */
.legal-stack-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 380px;
  perspective: 1400px;
  transform-style: preserve-3d;
  margin: 0 auto;
}

.legal-doc {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  padding: 30px;
  background: #FFFFFF;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  transform-style: preserve-3d;
  transition: transform var(--duration-normal) var(--ease-corporate),
              box-shadow var(--duration-normal) var(--ease-corporate);
  will-change: transform;
}

.legal-doc.doc-layer-1 {
  background: #F1F5F9;
  border-color: #CBD5E1;
  transform: perspective(1400px) rotateX(12deg) rotateY(-6deg) translate3d(-14px, -18px, -45px);
  filter: brightness(0.96);
}

.legal-doc.doc-layer-2 {
  background: #F8FAFC;
  border-color: var(--calexfin-blue-border);
  transform: perspective(1400px) rotateX(10deg) rotateY(-4deg) translate3d(-7px, -9px, -20px);
}

.legal-doc.doc-layer-3 {
  background: #FFFFFF;
  border: 1px solid var(--calexfin-blue-border);
  transform: perspective(1400px) rotateX(8deg) rotateY(-2deg) translate3d(0, 0, 10px);
  box-shadow: var(--shadow-elevated);
}

.legal-stack-container:hover .legal-doc.doc-layer-1 {
  transform: perspective(1400px) rotateX(7deg) rotateY(-4deg) translate3d(-28px, -28px, -60px);
}

.legal-stack-container:hover .legal-doc.doc-layer-2 {
  transform: perspective(1400px) rotateX(6deg) rotateY(-2deg) translate3d(-12px, -12px, 0px);
}

.legal-stack-container:hover .legal-doc.doc-layer-3 {
  transform: perspective(1400px) rotateX(4deg) rotateY(0deg) translate3d(12px, 16px, 60px);
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.16);
}

/* 2.5D Ledger Stack (Lighter Architecture) */
.ledger-stack-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 380px;
  perspective: 1400px;
  transform-style: preserve-3d;
  margin: 0 auto;
}

.ledger-card {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  padding: 24px;
  background: #FFFFFF;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-md);
  transform-style: preserve-3d;
  transition: transform var(--duration-normal) var(--ease-corporate),
              box-shadow var(--duration-normal) var(--ease-corporate);
}

.ledger-card.layer-1 {
  background: #F1F5F9;
  transform: perspective(1400px) rotateX(12deg) rotateY(6deg) translate3d(14px, -18px, -45px);
}

.ledger-card.layer-2 {
  background: #F8FAFC;
  transform: perspective(1400px) rotateX(10deg) rotateY(4deg) translate3d(7px, -9px, -20px);
}

.ledger-card.layer-3 {
  background: #FFFFFF;
  border: 1px solid var(--calexfin-blue-border);
  transform: perspective(1400px) rotateX(8deg) rotateY(2deg) translate3d(0, 0, 10px);
  box-shadow: var(--shadow-elevated);
}

.ledger-stack-container:hover .ledger-card.layer-1 {
  transform: perspective(1400px) rotateX(6deg) rotateY(4deg) translate3d(28px, -28px, -55px);
}

.ledger-stack-container:hover .ledger-card.layer-2 {
  transform: perspective(1400px) rotateX(5deg) rotateY(2deg) translate3d(14px, -14px, 5px);
}

.ledger-stack-container:hover .ledger-card.layer-3 {
  transform: perspective(1400px) rotateX(3deg) rotateY(0deg) translate3d(-10px, 14px, 55px);
  box-shadow: 0 28px 60px rgba(15, 23, 42, 0.16);
}

/* ============================================================
   7. SCROLL REVEALS & PAGE TRANSITIONS
   ============================================================ */
.reveal-on-scroll {
  opacity: 0;
  transform: translate3d(0, 24px, 0);
  transition: opacity 600ms var(--ease-corporate),
              transform 600ms var(--ease-corporate);
  will-change: opacity, transform;
}

.reveal-on-scroll.revealed {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.page-view {
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 18px, 0);
  transition: opacity var(--duration-normal) ease,
              transform var(--duration-normal) var(--ease-corporate),
              visibility 0ms linear var(--duration-normal);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
}

.page-view.active-page {
  opacity: 1;
  visibility: visible;
  transform: translate3d(0, 0, 0);
  position: relative;
  pointer-events: auto;
  transition: opacity var(--duration-normal) ease,
              transform var(--duration-normal) var(--ease-corporate),
              visibility 0ms;
}

/* ============================================================
   8. REDUCED MOTION ACCESSIBILITY (Spec Section 28)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .perspective-viewport, .perspective-deep {
    perspective: none !important;
  }

  .tilt-card-3d, .tilt-card-3d.tilting,
  .legal-doc, .ledger-card,
  .page-view, .reveal-on-scroll {
    transform: none !important;
  }

  .float-slow-a, .float-slow-b {
    animation: none !important;
  }

  .flap.top-flip, .flap.bottom-flip {
    animation: none !important;
  }
}

body.reduced-motion * {
  animation: none !important;
  transition: opacity 150ms ease !important;
}

body.reduced-motion .tilt-card-3d.tilting,
body.reduced-motion .legal-doc,
body.reduced-motion .ledger-card {
  transform: none !important;
}
