/* App layout + components. Visual spec: docs/design/v4-prototype/. The
   prototype's 390×844 phone frame is a canvas artifact — on device the app
   fills the viewport; on desktop it centers a phone-width column. */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
::-webkit-scrollbar { width: 0; height: 0; }
a { color: var(--accent-2); text-decoration: none; }

#frame {
  position: relative;
  max-width: 430px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }

@keyframes lvFlowY { from { background-position: 0 320px; } to { background-position: 0 -60px; } }
@keyframes lvBlink { 50% { opacity: 0.15; } }
@keyframes lvArc { from { stroke-dashoffset: 0; } to { stroke-dashoffset: var(--travel); } }

/* type utilities */
.mono { font-family: var(--mono); }
.display { font-family: var(--display); font-weight: var(--dw); }
.kicker { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.18em; }

/* header */
.topbar {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 30px 0;
}
.topbar .mark { display: block; }
.topbar-right { display: flex; align-items: center; gap: 16px; font-family: var(--mono); }
.topbar-ask { cursor: pointer; font-size: 9.5px; letter-spacing: 0.18em; color: var(--ink-45); padding: 8px 0; }
.topbar-ask.active { color: var(--accent-2); }
.health { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 8px 0; }
.health-dot { width: 6px; height: 6px; border-radius: 50%; }
.health-word { font-size: 9.5px; letter-spacing: 0.18em; color: var(--ink-45); }

/* start + setup */
.hero-center {
  flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 30px; padding: 0 44px; text-align: center;
}
.hero-center h1 { margin: 0; font-family: var(--display); font-weight: var(--dw); font-size: 44px; line-height: 1.05; color: var(--ink); }
.hero-body { font-size: 14px; line-height: 1.65; color: var(--ink-60); max-width: 250px; text-wrap: pretty; }

