:root {
  color-scheme: light;
  --navy: #013449;
  --ink: #112f3f;
  --muted: #456372;
  --teal: #006d62;
  --mint: #ddf5ef;
  --line: #d5e5e7;
  --panel: #f3f8f8;
  --amber: #79500b;
  --amber-panel: #fff1d8;
  --canvas: #eaf3f3;
  --surface: #fff;
  --on-accent: #fff;
  --step-fill: #e4edee;
  --track: #d7e7e8;
  --selected-line: #a7ddd0;
  --amber-line: #e6bc73;
  font: 400 15px/1.5 "HarmonyOS Sans SC", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
}
[data-theme="dark"] {
  color-scheme: dark;
  --navy: #0a2536;
  --ink: #e8f0f8;
  --muted: #a6bacb;
  --teal: #69dfce;
  --mint: #163b3b;
  --line: #29445b;
  --panel: #14273a;
  --amber: #ffd18a;
  --amber-panel: #3a2a17;
  --canvas: #08121f;
  --surface: #0e1c2c;
  --on-accent: #08262c;
  --step-fill: #253a4c;
  --track: #264258;
  --selected-line: #47867f;
  --amber-line: #986e3a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button { font: inherit; }
a, button { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible { outline: 3px solid #178a80; outline-offset: 3px; }
h1, h2, h3, p, figure { margin: 0; }

#ba-water-flow { max-width: 440px; margin-inline: auto; }
.phone {
  min-height: calc(100svh - 31px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 8px;
  min-height: 48px;
  padding: 2px 12px;
  background: var(--surface);
}
.library {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 3px;
  color: var(--teal);
  font-size: 13px;
  text-decoration: none;
}
.theme-switch {
  display: flex;
  gap: 2px;
  border-radius: 10px;
  background: var(--panel);
}
.theme-switch label { position: relative; cursor: pointer; }
.theme-switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.theme-switch span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.theme-switch input:checked + span { background: var(--mint); border-color: var(--selected-line); color: var(--teal); font-weight: 700; }
.theme-switch input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: -3px; }
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 10px 16px;
  background: var(--navy);
  color: white;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { display: block; height: 23px; width: auto; }
.brand-caption { color: #b8e8e6; font-size: 12px; }
header button {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #6da3ad;
  border-radius: 10px;
  background: transparent;
  color: white;
  font-size: 13px;
}
header button[aria-pressed="true"] { background: #b7efdf; color: var(--navy); border-color: #b7efdf; }
.screen { display: flex; flex-direction: column; flex: 1; gap: 12px; padding: 14px 16px 0; }
.stage-rail {
  display: grid;
  grid-template-columns: .82fr 1.12fr 1fr;
  gap: 4px;
  margin: 0 0 3px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  list-style: none;
}
.stage-rail li {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 3px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.stage-rail li span {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  background: var(--step-fill);
  font-size: 11px;
}
.stage-rail li[data-state="current"] { background: var(--mint); border-radius: 8px; color: var(--teal); font-weight: 700; }
.stage-rail li[data-state="current"] span { background: var(--teal); color: var(--on-accent); }
.stage-rail li[data-state="done"] { color: var(--teal); }
.stage-rail li[data-state="done"] span { background: var(--mint); font-size: 0; }
.stage-rail li[data-state="done"] span::after { content: "✓"; font-size: 12px; }
.stage-rail li[data-state="skipped"] { color: var(--amber); }
.stage-rail li[data-state="skipped"] span { background: var(--amber-panel); }
.sub { color: var(--muted); }
[data-role="step"] { font-size: 12px; font-weight: 600; margin-bottom: -7px; }
h1 { font-size: clamp(25px, 6.8vw, 30px); line-height: 1.16; letter-spacing: -.025em; }
[data-role="detail"] { font-size: 14px; }
.quick-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  list-style: none;
  padding: 0;
  margin: 0;
}
.quick-steps li {
  position: relative;
  min-width: 0;
}
.quick-steps li:not(:last-child)::after {
  content: "→";
  position: absolute;
  top: 50%;
  left: 100%;
  width: 16px;
  transform: translateY(-50%);
  text-align: center;
  line-height: 1;
  font-weight: 700;
  color: var(--teal);
  pointer-events: none;
}
.quick-steps button {
  display: grid;
  align-content: start;
  gap: 3px;
  width: 100%;
  height: 100%;
  padding: 8px 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  cursor: pointer;
}
.quick-steps button:hover { border-color: var(--teal); background: var(--mint); }
.quick-steps .step-number { color: var(--teal); font: 700 30px/1 system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.quick-steps strong { color: var(--ink); font-size: 14px; }
.step-hint { margin-top: -7px; color: var(--teal); font-size: 12px; }
.view {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 10px 8px;
  border-radius: 15px;
  background: radial-gradient(ellipse at center, #13465a, #082a3a 80%);
  color: #c0dfe4;
  overflow: hidden;
}
.finder {
  display: grid;
  place-items: center;
  position: relative;
  width: 76px;
  height: clamp(128px, 23svh, 200px);
}
.finder img {
  position: absolute;
  top: 8px;
  left: 50%;
  width: auto;
  height: calc(100% - 16px);
  max-width: calc(100% - 12px);
  transform: translateX(-50%);
  object-fit: contain;
  filter: drop-shadow(0 6px 7px #001420c0);
}
.frame { position: absolute; z-index: 1; inset: 1px 4px; pointer-events: none; }
.frame span { position: absolute; width: 15px; height: 15px; border: solid #82d7cf; }
.frame span:nth-child(1) { left: 0; top: 0; border-width: 2px 0 0 2px; border-top-left-radius: 5px; }
.frame span:nth-child(2) { right: 0; top: 0; border-width: 2px 2px 0 0; border-top-right-radius: 5px; }
.frame span:nth-child(3) { left: 0; bottom: 0; border-width: 0 0 2px 2px; border-bottom-left-radius: 5px; }
.frame span:nth-child(4) { right: 0; bottom: 0; border-width: 0 2px 2px 0; border-bottom-right-radius: 5px; }
.view[data-ready="true"] .frame span { border-color: #7af2d3; }
.view figcaption { font-size: 12px; }
.photo-review { overflow: hidden; border-radius: 15px; border: 1px solid var(--line); }
.photo-area {
  display: grid;
  place-items: center;
  padding: 12px;
  background: radial-gradient(ellipse at center, #40535c, #223741 90%);
}
.photo-area img { height: clamp(145px, 27svh, 250px); max-width: 100%; object-fit: contain; }
.photo-review figcaption { display: flex; justify-content: space-between; gap: 8px; padding: 8px 11px; font-size: 12px; }
.photo-stage { color: var(--teal); font-weight: 600; }
.photo-switch { display: flex; flex-wrap: wrap; gap: 8px; padding: 5px 10px 10px; }
.photo-switch button, .drawer-heading button {
  min-height: 44px;
  padding-inline: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
}
.photo-switch button[aria-pressed="true"] { background: var(--mint); color: var(--teal); border-color: var(--selected-line); }
.timer-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.clock { font-size: 32px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.timer-panel[data-state="ready"] { background: var(--mint); }
.timer-panel[data-state="ready"] .clock { color: var(--teal); }
.timer-panel > span { font-size: 13px; }
.timer-track { grid-column: 1/-1; height: 4px; border-radius: 4px; background: var(--track); overflow: hidden; }
.timer-track i { display: block; height: 100%; background: var(--teal); transform-origin: left; }
.status { padding: 8px 10px; background: var(--mint); border-radius: 9px; color: var(--teal); font-size: 13px; font-weight: 600; }
.results { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.results-hint { grid-column: 1/-1; font-size: 13px; }
.parameter {
  display: grid;
  align-content: center;
  gap: 4px;
  min-height: 65px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
  background: var(--panel);
  color: var(--ink);
}
.parameter-name { display: flex; align-items: baseline; flex-wrap: wrap; gap: 3px 6px; font-size: 13px; font-weight: 600; }
.parameter-code { color: var(--muted); font-size: 11px; font-weight: 500; }
[data-reading] { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.parameter[data-incomplete], .drawer-reading[data-incomplete] { background: var(--amber-panel); border-color: var(--amber-line); }
.parameter[data-incomplete] [data-reading], .drawer-reading[data-incomplete] output { color: var(--amber); }

.actions {
  position: sticky;
  z-index: 2;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: auto -16px 0;
  padding: 9px 16px max(9px,env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.actions button {
  flex: 1 1 140px;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--teal);
  font-weight: 600;
  font-size: 14px;
}
.actions .primary { flex-basis: 100%; min-height: 48px; background: var(--teal); border-color: var(--teal); color: var(--on-accent); }
.demo-label { margin: 0; padding: 6px 12px; text-align: center; color: var(--muted); font-size: 12px; }
.parameter-drawer {
  position: fixed;
  inset: auto 0 0;
  width: min(100%,440px);
  max-width: 100%;
  max-height: 86dvh;
  margin: 0 auto;
  padding: 16px 16px max(16px,env(safe-area-inset-bottom));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  color: var(--ink);
}
.parameter-drawer::backdrop { background: #07253295; }
.drawer-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.drawer-heading h2 { font-size: 23px; }
.drawer-reading { display: flex; justify-content: space-between; align-items: center; padding: 10px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; }
.drawer-reading output { font-size: 20px; font-weight: 700; color: var(--teal); }
.drawer-section { margin-top: 10px; font-size: 14px; }
.drawer-section h3 { font-size: 13px; color: var(--teal); margin-bottom: 3px; }
.step-demo .drawer-heading form { margin: 0; }
.step-demo p { margin-block: 12px; }
.demo-replay {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--teal);
  border-radius: 10px;
  background: var(--mint);
  color: var(--teal);
  font-weight: 600;
}
.demo-scene {
  position: relative;
  height: 190px;
  overflow: hidden;
  border-radius: 14px;
  background: radial-gradient(ellipse at center, #185063, #082a3a 82%);
}
.demo-scene > div { position: absolute; }
.demo-board { inset: 15px 0; display: grid; place-items: center; }
.demo-board img { height: 100%; max-height: 160px; width: auto; }
.demo-cup, .demo-tissue, .demo-strip, .demo-frame, .demo-shutter { display: none; }
.demo-strip {
  z-index: 1;
  top: 12px;
  left: calc(50% - 4px);
  width: 8px;
  height: 94px;
  padding: 39px 1px 0;
  border-radius: 2px;
  background: #f9fcf6;
}
.demo-strip i { display: block; height: 7px; margin: 3px 0; background: #f5be64; }
.demo-strip i:nth-child(2) { background: #75ceb6; }
.demo-strip i:nth-child(3) { background: #89b4dc; }
.demo-scene[data-step="dip"] .demo-strip,
.demo-scene[data-step="place"] .demo-strip,
.demo-scene[data-step="dip"] .demo-cup,
.demo-scene[data-step="place"] .demo-tissue,
.demo-scene[data-step="capture"] :is(.demo-frame,.demo-shutter) { display: block; }
.demo-cup {
  z-index: 2;
  top: 87px;
  left: calc(50% - 41px);
  width: 82px;
  height: 86px;
  border: 2px solid #a6dfe4;
  border-top: 0;
  border-radius: 0 0 13px 13px;
  background: linear-gradient(transparent 30%, #72d7e98f 31% 100%);
}
.demo-tissue { left: 12%; bottom: 29px; width: 25%; height: 21px; border-radius: 3px; background: #c7d7d7; transform: skew(-20deg); }
.demo-scene[data-step="place"] .demo-strip { top: 39px; }
.demo-frame { inset: 10px calc(50% - 39px); border: 2px dashed #9de7dc; border-radius: 7px; }
.demo-shutter {
  right: 14%;
  bottom: 17px;
  width: 25px;
  height: 25px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #a3ebdd;
  box-shadow: inset 0 0 0 2px #174f5c;
}
.demo-flash { inset: 0; background: #d9fff3; opacity: 0; pointer-events: none; }
.demo-scene[data-step="dip"].playing .demo-strip { animation: dip-demo 2.6s ease-in-out both; }
.demo-scene[data-step="place"].playing .demo-strip { animation: place-demo 2.7s ease-in-out both; }
.demo-scene[data-step="capture"].playing .demo-board { animation: aim-demo 1.9s ease-out both; }
.demo-scene[data-step="capture"].playing .demo-shutter { animation: shutter-demo 2.5s ease-in-out both; }
.demo-scene[data-step="capture"].playing .demo-flash { animation: flash-demo 2.5s ease-in-out both; }
@keyframes dip-demo {
  0%, 100% { transform: translateY(0); }
  33%, 72% { transform: translateY(64px); }
}
@keyframes place-demo {
  0% { transform: translate(-75px, -8px) rotate(24deg); }
  18%, 39% { transform: translate(-76px, 31px) rotate(29deg); }
  28% { transform: translate(-76px, 22px) rotate(29deg); }
  64% { transform: translate(-35px, -14px) rotate(12deg); }
  92% { transform: translate(0, 0); opacity: 1; }
  100% { transform: translate(0, 0); opacity: 0; }
}
@keyframes aim-demo {
  from { transform: translate(42px, 12px) rotate(11deg) scale(.82); }
  to { transform: translate(0, 0) rotate(0) scale(1); }
}
@keyframes shutter-demo {
  0%, 72%, 90%, 100% { transform: scale(1); }
  80% { transform: scale(.76); background: #fff; }
}
@keyframes flash-demo {
  0%, 76%, 94%, 100% { opacity: 0; }
  80% { opacity: .42; }
}
@media (prefers-reduced-motion: reduce) {
  .demo-scene.playing > div { animation: none !important; }
  .demo-scene[data-step="dip"] .demo-strip { transform: translateY(64px); }
  .demo-scene[data-step="place"] .demo-strip { opacity: 0; }
}
@media (min-width: 500px) {
  #ba-water-flow { padding-top: 16px; }
  .phone { min-height: calc(100svh - 49px); border-radius: 18px; overflow: clip; border: 1px solid var(--line); }
}
