""" Body Debt — Gradio App (dark "off-brand" edition) Quantifies physiological debt from lifestyle stressors and provides AI-backed recovery prescriptions using a local small model. """ from __future__ import annotations import html import time from datetime import datetime import gradio as gr import numpy as np from scoring import ( Stressor, compute_live_score, compute_system_scores, compute_counterfactual, STRESSOR_DEFS, SYSTEM_META, ) from face_scan import run_face_scan, features_to_array from stress_model import predict_stress_score from health_coach import stream_advice, stream_plan, _fallback_advice, _fallback_plan # ─── Design tokens (mirrors src/lib/design-tokens.ts) ──────────────────────── BG_BASE = "#0A0A0B" BG_SURFACE = "#141416" BG_ELEVATED = "#1C1C1F" BORDER = "rgba(168, 162, 158, 0.10)" BORDER_SOFT = "rgba(168, 162, 158, 0.06)" TEXT_PRIMARY = "#F5F5F4" TEXT_SECONDARY = "#A8A29E" TEXT_MUTED = "#524F4C" TEXT_FAINT = "#3a3835" BRAND_PRIMARY = "#EA580C" BRAND_SECONDARY = "#F59E0B" RECOVERY_GREEN = "#4ADE80" # Light mode tokens LT_BG_BASE = "#FAFAF9" LT_BG_SURFACE = "#F5F5F4" LT_BG_ELEVATED = "#E7E5E4" LT_BORDER = "rgba(0, 0, 0, 0.08)" LT_BORDER_SOFT = "rgba(0, 0, 0, 0.04)" LT_TEXT_PRIMARY = "#1C1917" LT_TEXT_SECONDARY = "#57534E" LT_TEXT_MUTED = "#7A7672" LT_TEXT_FAINT = "#B8B4B0" SYSTEM_ACCENTS = { "cardiovascular": ("#F43F5E", "rgba(244, 63, 94, 0.18)", "rgba(244, 63, 94, 0.40)"), "brain": ("#22D3EE", "rgba(34, 211, 238, 0.18)", "rgba(34, 211, 238, 0.40)"), "liver": ("#EAB308", "rgba(234, 179, 8, 0.18)", "rgba(234, 179, 8, 0.40)"), "muscular": ("#A78BFA", "rgba(167, 139, 250, 0.18)","rgba(167, 139, 250, 0.40)"), "gut": ("#2DD4BF", "rgba(45, 212, 191, 0.18)", "rgba(45, 212, 191, 0.40)"), } SYSTEM_GLYPHS = { "cardiovascular": "C", "brain": "N", "liver": "L", "muscular": "M", "gut": "G", } DEBT_TIERS = [ (0, 20, "#4ADE80", "You're clear. Minimal debt.", "low"), (20, 40, "#F59E0B", "Low debt. Minor adjustments needed.", "low"), (40, 60, "#EA580C", "Moderate debt. Recovery recommended.","moderate"), (60, 80, "#DC2626", "High debt. Prioritize recovery.", "high"), (80, 101,"#991B1B", "Critical debt. Full rest mode.", "critical"), ] TIME_OPTIONS = [] for h in range(12): for m in ["00", "30"]: if h == 0: TIME_OPTIONS.append(f"12:{m} AM") else: TIME_OPTIONS.append(f"{h}:{m} AM") for h in range(12): for m in ["00", "30"]: if h == 0: TIME_OPTIONS.append(f"12:{m} PM") else: TIME_OPTIONS.append(f"{h}:{m} PM") WINDOW_COLORS = { "RIGHT NOW": "#DC2626", "THIS MORNING": "#EA580C", "TODAY": "#F59E0B", "AVOID": "#A78BFA", } def debt_tier(score: int) -> tuple[str, str, str]: for lo, hi, color, verdict, _ in DEBT_TIERS: if lo <= score < hi: return color, verdict, DEBT_TIERS[DEBT_TIERS.index((lo, hi, color, verdict, _))][4] return "#4ADE80", "You're clear. Minimal debt.", "low" # ─── Custom CSS (off-brand dark theme) ─────────────────────────────────────── CUSTOM_CSS = f""" @import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600;700&display=swap'); :root {{ --bg-base: {BG_BASE}; --bg-surface: {BG_SURFACE}; --bg-elevated: {BG_ELEVATED}; --border: {BORDER}; --border-soft: {BORDER_SOFT}; --text-primary: {TEXT_PRIMARY}; --text-secondary: {TEXT_SECONDARY}; --text-muted: {TEXT_MUTED}; --text-faint: {TEXT_FAINT}; --brand: {BRAND_PRIMARY}; --brand-secondary: {BRAND_SECONDARY}; --recovery-green: {RECOVERY_GREEN}; }} body.light-mode {{ --bg-base: {LT_BG_BASE}; --bg-surface: {LT_BG_SURFACE}; --bg-elevated: {LT_BG_ELEVATED}; --border: {LT_BORDER}; --border-soft: {LT_BORDER_SOFT}; --text-primary: {LT_TEXT_PRIMARY}; --text-secondary: {LT_TEXT_SECONDARY}; --text-muted: {LT_TEXT_MUTED}; --text-faint: {LT_TEXT_FAINT}; --brand: {BRAND_PRIMARY}; --brand-secondary: {BRAND_SECONDARY}; --recovery-green: {RECOVERY_GREEN}; }} html, body, .gradio-container {{ background: var(--bg-base) !important; color: var(--text-primary) !important; font-family: 'Inter', system-ui, sans-serif !important; }} .gradio-container {{ max-width: 1180px !important; padding: 0 24px 60px !important; }} footer {{ display: none !important; }} /* Hide default Gradio chrome we don't need */ .block.padded, .panel, .gap, .form {{ background: transparent !important; border: none !important; }} /* The giant debt score number */ .debt-hero {{ font-family: 'DM Serif Display', Georgia, serif; font-size: clamp(7rem, 22vw, 11rem); font-weight: 400; line-height: 0.9; letter-spacing: -0.04em; margin: 0; text-shadow: 0 0 60px currentColor; transition: color 0.6s ease; animation: heroDrop 0.7s cubic-bezier(0.22, 1, 0.36, 1) backwards; }} .debt-hero-label {{ font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 8px; animation: fadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.05s backwards; }} .debt-verdict {{ font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-top: 6px; animation: fadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.25s backwards; }} /* The breathing orb behind the score */ .orb-wrap {{ position: relative; display: inline-block; padding: 40px 60px 30px; }} .orb-wrap::before {{ content: ''; position: absolute; inset: -30px; background: radial-gradient(circle, currentColor 0%, transparent 65%); opacity: 0.18; border-radius: 50%; animation: orbBreath 4s ease-in-out infinite; z-index: -2; }} .orb-wrap::after {{ content: ''; position: absolute; inset: -50px; background: radial-gradient(circle, currentColor 0%, transparent 70%); opacity: 0.06; border-radius: 50%; animation: orbBreath 4s ease-in-out infinite 0.5s; z-index: -3; filter: blur(8px); }} @keyframes orbBreath {{ 0%, 100% {{ transform: scale(1); }} 50% {{ transform: scale(1.10); }} }} @keyframes heroDrop {{ 0% {{ opacity: 0; transform: scale(0.6) translateY(8px); filter: blur(8px); }} 100% {{ opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }} }} @keyframes fadeUp {{ 0% {{ opacity: 0; transform: translateY(6px); }} 100% {{ opacity: 1; transform: translateY(0); }} }} /* Section labels */ .section-label {{ font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-muted); margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }} .section-label::after {{ content: ''; flex: 1; height: 1px; background: var(--border-soft); }} /* System meter */ .sys-meter {{ padding: 10px 14px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; transition: border-color 0.2s, background 0.2s; animation: fadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards; }} .sys-meter:nth-child(1) {{ animation-delay: 0.05s; }} .sys-meter:nth-child(2) {{ animation-delay: 0.10s; }} .sys-meter:nth-child(3) {{ animation-delay: 0.15s; }} .sys-meter:nth-child(4) {{ animation-delay: 0.20s; }} .sys-meter:nth-child(5) {{ animation-delay: 0.25s; }} .sys-meter.is-primary {{ background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent); }} .sys-glyph {{ width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 700; flex-shrink: 0; }} .sys-body {{ flex: 1; min-width: 0; }} .sys-row {{ display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }} .sys-label {{ font-size: 13px; font-weight: 600; color: var(--text-primary); }} .sys-time {{ font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--text-muted); }} .sys-bar {{ margin-top: 8px; height: 3px; background: rgba(168, 162, 158, 0.10); border-radius: 2px; overflow: hidden; }} .sys-bar-fill {{ height: 100%; border-radius: 2px; transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1); }} .sys-cause {{ font-size: 11px; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }} /* Protocol step */ .proto-step {{ display: flex; gap: 12px; padding: 8px 0; }} .proto-rail {{ display: flex; flex-direction: column; align-items: center; width: 30px; flex-shrink: 0; }} .proto-num {{ width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 700; border: 1px solid currentColor; background: rgba(255,255,255,0.02); }} .proto-conn {{ flex: 1; width: 1px; background: var(--border); min-height: 18px; margin-top: 4px; }} .proto-window {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 4px; }} .proto-action {{ font-size: 13px; color: var(--text-primary); line-height: 1.55; font-weight: 500; }} /* Science cards */ .sci-card {{ padding: 12px 14px; background: var(--bg-elevated); border-left: 2px solid currentColor; border-radius: 0 8px 8px 0; margin-bottom: 8px; }} .sci-fact {{ font-size: 12px; color: var(--text-secondary); line-height: 1.55; margin: 0 0 4px; }} .sci-cite {{ font-size: 10px; color: var(--text-faint); font-style: italic; margin: 0; font-family: 'JetBrains Mono', monospace; }} /* Face scan pill */ .face-pill {{ padding: 14px 16px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }} .face-pill-placeholder {{ padding: 20px; background: var(--bg-surface); border: 1.5px dashed var(--border); border-radius: 12px; text-align: center; margin-bottom: 16px; transition: border-color 0.2s; }} .face-pill-placeholder:hover {{ border-color: var(--brand); }} .face-pill-placeholder .icon {{ font-size: 28px; opacity: 0.4; margin-bottom: 6px; }} .face-pill-placeholder .label {{ font-size: 11px; color: var(--text-muted); font-weight: 500; }} .face-pill-placeholder .sub {{ font-size: 9px; color: var(--text-faint); margin-top: 2px; font-family: 'JetBrains Mono', monospace; }} .face-num {{ font-family: 'DM Serif Display', serif; font-size: 36px; line-height: 1; }} .face-label {{ font-size: 9px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-muted); }} .face-status {{ font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 4px; }} .face-meta {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; color: var(--text-faint); margin-top: 4px; }} .face-bar {{ margin-top: 8px; height: 4px; background: rgba(168, 162, 158, 0.08); border-radius: 2px; overflow: hidden; }} .face-bar-fill {{ height: 100%; border-radius: 2px; transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1); }} /* Agent trace */ .trace-step {{ display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 6px; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; }} .trace-step.is-active {{ color: var(--brand); background: rgba(234, 88, 12, 0.06); }} .trace-step.is-done {{ color: var(--recovery-green); }} .trace-dot {{ width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }} .trace-step.is-active .trace-dot {{ animation: pulse 1.2s ease-in-out infinite; }} @keyframes pulse {{ 0%,100% {{ opacity: 1; }} 50% {{ opacity: 0.3; }} }} /* AI coach block */ .coach-block {{ padding: 20px 22px; background: linear-gradient(180deg, var(--bg-surface), var(--bg-base)); border: 1px solid var(--border); border-radius: 14px; margin-top: 8px; }} .coach-header {{ display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--brand); }} .coach-pill {{ background: var(--bg-elevated); color: var(--text-muted); padding: 3px 8px; border-radius: 4px; font-size: 9px; }} .coach-body {{ font-size: 14px; color: var(--text-primary); line-height: 1.7; white-space: pre-wrap; min-height: 60px; }} .coach-cursor {{ display: inline-block; width: 7px; height: 14px; background: var(--brand); margin-left: 2px; vertical-align: text-bottom; animation: blink 1s steps(2, start) infinite; }} @keyframes blink {{ to {{ visibility: hidden; }} }} /* Buttons */ button.primary, .gr-button-primary {{ background: var(--brand) !important; color: white !important; border: none !important; border-radius: 10px !important; font-weight: 700 !important; letter-spacing: 0.02em !important; transition: transform 0.15s, box-shadow 0.15s !important; }} button.primary:hover, .gr-button-primary:hover {{ transform: translateY(-1px) !important; box-shadow: 0 6px 20px rgba(234, 88, 12, 0.35) !important; }} /* Inputs */ input, textarea, .gr-input, .gr-text-input, .gr-dropdown {{ background: var(--bg-surface) !important; border: 1px solid var(--border) !important; color: var(--text-primary) !important; border-radius: 8px !important; }} input:focus, textarea:focus {{ border-color: var(--brand) !important; outline: none !important; }} /* Checkbox */ .gr-checkbox {{ background: transparent !important; }} .gr-checkbox input[type="checkbox"] {{ appearance: none; width: 18px; height: 18px; border: 1.5px solid var(--text-muted); border-radius: 4px; background: var(--bg-surface); cursor: pointer; position: relative; transition: all 0.15s; }} .gr-checkbox input[type="checkbox"]:checked {{ background: var(--brand); border-color: var(--brand); }} .gr-checkbox input[type="checkbox"]:checked::after {{ content: '✓'; color: white; position: absolute; top: -2px; left: 3px; font-size: 14px; font-weight: 800; }} .gr-checkbox label {{ color: var(--text-primary) !important; font-weight: 500 !important; }} /* Care checkbox — green when checked (positive stressor) */ #care-checkbox input[type="checkbox"]:checked {{ background: var(--recovery-green) !important; border-color: var(--recovery-green) !important; }} #care-checkbox label {{ color: var(--recovery-green) !important; }} /* Image upload area */ .gr-image, .gr-image-upload {{ background: var(--bg-surface) !important; border: 1px dashed var(--border) !important; border-radius: 10px !important; }} /* Empty state */ .empty-state {{ text-align: center; padding: 80px 20px; color: var(--text-faint); }} .empty-state .icon {{ font-size: 48px; opacity: 0.3; margin-bottom: 12px; }} .empty-state .label {{ font-size: 14px; font-weight: 500; color: var(--text-muted); }} .empty-state .sub {{ font-size: 12px; color: var(--text-faint); margin-top: 4px; }} /* Hide group labels for cleaner look */ .gr-group {{ background: transparent !important; border: none !important; }} .gr-form {{ background: transparent !important; }} /* App header */ .app-header {{ text-align: center; padding: 36px 0 28px; border-bottom: 1px solid var(--border-soft); margin-bottom: 28px; }} .app-title {{ font-family: 'Inter', sans-serif; font-weight: 800; letter-spacing: 0.22em; text-transform: uppercase; font-size: 12px; color: var(--text-primary); margin: 0 0 6px; }} .app-subtitle {{ font-family: 'Inter', sans-serif; font-size: 13px; color: var(--text-muted); margin: 0; max-width: 480px; margin: 0 auto; }} /* Footer */ .app-footer {{ text-align: center; padding: 28px 16px 16px; margin-top: 36px; border-top: 1px solid var(--border-soft); font-size: 10px; color: var(--text-faint); font-family: 'JetBrains Mono', monospace; }} .app-footer a {{ color: var(--brand); text-decoration: none; }} /* Header attribution pills */ .attr-row {{ display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }} .attr-pill {{ display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 600; color: var(--text-secondary); background: var(--bg-surface); text-decoration: none; transition: border-color 0.15s, color 0.15s; }} .attr-pill:hover {{ border-color: var(--brand); color: var(--text-primary); }} .attr-pill .dot {{ width: 6px; height: 6px; border-radius: 50%; background: var(--recovery-green); box-shadow: 0 0 8px var(--recovery-green); }} /* Ready pulse for empty coach/trace */ .ready-pulse {{ display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); margin-right: 8px; animation: pulse 1.6s ease-in-out infinite; }} /* Triage plan */ .plan-block {{ margin-bottom: 20px; animation: fadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.15s backwards; }} .plan-source {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; color: var(--text-faint); font-weight: 600; margin-left: auto; text-transform: none; letter-spacing: 0.1em; }} .plan-line {{ display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-soft); animation: fadeUp 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards; }} .plan-line:last-child {{ border-bottom: none; }} .plan-tag {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 800; letter-spacing: 0.14em; padding: 3px 8px; border: 1px solid; border-radius: 4px; flex-shrink: 0; min-width: 78px; text-align: center; }} .plan-text {{ font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 500; color: var(--text-primary); line-height: 1.4; }} /* Counterfactual hint */ .cf-block {{ display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; background: var(--bg-surface); border: 1px solid var(--border); border-left: 2px solid; border-radius: 0 10px 10px 0; margin: 16px 0; animation: fadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.2s backwards; }} .cf-label {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 800; letter-spacing: 0.16em; flex-shrink: 0; padding-top: 2px; min-width: 140px; }} .cf-body {{ font-size: 13px; color: var(--text-secondary); line-height: 1.55; }} /* Running debt pill */ .debt-pill {{ display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 999px; font-family: 'JetBrains Mono', monospace; font-size: 11px; transition: all 0.15s; margin-bottom: 14px; }} /* Preset scenario chips */ .preset-row {{ display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }} .preset-chip {{ font-family: 'JetBrains Mono', monospace; font-size: 10px !important; font-weight: 700 !important; padding: 5px 14px !important; border-radius: 999px !important; border: 1px solid var(--border) !important; background: var(--bg-surface) !important; color: var(--text-secondary) !important; letter-spacing: 0.04em !important; transition: all 0.15s !important; box-shadow: none !important; }} .preset-chip:hover {{ border-color: var(--brand) !important; color: var(--text-primary) !important; background: rgba(234, 88, 12, 0.06) !important; }} /* Clear all button */ button.clear-all {{ font-family: 'JetBrains Mono', monospace !important; font-size: 10px !important; font-weight: 600 !important; padding: 4px 12px !important; border: 1px solid var(--border) !important; border-radius: 8px !important; background: transparent !important; color: var(--text-muted) !important; transition: all 0.15s !important; margin-bottom: 8px !important; }} button.clear-all:hover {{ border-color: var(--text-faint) !important; color: var(--text-secondary) !important; }} /* Sample badge */ .sample-badge {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }} .sample-badge .dot {{ width: 5px; height: 5px; border-radius: 50%; background: var(--brand); animation: pulse 1.6s ease-in-out infinite; }} /* Theme toggle button */ .theme-toggle {{ position: fixed; top: 16px; right: 20px; z-index: 9999; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg-surface); color: var(--text-secondary); font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; backdrop-filter: blur(8px); }} .theme-toggle:hover {{ border-color: var(--brand); color: var(--brand); transform: scale(1.08); }} /* Smooth theme transitions — 0.2s matches existing hover rhythms */ .gradio-container, .sys-meter, .coach-block, .coach-pill, .tl-wrap, .face-pill, .face-pill-placeholder, .cf-block, .debt-pill, .attr-pill, input, textarea, .gr-input, .gr-text-input, .gr-dropdown, .gr-checkbox input[type="checkbox"]:not(:checked), .gr-checkbox label, .theme-toggle, .sci-card, .trace-step, .plan-line, .plan-tag, .sample-badge, .app-header, .app-footer, .section-label, .section-label::after, .debt-hero-label, .debt-verdict, .sys-label, .sys-time, .sys-cause, .sys-bar-fill, .proto-conn, .proto-action, .face-label, .face-meta, .plan-source, .plan-text, .cf-label, .cf-body, .empty-state .label, .empty-state .sub, .orb-wrap::before, .orb-wrap::after, #care-checkbox input[type="checkbox"]:not(:checked) {{ transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease; }} /* These have !important on their existing transitions, so !important needed here too */ .preset-chip, button.clear-all, button.primary, .gr-button-primary {{ transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease !important; }} /* Comparison card carousel */ .cmp-section {{ margin-top: 28px; }} .cmp-row {{ display: flex; gap: 10px; overflow-x: auto; padding: 4px 0 12px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }} .cmp-card {{ min-width: 170px; max-width: 200px; flex-shrink: 0; scroll-snap-align: start; padding: 12px 14px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; position: relative; }} .cmp-hero {{ font-family: 'DM Serif Display', Georgia, serif; font-size: 30px; line-height: 1; margin-bottom: 2px; }} .cmp-label {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-secondary); }} .cmp-time {{ font-family: 'JetBrains Mono', monospace; font-size: 8px; color: var(--text-faint); margin-top: 2px; margin-bottom: 8px; }} .cmp-sys {{ display: flex; align-items: center; gap: 5px; margin-top: 5px; font-size: 10px; }} .cmp-sys-glyph {{ width: 16px; font-family: 'JetBrains Mono', monospace; font-weight: 700; flex-shrink: 0; }} .cmp-sys-bar {{ flex: 1; height: 3px; background: rgba(168, 162, 158, 0.10); border-radius: 2px; overflow: hidden; }} .cmp-sys-fill {{ height: 100%; border-radius: 2px; transition: width 0.4s ease; }} .cmp-del {{ position: absolute; top: 4px; right: 6px; width: 20px; height: 20px; border-radius: 50%; border: none; background: transparent; color: var(--text-faint); font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; font-family: system-ui, sans-serif; }} .cmp-del:hover {{ background: rgba(244, 63, 94, 0.15); color: #F43F5E; }} .cmp-empty {{ text-align: center; padding: 24px; color: var(--text-faint); font-size: 12px; }} /* Timeline chart */ .tl-wrap {{ margin: 16px 0; padding: 14px 16px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; }} .tl-label {{ font-family: 'JetBrains Mono', monospace; font-size: 7px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-faint); min-width: 32px; flex-shrink: 0; }} .tl-row {{ display: flex; align-items: center; gap: 6px; padding: 3px 0; }} .tl-bar-wrap {{ flex: 1; height: 10px; background: rgba(168, 162, 158, 0.06); border-radius: 5px; overflow: hidden; position: relative; }} .tl-bar {{ height: 100%; border-radius: 5px; transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1); }} .tl-bar-stack {{ height: 100%; display: flex; border-radius: 5px; overflow: hidden; }} .tl-seg {{ height: 100%; transition: flex 0.6s cubic-bezier(0.22, 1, 0.36, 1); }} .tl-seg:first-child {{ border-radius: 5px 0 0 5px; }} .tl-seg:last-child {{ border-radius: 0 5px 5px 0; }} .tl-seg:only-child {{ border-radius: 5px; }} .tl-score {{ font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 700; min-width: 22px; text-align: right; flex-shrink: 0; }} .tl-now {{ display: inline-block; font-size: 7px; font-weight: 800; letter-spacing: 0.1em; color: var(--brand); margin-left: 4px; }} .tl-dom {{ font-family: 'JetBrains Mono', monospace; font-size: 8px; font-weight: 800; min-width: 16px; text-align: center; flex-shrink: 0; }} /* Timeline legend */ .tl-legend {{ display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border-soft); }} .tl-leg {{ font-family: 'JetBrains Mono', monospace; font-size: 8px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }} .tl-leg-swatch {{ width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex-shrink: 0; }} /* Save compare button */ .save-compare {{ font-family: 'JetBrains Mono', monospace !important; font-size: 10px !important; font-weight: 700 !important; padding: 5px 12px !important; border-radius: 8px !important; border: 1px solid var(--border) !important; background: transparent !important; color: var(--text-secondary) !important; transition: all 0.15s !important; }} .save-compare:hover {{ border-color: var(--brand) !important; color: var(--brand) !important; }} /* Mobile / narrow viewport */ @media (max-width: 900px) {{ .gradio-container {{ padding: 0 16px 40px !important; }} .app-header {{ padding: 24px 0 20px; margin-bottom: 18px; }} .debt-hero {{ font-size: clamp(5.5rem, 28vw, 8rem); }} .orb-wrap {{ padding: 28px 20px 22px; }} .theme-toggle {{ top: 12px; right: 12px; width: 32px; height: 32px; font-size: 14px; }} .gradio-row > div {{ flex-wrap: wrap !important; }} }} @media (max-width: 600px) {{ .gradio-container {{ padding: 0 10px 28px !important; }} .app-header {{ padding: 18px 0 16px; margin-bottom: 14px; }} .app-title {{ font-size: 10px; }} .app-subtitle {{ font-size: 11px; }} .attr-pill {{ font-size: 8px; padding: 2px 8px; }} .debt-hero {{ font-size: clamp(3.8rem, 24vw, 5.5rem) !important; }} .debt-hero-label {{ font-size: 8px; }} .debt-verdict {{ font-size: 12px; }} .orb-wrap {{ padding: 20px 12px 16px; }} .orb-wrap::before {{ inset: -20px; }} .orb-wrap::after {{ inset: -35px; }} .section-label {{ font-size: 8px; margin: 0 0 8px; }} .sys-meter {{ padding: 8px 10px; gap: 8px; }} .sys-glyph {{ width: 22px; height: 22px; font-size: 10px; }} .sys-label {{ font-size: 11px; }} .sys-time {{ font-size: 8px; }} .sys-cause {{ font-size: 10px; }} .coach-block {{ padding: 14px 16px; }} .coach-body {{ font-size: 12px; min-height: 40px; }} .proto-action {{ font-size: 11px; }} .proto-step {{ gap: 8px; }} .preset-chip {{ font-size: 9px !important; padding: 4px 10px !important; }} .debt-pill {{ font-size: 9px; padding: 4px 10px; }} .face-pill {{ padding: 10px 12px; gap: 10px; }} .face-num {{ font-size: 28px; }} .cf-block {{ padding: 10px 12px; flex-direction: column; gap: 6px; }} .cf-label {{ min-width: auto; font-size: 8px; }} .cf-body {{ font-size: 11px; }} .plan-line {{ gap: 8px; padding: 7px 0; }} .plan-tag {{ font-size: 8px; min-width: 64px; padding: 2px 6px; }} .plan-text {{ font-size: 11px; }} .trace-step {{ font-size: 9px; padding: 4px 8px; }} .tl-legend {{ gap: 6px; }} .tl-leg {{ font-size: 7px; }} .tl-leg-swatch {{ width: 6px; height: 6px; }} .tl-dom {{ font-size: 7px; min-width: 12px; }} .cmp-card {{ min-width: 140px; max-width: 160px; padding: 10px 10px; }} .cmp-hero {{ font-size: 24px; }} .cmp-label {{ font-size: 8px; }} .empty-state {{ padding: 40px 16px; }} .empty-state .icon {{ font-size: 36px; }} .empty-state .label {{ font-size: 12px; }} .empty-state .sub {{ font-size: 10px; }} .sci-card {{ padding: 10px 12px; }} .sci-fact {{ font-size: 11px; }} .sci-cite {{ font-size: 9px; }} .theme-toggle {{ top: 10px; right: 10px; width: 28px; height: 28px; font-size: 12px; }} .face-meta {{ font-size: 8px; }} .face-status {{ font-size: 9px; }} input, textarea {{ font-size: 14px !important; }} .gr-checkbox input[type="checkbox"] {{ width: 22px; height: 22px; }} .gr-checkbox input[type="checkbox"]:checked::after {{ font-size: 16px; top: -1px; left: 5px; }} .gr-checkbox label {{ font-size: 14px !important; }} .gr-dropdown {{ font-size: 13px !important; }} }} @media (max-width: 420px) {{ .gradio-container {{ padding: 0 8px 24px !important; }} .app-header {{ padding: 14px 0 12px; margin-bottom: 12px; }} .app-title {{ font-size: 9px; letter-spacing: 0.16em; }} .debt-hero {{ font-size: clamp(2.8rem, 22vw, 3.8rem) !important; }} .orb-wrap {{ padding: 14px 8px 12px; }} .orb-wrap::before {{ inset: -14px; }} .orb-wrap::after {{ inset: -24px; }} .preset-row {{ gap: 4px; }} .preset-chip {{ font-size: 8px !important; padding: 3px 8px !important; }} .attr-pill {{ font-size: 7px; padding: 2px 6px; gap: 4px; }} .cmp-card {{ min-width: 120px; max-width: 140px; padding: 8px; }} .cmp-hero {{ font-size: 20px; }} .plan-tag {{ font-size: 7px; min-width: 54px; }} .coach-block {{ padding: 12px 12px; }} .coach-header {{ font-size: 8px; }} .coach-pill {{ font-size: 8px; padding: 2px 6px; }} button.clear-all {{ font-size: 9px !important; padding: 3px 8px !important; }} .save-compare {{ font-size: 9px !important; padding: 3px 10px !important; }} }} """ # ─── Theme toggle JS ───────────────────────────────────────────────────────── THEME_TOGGLE_HTML = """ """ # ─── HTML renderers ────────────────────────────────────────────────────────── def render_hero(score: int, verdict: str, is_sample: bool = False) -> str: color, _, _ = debt_tier(score) badge = "" if is_sample: badge = ( '
{html.escape(action)}
{html.escape(fact)}
— {html.escape(cite)}
Quantify your physiological debt. Get a precise, system-level recovery plan. On-device AI. Zero cloud calls.