/*
 * Responsive connection paths, icon-only cards, and ElastiCache capacity
 * animation. aws-flow.js calculates SVG paths from rendered object positions.
 */

#aws-system {
  --aws-surface: rgba(255, 255, 255, 0.8);
}

.aws-architecture {
  isolation: isolate;
}

.aws-architecture > :not(.aws-flow-map) {
  position: relative;
  z-index: 2;
}

/* Keep the infrastructure visible while allowing the background to show through. */
.aws-node,
.aws-service-cluster,
.aws-data-cluster,
.aws-task,
.aws-database-node {
  background: rgba(255, 255, 255, 0.8);
}

.aws-database-node--writer,
.aws-database-node--primary {
  background: rgba(255, 255, 255, 0.86);
}

/* The architecture background is intentionally icon-only. */
.aws-node,
.aws-task,
.aws-database-node {
  color: transparent;
  font-size: 0;
}

.aws-node small,
.aws-tier-label,
.aws-node-role,
.aws-scale-indicator {
  display: none !important;
}

.aws-node--client {
  width: 5.5rem;
  min-width: 5.5rem;
  height: 5.5rem;
  min-height: 5.5rem;
  padding: 0;
  border-radius: 50%;
}

.aws-node--client::before,
.aws-node--client::after {
  content: "";
  position: absolute;
  left: 50%;
  background: #475569;
  transform: translateX(-50%);
}

.aws-node--client::before {
  top: 1rem;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
}

.aws-node--client::after {
  bottom: 0.85rem;
  width: 3.25rem;
  height: 2.1rem;
  border-radius: 1.8rem 1.8rem 0.8rem 0.8rem;
}

.aws-node--cloudfront,
.aws-node--alb {
  width: 7.5rem;
  min-width: 7.5rem;
  height: 7.5rem;
  min-height: 7.5rem;
  padding: 0;
  border-radius: 1.25rem;
}

.aws-node--cloudfront::before,
.aws-node--alb::before {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.aws-service-cluster {
  padding: 1rem;
}

.aws-data-cluster {
  padding: 0.8rem;
}

.aws-task,
.aws-database-node {
  min-height: 6.5rem;
  padding: 0;
}

.aws-task::before,
.aws-database-node::before {
  top: 50%;
  transform: translate(-50%, -50%);
}

/* Keep layout spacing from the original connectors, but let SVG draw them. */
.aws-connector,
.aws-connector--split {
  background: none !important;
}

.aws-connector::after {
  display: none;
}

.aws-flow-map {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.aws-flow-segment {
  opacity: 1;
}

.aws-flow-line-glow,
.aws-flow-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.aws-flow-line-glow {
  stroke: rgba(56, 189, 248, 0.24);
  stroke-width: 15;
  filter: url("#aws-flow-line-glow");
}

.aws-flow-line {
  stroke: rgba(51, 65, 85, 0.86);
  stroke-width: 6;
}

.aws-flow-line--compute {
  stroke: rgba(217, 119, 6, 0.9);
}

.aws-flow-line--rds {
  stroke: rgba(59, 130, 246, 0.9);
}

.aws-flow-line--cache {
  stroke: rgba(219, 39, 119, 0.88);
}

.aws-flow-dot {
  r: 7;
  filter: url("#aws-flow-dot-glow");
}

.aws-flow-dot--rds {
  fill: #60a5fa;
}

.aws-flow-dot--cache {
  fill: #f472b6;
}

/* Primary remains in the center. Replicas scale out to left, then right. */
.aws-data-cluster--cache .aws-database-node:nth-child(1) {
  grid-column: 2;
  grid-row: 1;
  animation: aws-capacity-steady 6s ease-in-out infinite;
}

.aws-data-cluster--cache .aws-database-node:nth-child(2) {
  grid-column: 1;
  grid-row: 1;
  animation: aws-cache-left 32s ease-in-out infinite;
}

.aws-data-cluster--cache .aws-database-node:nth-child(3) {
  grid-column: 3;
  grid-row: 1;
  animation: aws-cache-right 32s ease-in-out infinite;
}

@keyframes aws-cache-left {
  0%, 14%, 86%, 100% {
    opacity: 0;
    transform: translateX(42%) translateY(0.8rem) scale(0.42);
    filter: grayscale(0.8) blur(1px);
  }
  26%, 74% {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
    filter: none;
  }
}

@keyframes aws-cache-right {
  0%, 34%, 66%, 100% {
    opacity: 0;
    transform: translateX(-42%) translateY(0.8rem) scale(0.42);
    filter: grayscale(0.8) blur(1px);
  }
  46%, 54% {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
    filter: none;
  }
}

@media (max-width: 48rem) {
  .aws-node--cloudfront,
  .aws-node--alb {
    width: 6.2rem;
    min-width: 6.2rem;
    height: 6.2rem;
    min-height: 6.2rem;
    padding: 0;
  }

  .aws-task,
  .aws-database-node {
    min-height: 5.7rem;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .aws-flow-dot {
    display: none;
  }

  .aws-data-cluster--cache .aws-database-node {
    opacity: 1;
    transform: none;
    filter: none;
    animation: none;
  }
}
