/* ===================================================================
   NeerScan — design tokens
   Palette sampled from the brand mark: deep indigo droplet body
   fading into a bright cyan-teal tip, concentric spectral arcs.
=================================================================== */
:root{
  --navy-950:#0B1330;
  --navy-900:#121A4A;
  --navy-800:#1B2560;
  --navy-700:#233178;
  --blue-600:#2A5CA8;
  --teal-400:#2DD4DA;
  --teal-300:#6FE6E9;
  --teal-200:#B4F3F3;

  --bg:#F3F7FB;
  --surface:#FFFFFF;
  --surface-2:#EBF1F8;
  --line:#DDE6F0;

  --ink:#0F1730;
  --ink-soft:#3C4867;
  --muted:#6C7A99;

  --good:#18A971;
  --good-bg:#E4F7EE;
  --warn:#DB9A2B;
  --warn-bg:#FBF1DD;
  --bad:#E14B3F;
  --bad-bg:#FCE7E5;

  --radius-lg:22px;
  --radius-md:16px;
  --radius-sm:10px;

  --shadow-card: 0 1px 2px rgba(15,23,48,.04), 0 8px 24px -12px rgba(15,23,48,.14);
  --shadow-pop: 0 12px 32px -8px rgba(15,23,48,.28);

  --font-display:'Space Grotesk', 'Inter', sans-serif;
  --font-body:'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:'JetBrains Mono', ui-monospace, Menlo, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family:var(--font-body);
  color:var(--ink);
  background:var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y:none;
}
h1,h2,h3{font-family:var(--font-display); margin:0; letter-spacing:-0.01em;}
p{margin:0;}
button{font-family:inherit; cursor:pointer;}
.hidden{display:none !important;}
.muted{color:var(--muted);}
.small{font-size:12.5px;}

