:root {
  /* Reuse shared dark palette from other apps */
  --bg-page: #040510;
  --bg-surface: #080b1c;
  --bg-surface-strong: #0b1026;
  --bg-elevated: rgba(13, 18, 42, 0.92);
  --bg-muted: rgba(20, 26, 54, 0.78);
  --surface-highlight: rgba(34, 40, 80, 0.75);
  --border-soft: rgba(129, 140, 248, 0.22);
  --border-strong: rgba(99, 102, 241, 0.48);
  --text-primary: #e8ebff;
  --text-secondary: rgba(232, 235, 255, 0.7);
  --accent-primary: #6366f1;
  --accent-primary-soft: rgba(99, 102, 241, 0.18);
  --accent-secondary: #f97316;
  --accent-secondary-soft: rgba(249, 115, 22, 0.2);
  --focus-ring: rgba(129, 140, 248, 0.38);
}

body {
  background:
    radial-gradient(
      circle at 18% 20%,
      rgba(88, 132, 255, 0.18),
      transparent 58%
    ),
    radial-gradient(
      circle at 82% 18%,
      rgba(48, 196, 255, 0.12),
      transparent 55%
    ),
    radial-gradient(
      circle at 70% 84%,
      rgba(60, 120, 235, 0.12),
      transparent 60%
    ),
    var(--bg-page);
  color: var(--text-primary);
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2.2rem 1.5rem 4rem;
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 3rem 0 4rem;
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
}

.banner-backdrop {
  display: none;
}

.floating-banner {
  /* Force centering and stickiness over bundled fixed positioning */
  position: sticky !important;
  top: 104px !important;
  left: 0 !important;
  right: 0 !important;
  transform: none !important;
  width: 100% !important;
  max-width: 1120px !important;
  margin: 0.4rem auto 0 !important;
  background: linear-gradient(135deg, rgba(38, 61, 135), rgba(18, 32, 75));
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  box-shadow: 0 20px 32px rgba(0, 0, 0, 0.32);
  color: var(--text-primary);
  padding: 0.9rem 1.25rem;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.micro-segment {
  background: rgba(255, 255, 255, 0.18);
  color: #0a1a34;
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-weight: 800;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.35);
}

.micro-segment span {
  color: #0a1a34;
}

.micro-tooltip {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-soft);
}

.micro-tooltip:after {
  border-bottom-color: var(--bg-surface);
}

.hero {
  background: linear-gradient(
    135deg,
    rgba(38, 61, 135, 0.9),
    rgba(18, 32, 75, 0.95)
  );
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.35);
  color: var(--text-primary);
}

.hero h1,
.hero h2,
.hero h3,
.hero p {
  color: var(--text-primary);
}

/* Reorder main sections so banner sits between hero and process train */
.hero {
  order: 1;
}

.floating-banner {
  order: 2;
  margin-top: 0.75rem;
}

.process-map {
  order: 3;
}

.eyebrow {
  color: rgba(232, 235, 255, 0.7);
}

.lede {
  color: var(--text-secondary);
}

.flow-control,
.process-map,
.timeline,
.chem {
  background: linear-gradient(
    135deg,
    rgba(38, 61, 135, 0.9),
    rgba(18, 32, 75, 0.95)
  );
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.32);
  color: var(--text-primary);
}

.flow-control label,
.process-map h2,
.timeline h2,
.chem h2 {
  color: var(--text-primary);
}

.process-map,
.timeline {
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.32);
}

.chem {
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.32);
}

.chem-card {
  background: linear-gradient(135deg, #1a2f61, #16254d);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.stage-row + .stage-row {
  border-top: 1px dashed var(--border-soft);
}

.unit-strip {
  gap: 0.5rem;
}

.unit-block {
  background: rgba(12, 18, 42, 0.9);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
}

.unit-block.on {
  border-color: rgba(99, 102, 241, 0.6);
  box-shadow: 0 14px 24px rgba(99, 102, 241, 0.25);
}

.unit-block.off {
  background: rgba(17, 24, 39, 0.85);
  color: var(--text-secondary);
  border-color: rgba(255, 255, 255, 0.08);
}

.injection-badge {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-soft);
  color: var(--text-primary);
}

.bar {
  color: var(--text-primary);
}

.muted {
  color: var(--text-secondary);
}

.flow-values span {
  color: var(--text-primary);
}

.injection-label,
.tt-line,
.tt-title {
  color: var(--text-primary);
}

.micro-timeline span,
.micro-segment span {
  color: var(--text-primary);
}

.page h1,
.page h2,
.page h3,
.page p,
.page span {
  color: var(--text-primary);
}

