/* ── Motion tokens ── */
:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --dur-fast: 0.18s;
  --dur-normal: 0.32s;
  --dur-slow: 0.55s;
}

/* ── Keyframes ── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.85);
  }
  70% {
    transform: scale(1.04);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulseSoft {
  0%, 100% { box-shadow: 0 0 0 0 rgba(13, 122, 107, 0); }
  50% { box-shadow: 0 0 0 6px rgba(13, 122, 107, 0.12); }
}

@keyframes computedPanelReveal {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
    filter: blur(8px);
    box-shadow:
      0 0 0 rgba(13, 122, 107, 0),
      0 0 0 1px rgba(255, 255, 255, 0),
      inset 0 1px 0 rgba(255, 255, 255, 0),
      inset 0 -1px 0 rgba(13, 122, 107, 0);
  }
  45% {
    filter: blur(0);
  }
  72% {
    transform: translateY(-3px) scale(1.012);
    box-shadow:
      0 10px 28px rgba(13, 122, 107, 0.24),
      0 0 0 1px rgba(255, 255, 255, 0.88),
      inset 0 1px 0 rgba(255, 255, 255, 0.98),
      inset 0 -1px 0 rgba(13, 122, 107, 0.14);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes computedLineReveal {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes shimmer {
  from { transform: translateX(-120%); }
  to { transform: translateX(120%); }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(10px) scale(0.98);
  }
}

@keyframes gridPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.75; }
}

@keyframes connectorGrow {
  from { transform: translateY(-50%) scaleX(0); }
  to { transform: translateY(-50%) scaleX(1); }
}

@keyframes highlightValue {
  0% { background-color: rgba(13, 122, 107, 0.22); }
  100% { background-color: transparent; }
}

/* ── Page load ── */
body.is-ready .header {
  animation: fadeDown var(--dur-slow) var(--ease-out) both;
}

body.is-ready .page {
  animation: fadeUp var(--dur-slow) var(--ease-out) 0.08s both;
}

body.is-ready .site-footer {
  animation: fadeIn var(--dur-normal) var(--ease-out) 0.2s both;
}

/* ── Header ambient motion ── */
.header__grid {
  animation: gridPulse 8s ease-in-out infinite;
}

/* ── View transitions ── */
.view.is-active {
  animation: fadeUp var(--dur-normal) var(--ease-out) both;
}

.view.is-active .view__head {
  animation: fadeUp var(--dur-normal) var(--ease-out) 0.04s both;
}

.view.is-active .form-block,
.view.is-active .form-footer,
.view.is-active .info-banner,
.view.is-active .warnings {
  animation: fadeUp var(--dur-normal) var(--ease-out) both;
}

.view.is-active .form-block:nth-child(1) { animation-delay: 0.06s; }
.view.is-active .form-block:nth-child(2) { animation-delay: 0.12s; }
.view.is-active .form-block:nth-child(3) { animation-delay: 0.18s; }
.view.is-active .form-block:nth-child(4) { animation-delay: 0.24s; }
.view.is-active .form-block:nth-child(5) { animation-delay: 0.3s; }
.view.is-active .form-block:nth-child(6) { animation-delay: 0.36s; }
.view.is-active .form-footer { animation-delay: 0.28s; }

.view.is-active .view__head--results {
  animation: fadeUp var(--dur-normal) var(--ease-out) 0.04s both;
}

/* ── Sidebar panels ── */
.panel {
  transition:
    transform var(--dur-normal) var(--ease-out),
    box-shadow var(--dur-normal) var(--ease-out),
    border-color var(--dur-fast) ease;
}

.panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.calc-preview__item.is-entering {
  animation: calcPreviewEnter 0.62s cubic-bezier(0.34, 1.25, 0.64, 1) both;
  animation-delay: var(--preview-stagger, 0s);
}

.calc-preview__item.is-exiting {
  animation: calcPreviewExit 0.34s ease both;
}

.calc-preview__item.is-readying {
  animation: calcPreviewReady 0.72s cubic-bezier(0.34, 1.35, 0.64, 1) both;
}

.calc-preview__item.is-readying .calc-preview__value {
  animation: calcPreviewValueIn 0.62s cubic-bezier(0.22, 1, 0.36, 1) 0.18s both;
}

.calc-preview__value.is-value-updated {
  animation: calcPreviewValuePulse 0.58s cubic-bezier(0.34, 1.35, 0.64, 1) both;
}

