.apec-root {
  --apec-ink: #18212f;
  --apec-muted: #586577;
  --apec-card: #fff;
  --apec-panel: #f5f7fb;
  --apec-control: #fff;
  --apec-line: #d6dde7;
  --apec-blue: #345f8c;
  --apec-green: #2f6f5f;
  --apec-red: #8b3a35;
  --apec-amber: #9a6b2f;
  --apec-shadow: 0 18px 46px rgba(20, 30, 44, 0.1);
  --apec-risk-level: 0.2;
  --apec-glyph-stroke: 1.68px;
  --apec-spoke-opacity: 0.31;
  --apec-glyph-cool: #4e8d82;
  --apec-glyph-mid: #a07a42;
  --apec-glyph-hot: #793b37;

  border: 1px solid var(--apec-line);
  border-radius: 8px;
  padding: clamp(14px, 3vw, 24px);
  background:
    repeating-linear-gradient(90deg, rgba(20, 30, 44, 0.025) 0 1px, transparent 1px 9px),
    var(--apec-card);
  box-shadow: var(--apec-shadow);
  color: var(--apec-ink);
  color-scheme: light;
}

.theme-dark .apec-root {
  --apec-ink: #f6f8fb;
  --apec-muted: #b6c2d2;
  --apec-card: #11161d;
  --apec-panel: #171d25;
  --apec-control: #121820;
  --apec-line: #313a46;
  --apec-blue: #7f9db8;
  --apec-green: #8ab7aa;
  --apec-red: #c1837c;
  --apec-amber: #c2a36d;
  --apec-shadow: 0 24px 58px rgba(0, 0, 0, 0.34);
  --apec-glyph-cool: #8ab7aa;
  --apec-glyph-mid: #c2a36d;
  --apec-glyph-hot: #9b5751;

  color-scheme: dark;
}

.apec-topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.apec-segment {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--apec-line);
  border-radius: 8px;
  background: var(--apec-control);
}

.apec-segment button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: var(--apec-ink);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

.apec-segment button.is-active {
  color: white;
  background: var(--apec-blue);
}

.theme-dark .apec-segment button.is-active {
  color: #08111f;
}

.apec-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(300px, 0.92fr);
  gap: 16px;
}

.apec-inputs,
.apec-results {
  border: 1px solid var(--apec-line);
  border-radius: 8px;
  padding: 14px;
  background: color-mix(in srgb, var(--apec-panel) 94%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    inset 0 -1px 0 rgba(20, 32, 48, 0.08);
  backdrop-filter: blur(16px) saturate(1.15);
}

.apec-field-grid,
.apec-time-pair,
.apec-metrics {
  display: grid;
  gap: 10px;
}

.apec-field-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.apec-time-pair {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.apec-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 12px;
}

.apec-root label {
  display: grid;
  gap: 6px;
  color: var(--apec-muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.apec-root input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--apec-line);
  border-radius: 7px;
  padding: 10px;
  color: var(--apec-ink);
  background: var(--apec-control);
  font: inherit;
  font-weight: 900;
}

.apec-slider {
  margin-top: 12px;
}

.apec-slider > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.apec-slider strong {
  color: var(--apec-ink);
}

.apec-slider input {
  padding: 0;
  accent-color: var(--apec-blue);
  background: transparent;
}

.apec-results article {
  min-height: 82px;
  border: 1px solid var(--apec-line);
  border-radius: 8px;
  padding: 12px;
  background: color-mix(in srgb, var(--apec-control) 94%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 8px 24px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(14px);
}

.apec-results span {
  display: block;
  color: var(--apec-muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.apec-results strong {
  display: block;
  margin-top: 8px;
  color: var(--apec-ink);
  font-size: clamp(1.15rem, 3vw, 1.8rem);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  transition:
    filter 180ms ease,
    opacity 180ms ease,
    transform 180ms ease,
    color 220ms ease;
}

.apec-results strong.is-counting {
  filter: blur(0.45px);
  transform: translateY(-1px);
}

.apec-results strong.is-morphing {
  opacity: 0;
  filter: blur(8px);
  transform: translateY(12px) scale(0.96);
}

.apec-results strong.is-rebuilt {
  animation: apec-rebuild 260ms ease-out both;
}

.apec-results article.apec-recommendation {
  min-height: 132px;
  border-color: color-mix(in srgb, var(--apec-green) 45%, var(--apec-line));
  background: color-mix(in srgb, var(--apec-green) 10%, var(--apec-control));
}

.apec-results article.apec-recommendation.is-risk-override {
  border-color: color-mix(in srgb, var(--apec-amber) 58%, var(--apec-line));
  background: color-mix(in srgb, var(--apec-amber) 12%, var(--apec-control));
}

.apec-recommendation strong {
  color: var(--apec-green);
  font-size: clamp(2rem, 7vw, 3.6rem);
}

.apec-recommendation.is-risk-override strong {
  color: var(--apec-amber);
}

.apec-recommendation small {
  display: block;
  margin-top: 8px;
  color: var(--apec-muted);
  font-weight: 850;
}

.apec-risk {
  margin-top: 14px;
  color: var(--apec-muted);
  font-weight: 850;
}

.apec-risk b {
  color: var(--apec-ink);
}

.apec-risk i {
  display: block;
  height: 12px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--apec-line) 72%, transparent);
}

.apec-risk i::before {
  display: block;
  width: var(--apec-risk, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--apec-glyph-cool);
  content: "";
  transition: width 320ms ease;
}

.apec-visualizer {
  display: grid;
  grid-template-columns: minmax(145px, 0.82fr) minmax(0, 1.18fr);
  gap: 12px;
  margin-bottom: 12px;
}

.apec-risk-glyph,
.apec-bed-map {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--apec-line) 82%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--apec-control) 92%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.48),
    0 16px 42px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(18px);
}

