:root {
  --bg-top: #e0f2fe;
  --bg-bottom: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --surface: #f8fafc;
  --accent: #0e7490;
  --accent-strong: #155e75;
  --heat: #f97316;
  --filter: #0ea5e9;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --off: #cbd5e1;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(var(--bg-top), var(--bg-bottom)) fixed;
}

/* ---------- header / nav ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 700;
}

.brand-icon {
  color: var(--heat);
  font-size: 1.4rem;
}

.nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: #f1f5f9;
}

.nav-tab {
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}

.nav-tab.active {
  background: var(--card);
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.connection {
  margin-left: auto;
  font-size: 0.85rem;
}

@media (max-width: 599px) {
  .app-header {
    padding: 10px 12px;
  }
  .nav {
    order: 3;
    width: 100%;
  }
  .nav-tab {
    flex: 1;
    text-align: center;
  }
}

/* ---------- layout ---------- */

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  transition: opacity 0.3s;
}

.page.stale {
  opacity: 0.55;
}

@media (max-width: 599px) {
  .page {
    padding: 12px;
  }
}

.card {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.loading {
  padding: 60px 20px;
  color: var(--muted);
  text-align: center;
}

.control-layout,
.diagnostic-layout {
  display: grid;
  gap: 20px;
}

@media (min-width: 900px) {
  .control-layout {
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    align-items: start;
  }
}

@media (min-width: 760px) {
  .diagnostic-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* ---------- status lights ---------- */

.status-light {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.light {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--off);
}

.light-on {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2), 0 0 12px var(--green);
}

.light-waiting {
  background: var(--yellow);
  animation: pulse 1.2s ease-in-out infinite;
}

.light-error {
  background: var(--red);
}

/* ---------- tub ---------- */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 12px;
}