@keyframes calcPreviewEnter {
  0% {
    opacity: 0;
    transform: translateX(-16px) scale(0.94);
    filter: blur(6px);
  }
  55% {
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0);
  }
}

@keyframes calcPreviewExit {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
    max-height: 4rem;
  }
  to {
    opacity: 0;
    transform: translateX(12px) scale(0.96);
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: -1px;
  }
}

@keyframes calcPreviewReady {
  0% {
    background: transparent;
  }
  35% {
    background: linear-gradient(
      90deg,
      rgba(212, 240, 234, 0.55) 0%,
      rgba(255, 255, 255, 0) 88%
    );
  }
  100% {
    background: transparent;
  }
}

@keyframes calcPreviewValueIn {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.88);
    letter-spacing: 0.08em;
    filter: blur(4px);
  }
  60% {
    letter-spacing: 0.02em;
    filter: blur(0);
  }
  82% {
    transform: translateY(-1px) scale(1.04);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    letter-spacing: 0;
  }
}

@keyframes calcPreviewValuePulse {
  0%, 100% {
    box-shadow:
      0 1px 4px rgba(13, 122, 107, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.85);
  }
  45% {
    box-shadow:
      0 0 0 3px rgba(13, 122, 107, 0.18),
      0 4px 14px rgba(13, 122, 107, 0.22),
      inset 0 1px 0 rgba(255, 255, 255, 0.95);
    transform: scale(1.04);
  }
}

/* ── Workflow steps (liquid rail) ── */
.workflow__step {
  transition:
    background var(--dur-fast) ease,
    border-color var(--dur-normal) var(--ease-out),
    box-shadow var(--dur-normal) ease;
}

.workflow__icon {
  transition:
    background var(--dur-normal) ease,
    border-color var(--dur-normal) ease,
    color var(--dur-fast) ease,
    box-shadow var(--dur-normal) ease;
}

.workflow__step.is-active .workflow__icon {
  animation: liquidIconGlow var(--dur-slow) var(--ease-out) both;
}

.workflow__step.is-done:not(:last-child)::after {
  transform-origin: left center;
  animation: connectorGrow 0.45s var(--ease-out) both;
}