.setup { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 26px; padding: 0 44px; }
.setup-progress { display: flex; gap: 5px; }
.setup-progress span { width: 22px; height: 2px; background: var(--ink-16); }
.setup-progress span.done { background: var(--accent); }
.setup h1 { margin: 0; font-family: var(--display); font-weight: var(--dw); font-size: 38px; line-height: 1.05; color: var(--ink); }
.setup-body { font-size: 14px; line-height: 1.65; color: var(--ink-60); text-wrap: pretty; }
.led-cue { display: flex; justify-content: center; padding: 20px 0; }
.led-ring {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.led-dot { width: 16px; height: 16px; border-radius: 50%; }
.led-dot.blink { animation: lvBlink 2.4s ease infinite; }
.setup-inputs { display: flex; flex-direction: column; gap: 18px; padding: 8px 0; }
.setup-inputs input {
  width: 100%; padding: 13px 2px; border: none; border-bottom: 1px solid var(--ink-16);
  background: transparent; color: var(--ink); font-size: 15px; font-family: var(--body); outline: none;
}
.setup-inputs input:focus { border-bottom-color: var(--accent); }

/* setup wizard (the full captive-portal flow in v4 idiom) */
.setup { justify-content: flex-start; padding-top: 26px; overflow-y: auto; gap: 18px; }
.setup h1 { font-size: 34px; }
.setup-progress { flex: none; }
.setup-progress span { flex: 1; width: auto; }
.setup-progress span.on { background: var(--accent); opacity: 0.55; }
.su-eyebrow { font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent-2); }
.su-list { display: flex; flex-direction: column; }
.su-row { border-top: 1px solid var(--ink-10); padding: 14px 0; display: flex; gap: 14px; font-size: 13.5px; line-height: 1.55; color: var(--ink-60); }
.su-row:last-child { border-bottom: 1px solid var(--ink-10); }
.su-row b { color: var(--ink); font-weight: 500; }
.su-n { font-family: var(--mono); color: var(--accent-2); font-size: 11px; padding-top: 2px; flex: none; }
.su-ic { font-size: 16px; flex: none; padding-top: 1px; }
.su-note { margin: 0; font-size: 13px; line-height: 1.6; color: var(--ink-45); }
.su-note b { color: var(--ink-60); font-weight: 500; }
.su-center { text-align: center; }
.su-terms {
  height: 210px; overflow-y: auto; border-top: 1px solid var(--ink-10); border-bottom: 1px solid var(--ink-10);
  padding: 14px 2px; font-size: 13px; line-height: 1.6; color: var(--ink-60);
}
.su-terms h3 { color: var(--ink); font-weight: 500; font-size: 13.5px; margin: 14px 0 4px; }
.su-terms h3:first-child { margin-top: 0; }
.su-terms p { margin: 0 0 10px; }
.su-terms .su-end { color: var(--ink-30); }
.su-hint { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; text-align: center; color: var(--ink-45); transition: opacity 0.3s; }
.su-consent { display: flex; gap: 11px; align-items: flex-start; cursor: pointer; font-size: 13px; line-height: 1.5; color: var(--ink-60); }
.su-consent.disabled { opacity: 0.45; cursor: default; }
.su-box {
  width: 19px; height: 19px; border-radius: 5px; flex: none; margin-top: 1px; border: 1px solid var(--ink-30);
  display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--bg); transition: all 0.2s;
}
.su-box.on { background: var(--accent); border-color: var(--accent); color: #1A1206; }
.su-box.on::after { content: "✓"; }
.su-nets { display: flex; flex-direction: column; gap: 7px; }
.su-nets:empty { display: none; }
.su-net {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 12px 13px;
  border: 1px solid var(--ink-16); border-radius: 12px; background: transparent; color: var(--ink);
  font: 400 14px var(--body); cursor: pointer; text-align: left; transition: all 0.15s;
}
.su-net:hover { border-color: var(--ink-30); }
.su-net.sel { border-color: var(--accent); background: rgba(240, 160, 48, 0.10); }
.su-net-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.su-net-sig { flex: none; font-family: var(--mono); letter-spacing: 1px; color: var(--accent-2); font-size: 12px; }
.su-scanrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.su-status { font-size: 12.5px; color: var(--ink-45); min-height: 16px; flex: 1; }
.su-ghostlink { background: none; border: none; color: var(--accent-2); font: 400 13px var(--body); cursor: pointer; padding: 6px 0; text-align: left; }
.su-ghostlink:hover { color: var(--ink-60); }
.su-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.su-fld { display: flex; flex-direction: column; gap: 6px; }
.su-lbl { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-45); }
.su-fld input {
  width: 100%; padding: 12px 2px; border: none; border-bottom: 1px solid var(--ink-16);
  background: transparent; color: var(--ink); font-size: 15px; font-family: var(--body); outline: none;
}
.su-fld input:focus { border-bottom-color: var(--accent); }
.su-pwwrap { position: relative; display: block; }
.su-pwwrap input { padding-right: 48px; }
.su-eye {
  position: absolute; right: 2px; bottom: 11px; background: none; border: none; cursor: pointer;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-2); padding: 4px;
}
.su-err { color: var(--danger); font-size: 12.5px; min-height: 15px; margin: 0; }
.su-err:empty { min-height: 0; }
.su-ok { color: var(--ok); font-size: 12.5px; margin: 0; }
.su-done { display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; padding: 10px 0; }
.su-check {
  width: 60px; height: 60px; border-radius: 50%;
  background: rgba(240, 160, 48, 0.14);
  box-shadow: 0 0 0 1px rgba(240, 160, 48, 0.4), 0 0 40px rgba(240, 160, 48, 0.35);
  display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--accent-2);
}
.su-devid {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink-60);
  border: 1px solid var(--ink-16); border-radius: 10px; padding: 11px 14px;
}
.su-ghost { background: none; border: none; color: var(--ink-45); font: 400 13.5px var(--body); cursor: pointer; padding: 6px; text-align: center; }
.su-ghost:hover { color: var(--ink-60); }
.cta:disabled { background: var(--ink-16); color: var(--ink-45); cursor: not-allowed; transform: none; }
.su-spin {
  display: inline-block; width: 15px; height: 15px; border: 2px solid var(--ink-30);
  border-top-color: var(--ink); border-radius: 50%; animation: suSpin 0.7s linear infinite; vertical-align: middle;
}
@keyframes suSpin { to { transform: rotate(360deg); } }