.banner-error {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.tub {
  display: block;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.ground {
  fill: rgba(15, 23, 42, 0.08);
}

.tub-shell {
  fill: #475569;
}

.tub-wall {
  fill: none;
  stroke: #94a3b8;
  stroke-width: 10;
  stroke-linejoin: round;
}

.tub-rim {
  stroke: #64748b;
  stroke-width: 1.5;
}

.rivet {
  fill: #64748b;
}

.tub-temp {
  font-size: 52px;
  font-weight: 800;
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(3, 105, 161, 0.6);
  stroke-width: 4px;
}

.tub-temp-caption {
  font-size: 15px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  fill: #e0f2fe;
}

.wave {
  animation: wave 4s linear infinite;
}

.wave-back {
  opacity: 0.8;
  animation-duration: 6s;
  animation-direction: reverse;
}

.duck-bob {
  transform-box: fill-box;
  transform-origin: center;
  animation: bob 2.4s ease-in-out infinite;
}

.steam {
  opacity: 0;
  transition: opacity 1s;
}

.steam.on {
  opacity: 1;
}

.steam-puff {
  fill: none;
  stroke: #cbd5e1;
  stroke-width: 5;
  stroke-linecap: round;
  animation: rise 3s ease-in-out infinite;
}

.steam-puff:nth-child(2) {
  animation-delay: 1s;
}

.steam-puff:nth-child(3) {
  animation-delay: 2s;
}

/* ---------- pumps ---------- */

.pumps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 420px;
  margin: 8px auto 0;
}

.pump {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pump-svg {
  width: 96px;
  height: 96px;
}

.pump-frame {
  fill: #f1f5f9;
  stroke: var(--border);
  stroke-width: 2;
}

.pump-housing {
  fill: #1e293b;
}

.pump-hub {
  fill: #e2e8f0;
}

.fan-blades {
  opacity: 0.5;
  transform-box: view-box;
  transform-origin: 60px 60px;
  transition: opacity 0.3s;
}

.pump-heat .fan-blades {
  fill: var(--heat);
}

.pump-filter .fan-blades {
  fill: var(--filter);
}

.pump.running .fan-blades {
  opacity: 1;
  animation: spin 0.9s linear infinite;
}

.pump-label {
  font-weight: 700;
}

@media (max-width: 400px) {
  .pump-svg {
    width: 80px;
    height: 80px;
  }
}

/* ---------- settings ---------- */

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.target-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.target-value {
  color: var(--accent-strong);
  font-size: 3.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.round-btn {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.round-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.modes {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font: inherit;
  font-size: 1.05rem;
}

.summary {
  display: grid;
  gap: 10px;
  margin: 0;
}

.summary div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.summary dt {
  color: var(--muted);
}

.summary dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 22px;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text);
}

.btn-small {
  padding: 6px 12px;
  background: #991b1b;
  color: #fff;
  font-size: 0.875rem;
}

.big-button {
  width: 100%;
  min-height: 110px;
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #fff;
  font: inherit;
  font-size: 1.75rem;
  font-weight: 800;
  cursor: pointer;
}

.big-button-backflush {
  background: linear-gradient(135deg, #0ea5e9, #0369a1);
}

.big-button-setup {
  background: linear-gradient(135deg, #14b8a6, #0f766e);
}

.big-button:active:not(:disabled) {
  transform: translateY(1px);
}

.round-btn:disabled,
.btn:disabled,
.big-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- diagnostic ---------- */

.backflush-slot {
  display: grid;
  place-items: center;
  min-height: 190px;
  margin-top: 16px;
}

.hint {
  max-width: 320px;
  color: var(--muted);
  text-align: center;
}

.backflush-anim {
  color: var(--accent-strong);
  font-weight: 600;
  text-align: center;
}

.backflush-anim svg {
  width: 140px;
  height: 140px;
}

.backflush-anim p {
  margin: 6px 0 0;
}

.backflush-arrows {
  fill: none;
  stroke: var(--filter);
  stroke-width: 6;
  stroke-linecap: round;
  transform-box: view-box;
  transform-origin: 60px 60px;
  animation: spin 2s linear infinite;
}

.backflush-arrows .arrowhead {
  fill: var(--filter);
  stroke: none;
}

.droplet {
  fill: #38bdf8;
}

.droplet-eye {
  fill: var(--text);
}

.droplet-smile {
  fill: none;
  stroke: var(--text);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.bubble {
  fill: #7dd3fc;
  transform-box: fill-box;
  animation: bubble 1.8s ease-in infinite;
}

.bubble.b2 {
  animation-delay: 0.6s;
}

.bubble.b3 {
  animation-delay: 1.2s;
}

.readings {
  margin-top: 20px;
}

.readings-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.setup-state {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: capitalize;
}

.probe-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.probe-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
}

.probe-row .status-light {
  color: var(--text);
}

.probe-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- sensor setup ---------- */

.setup-card {
  max-width: 640px;
  margin: 0 auto;
}

.setup-card h1 {
  margin: 0 0 16px;
  font-size: 1.5rem;
}

.stepper {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stepper li {
  flex: 1;
  padding-top: 10px;
  border-top: 4px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.stepper li.done,
.stepper li.current {
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
}

.setup-step h2 {
  margin: 24px 0 8px;
  font-size: 1.25rem;
}

.setup-step p {
  color: var(--muted);
  line-height: 1.5;
}

.setup-status {
  margin: 20px 0;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface);
}

.setup-status .status-light {
  color: var(--text);
  font-size: 1.1rem;
}

.setup-status .light {
  width: 22px;
  height: 22px;
}

.actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 24px;
}

/* ---------- mock backend panel (not part of the app) ---------- */

.mock-panel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 50;
  max-width: 250px;
  border: 2px dashed #f59e0b;
  border-radius: 12px;
  background: #fffbeb;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
}

.mock-panel summary {
  padding: 8px 12px;
  color: #92400e;
  font-weight: 700;
  cursor: pointer;
}

.mock-panel-body {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.mock-panel label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mock-panel button {
  padding: 6px 8px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* ---------- animation ---------- */

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

@keyframes wave {
  to {
    transform: translateX(-100px);
  }
}

@keyframes bob {
  50% {
    transform: translateY(4px) rotate(-4deg);
  }
}

@keyframes rise {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  40% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translateY(-14px);
  }
}

@keyframes bubble {
  0% {
    opacity: 0;
    transform: translateY(0);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-40px);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
