/* Hallmark · pre-emit critique: P5 H5 E5 S5 R4 V4
 * genre: playful · macrostructure: Map / Diagram (user-directed reuse) · theme: Hum
 * tone: colourful, mechanical, hydraulic · anchor: clear water blue · nav: N9 · footer: Ft2
 * motion: staged current · mechanical turns · continuous pressure surge
 * enrichment: E5 hand-built SVG hydraulic system
 * knobs: flow=depth-staged (was simultaneous) · pipes=layered mechanical (was flat) · HUD=live gauges (was status-only)
 * contrast: pass (40–41) · slop: static pass except phone-width render held for formal Ready Check
 */
* { box-sizing: border-box; }

html {
  min-width: 320px;
  overflow-x: clip;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: clip;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.55;
}

button,
a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[tabindex="-1"]:focus { outline: none; }

.edge-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3.2rem;
  padding: 0.45rem max(0.6rem, env(safe-area-inset-left));
  border-bottom: 3px solid var(--ink);
  color: var(--ink);
  background: var(--signal);
  box-shadow: 0 5px 0 var(--pump);
}

.edge-nav__brand {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.edge-nav__tools {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.edge-nav__link,
.plain-button {
  min-height: 2.45rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid transparent;
  color: var(--ink);
  background: transparent;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.edge-nav__link { display: none; }
.edge-nav__link:active,
.plain-button:active { transform: translateY(2px); }
.plain-button:disabled { cursor: not-allowed; opacity: 0.55; background: var(--paper); }

.ad-rail {
  width: min(calc(100% - 0.7rem), var(--measure));
  min-height: 5.5rem;
  margin: 0.7rem auto;
  border: 2px dashed var(--ink);
  border-radius: var(--radius-input);
  color: var(--muted);
  background: var(--paper-2);
  text-align: center;
}

.ad-rail__label {
  margin: 0;
  padding: 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pipes-app {
  width: min(calc(100% - 0.7rem), 60rem);
  margin: 0 auto;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: var(--radius-card);
  background: var(--paper-2);
  box-shadow: 12px 14px 0 var(--pump), 0 1.2rem 2.8rem var(--shadow);
}

.screen { min-height: 0; }
.screen--title {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.title-copy {
  align-self: center;
  padding: 1.4rem 1.15rem 2rem;
}

.kicker,
.line-code,
.metric dt,
.control-key,
.campaign-status {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.kicker { color: var(--pump); font-weight: 800; }
h1,
h2,
h3,
p { margin-top: 0; }
h1,
h2 { min-width: 0; overflow-wrap: anywhere; font-style: normal; }

.title-copy h1 {
  max-width: 11ch;
  min-width: 0;
  margin-bottom: var(--space-3);
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: var(--step-4);
  line-height: 1;
  letter-spacing: -0.055em;
}

.title-copy__lede {
  max-width: 36rem;
  color: var(--muted);
  font-size: var(--step-1);
}

.campaign-status {
  margin-block: var(--space-4);
  color: var(--muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.button {
  min-height: 2.9rem;
  padding: 0.7rem 1rem;
  border: 2px solid var(--ink);
  border-radius: var(--radius-input);
  color: var(--ink);
  background: var(--paper-3);
  box-shadow: 0 5px 0 var(--ink);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-short) var(--ease-out);
}

.button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--ink);
}

.button--primary {
  border-color: var(--pump);
  color: var(--accent-ink);
  background: var(--pump);
}

.button--valve {
  border-color: var(--water-deep);
  color: var(--paper);
  background: var(--water-deep);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.flow-map {
  display: grid;
  place-items: center;
  min-height: 14rem;
  margin: 0;
  padding: 1.25rem;
  border-top: 4px solid var(--ink);
  color: var(--ink);
  background: var(--cyan);
}

.flow-map svg {
  width: min(100%, 23rem);
  max-height: 14rem;
  height: auto;
}

.flow-map:hover *,
.flow-map:focus * { animation-play-state: paused; }

.map-pipe-casing,
.map-pipe-channel,
.map-water {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.map-pipe-casing { stroke: var(--pipe-casing); stroke-width: 24; }
.map-pipe-channel { stroke: var(--pipe-channel); stroke-width: 14; }
.map-water {
  stroke: var(--water);
  stroke-width: 9;
  opacity: 0.8;
}

.map-current {
  fill: var(--water-foam);
  stroke: var(--water-deep);
  stroke-width: 2;
  transform-box: fill-box;
  transform-origin: center;
}

.map-current--rise { animation: map-current-rise 2.4s linear infinite; }
.map-current--branch { animation: map-current-branch 1.8s linear 360ms infinite; }
.map-current--roof { animation: map-current-roof 1.4s linear 720ms infinite; }

.map-pump-ring {
  fill: none;
  stroke: var(--pump);
  stroke-width: 5;
  transform-box: fill-box;
  transform-origin: center;
  animation: pressure-pulse 1.4s var(--ease-in-out) infinite;
}

.map-pump { fill: var(--pump); stroke: var(--ink); stroke-width: 4; }
.map-outlet { fill: var(--outlet-wet); stroke: var(--water-deep); stroke-width: 5; }
.map-outlet.outlet-b { fill: var(--safe); }
.map-outlet.outlet-c { fill: var(--lavender); }
.map-joint { fill: var(--water); stroke: var(--ink); stroke-width: 4; }
.map-valve {
  fill: var(--signal);
  stroke: var(--ink);
  stroke-width: 3;
  transform-box: fill-box;
  transform-origin: center;
  animation: map-valve-turn 3.2s linear infinite;
}

.map-valve path { fill: none; stroke-linecap: round; }
.map-label { fill: var(--muted); font: 700 9px var(--font-mono); letter-spacing: 1px; }

.screen--levels {
  padding: clamp(1rem, 4vw, 2.5rem);
}

.screen-heading {
  position: relative;
  display: block;
  padding-right: 5rem;
  border-bottom: 1px solid var(--rule);
}

.screen-heading .plain-button {
  position: absolute;
  right: 0;
  bottom: 0.5rem;
}

.screen-heading h1 {
  font-family: var(--font-mono);
  font-size: var(--step-3);
  letter-spacing: -0.04em;
}

.district { margin-block: var(--space-5); }
.district h2 {
  color: var(--muted);
  font: 700 var(--step--1) var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

.level-button {
  display: grid;
  min-height: 4rem;
  min-width: 0;
  padding: 0.45rem;
  border: 2px solid var(--ink);
  border-radius: var(--radius-input);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform var(--dur-short) var(--ease-out);
}

.level-button strong {
  color: var(--water-deep);
  font: 700 var(--step-1) var(--font-mono);
}

.level-button span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-button:disabled { opacity: 0.38; cursor: not-allowed; }
.level-button:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.level-button:nth-child(5n + 1) { background: var(--color-coral-band); }
.level-button:nth-child(5n + 2) { background: var(--color-cyan-band); }
.level-button:nth-child(5n + 3) { background: var(--color-mint); }
.level-button:nth-child(5n + 4) { background: var(--color-paper-2); }
.level-button:nth-child(5n) { background: color-mix(in oklch, var(--lavender) 42%, var(--paper)); }

.screen--play { padding: 0.65rem 0.35rem; }
.line-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 0.4rem;
  padding: 0.25rem 0 0.7rem;
  border-bottom: 1px solid var(--rule);
}

.line-header h1 {
  margin-bottom: 0.1rem;
  font: 700 var(--step-2) var(--font-mono);
  letter-spacing: -0.04em;
}

.line-code { margin-bottom: 0; color: var(--water-deep); }
.line-district { margin: 0; color: var(--muted); }
.metric { min-width: 3.3rem; margin: 0; text-align: right; }
.metric dt { color: var(--muted); }
.metric dd { margin: 0; font: 700 var(--step-2) var(--font-mono); }

.flow-status {
  min-height: 2.8rem;
  width: min(100%, 32rem);
  margin: 0 auto;
  padding: 0.65rem 0.1rem;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 700;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.25rem;
  width: min(100%, 32rem);
  margin: 0 auto;
}

.control {
  min-height: 3.15rem;
  padding: 0.45rem 0.2rem;
  font-size: 0.76rem;
}

.control-key { display: block; color: currentColor; opacity: 0.72; }
.valve { grid-column: 1 / -1; }
.valve:not(:disabled) { animation: valve-ready 1.25s var(--ease-in-out) infinite; }

.game-note {
  width: min(calc(100% - 1.25rem), 60rem);
  margin: var(--space-6) auto;
  color: var(--muted);
}

.game-note h2,
.game-note h3 {
  break-after: avoid;
  color: var(--ink);
  font-family: var(--font-mono);
}

.game-note h2 { font-size: var(--step-2); }
.game-note h3 { font-size: var(--step-1); }
.game-note a { color: var(--water-deep); }

.inline-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem max(0.75rem, env(safe-area-inset-left)) max(1.2rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  color: var(--muted);
  background: var(--paper-2);
  font-size: var(--step--1);
}

.inline-footer nav { display: flex; flex-wrap: wrap; gap: 1rem; }
.inline-footer a { white-space: nowrap; }

dialog {
  position: fixed;
  inset: 0;
  width: min(calc(100% - 1.25rem), 34rem);
  height: fit-content;
  max-height: min(85vh, 42rem);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 4px solid var(--ink);
  border-radius: var(--radius-card);
  color: var(--ink);
  background: var(--paper-2);
  box-shadow: 12px 14px 0 var(--pump);
}

dialog::backdrop { background: var(--backdrop); }
.dialog-body { padding: clamp(1rem, 4vw, 2rem); }
.dialog-body h2 { font: 700 var(--step-2) var(--font-mono); }
.dialog-body ol { padding-left: 1.25rem; }
.dialog-body li + li { margin-top: 0.65rem; }
.stars { color: var(--pump); font-size: var(--step-3); letter-spacing: 0.1em; }

@media (hover: hover) and (pointer: fine) {
  .edge-nav__link:hover,
  .plain-button:hover { border-color: var(--ink); background: var(--paper-2); }
  .button:hover:not(:disabled),
  .level-button:not(:disabled):hover,
  .pipe-tile:hover { transform: translateY(-2px); }
}

@media (pointer: coarse) {
  .button,
  .plain-button,
  .edge-nav__link { min-height: 48px; }
}

@media (min-width: 40rem) {
  .edge-nav__link { display: inline-flex; align-items: center; }
  .level-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .screen--play { padding: clamp(0.65rem, 2vw, 1.2rem); }
  .line-header { gap: 0.75rem; }
  .metric { min-width: 4.2rem; }
  .controls { gap: 0.35rem; }
  .control { padding-inline: 0.25rem; font-size: var(--step--1); }
  .game-note { columns: 2 22rem; column-gap: 3rem; }
}

@media (min-width: 45rem) {
  .screen--title { grid-template-columns: minmax(0, 1.1fr) minmax(15rem, 0.9fr); }
  .title-copy { padding: clamp(1.4rem, 5vw, 4rem); padding-block-end: clamp(2rem, 7vw, 5.5rem); }
  .flow-map { min-height: 22rem; padding: clamp(1.25rem, 4vw, 3rem); border-top: 0; border-left: 4px solid var(--ink); }
  .flow-map svg { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }

  .map-current,
  .map-valve,
  .water-bead,
  .pump-rotor,
  .outlet-tank b,
  .pipe-leak i,
  .pipes-board::after,
  .surge-tail { display: none; }

  .pipe-leak::after,
  .flow-burst { display: none; }
}