.apec-risk-glyph svg,
.apec-bed-map svg {
  display: block;
  width: 100%;
  height: auto;
}

.apec-risk-glyph svg {
  aspect-ratio: 1;
  filter: drop-shadow(0 14px 24px color-mix(in srgb, var(--apec-glyph-cool) 18%, transparent));
}

.apec-risk-glyph figcaption,
.apec-bed-map figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid color-mix(in srgb, var(--apec-line) 76%, transparent);
  padding: 9px 10px;
}

.apec-risk-glyph figcaption span,
.apec-bed-map figcaption span {
  color: var(--apec-muted);
  font-size: 0.7rem;
  font-weight: 900;
}

.apec-risk-glyph figcaption strong,
.apec-bed-map figcaption strong {
  margin: 0;
  color: var(--apec-ink);
  font-size: 0.95rem;
}

.apec-glyph-halo {
  fill: none;
  stroke: color-mix(in srgb, var(--apec-glyph-cool) 54%, var(--apec-red));
  stroke-dasharray: 2 7;
  stroke-width: 1.2;
  opacity: 0.52;
  transform-origin: 90px 90px;
  animation: apec-spin 18s linear infinite;
}

.apec-glyph-mesh {
  fill: url("#apec-glyph-core");
  filter: url("#apec-glyph-glow");
  stroke: color-mix(in srgb, var(--apec-glyph-cool) 48%, var(--apec-red));
  stroke-width: var(--apec-glyph-stroke);
  transition:
    d 240ms ease,
    stroke 240ms ease,
    stroke-width 240ms ease;
}

.apec-glyph-spokes line {
  stroke: color-mix(in srgb, var(--apec-glyph-cool) 44%, var(--apec-amber));
  stroke-width: 0.7;
  opacity: var(--apec-spoke-opacity);
  transform-origin: 90px 90px;
}

.apec-glyph-core {
  fill: color-mix(in srgb, var(--apec-glyph-cool) 46%, var(--apec-red));
  opacity: 0.92;
}

.apec-bed-plate {
  fill:
    color-mix(in srgb, var(--apec-panel) 72%, transparent);
  stroke: color-mix(in srgb, var(--apec-line) 86%, transparent);
  stroke-width: 1.4;
}

.apec-bed-path {
  fill: none;
  stroke: color-mix(in srgb, var(--apec-blue) 72%, transparent);
  stroke-dasharray: 4 6;
  stroke-linecap: round;
  stroke-width: 1.5;
  transition:
    d 280ms ease,
    opacity 260ms ease,
    stroke 260ms ease;
}

.apec-bed-part {
  animation: apec-batch-pulse 1400ms ease-in-out infinite;
  animation-delay: var(--apec-delay, 0ms);
}

.apec-bed-part rect,
.apec-bed-part ellipse {
  fill: color-mix(in srgb, var(--apec-glyph-cool) 68%, var(--apec-control));
  stroke: color-mix(in srgb, var(--apec-ink) 32%, transparent);
  stroke-width: 0.8;
  transition:
    fill 260ms ease,
    opacity 260ms ease,
    transform 260ms ease;
}

.apec-root[data-apec-strategy="sequential"] .apec-bed-part {
  animation-name: apec-sequential-light;
  animation-duration: 1800ms;
}

.apec-root[data-apec-strategy="sequential"] .apec-bed-part rect,
.apec-root[data-apec-strategy="sequential"] .apec-bed-part ellipse {
  fill: color-mix(in srgb, var(--apec-amber) 70%, var(--apec-control));
}

.apec-bed-zone {
  fill: color-mix(in srgb, var(--apec-amber) 12%, transparent);
  stroke: color-mix(in srgb, var(--apec-amber) 50%, transparent);
  stroke-dasharray: 3 5;
  stroke-width: 1;
  animation: apec-zone-breathe 1800ms ease-in-out infinite;
  animation-delay: var(--apec-delay, 0ms);
}

@keyframes apec-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes apec-batch-pulse {
  0%,
  100% {
    opacity: 0.82;
    transform: translateY(0);
  }

  50% {
    opacity: 1;
    transform: translateY(-1px);
  }
}

@keyframes apec-sequential-light {
  0%,
  74%,
  100% {
    opacity: 0.42;
    transform: scale(0.94);
  }

  18%,
  44% {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes apec-zone-breathe {
  0%,
  100% {
    opacity: 0.16;
    transform: scale(0.94);
  }

  45% {
    opacity: 0.58;
    transform: scale(1.05);
  }
}

@keyframes apec-rebuild {
  from {
    opacity: 0;
    filter: blur(6px);
    transform: translateY(-10px) scale(1.04);
  }

  to {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 860px) {
  .apec-layout,
  .apec-field-grid,
  .apec-time-pair,
  .apec-metrics,
  .apec-visualizer {
    grid-template-columns: 1fr;
  }

  .apec-topbar {
    justify-content: stretch;
  }

  .apec-segment,
  .apec-segment button {
    flex: 1;
  }
}