/* home — glance */
.glance {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  gap: 36px; padding: 0 44px;
}
.glance-row { display: flex; align-items: center; justify-content: center; gap: 34px; }
.twin-col { flex: none; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.twin-linear {
  width: 16px; height: 330px; border-radius: 8px; background: var(--ink-06);
  box-shadow: inset 0 0 0 1px var(--ink-10);
  position: relative; cursor: pointer;
}
.twin-tick { position: absolute; left: -6px; width: 4px; top: 50%; height: 1px; background: var(--ink-30); }
.twin-piece { position: absolute; left: 2.5px; right: 2.5px; border-radius: 6px; overflow: hidden; }
.twin-flow {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  background-size: 100% 60px; background-repeat: no-repeat;
  animation: lvFlowY var(--dur, 3s) linear infinite;
}
.twin-round { cursor: pointer; }
.twin-round svg { display: block; overflow: visible; }
.fix-name { font-family: var(--mono); font-size: 9px; letter-spacing: 0.2em; color: var(--ink-30); }
.seg-col { display: flex; flex-direction: column; gap: 28px; }
.seg { display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.seg-name { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em; color: var(--ink-45); }
.seg-pct { font-family: var(--display); font-weight: var(--dw); font-size: 48px; line-height: 1; }
.seg-note { font-family: var(--mono); font-size: 9.5px; color: var(--ink-45); }
.home-line { text-align: center; font-size: 14px; line-height: 1.65; color: var(--ink-60); text-wrap: pretty; }

/* bottom bar */
.bottom { flex: none; display: flex; flex-direction: column; gap: 10px; padding: 14px 44px calc(env(safe-area-inset-bottom, 0px) + 18px); }
.cta {
  padding: 17px 0; text-align: center; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: #1A1206;
  font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.18em; text-transform: uppercase;
  box-shadow: 0 0 28px -8px var(--accent);
  border: none; width: 100%;
}
.cta:active { transform: scale(0.98); }
.nav { display: flex; justify-content: center; gap: 38px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em; }
.nav span { cursor: pointer; padding: 13px 2px; color: var(--ink-30); border-bottom: 1px solid transparent; }
.nav span.active { color: var(--ink); border-bottom-color: var(--accent); }

/* trends */
.trends { flex: 1; display: flex; flex-direction: column; gap: 24px; padding: 34px 44px 0; overflow-y: auto; }
.trends-tabs { display: flex; gap: 20px; align-items: baseline; font-size: 10px; letter-spacing: 0.16em; }
.trends-tabs span { cursor: pointer; padding: 8px 0; color: var(--ink-30); border-bottom: 1px solid transparent; }
.trends-tabs span.active { color: var(--ink); border-bottom-color: var(--accent); }
.trends-tabs .spacer { flex: 1; cursor: default; }
.trend-hero { display: flex; justify-content: space-between; align-items: flex-end; }
.trend-hero-left { display: flex; flex-direction: column; gap: 4px; }
.trend-cost-row { display: flex; align-items: baseline; gap: 10px; }
.trend-cost { font-size: 54px; line-height: 0.95; color: var(--ink); }
.trend-delta { font-size: 11px; }
.trend-note { font-size: 13.5px; color: var(--ink-60); }
.trend-stepper { display: flex; align-items: center; gap: 8px; font-size: 10px; color: var(--ink-45); padding-bottom: 6px; }
.trend-stepper span[data-act] { cursor: pointer; padding: 8px 6px; }
.trend-stepper .dim { color: var(--ink-16); cursor: default; }
.trend-offset { letter-spacing: 0.12em; }
.trend-rows { display: flex; flex-direction: column; padding-bottom: 10px; }
.trend-row { border-top: 1px solid var(--ink-10); padding: 17px 0; display: flex; flex-direction: column; gap: 12px; cursor: pointer; }
.trend-row-head { display: flex; align-items: baseline; gap: 12px; }
.trend-dot { width: 5px; height: 5px; border-radius: 50%; align-self: center; }
.trend-name { flex: 1; font-size: 14.5px; color: var(--ink-75); }
.trend-value { font-size: 13px; color: var(--ink-75); font-variant-numeric: tabular-nums; }
.trend-rdelta { width: 40px; text-align: right; font-size: 10px; }
.trend-rcost { width: 46px; text-align: right; font-size: 10.5px; color: var(--ink-45); }
.trend-chart { display: block; }
.trend-peak { font-size: 9.5px; letter-spacing: 0.08em; margin-top: -6px; }
.trend-bars { display: flex; align-items: flex-end; gap: 4px; height: 60px; border-bottom: 1px solid var(--ink-16); }
.trend-bar-slot { flex: 1; display: flex; align-items: flex-end; gap: 1px; height: 100%; }
.trend-bar-slot span { flex: 1; }
.trend-cap { display: flex; justify-content: space-between; font-size: 9.5px; letter-spacing: 0.1em; color: var(--ink-45); }
.trend-cap b { font-weight: 500; color: var(--ink-75); }
.trend-insight { font-size: 13px; line-height: 1.6; color: var(--ink-60); text-wrap: pretty; }
.trend-level { height: 2px; background: var(--ink-06); position: relative; }
.trend-level span { position: absolute; left: 0; top: 0; bottom: 0; }

/* sheets (overlays) */
.scrim { position: absolute; inset: 0; background: var(--scrim); display: flex; flex-direction: column; justify-content: flex-end; z-index: 5; }
.sheet {
  background: var(--sheet); border-radius: 26px 26px 0 0;
  padding: 26px 34px calc(env(safe-area-inset-bottom, 0px) + 34px);
  display: flex; flex-direction: column; gap: 4px; max-height: 80%; overflow-y: auto;
}
.sheet-title { font-family: var(--display); font-weight: var(--dw); font-size: 26px; color: var(--ink); padding-bottom: 6px; }
.sheet-row {
  border-top: 1px solid var(--ink-10); padding: 14px 0;
  display: flex; justify-content: space-between; align-items: baseline; gap: 14px; cursor: pointer;
}

/* landscape big chart */
.big { position: absolute; inset: 0; background: var(--bg); overflow: hidden; z-index: 6; }
.big-panel {
  position: absolute; top: 50%; left: 50%;
  width: 100vmax; max-width: 844px; height: 390px;
  transform: translate(-50%, -50%) rotate(90deg);
  display: flex; flex-direction: column; padding: 24px 34px; gap: 14px;
}
.big-head { display: flex; justify-content: space-between; align-items: baseline; }
.big-head-left { display: flex; align-items: baseline; gap: 14px; }
.big-name { font-size: 26px; color: var(--ink); }
.big-value { font-size: 13px; }
.big-cost { font-size: 11px; color: var(--ink-45); }
.big-close { cursor: pointer; font-size: 12px; color: var(--ink-45); padding: 8px 0 8px 20px; }
.big-step { display: flex; align-items: baseline; gap: 12px; font-size: 10px; letter-spacing: 0.1em; color: var(--ink-45); }
/* finger-sized taps: this panel is rotated, so vertical padding widens the
   target along the screen axis the thumb actually travels */
.big-step span[data-act] { cursor: pointer; padding: 10px 12px; margin: -10px -6px; font-size: 13px; }
.big-step .dim { opacity: 0.25; cursor: default; }
.big-offset { color: var(--ink-60); }
.big-controls { display: flex; justify-content: space-between; gap: 20px; margin-top: -6px; }
.big-tabs { display: flex; gap: 14px; font-size: 9.5px; }
.big-tabs span { cursor: pointer; color: var(--ink-30); padding: 6px 0 3px; border-bottom: 1px solid transparent; }
.big-tabs span.active { color: var(--ink); border-bottom-color: var(--accent); }
.big-chart { flex: 1; min-height: 0; position: relative; cursor: crosshair; touch-action: none; }
.big-ptr-line { position: absolute; top: 0; bottom: 0; width: 1.5px; background: var(--ink-45); pointer-events: none; z-index: 3; }
.big-tip {
  position: absolute; top: -6px; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 9px; background: var(--sheet); border: 1px solid var(--ink-16);
  pointer-events: none; z-index: 4; display: flex; gap: 8px; align-items: baseline; white-space: nowrap;
}
.big-tip-time { font-family: var(--mono); font-size: 9.5px; color: var(--ink-45); }
.big-tip-val { font-family: var(--mono); font-size: 12px; }
.big-bars { display: flex; align-items: flex-end; gap: 6px; height: 100%; border-bottom: 1px solid var(--ink-16); }
.big-bar-slot { flex: 1; display: flex; align-items: flex-end; gap: 2px; height: 100%; }
.big-bar-slot[data-act] { cursor: zoom-in; }
.big-bar-slot span { flex: 1; }
.big-foot { display: flex; justify-content: space-between; font-size: 10px; letter-spacing: 0.12em; color: var(--ink-45); }

/* ask + system sheets */
.ask-q { font-size: 13.5px; color: var(--ink-60); text-align: right; }
.ask-a { margin: 0; font-size: 15px; line-height: 1.65; color: var(--ink); }
.ask-input-row { display: flex; gap: 12px; align-items: center; border-top: 1px solid var(--ink-10); padding-top: 14px; }
.ask-input-row input { flex: 1; padding: 10px 2px; border: none; background: transparent; color: var(--ink); font-size: 14px; font-family: var(--body); outline: none; }
.ask-send { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--accent-2); cursor: pointer; padding: 8px 0; }
.sheet-close { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--ink-45); cursor: pointer; padding: 8px 0 8px 16px; }
.sheet-section { font-family: var(--mono); font-size: 9px; letter-spacing: 0.22em; color: var(--accent-2); padding: 14px 0 6px; }
.sys-value { font-family: var(--mono); font-size: 12px; }
.sys-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--ink-45); }