@keyframes liquidShimmer {
  0%, 100% {
    opacity: 0.55;
    transform: translateX(-10%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateX(10%) scale(1.03);
  }
}

@keyframes liquidIconGlow {
  0% {
    transform: scale(0.94);
    box-shadow: 0 0 0 rgba(255, 255, 255, 0);
  }
  55% {
    transform: scale(1.04);
    box-shadow: 0 0 12px rgba(94, 234, 212, 0.35);
  }
  100% {
    transform: scale(1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
  }
}

.liquid-segment__indicator-glass,
.workflow-rail__liquid-glass {
  transition:
    transform 0.58s cubic-bezier(0.45, 0.02, 0.15, 1),
    box-shadow 0.5s ease,
    filter 0.45s ease,
    border-color 0.45s ease;
}

.liquid-segment__indicator-glass[data-hover-state="active"],
.workflow-rail__liquid-glass[data-hover-state="active"] {
  transform: scale(1.028);
  filter: brightness(1.1) saturate(1.06);
}

.liquid-segment__indicator-glass[data-hover-state="active"] {
  box-shadow:
    0 6px 24px rgba(13, 122, 107, 0.38),
    0 0 0 1px rgba(255, 255, 255, 0.75),
    inset 0 2px 0 rgba(255, 255, 255, 1),
    inset 0 -2px 0 rgba(13, 122, 107, 0.16);
  border-color: rgba(13, 122, 107, 0.68);
}

.workflow-rail__liquid-glass[data-hover-state="active"] {
  box-shadow:
    0 8px 28px rgba(8, 58, 48, 0.62),
    0 0 0 1px rgba(0, 0, 0, 0.14),
    inset 0 2px 0 rgba(255, 255, 255, 0.38),
    inset 0 -2px 0 rgba(0, 0, 0, 0.14);
  border-color: rgba(255, 255, 255, 0.48);
}

.liquid-segment__indicator-glass[data-hover-state="intent"] {
  transform: translate3d(var(--pull-x, 0), 0, 0) scaleX(var(--stretch-x, 1.05)) scaleY(0.988);
  filter: brightness(1.06) saturate(1.05);
  border-color: rgba(13, 122, 107, 0.52);
}

.toggle__track-glass[data-hover-state="intent"] {
  transform: scaleX(var(--stretch-x, 1.06));
  filter: brightness(1.06) saturate(1.05);
  border-color: rgba(13, 122, 107, 0.52);
}

.toggle__knob-glass[data-hover-state="intent"] {
  transform: translate3d(var(--pull-x, 0), 0, 0);
}

.liquid-segment--inline:has(.liquid-unit__option:hover) .liquid-segment__indicator-glass::after {
  animation-duration: 1.6s;
  opacity: 1;
}

.workflow-rail__liquid-glass[data-hover-state="intent"] {
  transform: translate3d(var(--pull-x, 0), 0, 0) scaleX(var(--stretch-x, 1.05)) scaleY(0.992);
  filter: brightness(1.1) saturate(1.06);
}

.liquid-segment:has(.unit-system-toggle__option:hover) .liquid-segment__indicator-glass::after,
.liquid-segment:has(.choice:hover) .liquid-segment__indicator-glass::after,
.workflow-rail:has(.workflow__step-btn:not(:disabled):hover) .workflow-rail__liquid-glass::after {
  animation-duration: 1.6s;
  opacity: 1;
}

/* ── Form interactions ── */
.form-block {
  transition:
    transform var(--dur-normal) var(--ease-out),
    box-shadow var(--dur-normal) ease,
    border-color var(--dur-fast) ease;
}

.form-block:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.input-group {
  transition:
    border-color var(--dur-fast) ease,
    box-shadow var(--dur-normal) var(--ease-out),
    transform var(--dur-fast) ease;
}

.input-group:focus-within {
  transform: translateY(-1px);
}

.computed-value.is-updated {
  animation: pulseSoft 0.65s var(--ease-out);
}

.btn--label-swap.is-label-swapping {
  animation: labContinueBtnPulse 0.58s cubic-bezier(0.45, 0.02, 0.15, 1) both;
}

@keyframes labContinueBtnPulse {
  0% {
    box-shadow: 0 2px 6px rgba(26, 77, 109, 0.25);
  }
  42% {
    box-shadow: 0 4px 18px rgba(13, 122, 107, 0.38);
  }
  100% {
    box-shadow: 0 2px 6px rgba(26, 77, 109, 0.25);
  }
}

.liquid-unit__flip.is-flipping .liquid-unit__flip-current {
  animation: unitFlipOut 0.34s cubic-bezier(0.45, 0.02, 0.15, 1) both;
}

.liquid-unit__flip.is-flipping .liquid-unit__flip-next {
  opacity: 1;
  animation: unitFlipIn 0.42s cubic-bezier(0.34, 1.35, 0.64, 1) 0.08s both;
}

.liquid-unit__flip.is-flipping .liquid-unit__flip-icon {
  animation: unitFlipIconSpin 0.42s cubic-bezier(0.34, 1.35, 0.64, 1) both;
}

@keyframes unitFlipOut {
  to {
    opacity: 0;
    transform: translateY(-115%) scale(0.9);
    filter: blur(3px);
  }
}

@keyframes unitFlipIn {
  from {
    opacity: 0;
    transform: translateY(115%) scale(0.9);
    filter: blur(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes unitFlipIconSpin {
  50% {
    transform: rotate(180deg) scale(1.15);
    opacity: 1;
  }
}

.computed-panel.is-revealing {
  animation: computedPanelReveal 0.72s var(--ease-spring) both;
}

.computed-panel.is-revealing .form-field__label {
  animation: fadeDown 0.55s var(--ease-out) 0.08s both;
}

.computed-panel.is-revealing .computed-value__result--stack span {
  animation: computedLineReveal 0.58s var(--ease-out) both;
}

.computed-panel.is-revealing .computed-value__result--stack span:nth-child(1) {
  animation-delay: 0.16s;
}

.computed-panel.is-revealing .computed-value__result--stack span:nth-child(2) {
  animation-delay: 0.28s;
}

.computed-panel.is-revealing .computed-value__result--stack span:nth-child(3) {
  animation-delay: 0.4s;
}

.computed-value__result--stack span.is-new {
  animation: highlightValue 0.9s var(--ease-out);
}

.checklist__item {
  transition:
    background var(--dur-fast) ease,
    box-shadow var(--dur-fast) ease;
}

.checklist__liquid {
  transition:
    opacity 0.45s ease,
    transform 0.58s cubic-bezier(0.45, 0.02, 0.15, 1);
}

@keyframes checklistLiquidIn {
  0% {
    transform: scale(0.94);
    filter: brightness(0.96);
  }
  55% {
    transform: scale(1.012);
    filter: brightness(1.06);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

.checklist__box {
  transition:
    border-color var(--dur-fast) ease,
    background var(--dur-fast) ease,
    transform var(--dur-normal) var(--ease-spring);
}

.checklist__item input:checked ~ .checklist__box {
  transform: scale(1.08);
}

.choice span {
  transition:
    color var(--dur-fast) ease,
    font-weight var(--dur-fast) ease;
}

.liquid-segment__indicator,
.workflow-rail__liquid {
  transition:
    transform 0.72s cubic-bezier(0.45, 0.02, 0.15, 1),
    width 0.72s cubic-bezier(0.45, 0.02, 0.15, 1),
    height 0.72s cubic-bezier(0.45, 0.02, 0.15, 1),
    border-radius 0.72s cubic-bezier(0.45, 0.02, 0.15, 1),
    opacity 0.22s ease;
}

.choice input:checked + span {
  transform: none;
}

.toggle__track,
.toggle__track::before,
.toggle__track-glass,
.toggle__knob-glass {
  transition: all var(--dur-normal) var(--ease-spring);
}

/* ── Buttons ── */
.btn {
  position: relative;
  overflow: hidden;
  transition:
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-normal) ease,
    background var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    color var(--dur-fast) ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn--primary:not(.btn--liquid)::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 35%,
    rgba(255, 255, 255, 0.22) 50%,
    transparent 65%
  );
  transform: translateX(-120%);
  transition: none;
  pointer-events: none;
}

.btn--primary:not(.btn--liquid):hover::after {
  animation: shimmer 0.75s var(--ease-out);
}

.btn--primary:active,
.btn--secondary:active,
.btn--ghost:active {
  transform: translateY(0) scale(0.98);
}

.btn--liquid:hover {
  transform: translateY(-1px);
}

.btn--liquid:active {
  transform: translateY(0);
}

/* ── Results ── */
.results.is-revealing .result-card {
  animation: fadeUp var(--dur-normal) var(--ease-out) both;
}

.results.is-revealing .result-card:nth-child(1) { animation-delay: 0.05s; }
.results.is-revealing .result-card:nth-child(2) { animation-delay: 0.1s; }
.results.is-revealing .result-card:nth-child(3) { animation-delay: 0.15s; }
.results.is-revealing .result-card:nth-child(4) { animation-delay: 0.2s; }
.results.is-revealing .result-card:nth-child(5) { animation-delay: 0.25s; }
.results.is-revealing .result-card:nth-child(6) { animation-delay: 0.3s; }

.view.is-active .warnings {
  animation: fadeUp var(--dur-normal) var(--ease-out) 0.35s both;
}

.result-card {
  transition:
    transform var(--dur-normal) var(--ease-out),
    box-shadow var(--dur-normal) ease;
}

.result-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.result-metric {
  transition: background var(--dur-fast) ease;
}

/* ── Toast ── */
.toast {
  animation: toastIn var(--dur-normal) var(--ease-spring) both;
}

.toast.is-hiding {
  animation: toastOut var(--dur-fast) ease both;
}

/* ── Content card subtle depth ── */
.content {
  transition: box-shadow var(--dur-normal) ease;
}

@keyframes modules-marquee {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-50%, 0, 0); }
}

.content:hover {
  box-shadow: 0 10px 36px rgba(15, 28, 40, 0.13);
}

/* ── Mobile: stable layout while typing (no horizontal overflow) ── */
@media (max-width: 768px) {
  .input-group:focus-within {
    transform: none !important;
  }

  .form-block:hover,
  .panel:hover {
    transform: none;
    box-shadow: var(--shadow-xs);
  }

  .calc-preview__item.is-entering,
  .calc-preview__item.is-exiting,
  .calc-preview__item.is-readying,
  .calc-preview__item.is-readying .calc-preview__value,
  .calc-preview__value.is-value-updated {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }

  .computed-panel.is-revealing {
    animation: computedPanelRevealMobile 0.35s ease both;
  }

  .computed-panel.is-revealing .form-field__label,
  .computed-panel.is-revealing .computed-value__result--stack span {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .computed-value.is-updated {
    animation: none !important;
  }
}

@keyframes computedPanelRevealMobile {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html { scroll-behavior: auto; }
}

@media print {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
