:root {
  --bg: #fdfaf5;          /* warm off-white page */
  --panel: #ffffff;       /* clean white cards */
  --panel-2: #fbf4e9;     /* soft cream for insets */
  --ink: #3a2f26;         /* warm dark-brown text */
  --muted: #9b8c7b;       /* muted warm grey-brown */
  --line: #efe4d4;        /* light warm border */
  --accent: #f59e0b;      /* amber — full montage / primary */
  --accent-2: #ea7317;    /* deeper orange — reduced montage */
  --good: #e0a100;        /* golden yellow — positive */
  --bad: #e5484d;         /* kept red for genuine warnings */
  --truth: #d97706;       /* warm orange for ground truth */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: linear-gradient(180deg, #fffdf9, #fdf6ec);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 30px;
  color: var(--accent);
  background: var(--panel-2);
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 12px;
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: 0.3px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.dataset-badge {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px;
}

/* nav */
.nav { display: flex; gap: 6px; }
.nav a {
  color: var(--muted); text-decoration: none; font-size: 14px;
  padding: 8px 14px; border-radius: 8px;
}
.nav a:hover { color: var(--ink); background: var(--panel-2); }
.nav a.active { color: var(--ink); background: var(--panel-2); font-weight: 600; }

/* explanation page */
.explain .step { display: flex; gap: 20px; align-items: flex-start; }
.step-num {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--accent); color: #ffffff;
  font-weight: 700; font-size: 18px; border-radius: 10px;
  margin-top: 2px;
}
.explain p { margin: 0 0 12px; }
.explain .note {
  background: var(--panel-2); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 6px; font-size: 13px; color: var(--muted);
}
.feat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 4px 0 14px; }
.feat-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.feat-box h3 { margin: 0 0 8px; font-size: 13px; color: var(--accent); }
.feat-box ul { margin: 0; padding-left: 16px; font-size: 13px; color: var(--muted); }
.feat-box li { margin-bottom: 5px; }
.feat-box b { color: var(--ink); }

.metric-explain { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 8px; }
.metric-explain h3 { margin: 0 0 6px; font-size: 14px; }
.metric-explain p { font-size: 13px; }
.formula {
  display: inline-block; margin-top: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--panel-2); padding: 3px 8px; border-radius: 6px;
  color: var(--accent); font-size: 12px;
}
.good-text { color: var(--good) !important; font-size: 12px !important; }

ul.plain { margin: 6px 0 0; padding-left: 18px; font-size: 14px; }
ul.plain li { margin-bottom: 8px; }
ul.plain em { color: var(--accent-2); font-style: normal; }

/* math section */
.math-h {
  margin: 22px 0 10px; font-size: 14px; color: var(--accent);
  border-top: 1px solid var(--line); padding-top: 16px;
}
.math-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 16px; margin-bottom: 10px;
}
.math-label { font-size: 13px; color: var(--muted); }
.math-eq { overflow-x: auto; color: var(--ink); }
.math-eq.center { text-align: center; margin: 10px 0 4px; }
mjx-container { color: var(--ink); }