/* Normalize global nav appearance to match other apps */
.global-nav a,
.global-nav__link,
.global-nav__dropdown-link {
  text-decoration: none !important;
  font-size: 1rem;
  font-weight: 600;
}

.global-nav__dropdown-link {
  padding: 0.65rem 0.9rem;
}

.page h2 {
  letter-spacing: 0;
}

input[type="range"]::-webkit-slider-thumb {
  background: var(--accent-primary);
  height: 14px;
  width: 14px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
  margin-top: -4px;
}

input[type="range"]::-moz-range-thumb {
  background: var(--accent-primary);
  height: 14px;
  width: 14px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

.flow-control input[type="range"] {
  appearance: none;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1f2d51 0%, #2f4477 100%);
  border: 1px solid var(--border-soft);
}

.flow-control input[type="range"]::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1f2d51 0%, #2f4477 100%);
}

.flow-control input[type="range"]::-moz-range-track {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1f2d51 0%, #2f4477 100%);
}

/* Align process train button colors with total-detention badge palette */
.unit-block.on.stage-flash {
  --stage-bg: linear-gradient(150deg, #7fb7da 0%, #4e85ad 100%);
  --stage-border: #6ba6ce;
}

.unit-block.on.stage-floc {
  --stage-bg: linear-gradient(150deg, #8698d7 0%, #5566a7 100%);
  --stage-border: #7385c8;
}

.unit-block.on.stage-clar {
  --stage-bg: linear-gradient(150deg, #d7bd86 0%, #a07f4b 100%);
  --stage-border: #c29a63;
}

.unit-block.on.stage-pac {
  --stage-bg: linear-gradient(150deg, #84c3a4 0%, #568871 100%);
  --stage-border: #6fab93;
}

.unit-block.on.stage-filters {
  --stage-bg: linear-gradient(150deg, #ada0e0 0%, #7c68b6 100%);
  --stage-border: #9a87d6;
}

.unit-block.on.stage-clearwell {
  --stage-bg: linear-gradient(150deg, #86c5c5 0%, #5b9696 100%);
  --stage-border: #74b8b8;
}

:root {
  --bar-flash: #6ba6ce;
  --bar-floc: #7385c8;
  --bar-clar: #c29a63;
  --bar-pac: #6fab93;
  --bar-filters: #9a87d6;
  --bar-clearwell: #74b8b8;
}

/* Match button text/border treatment to banner badges */
.unit-block.on.stage-flash,
.unit-block.on.stage-floc,
.unit-block.on.stage-clar,
.unit-block.on.stage-pac,
.unit-block.on.stage-filters,
.unit-block.on.stage-clearwell {
  color: #0f1a2e;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.28);
}

/* --- Responsive & small-screen fixes --- */
/* Ensure banner content can shrink on smaller viewports */
.floating-banner {
  min-width: 0;
}

.micro-timeline {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

@media (max-width: 960px) {
  .floating-banner {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
  }

  .floating-banner > div:first-child {
    min-width: 180px;
  }

  .micro-timeline {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.35rem;
    width: 100%;
  }

  .micro-segment {
    justify-content: center;
    text-align: center;
  }

  .micro-segment span {
    white-space: normal;
  }
}

@media (max-width: 720px) {
  main,
  .page {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .floating-banner {
    top: 76px !important;
  }

  .hero {
    grid-template-columns: 1fr !important;
  }

  .stage-row {
    grid-template-columns: 1fr;
    padding: 0.9rem 0;
  }

  .stage-line {
    gap: 0.65rem;
  }

  .unit-strip {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .unit-strip.filters-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .injection-badges {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .floating-banner {
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    gap: 0.6rem;
  }

  .banner-total {
    font-size: 1.2rem;
  }

  .micro-timeline {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    row-gap: 0.25rem;
  }

  .micro-segment {
    padding: 0.2rem 0.4rem;
    font-size: 0.74rem;
  }

  .unit-strip {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.3rem;
  }

  .unit-block {
    min-width: auto;
    padding: 0.5rem 0.6rem;
  }
}

/* --- Help modal --- */
.help-launch {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border-soft);
  background: linear-gradient(135deg, #1a2f61, #0f1f3f);
  color: var(--text-primary);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
  z-index: 30;
}

.help-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 40;
}

.help-modal[aria-hidden="false"] {
  display: flex;
}

.help-modal__surface {
  width: min(480px, 90vw);
  background: var(--bg-surface-strong);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.5);
  padding: 1.1rem 1.25rem 1.25rem;
  color: var(--text-primary);
}

.help-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.help-modal__header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.help-close {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 1.4rem;
  cursor: pointer;
}

.help-modal__body ol {
  margin: 0.6rem 0 0;
  padding-left: 1.2rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
