:root {
  --bg: #0b1a24;
  --card: #12273a;
  --card-2: #183349;
  --line: #24425c;
  --text: #eaf4fb;
  --muted: #8fb0c6;
  --accent: #3fc1ff;
  --accent-ink: #04263a;
  --good: #4fd69c;
  --warn: #ffc24b;
  --bad: #ff6b6b;
  --heat: #ff8a4c;
  --cool: #6fb8ff;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.hidden-input { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* layout */
.screen { min-height: 100vh; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(11, 26, 36, 0.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.title { font-weight: 700; font-size: 20px; letter-spacing: 0.2px; }
main { padding: 4px 16px calc(env(safe-area-inset-bottom) + 84px); max-width: 560px; margin: 0 auto; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: rgba(13, 31, 44, 0.96); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.tabs button { background: none; border: 0; color: var(--muted); font-size: 11px; padding: 4px 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button .ti { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--accent); }

/* cards */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.card-h { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.card-h.row { display: flex; align-items: center; justify-content: space-between; }
.sub { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }
.label { color: var(--muted); font-size: 13px; margin: 14px 0 6px; }
.stamp { color: var(--muted); font-size: 11px; margin-top: 10px; }

/* hero */
.hero { background: linear-gradient(160deg, #134563 0%, #12273a 70%); }
.hero-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.big { font-size: 64px; font-weight: 700; line-height: 1; letter-spacing: -2px; }
.ready { font-size: 18px; font-weight: 600; margin-top: 8px; }
.ready.good { color: var(--good); }
.ready.wait { color: var(--warn); }
.hero-side { text-align: right; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--card-2); font-size: 13px; font-weight: 600; }
.pill.heat { background: rgba(255, 138, 76, 0.18); color: var(--heat); }
.pill.cool { background: rgba(111, 184, 255, 0.18); color: var(--cool); }
.alert { margin-top: 10px; padding: 8px 10px; border-radius: 10px; font-size: 14px; background: rgba(255, 194, 75, 0.12); color: var(--warn); }
.alert.bad { background: rgba(255, 107, 107, 0.14); color: var(--bad); }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; background: var(--card-2); font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn:disabled, .busy { opacity: 0.55; pointer-events: none; }
.link { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 6px 0; }
.round { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--card-2); font-size: 28px; font-weight: 500; }
.temp-row { display: flex; align-items: center; justify-content: space-between; }
.temp-target { font-size: 40px; font-weight: 700; }

/* segmented control */
.seg { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 4px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* switch */
.switch { width: 52px; height: 32px; border-radius: 16px; border: 0; background: #2c4a63; position: relative; padding: 0; flex: none; }
.switch span { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.switch[aria-checked="true"] { background: var(--good); }
.switch[aria-checked="true"] span { left: 23px; }

/* jets */
.jets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.jet { background: var(--card-2); border-radius: 12px; padding: 10px; text-align: center; }
.jet .jn { font-weight: 700; }
.jet .js { font-size: 12px; color: var(--muted); min-height: 16px; }
.jet .jb { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.jet .jb button { border: 0; border-radius: 9px; padding: 7px 0; background: #22425c; font-size: 13px; font-weight: 600; }
.jet .jb button.on { background: var(--accent); color: var(--accent-ink); }
.jet.running { outline: 2px solid var(--accent); }

/* light */
.light-sum { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; border: 2px solid rgba(255, 255, 255, 0.25); vertical-align: middle; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.swatches button { aspect-ratio: 1; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.swatches button.on { border-color: #fff; }
.custom-color { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.custom-color input { width: 44px; height: 32px; border: 0; background: none; padding: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }
.zone { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.zone:first-child { border-top: 0; }
.zone .zl { display: flex; align-items: center; gap: 10px; }

/* scenes */
.scenes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scene { background: var(--card-2); border: 0; border-radius: 12px; padding: 12px; text-align: left; }
.scene b { display: block; }
.scene span { font-size: 12px; color: var(--muted); }

/* care */
.rem, .wc { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.rem:first-child, .wc:first-child { border-top: 0; }
.rem .rd { font-size: 13px; color: var(--muted); }
.rem .rd.due { color: var(--warn); font-weight: 600; }
.rem .ri { background: none; border: 0; color: var(--muted); font-size: 12px; text-decoration: underline; padding: 0; }
.wc { align-items: flex-start; text-align: left; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; color: inherit; }
.wc .wn { font-weight: 600; }
.wc .wd { font-size: 13px; color: var(--muted); margin-top: 2px; }
.wc .wcheck { color: var(--accent); font-weight: 700; flex: none; }
.wc.on .wn { color: var(--accent); }
.log div { font-size: 13px; padding: 6px 0; border-top: 1px solid var(--line); color: var(--muted); }
.log div:first-child { border-top: 0; }
.log b { color: var(--text); font-weight: 600; }

/* chart */
.chart { margin-top: 12px; height: 220px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .empty { color: var(--muted); font-size: 14px; padding: 80px 0; text-align: center; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.lg { width: 14px; height: 3px; display: inline-block; margin-left: 8px; }
.lg.water { background: var(--accent); }
.lg.set { background: var(--muted); }
.lg.heat { background: rgba(255, 138, 76, 0.5); height: 8px; }

/* login */
.login-box { max-width: 360px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 60px) 24px 40px; text-align: center; }
.login-icon { width: 84px; height: 84px; border-radius: 20px; }
.login-box h1 { font-size: 22px; margin: 16px 0 24px; }
.login-box .seg { margin-bottom: 12px; }
.login-box input[type=password] { width: 100%; font-size: 17px; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.msg { color: var(--warn); min-height: 22px; font-size: 14px; }

/* toast + sheet */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 76px); z-index: 20;
  max-width: 528px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: #1f3c55; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); font-size: 14px;
}
.toast.bad { background: #5a2430; }
.toast.good { background: #1d4b3c; }
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; }
.sheet-box { width: 100%; max-width: 560px; margin: 0 auto; background: var(--card); border-radius: 18px 18px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
body.sending main button, body.sending main input { pointer-events: none; opacity: 0.6; }

/* ready by */
.plan { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--card-2); display: flex; gap: 10px; align-items: center; justify-content: space-between; font-size: 14px; }
.plan b { color: var(--accent); }
.plan-form { margin-top: 8px; }
.temp-row.compact { justify-content: center; gap: 24px; }
.round.small { width: 44px; height: 44px; font-size: 22px; }
.temp-target.small { font-size: 28px; }
.time-row { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
input[type=time], .loop-form input[type=text] {
  font: inherit; font-size: 17px; color: var(--text); background: var(--card-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; color-scheme: dark;
}
.check { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.preview { color: var(--muted); font-size: 13px; margin-top: 12px; min-height: 18px; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.row-btns.three { grid-template-columns: 1fr 1fr 1fr; }

/* color loops */
.loop { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.loop:first-child { border-top: 0; }
.loop-main { background: none; border: 0; padding: 0; text-align: left; flex: 1; }
.loop-name { font-weight: 600; }
.loop .playing { color: var(--good); font-size: 12px; font-weight: 600; }
.loop-dots { display: flex; align-items: center; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.loop-dots .dot { width: 14px; height: 14px; }
.loop-form { margin-top: 12px; }
.loop-form input[type=text] { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 36px; align-items: center; }
.chip { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5); padding: 0; }
.swatches.small { grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 10px; }
.vibe-dot { width: 44px !important; border-radius: 7px !important; background: linear-gradient(90deg, #ff2b2b, #ffb020, #3cff6a, #3fd5ff, #8a4dff, #ff2bd6); }

/* settings */
.trow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.trow:first-child { border-top: 0; }

/* water chemistry */
.chem-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chem-tile { background: var(--card-2); border-radius: 12px; padding: 10px; text-align: center; }
.chem-tile .v { font-size: 22px; font-weight: 700; }
.chem-tile .l { font-size: 12px; color: var(--muted); }
.chem-tile.ok .v { color: var(--good); }
.chem-tile.low .v, .chem-tile.high .v { color: var(--warn); }
.chem-advice { font-size: 14px; color: var(--warn); margin-top: 8px; }
.chem-when { font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
.chem-when.due { color: var(--warn); font-weight: 600; }
.chipset { display: flex; flex-wrap: wrap; gap: 6px; }
.chipset button { border: 0; border-radius: 999px; padding: 8px 12px; background: var(--card-2); font-size: 14px; font-weight: 600; }
.chipset button.on { background: var(--accent); color: var(--accent-ink); }
#chem-form input[type=text] { width: 100%; margin-top: 12px; font: inherit; font-size: 16px; color: var(--text); background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.chem-tabs { margin-top: 16px; }
.chart.small { height: 170px; }
.log .del { float: right; background: none; border: 0; color: var(--muted); font-size: 16px; padding: 0 4px; }

/* supplies */
.sup { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.sup:first-child { border-top: 0; }
.sup-main { background: none; border: 0; padding: 0; text-align: left; flex: 1; min-width: 0; }
.sup-name { font-weight: 600; }
.sup-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sup-low { font-size: 12px; font-weight: 700; color: var(--warn); }
.sup-btns { display: flex; gap: 6px; flex: none; }
a.btn { text-decoration: none; display: inline-block; text-align: center; }
.sup-form input[type=text], .sup-form input[type=url] {
  width: 100%; margin-top: 10px; font: inherit; font-size: 16px; color: var(--text); background: var(--card-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.alert.link { cursor: pointer; }
