:root {
  --water: #d8ebfb;
  --water-line: #2a78d6;
  --s-amonia: #eb6834;
  --s-nitrito: #2a78d6;
  --s-nitrato: #1baf7a;
  --ok: #0a7a3a;
  --ok-bg: #e7f6ec;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --bad: #b3261e;
  --bad-bg: #fde8e6;
  --line: #e4e4e4;
}

.back {
  display: inline-block;
  margin-bottom: 24px;
  color: #555;
  text-decoration: none;
  font-size: 15px;
}

.back:hover {
  color: #111;
}

h3 {
  margin: 28px 0 8px;
  font-size: 19px;
  line-height: 1.3;
}

h4 {
  margin-bottom: 4px;
  font-size: 16px;
}

.step ul,
.step ol,
.sources ol {
  padding-left: 20px;
}

.step li {
  margin-bottom: 6px;
}

.step p + p,
.intro p + p {
  margin-top: 12px;
}

.intro {
  margin-bottom: 32px;
}

.aside {
  margin-top: 16px;
  padding: 12px 16px;
  border-left: 3px solid #a35cff;
  background: #f7f3ff;
  border-radius: 0 8px 8px 0;
  font-size: 15px;
  color: #333;
}

/* Glossary terms: dotted underline, definition pops up on tap/hover/focus */
.term {
  color: inherit;
  text-decoration: underline dotted #a35cff 2px;
  text-underline-offset: 3px;
  cursor: help;
}