/* tier flow diagram (how-it-works) */
.tier-flow { display: flex; align-items: stretch; gap: 10px; margin: 16px 0; }
.tier-node {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line);
  border-top-width: 3px; border-radius: 10px; padding: 14px 16px;
}
.tier-node h3 { margin: 0 0 6px; font-size: 14px; }
.tier-node p { margin: 0; font-size: 12px; color: var(--muted); }
.tier-node.dismiss { border-top-color: #d8c9b6; }
.tier-node.notify { border-top-color: var(--accent-2); }
.tier-node.notify h3 { color: var(--accent-2); }
.tier-node.escalate { border-top-color: var(--bad); }
.tier-node.escalate h3 { color: var(--bad); }
.tier-arrow { display: flex; align-items: center; color: var(--muted); font-size: 22px; }

@media (max-width: 720px) {
  .feat-grid, .metric-explain, .math-row { grid-template-columns: 1fr; }
  .tier-flow { flex-direction: column; }
  .tier-arrow { transform: rotate(90deg); justify-content: center; }
}

.container { max-width: 980px; margin: 0 auto; padding: 24px 20px 60px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 18px;
  box-shadow: 0 2px 10px rgba(180, 140, 80, 0.06);
}
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.intro p { margin: 0 0 18px; }
.controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.controls label { color: var(--muted); font-size: 13px; }
select {
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: 14px;
}
.montage-toggle { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.montage-toggle button {
  background: var(--panel-2); color: var(--muted);
  border: none; padding: 8px 14px; cursor: pointer; font-size: 13px;
}
.montage-toggle button.active { background: var(--accent); color: #ffffff; font-weight: 600; }
.montage-toggle button:last-child.active { background: var(--accent-2); }

/* metric cards */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 18px;
  box-shadow: 0 2px 8px rgba(180, 140, 80, 0.05);
}
.metric .val { font-size: 28px; font-weight: 700; }
.metric .lab { color: var(--muted); font-size: 12px; margin-top: 2px; }
.metric .val.good { color: var(--good); }
.metric .val.warn { color: var(--accent-2); }

.legend { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.truth { background: var(--truth); }
.sw.hit { background: var(--good); }
.sw.fa { background: var(--bad); }
.sw.bg { background: #e3d7c5; }

.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.disclaimer ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.disclaimer li { margin-bottom: 6px; }

.foot {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  max-width: 980px; margin: 0 auto; padding: 20px;
  color: var(--muted); font-size: 12px; border-top: 1px solid var(--line);
}

/* alert tiers */
.tier-legend { font-size: 12px; color: var(--muted); margin-bottom: 14px; line-height: 2; }
.tier-chip {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; margin: 0 4px 0 10px;
}
.tier-chip:first-child { margin-left: 0; }
.tier-chip.dismiss { background: #efe4d4; color: #8a7a68; }
.tier-chip.notify { background: rgba(234,115,23,0.16); color: var(--accent-2); }
.tier-chip.escalate { background: rgba(229,72,77,0.16); color: var(--bad); }

.tier-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.tier-summary .val.bad { color: var(--bad); }

.episode-list { display: flex; flex-direction: column; gap: 8px; }
.episode {
  display: grid; grid-template-columns: 110px 130px 1fr auto; gap: 12px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-left-width: 4px; border-radius: 8px; padding: 10px 14px; font-size: 13px;
}
.episode.escalate { border-left-color: var(--bad); }
.episode.notify { border-left-color: var(--accent-2); }
.episode.dismiss { border-left-color: #d8c9b6; }
.ep-tier { font-weight: 700; font-size: 12px; letter-spacing: 0.5px; }
.episode.escalate .ep-tier { color: var(--bad); }
.episode.notify .ep-tier { color: var(--accent-2); }
.episode.dismiss .ep-tier { color: var(--muted); }
.ep-time { color: var(--ink); font-family: ui-monospace, Menlo, monospace; }
.ep-meta { color: var(--muted); }
.ep-truth { font-size: 12px; }
.ep-truth.real { color: var(--good); }
.ep-truth.nonreal { color: var(--muted); }
.sim-note { color: var(--muted); font-size: 11px; margin-top: 12px; font-style: italic; }

@media (max-width: 720px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .compare-grid { grid-template-columns: 1fr; }
  .tier-summary { grid-template-columns: repeat(2, 1fr); }
  .episode { grid-template-columns: 1fr 1fr; }
}

/* ===== companion app demo ===== */
.demo-intro .demo-controls { display: flex; gap: 12px; margin: 14px 0 6px; flex-wrap: wrap; }
.demo-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  padding: 10px 18px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.demo-btn:hover { border-color: var(--accent); }
.demo-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.demo-btn.primary:hover { background: var(--accent-2); }
.demo-btn.big { width: 100%; margin-top: 10px; padding: 13px; }

.phone-row { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; }

/* the phone shell */
.phone {
  position: relative;
  width: 300px; height: 600px;
  background: #241b12;
  border-radius: 42px;
  padding: 14px;
  box-shadow: 0 18px 50px rgba(120, 80, 20, 0.22);
  flex: 0 0 auto;
}
.phone-notch {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  width: 120px; height: 24px; background: #241b12; border-radius: 0 0 16px 16px; z-index: 3;
}
.phone-screen {
  width: 100%; height: 100%;
  border-radius: 30px; overflow: hidden;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #fffdf9, #fdf4e7);
  color: var(--ink);
  transition: background 0.4s ease;
}

/* status bar */
.app-status {
  display: flex; align-items: center; gap: 8px;
  padding: 40px 22px 14px; font-size: 13px; font-weight: 600;
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; }
.status-dot.ok { background: var(--good); box-shadow: 0 0 0 4px rgba(224,161,0,0.18); }
.status-dot.alert { background: var(--bad); box-shadow: 0 0 0 4px rgba(229,72,77,0.18); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.app-foot { margin-top: auto; padding: 16px 22px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }

/* idle */
.idle-body, .detect-body, .checkin-body, .escalate-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 24px; gap: 10px; }
.brain-pulse { font-size: 40px; color: var(--accent); letter-spacing: 2px; }
.idle-title { font-size: 22px; font-weight: 700; margin: 4px 0 0; }
.idle-sub { font-size: 13px; color: var(--muted); margin: 0; }
.big-check { font-size: 60px; color: var(--good); }

/* detect */
.state-detect .phone-screen, .phone-screen.state-detect { background: linear-gradient(180deg,#fff6ec,#ffe9d2); }
.detect-icon { font-size: 54px; }
.detect-title { font-size: 20px; font-weight: 700; margin: 0; color: var(--accent-2); }
.detect-sub { font-size: 13px; color: var(--muted); margin: 0; }

/* check-in */
.phone-screen.state-checkin { background: linear-gradient(180deg,#fff4e6,#ffe6cc); }
.checkin-title { font-size: 24px; font-weight: 800; margin: 0; }
.ring {
  width: 110px; height: 110px; border-radius: 50%;
  border: 6px solid var(--accent); display: grid; place-items: center;
  font-size: 40px; font-weight: 800; color: var(--accent-2); margin: 6px 0;
}
.checkin-sub { font-size: 12px; color: var(--muted); margin: 0; }

/* dismissed */
.phone-screen.state-dismissed { background: linear-gradient(180deg,#fdfbf5,#f3f8ee); }

/* escalate */
.phone-screen.state-escalate { background: linear-gradient(180deg,#fff0f0,#ffe0e0); }
.escalate-icon { font-size: 50px; }
.escalate-title { font-size: 17px; font-weight: 700; color: var(--bad); margin: 0; }
.escalate-list { list-style: none; padding: 0; margin: 8px 0 0; width: 100%; font-size: 13px; text-align: left; }
.escalate-list li { padding: 8px 10px; border-radius: 8px; color: var(--muted); margin-bottom: 6px; background: rgba(0,0,0,0.03); }
.escalate-list li.done { color: var(--good); }
.escalate-list li.active { color: var(--bad); font-weight: 600; background: rgba(229,72,77,0.1); }
.sim-badge { margin-top: 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; color: var(--bad); border: 1px dashed var(--bad); padding: 5px 10px; border-radius: 6px; }

/* side explainer */
.demo-explain { flex: 1; min-width: 280px; }
.demo-explain h3 { margin: 0 0 10px; font-size: 15px; }
.flow-steps { margin: 0; padding-left: 20px; font-size: 13px; color: var(--muted); }
.flow-steps li { margin-bottom: 10px; padding: 4px 8px; border-radius: 6px; transition: all 0.3s; }
.flow-steps li.active { background: rgba(245,158,11,0.12); color: var(--ink); font-weight: 600; }
.flow-steps em { color: var(--accent-2); font-style: normal; }

@media (max-width: 720px) {
  .phone-row { justify-content: center; }
}

/* ===== Big Idea landing page ===== */
.hero { background: linear-gradient(180deg,#fffaf0,#fff); }
.hero-h { font-size: 15px; color: var(--accent-2); margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.hero-p { font-size: 16px; line-height: 1.6; margin: 0 0 14px; }
.hero-q {
  font-size: 22px; font-weight: 800; color: var(--ink);
  text-align: center; margin: 18px 0; padding: 16px;
  background: var(--panel-2); border-radius: 12px; border-left: 4px solid var(--accent);
}

.section-lead { font-size: 15px; font-weight: 700; color: var(--ink); margin: 8px 2px 10px; }
.plain-lead { font-size: 14px; color: var(--ink); background: var(--panel-2);
  border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; }
.intro-lead { font-size: 14px; margin: 0 0 14px; }

/* takeaway cards */
.hero-takeaways { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 4px; }
.hero-takeaways.big { margin-bottom: 18px; }
.hero-take {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 16px; text-align: center; box-shadow: 0 2px 10px rgba(180,140,80,0.06);
}
.ht-big { font-size: 34px; margin-bottom: 8px; }
.ht-txt { font-size: 13px; line-height: 1.5; color: var(--ink); }
.ht-txt strong { color: var(--accent-2); }
.hero-explore { font-size: 14px; color: var(--muted); margin: 6px 0 0; }

/* product story steps */
.story-steps { margin: 6px 0 12px; padding-left: 22px; }
.story-steps li { margin-bottom: 10px; font-size: 15px; line-height: 1.5; }

/* navigation cards */
.nav-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.nav-cards.three { grid-template-columns: repeat(3, 1fr); }
.nav-card {
  display: block; text-decoration: none; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 24px; transition: all 0.2s; box-shadow: 0 2px 10px rgba(180,140,80,0.06);
}
.nav-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(234,115,23,0.12); }
.nc-ico { font-size: 32px; margin-bottom: 8px; }
.nav-card h3 { margin: 0 0 6px; font-size: 18px; }
.nav-card p { margin: 0 0 12px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.nc-go { font-size: 14px; font-weight: 700; color: var(--accent-2); }

@media (max-width: 720px) {
  .hero-takeaways { grid-template-columns: 1fr; }
  .nav-cards, .nav-cards.three { grid-template-columns: 1fr; }
}

/* footer credit */
.foot .credit { max-width: 540px; text-align: right; }
.foot .credit a { color: var(--accent-2); text-decoration: none; }
.foot .credit a:hover { text-decoration: underline; }

/* worked example (collapsible) */
.worked { margin-top: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.worked summary {
  cursor: pointer; padding: 14px 16px; font-weight: 700; font-size: 14px;
  color: var(--accent-2); list-style: none;
}
.worked summary::-webkit-details-marker { display: none; }
.worked[open] summary { border-bottom: 1px solid var(--line); }
.worked .caret { display: inline-block; transition: transform 0.2s ease; font-size: 11px; }
.worked[open] .caret { transform: rotate(90deg); }
.worked-body { padding: 16px; }
.worked-intro { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.worked-head { font-size: 13px; font-weight: 700; color: var(--accent); margin: 16px 0 6px; }
.worked-list { margin: 0 0 8px; padding-left: 18px; font-size: 13px; }
.worked-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.worked-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.worked-table td:last-child { text-align: right; white-space: nowrap; color: var(--ink); }
.worked-note { font-size: 13px; color: var(--muted); margin: 14px 0 0; background: var(--panel);
  border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 6px; line-height: 1.5; }
.worked-note strong { color: var(--ink); }

/* ===== QOL: QR box ===== */
.qr-box { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.qr-box-text { flex: 1; min-width: 240px; }
.qr-box-text h2 { margin: 0 0 8px; }
.qr-box-text p { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.qr-or a { color: var(--accent-2); text-decoration: none; font-weight: 600; }
.qr-or a:hover { text-decoration: underline; }
.qr-box-img { text-align: center; }
.qr-box-img img { width: 150px; height: 150px; border: 1px solid var(--line); border-radius: 12px; padding: 6px; background: #fff; }
.qr-box-img span { display: block; font-size: 11px; color: var(--muted); margin-top: 6px; letter-spacing: 1px; text-transform: uppercase; }

/* ===== QOL: page-to-page continue link ===== */
.page-next { display: flex; justify-content: flex-end; margin: 4px 0 24px; }
.page-next a {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff; text-decoration: none;
  padding: 12px 20px; border-radius: 10px; font-weight: 600; font-size: 15px;
  transition: background 0.2s;
}
.page-next a:hover { background: var(--accent-2); }

/* ===== QOL: scroll-to-top button ===== */
#toTop {
  position: fixed; right: 22px; bottom: 22px; z-index: 50;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  font-size: 20px; box-shadow: 0 6px 18px rgba(234,115,23,0.3);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
#toTop.show { opacity: 1; pointer-events: auto; }
#toTop:hover { background: var(--accent-2); }



/* device electrode map */
.electrode-map { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 4px; }
.em-region {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-left-width: 4px; border-radius: 10px; padding: 12px 14px;
}
.em-region.best { border-left-color: #f59e0b; }
.em-region.key  { border-left-color: #ea7317; }
.em-region.opt  { border-left-color: #d8c9b6; }
.em-dot {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff;
}
.em-region.best .em-dot { background: #f59e0b; }
.em-region.key  .em-dot { background: #ea7317; }
.em-dot.dash { background: #fff; color: var(--accent-2); border: 2px dashed var(--accent-2); }
.em-label { font-size: 14px; }
.em-label strong { display: block; }
.em-label span { font-size: 12px; color: var(--muted); }