/* ===================== SPLASH ===================== */
.splash{
  position:fixed; inset:0; z-index:100;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  background:
    radial-gradient(120% 90% at 50% -10%, #1E2E86 0%, transparent 55%),
    linear-gradient(165deg, var(--navy-900) 0%, var(--navy-950) 70%);
  overflow:hidden;
  transition:opacity .5s ease, visibility .5s ease;
}
.splash.fade-out{opacity:0; visibility:hidden; pointer-events:none;}

.splash-rings{position:absolute; inset:0; display:flex; align-items:center; justify-content:center;}
.ring-svg{width:min(90vw,420px); height:min(90vw,420px); opacity:.55;}
.ring{fill:none; stroke:var(--teal-400); stroke-width:0.6; transform-origin:100px 100px;}
.ring.r1{stroke-opacity:.55; animation:ringPulse 3.2s ease-in-out infinite;}
.ring.r2{stroke-opacity:.35; animation:ringPulse 3.2s ease-in-out infinite .4s;}
.ring.r3{stroke-opacity:.2; animation:ringPulse 3.2s ease-in-out infinite .8s;}
@keyframes ringPulse{
  0%,100%{transform:scale(1); stroke-opacity:.15;}
  50%{transform:scale(1.06); stroke-opacity:.55;}
}

.splash-content{position:relative; display:flex; flex-direction:column; align-items:center; gap:18px; animation:riseIn 1s ease both;}
.splash-logo{width:min(46vw, 200px); filter:drop-shadow(0 18px 40px rgba(45,212,218,.25));}
.splash-tag{font-family:var(--font-display); color:var(--teal-200); font-size:14px; letter-spacing:.06em; text-transform:uppercase; opacity:.85;}
@keyframes riseIn{from{opacity:0; transform:translateY(14px);} to{opacity:1; transform:translateY(0);}}

.splash-foot{position:absolute; bottom:calc(48px + var(--safe-bottom)); left:0; right:0; display:flex; flex-direction:column; align-items:center; gap:12px; padding:0 40px;}
.splash-progress{width:180px; height:3px; border-radius:3px; background:rgba(255,255,255,.12); overflow:hidden;}
.splash-progress-bar{height:100%; width:35%; border-radius:3px; background:linear-gradient(90deg, var(--blue-600), var(--teal-400)); animation:loadSweep 1.4s ease-in-out infinite;}
@keyframes loadSweep{
  0%{transform:translateX(-100%);}
  50%{transform:translateX(120%);}
  100%{transform:translateX(320%);}
}
.splash-status{font-size:12.5px; color:rgba(255,255,255,.55); letter-spacing:.02em;}

/* ===================== APP SHELL ===================== */
.app{max-width:480px; margin:0 auto; min-height:100vh; display:flex; flex-direction:column; background:var(--bg);}

.topbar{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between;
  padding:calc(14px + var(--safe-top)) 18px 12px;
  background:linear-gradient(180deg, var(--navy-900), var(--navy-800));
  color:#fff;
}
.topbar-id{display:flex; align-items:center; gap:10px;}
.topbar-logo{width:30px; height:auto;}
.topbar-title{font-family:var(--font-display); font-weight:700; font-size:16px; line-height:1.1;}
.topbar-sub{font-size:11.5px; color:var(--teal-200); opacity:.8;}
.conn-pill{
  display:flex; align-items:center; gap:7px;
  background:rgba(255,255,255,.1); border:1px solid rgba(255,255,255,.16);
  color:#fff; padding:7px 13px; border-radius:999px; font-size:12.5px; font-weight:600;
}
.conn-pill .dot{width:7px; height:7px; border-radius:50%; background:var(--muted);}
.conn-pill.connected .dot{background:var(--teal-300); box-shadow:0 0 0 3px rgba(45,212,218,.25);}
.conn-pill.connecting .dot{background:var(--warn); animation:blink 1s ease-in-out infinite;}
@keyframes blink{0%,100%{opacity:1;} 50%{opacity:.3;}}

.screens{flex:1; padding:16px 16px calc(96px + var(--safe-bottom));}
.screen{display:none; animation:fadeUp .35s ease both;}
.screen.active{display:block;}
@keyframes fadeUp{from{opacity:0; transform:translateY(8px);} to{opacity:1; transform:translateY(0);}}

/* ===================== BUTTONS ===================== */
.btn{
  border:none; border-radius:14px; padding:14px 18px; font-weight:700; font-size:15px;
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  width:100%; transition:transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn:active{transform:scale(.97);}
.btn-primary{background:linear-gradient(135deg, var(--blue-600), var(--teal-400)); color:#fff; box-shadow:0 10px 24px -10px rgba(42,92,168,.6);}
.btn-lg{padding:16px 18px; font-size:16px; border-radius:16px;}
.btn-ghost{background:transparent; color:var(--blue-600); font-weight:600;}
.btn-outline{background:#fff; color:var(--ink); border:1.5px solid var(--line); margin-top:10px;}
.btn-danger-outline{background:#fff; color:var(--bad); border:1.5px solid #F3C9C5; margin-top:14px;}
.btn-small{background:var(--navy-800); color:#fff; padding:9px 14px; font-size:13px; border-radius:11px; width:auto; white-space:nowrap;}
.btn:disabled{opacity:.45; pointer-events:none;}
.link-btn{background:none; border:none; color:var(--blue-600); font-size:12.5px; font-weight:600;}
.icon-btn{background:var(--surface); border:1px solid var(--line); width:38px; height:38px; border-radius:12px; display:flex; align-items:center; justify-content:center; font-size:16px; color:var(--ink);}

/* ===================== CONNECT SCREEN ===================== */
.hero-card{
  background:linear-gradient(160deg, var(--navy-900), var(--navy-800) 65%, var(--blue-600));
  border-radius:var(--radius-lg); padding:30px 24px 26px; color:#fff; text-align:center;
  box-shadow:var(--shadow-pop);
}
.hero-icon{width:74px; height:74px; margin:0 auto 14px; background:rgba(255,255,255,.08); border-radius:22px; display:flex; align-items:center; justify-content:center; border:1px solid rgba(255,255,255,.14);}
.hero-icon img{width:42px;}
.hero-card h1{font-size:21px; margin-bottom:8px;}
.hero-card p{color:rgba(255,255,255,.72); font-size:13.5px; line-height:1.5; margin-bottom:20px;}
.hero-card .btn-ghost{color:var(--teal-200); margin-top:6px;}

.info-grid{display:grid; grid-template-columns:1fr; gap:10px; margin-top:16px;}
.info-card{background:var(--surface); border-radius:var(--radius-md); padding:14px 16px; display:flex; gap:12px; align-items:flex-start; box-shadow:var(--shadow-card);}
.info-num{font-family:var(--font-display); font-weight:700; color:var(--teal-400); background:var(--navy-900); width:30px; height:30px; flex:none; border-radius:9px; display:flex; align-items:center; justify-content:center; font-size:12px;}
.info-card p{font-size:13.5px; line-height:1.4; color:var(--ink-soft);}

.support-note{margin-top:16px; background:var(--warn-bg); border:1px solid #F0DCAE; border-radius:var(--radius-md); padding:14px 16px;}
.support-note strong{font-size:13.5px; color:#8A5B0F;}
.support-note p{font-size:12.5px; color:#8A5B0F; margin-top:6px; line-height:1.5;}

/* ===================== HOME ===================== */
.baseline-banner{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md);
  padding:14px 16px; margin-bottom:16px; box-shadow:var(--shadow-card);
}
.baseline-banner.calibrated{background:var(--good-bg); border-color:#BFE9D5;}
.bb-left{display:flex; align-items:center; gap:12px;}
.bb-icon{font-size:20px; color:var(--warn);}
.baseline-banner.calibrated .bb-icon{color:var(--good);}
.bb-title{font-weight:700; font-size:14px;}
.bb-sub{font-size:12px; color:var(--muted); margin-top:2px;}

.quick-actions{display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:22px;}
.qa-btn{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md);
  padding:16px 14px; text-align:left; display:flex; flex-direction:column; gap:6px;
  box-shadow:var(--shadow-card);
}
.qa-btn.qa-primary{grid-column:1/-1; background:linear-gradient(120deg, var(--navy-900), var(--blue-600)); border:none; color:#fff; flex-direction:row; align-items:center;}
.qa-primary .qa-icon{font-size:22px;}
.qa-primary .qa-label{font-size:15px; font-weight:700;}
.qa-primary .qa-sub{font-size:11.5px; color:var(--teal-200); margin-left:auto; text-align:right; max-width:110px;}
.qa-icon{font-size:19px; color:var(--blue-600);}
.qa-label{font-size:13px; font-weight:700; color:var(--ink);}

.section-head{display:flex; align-items:center; justify-content:space-between; margin:6px 2px 10px;}
.section-head h2{font-size:15px;}

.summary-card{background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md); padding:16px; margin-bottom:22px; box-shadow:var(--shadow-card);}
.summary-card.empty{color:var(--muted); font-size:13px; text-align:center; padding:24px 16px;}
.summary-card .sc-top{display:flex; align-items:center; justify-content:space-between; margin-bottom:10px;}
.summary-tag{font-size:11px; font-weight:800; letter-spacing:.04em; padding:5px 10px; border-radius:999px;}
.tag-safe{background:var(--good-bg); color:var(--good);}
.tag-caution{background:var(--warn-bg); color:var(--warn);}
.tag-critical{background:var(--bad-bg); color:var(--bad);}
.summary-metrics{display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin-top:10px;}
.sm-item{background:var(--surface-2); border-radius:10px; padding:8px 6px; text-align:center;}
.sm-item .v{font-family:var(--font-display); font-weight:700; font-size:14px;}
.sm-item .l{font-size:9.5px; color:var(--muted); text-transform:uppercase; letter-spacing:.03em;}

.history-list{display:flex; flex-direction:column; gap:8px;}
.empty-hint{text-align:center; padding:18px; background:var(--surface); border-radius:var(--radius-md); border:1px dashed var(--line);}
.history-item{display:flex; align-items:center; justify-content:space-between; background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:11px 14px;}
.hi-left{display:flex; align-items:center; gap:10px;}
.hi-dot{width:9px; height:9px; border-radius:50%;}
.hi-time{font-size:12px; color:var(--muted);}
.hi-label{font-size:13px; font-weight:700;}

/* ===================== RESULTS ===================== */
.results-head{display:flex; align-items:center; gap:12px; margin-bottom:16px;}
.results-head h1{font-size:18px;}
.results-head > div{flex:1;}
.results-head #btnShareResult{margin-left:auto;}

.overall-band{border-radius:var(--radius-lg); padding:18px; margin-bottom:16px; color:#fff; background:linear-gradient(135deg, var(--navy-900), var(--blue-600));}
.overall-band.safe{background:linear-gradient(135deg,#0E7A54,#1FC983);}
.overall-band.caution{background:linear-gradient(135deg,#9C6B10,#E8A93A);}
.overall-band.critical{background:linear-gradient(135deg,#8E241C,#E4483D);}
.overall-tag{display:inline-block; font-size:11px; font-weight:800; letter-spacing:.06em; background:rgba(255,255,255,.18); padding:5px 10px; border-radius:999px; margin-bottom:10px;}
.overall-text{font-size:13.5px; line-height:1.5; color:rgba(255,255,255,.92);}

.param-grid{display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:18px;}
.param-card{background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md); padding:14px; box-shadow:var(--shadow-card);}
.param-card.full{grid-column:1/-1;}
.pc-top{display:flex; align-items:center; justify-content:space-between; margin-bottom:8px;}
.pc-name{font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.02em; color:var(--muted);}
.pc-badge{font-size:10px; font-weight:800; padding:3px 7px; border-radius:6px;}
.pc-value{font-family:var(--font-display); font-size:22px; font-weight:700; margin-bottom:4px;}
.pc-desc{font-size:11.5px; color:var(--ink-soft); line-height:1.4;}
.pc-bar{height:6px; border-radius:6px; background:var(--surface-2); margin:8px 0; overflow:hidden;}
.pc-bar-fill{height:100%; border-radius:6px;}

/* ===================== COLLAPSIBLES ===================== */
.collapsible{background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md); margin-bottom:12px; overflow:hidden; box-shadow:var(--shadow-card);}
.collapsible-head{width:100%; background:none; border:none; padding:14px 16px; display:flex; align-items:center; justify-content:space-between; font-weight:700; font-size:13.5px; color:var(--ink);}
.collapsible-head .chev{transition:transform .25s ease; color:var(--muted); font-size:16px;}
.collapsible.open .chev{transform:rotate(180deg);}
.collapsible-body{max-height:0; overflow:hidden; transition:max-height .3s ease;}
.collapsible.open .collapsible-body{max-height:1400px;}
.collapsible-body-inner{padding:0 16px 16px;}

.spectral-row{display:grid; grid-template-columns:1.3fr .8fr .5fr; gap:8px; align-items:center; padding:7px 0; border-bottom:1px solid var(--surface-2); font-size:12.5px;}
.spectral-row:last-child{border-bottom:none;}
.spectral-row .ch-name{font-weight:600;}
.spectral-row .ch-val{font-family:var(--font-mono); color:var(--ink-soft); text-align:right;}
.spectral-row .ch-dev{font-family:var(--font-mono); text-align:right; font-weight:700;}
.dev-pos{color:var(--bad);}
.dev-neg{color:var(--blue-600);}
.dev-ok{color:var(--muted);}

.deviation-row{display:flex; align-items:center; gap:10px; padding:7px 0; border-bottom:1px solid var(--surface-2); font-size:12px;}
.deviation-row:last-child{border-bottom:none;}
.dr-name{width:56px; flex:none; font-weight:600; font-family:var(--font-mono); font-size:11px;}
.dr-bar-track{flex:1; height:8px; background:var(--surface-2); border-radius:4px; position:relative; overflow:hidden;}
.dr-bar-fill{position:absolute; top:0; bottom:0; border-radius:4px;}
.dr-pct{width:52px; flex:none; text-align:right; font-family:var(--font-mono); font-weight:700; font-size:11.5px;}
.dr-flag{width:14px; flex:none; text-align:center;}

.raw-pre{font-family:var(--font-mono); font-size:10.5px; line-height:1.6; white-space:pre-wrap; word-break:break-word; color:var(--ink-soft); background:var(--surface-2); padding:12px; border-radius:10px; max-height:340px; overflow:auto;}

/* ===================== CALIBRATION ===================== */
.cal-wrap{text-align:center; padding-top:6px;}
.cal-back{position:absolute; margin-top:-2px;}
.cal-icon{position:relative; width:120px; height:120px; margin:20px auto 22px;}
.cal-svg{width:100%; height:100%; transform:rotate(-90deg);}
.cal-ring{fill:none; stroke-width:6; stroke-linecap:round;}
.cal-ring-track{stroke:var(--surface-2);}
.cal-ring-progress{stroke:url(#none); stroke:var(--teal-400); stroke-dasharray:327; stroke-dashoffset:327; transition:stroke-dashoffset .5s ease;}
.cal-step-num{position:absolute; inset:0; display:flex; align-items:center; justify-content:center; font-family:var(--font-display); font-weight:700; font-size:22px; color:var(--navy-900);}

.cal-wrap h1{font-size:20px; margin-bottom:10px;}
.cal-wrap .muted{font-size:13.5px; line-height:1.55; display:block; margin-bottom:18px; padding:0 6px;}
.checklist{list-style:none; padding:0; margin:0 0 22px; text-align:left; display:flex; flex-direction:column; gap:10px;}
.checklist li{font-size:13px; color:var(--ink-soft); padding-left:26px; position:relative;}
.checklist li::before{content:"✓"; position:absolute; left:0; top:0; width:18px; height:18px; border-radius:50%; background:var(--good-bg); color:var(--good); font-size:11px; display:flex; align-items:center; justify-content:center; font-weight:800;}

.cal-log{background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md); padding:14px 16px; text-align:left; font-family:var(--font-mono); font-size:11.5px; color:var(--ink-soft); max-height:180px; overflow-y:auto; line-height:1.8;}
.cal-log div.done{color:var(--good);}

.cal-check{width:64px; height:64px; border-radius:50%; background:var(--good-bg); color:var(--good); font-size:30px; display:flex; align-items:center; justify-content:center; margin:10px auto 18px; font-weight:800;}

/* ===================== SETTINGS ===================== */
#screen-settings h1{font-size:19px; margin-bottom:16px;}
.settings-card{background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md); padding:16px; margin-bottom:14px; box-shadow:var(--shadow-card);}
.settings-card h3{font-size:13.5px; margin-bottom:10px;}
.settings-row{display:flex; align-items:center; justify-content:space-between; padding:9px 0; font-size:13.5px; border-bottom:1px solid var(--surface-2);}
.settings-row:last-of-type{border-bottom:none;}
.settings-row .value{color:var(--muted); font-weight:600;}
.about-card{text-align:center;}
.about-logo{width:40px; margin-bottom:10px;}
.about-card p{margin-top:4px;}

/* ===================== BOTTOM NAV ===================== */
.bottom-nav{
  position:fixed; left:0; right:0; bottom:0; z-index:30;
  max-width:480px; margin:0 auto;
  display:flex; background:var(--surface); border-top:1px solid var(--line);
  padding:8px 6px calc(8px + var(--safe-bottom));
  box-shadow:0 -6px 24px -8px rgba(15,23,48,.12);
}
.nav-btn{flex:1; display:flex; flex-direction:column; align-items:center; gap:4px; background:none; border:none; color:var(--muted); padding:6px 0; border-radius:12px; font-size:10.5px; font-weight:600;}
.nav-btn svg{stroke:var(--muted);}
.nav-btn.active{color:var(--blue-600);}
.nav-btn.active svg{stroke:var(--blue-600);}

/* ===================== TOAST ===================== */
.toast{
  position:fixed; left:50%; bottom:96px; transform:translate(-50%, 20px);
  background:var(--navy-950); color:#fff; padding:12px 18px; border-radius:12px;
  font-size:13px; font-weight:600; box-shadow:var(--shadow-pop); z-index:200;
  opacity:0; pointer-events:none; transition:all .3s ease; max-width:88%; text-align:center;
}
.toast.show{opacity:1; transform:translate(-50%, 0);}
.toast.err{background:var(--bad);}
.toast.ok{background:var(--good);}

/* ===================== MISC ===================== */
::selection{background:var(--teal-200);}
@media (min-width:520px){
  body{background:var(--navy-950);}
  .app{box-shadow:0 0 0 1px rgba(255,255,255,.06), 0 40px 100px -30px rgba(0,0,0,.6); min-height:100vh;}
}