.tooltip {
  position: absolute;
  z-index: 50;
  max-width: min(300px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 10px;
  background: #111;
  color: #fff;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.tooltip strong {
  display: block;
  margin-bottom: 2px;
}

/* Progress */
.progress {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 -16px 24px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

.progress-label {
  font-size: 14px;
  font-weight: 700;
}

.progress-bar {
  height: 6px;
  margin: 6px 0 10px;
  border-radius: 999px;
  background: #eee;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: #111;
  transition: width 0.3s ease;
}

.progress-steps {
  display: flex;
  gap: 6px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}

.progress-steps::-webkit-scrollbar {
  display: none;
}

.progress-steps button {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid #ccc;
  border-radius: 999px;
  background: #fff;
  color: #555;
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.progress-steps button.is-done {
  border-color: #111;
  color: #111;
}

.progress-steps button[aria-current="step"] {
  border-color: #111;
  background: #111;
  color: #fff;
}

/* Steps: all visible without JS, one at a time with it */
.js .step {
  display: none;
}

.js .step.is-current {
  display: block;
}

.step {
  margin-bottom: 48px;
  scroll-margin-top: 120px;
}

.step-kicker {
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 700;
  color: #a35cff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Overrides the small uppercase h2 from the main stylesheet */
.step-title {
  margin-bottom: 16px;
  font-size: 30px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-transform: none;
  color: #111;
}

.step-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 48px;
}

.pill-button {
  padding: 10px 20px;
  border: 1px solid #111;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.pill-button:hover,
.pill-solid {
  background: #111;
  color: #fff;
}

.pill-solid:hover {
  background: #333;
}

.pill-button:disabled {
  visibility: hidden;
}

.link-button {
  border: 0;
  background: none;
  color: #555;
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

:is(.pill-button, .link-button, .progress-steps button, .part, .quiz button):focus-visible {
  outline: 3px solid #a35cff;
  outline-offset: 2px;
}

/* Comparison table */
.table-wrap {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}

.compare {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.4;
}

.compare th,
.compare td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.compare thead th {
  font-size: 14px;
  color: #555;
}

/* System diagram */
.diagram,
.cycle,
.chart {
  margin: 20px 0;
}

.diagram svg,
.cycle svg {
  display: block;
  width: 100%;
  height: auto;
}

.part-box {
  fill: #fff;
  stroke: #111;
  stroke-width: 2;
}

.water {
  fill: var(--water);
}

.sludge {
  fill: #8a6d4b;
}

.media circle {
  fill: #fff;
  stroke: #777;
  stroke-width: 1.5;
}

.shelter {
  stroke: #777;
  stroke-width: 6;
  stroke-linecap: round;
}

.bubble {
  fill: #fff;
  stroke: #2a78d6;
}

.pump {
  fill: #111;
}

.part-label {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-anchor: middle;
  fill: #111;
}

.part-label.small {
  fill: #fff;
}

.emoji {
  font-size: 22px;
  text-anchor: middle;
}

.part {
  cursor: pointer;
  outline: none;
}

.part:hover .part-box,
.part:focus-visible .part-box {
  stroke: #a35cff;
  stroke-width: 3;
}

.part.is-active .part-box {
  stroke: #a35cff;
  stroke-width: 4;
}

.pump.part-box {
  fill: #111;
}

.flow {
  fill: none;
  stroke: var(--water-line);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 8 8;
  animation: flow 0.8s linear infinite;
}

.air {
  fill: none;
  stroke: #999;
  stroke-width: 2;
  stroke-dasharray: 2 5;
  animation: flow 1.4s linear infinite;
}

.paused .flow,
.paused .air {
  animation-play-state: paused;
}

@keyframes flow {
  to {
    stroke-dashoffset: -16;
  }
}

.diagram figcaption {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
  font-size: 14px;
  color: #555;
}

.legend-water {
  color: var(--water-line);
  font-weight: 700;
}

.diagram .link-button {
  margin-left: auto;
}

.part-info {
  min-height: 120px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafafa;
}

.part-info h3 {
  margin-top: 0;
}

.part-info-empty {
  color: #777;
}

.part-info .bed-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 8px;
}

.part-info .bed-tabs button {
  padding: 4px 12px;
  border: 1px solid #111;
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.part-info .bed-tabs button[aria-pressed="true"] {
  background: #111;
  color: #fff;
}

/* Nitrogen cycle */
.cycle svg {
  max-width: 360px;
  margin: 0 auto;
}

.cycle-ring {
  fill: none;
  stroke: #e4e4e4;
  stroke-width: 10;
}

.cycle-node circle {
  fill: #fff;
  stroke: #111;
  stroke-width: 2;
  transition: fill 0.3s, stroke 0.3s;
}

.cycle-node.is-active circle {
  fill: #f7f3ff;
  stroke: #a35cff;
  stroke-width: 4;
}

.cycle-node text {
  font-family: "Bricolage Grotesque", sans-serif;
  text-anchor: middle;
  font-size: 20px;
}

.cycle-node .node-formula {
  font-weight: 800;
  font-size: 18px;
}

.cycle-node .node-label {
  font-size: 12px;
  fill: #555;
}

.cycle-arrow-label {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 12px;
  font-style: italic;
  text-anchor: middle;
  fill: #555;
}

.cycle figcaption {
  text-align: center;
}

.cycle-caption {
  min-height: 72px;
  margin: 8px auto 12px;
  max-width: 440px;
  font-size: 15px;
}

.cycle-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
}

/* Cycling chart */
.chart {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.chart-title {
  font-weight: 700;
  font-size: 15px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 6px 0 4px;
  font-size: 13px;
  color: #333;
}

.chart-legend i {
  display: inline-block;
  width: 12px;
  height: 3px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: middle;
}

#chart-svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
}

.chart-grid {
  stroke: #eee;
}

.chart-axis {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 12px;
  fill: #737373;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.chart-label {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 12px;
  font-weight: 700;
  fill: #333;
}

.chart-cross {
  stroke: #111;
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-dot {
  stroke: #fff;
  stroke-width: 2;
}

.chart-slider {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
}

.chart-slider input {
  display: block;
  width: 100%;
  margin-top: 4px;
  accent-color: #111;
}

.chart-readout {
  margin-top: 8px;
  font-size: 15px;
}

.chart-table {
  margin-top: 8px;
  font-size: 14px;
}

.chart-table table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
}

.chart-table th,
.chart-table td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

/* Forms */
.calc,
.checker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 16px;
  margin: 20px 0;
}

.field label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #bbb;
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 16px;
}

.field input:focus,
.field select:focus {
  outline: 2px solid #a35cff;
  outline-offset: 1px;
  border-color: transparent;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: end;
  padding-bottom: 10px;
}

.field-check input {
  width: 20px;
  height: 20px;
  accent-color: #111;
}

.field-check label {
  margin: 0;
}

.field .hint {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: #737373;
}

.calc-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.result {
  padding: 14px;
  border-radius: 12px;
  background: #f4f4f4;
}

.result-label {
  font-size: 13px;
  color: #555;
}

.result-value {
  margin: 2px 0;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.result-note {
  font-size: 13px;
  line-height: 1.35;
  color: #555;
}

.calc-warning {
  grid-column: 1 / -1;
  font-size: 15px;
}

.assumptions,
.problems details {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
}

.assumptions summary,
.problems summary,
.chart-table summary {
  font-weight: 700;
  cursor: pointer;
}

.assumptions ul {
  margin-top: 8px;
  font-size: 15px;
}

.problems details {
  margin-top: 8px;
}

.problems details p {
  margin-top: 8px;
  font-size: 15px;
}

/* Parameter checker */
.checker-results {
  display: grid;
  gap: 8px;
}

.status {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.4;
}

.status-icon {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  font-size: 15px;
}

.status-head {
  font-weight: 700;
}

.status-ok {
  background: var(--ok-bg);
}

.status-ok .status-icon {
  background: var(--ok);
}

.status-warn {
  background: var(--warn-bg);
}

.status-warn .status-icon {
  background: var(--warn);
}

.status-bad {
  background: var(--bad-bg);
}

.status-bad .status-icon {
  background: var(--bad);
}

/* Routine */
.routine {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.routine > div {
  padding: 14px;
  border-radius: 12px;
  background: #f4f4f4;
  font-size: 15px;
}

.routine ul {
  padding-left: 18px;
}

/* Quiz */
.quiz-q {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.quiz-question {
  margin-bottom: 10px;
  font-weight: 700;
}

.quiz-options {
  display: grid;
  gap: 6px;
}

.quiz-options button {
  padding: 10px 14px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #fff;
  color: #111;
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.quiz-options button:hover:not(:disabled) {
  border-color: #111;
}

.quiz-options button:disabled {
  cursor: default;
  color: #555;
}

.quiz-options button.is-right {
  border-color: var(--ok);
  background: var(--ok-bg);
  color: #111;
}

.quiz-options button.is-wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
  color: #111;
}

.quiz-feedback {
  margin-top: 10px;
  font-size: 15px;
}

.quiz-score {
  margin-top: 24px;
  padding: 16px;
  border-radius: 12px;
  background: #111;
  color: #fff;
  text-align: center;
}

.quiz-score p:first-child {
  font-size: 22px;
  font-weight: 800;
}

.quiz-score .pill-button {
  margin-top: 12px;
}

/* Glossary & sources */
.glossary,
.sources {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.glossary dl {
  font-size: 15px;
}

.glossary dt {
  margin-top: 12px;
  font-weight: 700;
  scroll-margin-top: 140px;
}

.glossary dt:target {
  color: #a35cff;
}

.sources li {
  margin-bottom: 12px;
  font-size: 15px;
  line-height: 1.5;
}

.sources a {
  color: #111;
  font-weight: 600;
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  .step-title {
    font-size: 26px;
  }

  h1 {
    font-size: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flow,
  .air {
    animation: none;
  }

  .progress-bar span,
  .cycle-node circle {
    transition: none;
  }
}

/* Simulator */
.sim {
  margin: 20px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fafafa;
}

.sim-bed {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px 10px 0 0;
  background: linear-gradient(180deg, transparent 55%, #b98f5f 55%);
  font-size: 30px;
  line-height: 1;
}

.sim-plant {
  transform-origin: bottom center;
  transition: transform 0.4s;
}

.sim-tank {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border: 3px solid #111;
  border-radius: 0 0 12px 12px;
  background: linear-gradient(180deg, #cfe6fa 0%, #a9d1f3 70%, #d9c7a3 88%, #c8b38b 100%);
  cursor: crosshair;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.sim-night {
  position: absolute;
  inset: 0;
  background: #0b1a3a;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s;
}

.sim-shrimp {
  position: absolute;
  font-size: clamp(20px, 5vw, 28px);
  line-height: 1;
  pointer-events: none;
  will-change: transform, left, top;
}

.sim-shrimp.is-soft {
  opacity: 0.55;
  filter: saturate(0.3) brightness(1.3);
}

.sim-shrimp.is-sick {
  filter: grayscale(0.8);
}

.sim-pellet {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8a5a2b;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.sim-pellet.is-old {
  background: #5f6b2a;
}

.sim-shelters {
  position: absolute;
  inset: auto 0 6% 0;
  height: 0;
  pointer-events: none;
}

.sim-shelters i {
  position: absolute;
  bottom: -4px;
  width: 8%;
  height: 12px;
  border-radius: 6px;
  background: #777;
  box-shadow: inset 0 0 0 3px #5f5f5f;
  transform: translateX(-50%);
}

.sim-shelters i:nth-child(1) { left: 9%; }
.sim-shelters i:nth-child(2) { left: 25%; }
.sim-shelters i:nth-child(3) { left: 41%; }
.sim-shelters i:nth-child(4) { left: 59%; }
.sim-shelters i:nth-child(5) { left: 75%; }
.sim-shelters i:nth-child(6) { left: 91%; }

.sim-tank.no-shelters .sim-shelters {
  display: none;
}

.sim-bubbles i {
  position: absolute;
  bottom: 4%;
  left: 50%;
  width: 8px;
  height: 8px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  animation: sim-bubble 2.4s linear infinite;
}

.sim-bubbles i:nth-child(2) { left: 52%; animation-delay: 0.6s; }
.sim-bubbles i:nth-child(3) { left: 49%; animation-delay: 1.2s; }
.sim-bubbles i:nth-child(4) { left: 51%; animation-delay: 1.8s; }

.air-off .sim-bubbles {
  display: none;
}

@keyframes sim-bubble {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-1200%);
    opacity: 0;
  }
}

.sim-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
  cursor: default;
}

.sim-overlay[hidden] {
  display: none;
}

.sim-result {
  max-width: 420px;
  font-weight: 700;
  line-height: 1.4;
}

.sim-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.sim-clock {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sim-speed {
  display: flex;
  gap: 4px;
}

.sim-chip {
  min-width: 44px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #111;
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.sim-chip[aria-pressed="true"] {
  background: #111;
  color: #fff;
}

.sim-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.sim-action {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #111;
  border-radius: 12px;
  background: #fff;
  color: #111;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.sim-action:hover:not(:disabled) {
  background: #f0f0f0;
}

.sim-action[aria-pressed="false"] {
  border-style: dashed;
  color: #555;
}

.sim-action:disabled {
  border-color: #ccc;
  color: #aaa;
  cursor: default;
}

:is(.sim-chip, .sim-action):focus-visible {
  outline: 3px solid #a35cff;
  outline-offset: 2px;
}

.sim-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0 16px;
  margin-top: 12px;
  font-size: 14px;
}

.sim-stats dt {
  margin-top: 8px;
  color: #555;
}

.sim-stats dd {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sim-status {
  font-weight: 600;
}

.sim-ok .sim-status { color: var(--ok); }
.sim-warn .sim-status { color: var(--warn); }
.sim-bad .sim-status { color: var(--bad); }

.sim-log {
  min-height: 48px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #111;
  color: #fff;
  font-size: 15px;
}

@media (prefers-reduced-motion: reduce) {
  .sim-bubbles i {
    animation: none;
    opacity: 0.8;
  }

  .sim-bubbles i:nth-child(2) { transform: translateY(-300%); }
  .sim-bubbles i:nth-child(3) { transform: translateY(-600%); }
  .sim-bubbles i:nth-child(4) { transform: translateY(-900%); }

  .sim-night,
  .sim-plant {
    transition: none;
  }
}