/* settings */
.settings { flex: 1; display: flex; flex-direction: column; gap: 8px; padding: 34px 44px 0; overflow-y: auto; }
.set-title { font-size: 34px; color: var(--ink); padding-bottom: 10px; }
.settings .sheet-row { border-top: 1px solid var(--ink-10); padding: 16px 0; }
.set-value { font-size: 13.5px; color: var(--ink); text-align: right; }
.set-why { margin: 10px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--ink-45); text-wrap: pretty; }
.fix-opt { font-size: 14px; color: var(--ink-60); }
.fix-opt.active { color: var(--ink); }

/* settings sub-pages */
.sp-ctl { display: flex; align-items: center; gap: 10px; }
input[type="range"] { accent-color: var(--accent); }
.sp-tgl {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; cursor: pointer;
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--ink-16); color: var(--ink-45);
}
.sp-tgl.on { border-color: var(--accent); color: var(--ink); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.sp-tgl.dis { opacity: 0.4; cursor: default; }
.sp-num, .sp-txt {
  padding: 8px 2px; border: none; border-bottom: 1px solid var(--ink-16); background: transparent;
  color: var(--ink); font-size: 14px; font-family: var(--body); outline: none; text-align: right; max-width: 160px;
}
.sp-txt { text-align: left; width: 160px; }
.sp-num { width: 84px; font-variant-numeric: tabular-nums; }
.sp-num:focus, .sp-txt:focus { border-bottom-color: var(--accent); }
.sp-sel {
  padding: 8px 2px; border: none; border-bottom: 1px solid var(--ink-16); background: transparent;
  color: var(--ink); font-size: 14px; font-family: var(--body); outline: none;
}
.sp-color { width: 34px; height: 26px; border: 1px solid var(--ink-16); border-radius: 6px; background: transparent; padding: 1px; cursor: pointer; }
.sp-btn {
  margin: 12px 0 4px; padding: 13px 0; width: 100%; text-align: center; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid var(--ink-16); color: var(--ink);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
}
.sp-btn.danger { border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); }
.sp-btn:active { transform: scale(0.98); }
.sp-chip {
  font-family: var(--mono); font-size: 10px; cursor: pointer; padding: 4px 9px;
  border-radius: 999px; border: 1px solid var(--ink-16); color: var(--ink-30);
}
.sp-chip.on { border-color: var(--accent); color: var(--ink); }
.sp-dev { border-top: 1px solid var(--ink-10); padding: 14px 0; display: flex; flex-direction: column; gap: 8px; }

/* status colors */
.c-ok { color: var(--ok); } .bg-ok { background: var(--ok); }
.c-warn { color: var(--warn); } .bg-warn { background: var(--warn); }
.c-danger { color: var(--danger); } .bg-danger { background: var(--danger); }
.c-cloud { color: var(--cloud); } .bg-cloud { background: var(--cloud); }
.c-accent { color: var(--accent); } .bg-accent { background: var(--accent); }
.bg-setup { background: var(--setup-blue); }
.bg-muted { background: var(--ink-30); }
.c-muted { color: var(--ink-45); }
