/* Lo-fi black & white wireframe theme. */
:root {
  --ink: #000; --paper: #fff; --muted: #666; --line: #000;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); -webkit-text-size-adjust: 100%; }

.topbar { padding: 16px 18px 4px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 1.3rem; font-weight: 700; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }

.app { max-width: 620px; margin: 0 auto; padding: 14px 16px 30px; }
.screen { display: flex; flex-direction: column; gap: 12px; }
.lead { margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.muted-note { color: var(--muted); font-size: 0.82rem; margin: 4px 0 0; }

.screen-head { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.back { background: none; border: 0; color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; padding: 4px 2px; }
.screen-title { margin: 0; font-size: 1.15rem; text-align: center; flex: 1; }

/* Home / menu cards */
.card-btn, .menu-btn {
  text-align: left; display: flex; flex-direction: column; gap: 4px; position: relative;
  padding: 16px; border: 2px solid var(--line); border-radius: 6px;
  background: var(--paper); color: var(--ink); font: inherit; cursor: pointer;
}
.card-title { font-size: 1.1rem; font-weight: 700; }
.card-desc, .menu-desc { color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.menu-title { font-weight: 700; }
.menu-btn.disabled { opacity: 0.5; cursor: default; }
.badge { position: absolute; top: 12px; right: 12px; font-size: 0.66rem; font-weight: 700; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; }
.badge.big { position: static; align-self: flex-start; }
.plan-list { margin: 4px 0; padding-left: 18px; color: var(--muted); font-size: 0.86rem; line-height: 1.6; }

/* Buttons */
.btn { flex: 1 1 auto; min-width: 90px; padding: 11px 12px; border: 2px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.exit { width: 100%; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* Segmented toggles */
.segmented { display: flex; gap: 0; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented.small { flex: 0 0 auto; }
.seg { flex: 1; padding: 9px 12px; border: 0; border-right: 1px solid var(--line); background: var(--paper); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.seg:last-child { border-right: 0; }
.seg.active { background: var(--ink); color: var(--paper); }

/* Phone-style stage (Exercise + Error test) */
.phone { align-items: stretch; }
.ex-title { margin: 6px 0 0; font-size: 1.5rem; font-weight: 800; text-align: center; }
.ex-sub { margin: 0; text-align: center; color: var(--ink); font-size: 1rem; }
.ex-headermsg { margin: 0; text-align: center; font-weight: 700; }
.phone-stage { position: relative; width: 100%; max-width: 360px; margin: 4px auto; aspect-ratio: 3 / 4; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; background: #eee; }
.cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam.hidden { opacity: 0; }
.overlay-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.demo-overlay { position: absolute; inset: 0; margin: auto; max-width: 78%; max-height: 82%; object-fit: contain; opacity: 0.6; pointer-events: none; }
.indication { position: absolute; left: 16%; right: 16%; bottom: 20%; height: 22%; border: 2px solid var(--ink); }
.speaking { position: absolute; left: 50%; bottom: 18%; transform: translateX(-50%); width: 66px; height: 66px; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper); display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 700; }
.correction-overlay { position: absolute; left: 8%; right: 8%; top: 10%; background: rgba(255,255,255,0.88); border: 2px solid var(--ink); padding: 8px 10px; font-size: 0.88rem; font-weight: 700; text-align: center; }

/* Test controls (Exercise AB) */
.test-controls { display: flex; flex-direction: column; gap: 8px; border: 1px dashed var(--line); border-radius: 6px; padding: 10px; }
.ctl-row { display: flex; align-items: center; gap: 10px; }
.ctl-label { width: 70px; font-size: 0.8rem; font-weight: 700; }

/* Breath-tracking visualisation (Training) */
.stage { position: relative; background: #eee; border-radius: 6px; overflow: hidden; border: 2px solid var(--line); aspect-ratio: 4 / 3; }
.view { display: block; width: 100%; height: 100%; object-fit: cover; touch-action: none; }
.hint { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 6px 8px; font-size: 0.78rem; background: rgba(255,255,255,0.85); }
.viz { display: flex; gap: 12px; height: 140px; }
.level { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 46px; }
.level-track { flex: 1; width: 100%; border: 2px solid var(--line); border-radius: 4px; display: flex; align-items: flex-end; overflow: hidden; }
.level-fill { width: 100%; height: 0%; background: var(--ink); }
.level-label, .wave-label { font-size: 0.7rem; color: var(--muted); }
.wave-wrap { flex: 1; display: flex; flex-direction: column; gap: 6px; border: 2px solid var(--line); border-radius: 4px; padding: 6px; }
.wave { flex: 1; width: 100%; height: 100%; display: block; }

/* Checklist */
.checklist { display: flex; flex-direction: column; gap: 8px; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 2px solid var(--line); border-radius: 6px; font-size: 0.9rem; cursor: pointer; }
.check-item input { width: 18px; height: 18px; accent-color: #000; }

.status { color: var(--muted); font-size: 0.84rem; margin: 4px 2px 0; min-height: 1.2em; }
.debug { color: var(--muted); font-size: 0.72rem; margin: 2px; white-space: pre-wrap; }
.foot { max-width: 620px; margin: 0 auto; padding: 14px 16px; font-size: 0.74rem; line-height: 1.4; color: var(--muted); border-top: 1px solid var(--line); }

/* --- Demo overlays (Exercise) --- */
.demo-2d-panel { position: absolute; top: 10%; left: 50%; transform: translateX(-50%);
  width: 62%; height: 44%; background: rgba(110,110,110,0.45); border-radius: 18px;
  display: flex; align-items: center; justify-content: center; pointer-events: none; }
.demo-2d { max-width: 92%; max-height: 92%; object-fit: contain; }
.demo-3d { position: absolute; top: 6px; right: 6px; width: 34%; max-height: 42%; object-fit: contain; opacity: 1; pointer-events: none; }

/* Speaking circle sits near the bottom edge of the grey panel on the Exercise screen. */
.speaking.ex-speaking { top: 50%; bottom: auto; }

/* --- Error box / auto belly box: positioned by JS --- */
.error-box { position: absolute; border: 3px solid var(--ink); display: none; pointer-events: none; }

/* ===================== Breath Flow (exact to SVG spec) ===================== */
:root {
  --bf-blue-l: #3DADFF; --bf-blue-d: #256899;
  --bf-amber-l: #FFCB3D; --bf-amber-d: #C78D11;
  --bf-grey: #D9D9D9; --bf-ink: #444444; --bf-sub: #A3A3A3;
}
/* Hide the app chrome while a Breath Flow screen is showing (flow test = clean screen). */
body:has(.bf-root) .topbar,
body:has(.bf-root) .foot { display: none; }
body:has(.bf-root) .app { max-width: 390px; padding: 0; margin: 0 auto; }

.bf-root { color: var(--bf-ink); }
/* Full-height screen: text block at top, visual centered, button pinned at bottom. */
.bf-screen { position: relative; min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; text-align: center; padding: 46px 28px 30px; }
.bf-top { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.bf-mid { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; width: 100%; }
.bf-close { position: absolute; top: 16px; right: 18px; background: none; border: 0; font-size: 1.8rem; line-height: 1; color: var(--bf-sub); cursor: pointer; }

.bf-title { margin: 0; font-size: 1.6rem; font-weight: 800; color: var(--bf-ink); }
.bf-sub { margin: 0; color: var(--bf-sub); font-size: 1rem; line-height: 1.45; }
.bf-body { margin: 0; color: var(--bf-sub); font-size: 1rem; max-width: 300px; line-height: 1.5; align-self: center; }
.bf-icon { width: 120px; height: 120px; object-fit: contain; }
.bf-img { max-width: 190px; max-height: 240px; object-fit: contain; }
.bf-mins { margin: 0; color: var(--bf-sub); font-size: 0.95rem; }
.bf-bullets { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 300px; }
.bf-bullet { display: flex; align-items: center; gap: 12px; text-align: left; color: var(--bf-sub); font-size: 0.92rem; }
.bf-bicon { width: 26px; height: 26px; object-fit: contain; flex: 0 0 auto; }
.bf-btn { width: 100%; max-width: 300px; margin-top: 12px; padding: 14px 18px; border: 0; border-radius: 8px;
  background: #333; color: #fff; font: inherit; font-size: 1rem; font-weight: 700; cursor: pointer; }

/* Intro "Breathing 1" target: two grey rings + blue dot (radii 126.37 / 96.87 / 48) */
.bf-target { position: relative; width: 253px; height: 253px; display: flex; align-items: center; justify-content: center; }
.bf-target .r1 { position: absolute; width: 253px; height: 253px; border-radius: 50%; background: var(--bf-grey); opacity: .5; }
.bf-target .r2 { position: absolute; width: 194px; height: 194px; border-radius: 50%; background: var(--bf-grey); }
.bf-target .dot { position: absolute; width: 96px; height: 96px; border-radius: 50%; background: linear-gradient(90deg, var(--bf-blue-d), var(--bf-blue-l)); }

/* ---- Breathing run ---- */
.bf-phase { margin: 0; font-size: 2rem; font-weight: 800; color: var(--bf-ink); min-height: 1.15em; }
.bf-stage { position: relative; display: flex; align-items: center; justify-content: center; }
.hidden { display: none !important; }

/* Balloon: ring r=126.37 (d=253); blue small r=48 (scale .38) -> big r=126.37 (scale 1) */
.bf-stage.balloon { width: 253px; height: 253px; }
.bf-ring { position: absolute; width: 253px; height: 253px; border-radius: 50%; background: var(--bf-grey); }
.bf-balloon { position: relative; width: 253px; height: 253px; border-radius: 50%;
  background: linear-gradient(90deg, var(--bf-blue-d), var(--bf-blue-l)); transform: scale(.38); }
.bf-balloon.amber { background: linear-gradient(90deg, var(--bf-amber-d), var(--bf-amber-l)); }

/* Thermometer */
.bf-stage.thermo { width: 200px; height: 360px; }
.bf-trail { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); width: 120px; height: 300px;
  background: var(--bf-grey); clip-path: polygon(47% 0, 53% 0, 100% 100%, 0 100%); }
.bf-starsvg { width: 92px; height: auto; display: block; }
.bf-star-move { position: absolute; left: 50%; margin-left: -46px; bottom: 8px; transform: translateY(0); }
.bf-star-target { position: absolute; left: 50%; margin-left: -46px; top: 4px; }

/* ===================== Training flow ===================== */
:root { --tr-blue: #3DADFF; --tr-grey: #D9D9D9; --tr-ink: #444444; --tr-sub: #A3A3A3; }
body:has(.tr-root) .topbar, body:has(.tr-root) .foot { display: none; }
body:has(.tr-root) .app { max-width: 390px; padding: 0; margin: 0 auto; }
.tr-root { color: var(--tr-ink); }
.tr-screen { position: relative; min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 16px 24px 30px; }
.tr-head { position: relative; width: 100%; display: flex; align-items: center; justify-content: center; height: 34px; }
.tr-back { position: absolute; left: 0; background: none; border: 0; font-size: 1.7rem; line-height: 1; color: var(--tr-blue); cursor: pointer; }
.tr-htitle { font-size: 0.95rem; font-weight: 700; color: var(--tr-ink); }
.tr-progress { width: 100%; max-width: 324px; margin: 14px 0 8px; }
.tr-plabel { font-size: 0.85rem; color: var(--tr-ink); margin-bottom: 8px; }
.tr-bar { display: flex; gap: 5px; }
.tr-seg { flex: 1; height: 14px; border-radius: 7px; background: var(--tr-grey); }
.tr-seg.on { background: var(--tr-blue); }
.tr-title { margin: 14px 0 0; font-size: 1.35rem; font-weight: 800; color: var(--tr-ink); }
.tr-sub { margin: 8px 0 0; color: var(--tr-sub); font-size: 0.95rem; line-height: 1.45; max-width: 300px; }
.tr-note { margin: 14px 0 0; color: var(--tr-sub); font-size: 0.85rem; }
.tr-mid { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
.tr-circle { width: 219px; height: 219px; border-radius: 50%; background: linear-gradient(135deg, #BBE2FF, #23A2FF); }
.tr-number { font-size: 64px; font-weight: 800; color: var(--tr-ink); display: none; }
.tr-posture { max-width: 300px; max-height: 240px; object-fit: contain; display: none; }
.tr-btn { width: 100%; max-width: 300px; padding: 14px 18px; border: 0; border-radius: 8px; background: #333;
  color: #fff; font: inherit; font-size: 1rem; font-weight: 700; cursor: pointer; }

/* ===================== Camera Training ===================== */
:root { --ct-blue: #1D9FFF; --ct-green: #03DA03; --ct-grey: #D9D9D9; }
body:has(.ct-root) .topbar, body:has(.ct-root) .foot { display: none; }
body:has(.ct-root) .app { max-width: 390px; padding: 0; margin: 0 auto; }
.ct-root { color: var(--ct-blue); }
.ct-screen { min-height: 100dvh; display: flex; flex-direction: column; }
.ct-head { position: relative; display: flex; align-items: center; justify-content: center; height: 40px; padding: 6px 20px 0; }
.ct-back { position: absolute; left: 16px; top: 6px; background: none; border: 0; font-size: 1.7rem; line-height: 1; color: var(--ct-blue); cursor: pointer; }
.ct-htitle { font-size: 0.95rem; font-weight: 700; color: var(--ct-blue); }
.ct-title { margin: 14px 20px 0; text-align: center; font-size: 1.35rem; font-weight: 800; color: var(--ct-blue); }
.ct-sub { margin: 8px 20px 0; text-align: center; font-size: 0.95rem; line-height: 1.45; color: var(--ct-blue); }
.ct-mid { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; margin-top: 14px; }
.ct-bigcircle { width: 219px; height: 219px; border-radius: 50%; background: linear-gradient(135deg, #BBE2FF, #23A2FF); }
.ct-posture { max-width: 300px; max-height: 180px; object-fit: contain; }
.ct-box { position: relative; width: 100%; height: 100%; background: var(--ct-grey); overflow: hidden; }
.ct-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ct-ball { position: absolute; left: 50%; bottom: 46px; margin-left: -39px; width: 78px; height: 78px; border-radius: 50%;
  background: linear-gradient(135deg, #BBE2FF, #23A2FF); transform: scale(1); }
.ct-ball.green { background: var(--ct-green); }
.ct-btnwrap { padding: 16px 20px 26px; }
.ct-btn { width: 100%; padding: 14px 18px; border: 0; border-radius: 999px; background: var(--ct-blue); color: #fff;
  font: inherit; font-size: 1rem; font-weight: 700; cursor: pointer; }
.ct-btn.ghost { background: #fff; color: var(--ct-blue); border: 2px solid var(--ct-blue); }
.ct-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* Camera Training box fills the middle area reliably */
.ct-mid { position: relative; }
.ct-box { position: absolute; inset: 0; width: auto; height: auto; }
.ct-canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }

/* ===================== Voice Assistant test ===================== */
.voice-label { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; }
.voice-url { width: 100%; padding: 10px 12px; border: 2px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink); font: inherit; }
.voice-convo { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.voice-bubble { padding: 10px 12px; border: 2px solid var(--line); border-radius: 10px; min-height: 1.2em; font-size: 0.95rem; }
.voice-bubble:empty { display: none; }
.voice-bubble.bot { background: var(--ink); color: var(--paper); }

/* ===================== AI Voice Training ===================== */
.vt-stage { position: relative; flex: none; width: 220px; height: 220px; display: flex; align-items: center; justify-content: center; }
.vt-ring { position: absolute; width: 220px; height: 220px; border-radius: 50%; background: #D9D9D9; visibility: hidden; }
.vt-circle { position: relative; width: 220px; height: 220px; border-radius: 50%; background: linear-gradient(135deg, #BBE2FF, #23A2FF); transform: scale(.4); will-change: transform; }
.vt-circle.amber { background: linear-gradient(135deg, #FFD97A, #E0921A); }
.vt-posture { max-width: 280px; max-height: 170px; object-fit: contain; display: none; }
.vt-text { width: 100%; height: 150px; flex: none; display: flex; flex-direction: column; align-items: center; }   /* same size on every screen, so nothing below it moves */
.vt-text .tr-title:empty, .vt-text .tr-sub:empty, .vt-text .tr-note:empty { display: none; }
.vt-status { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; max-width: 320px;
  height: 2.9em; flex: none; margin: 4px 0 8px; font-size: .8rem; line-height: 1.3; color: var(--tr-sub); text-align: center; }
.vt-logtext { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vt-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: #C9C9C9; }
.vt-dot.listening { background: #3DC46A; }
.vt-dot.hearing { background: var(--tr-blue); animation: vt-pulse .7s ease-in-out infinite; }
.vt-dot.thinking { background: #F2A31B; }
.vt-dot.speaking { background: var(--tr-blue); }
@keyframes vt-pulse { 50% { transform: scale(1.6); opacity: .6; } }

/* debug panel (top-right "debug" toggle) */
.vt-dbgbtn { position: absolute; right: 0; background: none; border: 0; padding: 4px; font: inherit; font-size: .72rem; color: var(--tr-sub); cursor: pointer; }
.vt-debug { display: none; width: 100%; max-width: 320px; margin: 0 0 10px; text-align: left; }
.vt-debug.open { display: block; }
.vt-dbg-wave { display: block; width: 100%; height: 80px; border: 1px solid var(--tr-grey); border-radius: 8px; }
.vt-dbg-text { margin: 6px 0; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; font-size: .68rem; line-height: 1.4; color: #666; }
.vt-dbg-row { display: flex; gap: 8px; }
.vt-dbg-btn { flex: 1; padding: 6px 8px; border: 1px solid var(--tr-grey); border-radius: 8px; background: #fff; color: var(--tr-ink); font: inherit; font-size: .75rem; cursor: pointer; }

/* Sensor Validation: full-screen flash for the camera sync point. */
.sv-flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 9999; transition: opacity 60ms linear; }
.sv-flash.on { opacity: 1; }
