#!/usr/bin/env python3
"""Build the Wheel of Wellness assessment site."""
import json, textwrap

# ── Question data ────────────────────────────────────────────
QUESTIONS = {
    "generalized": {
        "title": "General",
        "subtitle": "For anyone who wants to check in on their wellness",
        "scale": ["Almost all the time", "More than half the time", "Some of the time", "Once in a while"],
        "emoji": None,
        "items": [
            {"id":"G1","dim":"physical","text":"In the past month, how often have you felt tired or worn out?","reverse":True},
            {"id":"G2","dim":"physical","text":"How would you rate your overall physical health right now?","reverse":False},
            {"id":"G3","dim":"physical","text":"In a typical week, how often do you move your body in a way that feels good (walking, stretching, playing)?","reverse":False},
            {"id":"G4","dim":"emotional","text":"In the past two weeks, how often have you felt calm and at ease?","reverse":False},
            {"id":"G5","dim":"emotional","text":"In the past two weeks, how often have you felt cheerful or in good spirits?","reverse":False},
            {"id":"G6","dim":"emotional","text":"How often have you felt worried, sad, or upset in a way that was hard to shake?","reverse":True},
            {"id":"G7","dim":"social","text":"Do you have people in your life you can count on when things get hard?","reverse":False},
            {"id":"G8","dim":"social","text":"How satisfied are you with how you get along with the people closest to you?","reverse":False},
            {"id":"G9","dim":"social","text":"In the past month, how often have you felt alone even when other people were around?","reverse":True},
            {"id":"G10","dim":"daily-life","text":"How confident are you that you can handle everyday tasks like bills, forms, and schedules?","reverse":False},
            {"id":"G11","dim":"daily-life","text":"In the past two weeks, how often has your sleep been restful?","reverse":False},
            {"id":"G12","dim":"daily-life","text":"How safe do you feel in your home and neighborhood?","reverse":False},
            {"id":"G13","dim":"purpose","text":"In the past two weeks, how often has your daily life been filled with things that interest you?","reverse":False},
            {"id":"G14","dim":"purpose","text":"How would you rate your quality of life right now?","reverse":False},
            {"id":"G15","dim":"purpose","text":"Do you feel like your life has meaning or direction?","reverse":False},
            {"id":"G16","dim":"growth","text":"In the past two weeks, how often have you felt active and full of energy?","reverse":False},
            {"id":"G17","dim":"growth","text":"Are you learning or trying anything new right now?","reverse":False},
            {"id":"G18","dim":"growth","text":"How often do you make time for things that help you grow (reading, classes, hobbies)?","reverse":False},
        ],
    },
    "parent-caregiver": {
        "title": "Parent / Caregiver",
        "subtitle": "For parents and caregivers of people with disabilities",
        "scale": ["Almost every day", "More days than not", "Once in a while", "Rarely"],
        "emoji": None,
        "items": [
            {"id":"P1","dim":"physical","text":"When did you last see a doctor for YOUR own health check?","reverse":False},
            {"id":"P2","dim":"physical","text":"In the past month, how often have you felt tired or worn out from caregiving?","reverse":True},
            {"id":"P3","dim":"physical","text":"In a typical week, how often do you get enough sleep?","reverse":False},
            {"id":"P4","dim":"emotional","text":"How often do you feel worn out or weighed down by all you have to do?","reverse":True},
            {"id":"P5","dim":"emotional","text":"In the past two weeks, how often have you been bothered by not being able to stop or control worrying?","reverse":True},
            {"id":"P6","dim":"emotional","text":"How often do you feel like you are doing a good job as a caregiver?","reverse":False},
            {"id":"P7","dim":"social","text":"Do you have someone who can watch your kids so you can take a break?","reverse":False},
            {"id":"P8","dim":"social","text":"Is there someone you can talk to honestly about how hard caregiving can be?","reverse":False},
            {"id":"P9","dim":"social","text":"How often do you spend time with friends or do something fun for yourself?","reverse":False},
            {"id":"P10","dim":"daily-life","text":"How confident are you about handling school meetings, doctor visits, and paperwork for your family?","reverse":False},
            {"id":"P11","dim":"daily-life","text":"Does your family have the money and resources to cover your basic needs?","reverse":False},
            {"id":"P12","dim":"daily-life","text":"Are you able to get the services and supports your family member with a disability needs?","reverse":False},
            {"id":"P13","dim":"purpose","text":"Do you feel accepted and respected by the professionals who work with your family?","reverse":False},
            {"id":"P14","dim":"purpose","text":"How often do you feel like your role as a caregiver gives your life meaning?","reverse":False},
            {"id":"P15","dim":"purpose","text":"Is there anything outside of caregiving that is important to who you are?","reverse":False},
            {"id":"P16","dim":"growth","text":"Are you learning new things about how to support your family member?","reverse":False},
            {"id":"P17","dim":"growth","text":"How often do you feel stuck or like nothing you do makes a difference?","reverse":True},
            {"id":"P18","dim":"growth","text":"In the past month, have you done anything just for you (a class, a hobby, time with a friend)?","reverse":False},
        ],
    },
    "family-member": {
        "title": "Family Member",
        "subtitle": "For household members of people with disabilities",
        "scale": ["Very satisfied", "Satisfied", "Neither satisfied nor dissatisfied", "Dissatisfied"],
        "emoji": None,
        "items": [
            {"id":"F1","dim":"physical","text":"Do members of your family get the medical care they need when they need it?","reverse":False},
            {"id":"F2","dim":"physical","text":"Does your family feel safe at home, work, school, and in the neighborhood?","reverse":False},
            {"id":"F3","dim":"physical","text":"Does your family have transportation to get to the places you need to be?","reverse":False},
            {"id":"F4","dim":"emotional","text":"Does your family have the support you need to handle stress?","reverse":False},
            {"id":"F5","dim":"emotional","text":"Do family members have some time to pursue their own interests?","reverse":False},
            {"id":"F6","dim":"emotional","text":"Do family members have outside help available for special needs?","reverse":False},
            {"id":"F7","dim":"social","text":"Do family members have friends or others outside the home they can lean on?","reverse":False},
            {"id":"F8","dim":"social","text":"Does your family enjoy spending time together?","reverse":False},
            {"id":"F9","dim":"social","text":"Do family members show that they love and care for each other?","reverse":False},
            {"id":"F10","dim":"daily-life","text":"Are you able to get the services and supports your family member with a disability needs?","reverse":False},
            {"id":"F11","dim":"daily-life","text":"Does your family have a way to take care of expenses?","reverse":False},
            {"id":"F12","dim":"daily-life","text":"Does your family have a good relationship with the service providers who work with your family member?","reverse":False},
            {"id":"F13","dim":"purpose","text":"Does your family solve problems together?","reverse":False},
            {"id":"F14","dim":"purpose","text":"Do family members support each other to accomplish goals?","reverse":False},
            {"id":"F15","dim":"purpose","text":"Does your family feel like it is handling life\u2019s ups and downs well?","reverse":False},
            {"id":"F16","dim":"growth","text":"Do family members help the children learn to be independent?","reverse":False},
            {"id":"F17","dim":"growth","text":"Do adults in the family know other people in the children\u2019s lives (friends, teachers)?","reverse":False},
            {"id":"F18","dim":"growth","text":"Do family members talk openly with each other?","reverse":False},
        ],
    },
    "professional": {
        "title": "Professional",
        "subtitle": "For therapists, counselors, educators, and healthcare workers",
        "scale": ["Almost every day", "Several days a week", "Once in a while", "Rarely"],
        "emoji": None,
        "items": [
            {"id":"PR1","dim":"physical","text":"How often do you feel physically drained after your workday?","reverse":True},
            {"id":"PR2","dim":"physical","text":"In the past month, how often have you lost sleep over the experiences of people you help?","reverse":True},
            {"id":"PR3","dim":"physical","text":"How often do you feel on edge or jumpy because of things you hear at work?","reverse":True},
            {"id":"PR4","dim":"emotional","text":"I find my work as a helper to be deeply satisfying.","reverse":False},
            {"id":"PR5","dim":"emotional","text":"How often do you feel depressed because of the experiences of people you help?","reverse":True},
            {"id":"PR6","dim":"emotional","text":"How often do you feel overwhelmed because your workload seems endless?","reverse":True},
            {"id":"PR7","dim":"social","text":"Do you have colleagues or peers you can talk with honestly about difficult cases?","reverse":False},
            {"id":"PR8","dim":"social","text":"How often do you feel connected to the people around you at work?","reverse":False},
            {"id":"PR9","dim":"social","text":"How often do you feel trapped by your job?","reverse":True},
            {"id":"PR10","dim":"daily-life","text":"How well do you maintain a boundary between your work and your personal life?","reverse":False},
            {"id":"PR11","dim":"daily-life","text":"I am pleased with how I keep up with professional techniques and protocols.","reverse":False},
            {"id":"PR12","dim":"daily-life","text":"How often do you feel bogged down by the systems and rules at work?","reverse":True},
            {"id":"PR13","dim":"purpose","text":"I believe I can make a difference through my work.","reverse":False},
            {"id":"PR14","dim":"purpose","text":"How often do you have happy thoughts about the people you help?","reverse":False},
            {"id":"PR15","dim":"purpose","text":"Are you happy that you chose this line of work?","reverse":False},
            {"id":"PR16","dim":"growth","text":"I am pleased with how I am able to keep up with helping techniques and protocols.","reverse":False},
            {"id":"PR17","dim":"growth","text":"How often do you avoid situations that remind you of frightening things people you help have told you?","reverse":True},
            {"id":"PR18","dim":"growth","text":"Are you the person you always wanted to be in this work?","reverse":False},
        ],
    },
    "special-needs": {
        "title": "Accessible",
        "subtitle": "For people with disabilities (a support person may help you read)",
        "scale": ["Not Good", "Okay", "Pretty Good", "Good", "Very Good"],
        "emoji": ["😟", "😐", "🙂", "😊", "😄"],
        "items": [
            {"id":"SN1","dim":"physical","text":"How do you feel about your health?","reverse":False},
            {"id":"SN2","dim":"physical","text":"How do you feel about how safe you feel?","reverse":False},
            {"id":"SN3","dim":"emotional","text":"In the past two weeks, how often have you felt happy?","reverse":False},
            {"id":"SN4","dim":"emotional","text":"In the past two weeks, how often have you felt calm?","reverse":False},
            {"id":"SN5","dim":"social","text":"How do you feel about how you get along with people? Like your family and friends.","reverse":False},
            {"id":"SN6","dim":"social","text":"How do you feel about doing things outside your home? Like in your community or neighborhood.","reverse":False},
            {"id":"SN7","dim":"daily-life","text":"How do you feel about the things you have? Like your money and the things you own.","reverse":False},
            {"id":"SN8","dim":"daily-life","text":"How do you feel about how your day goes? Like your routine and what you do.","reverse":False},
            {"id":"SN9","dim":"purpose","text":"How do you feel about the things you do or make?","reverse":False},
            {"id":"SN10","dim":"purpose","text":"How do you feel about your life as a whole?","reverse":False},
            {"id":"SN11","dim":"growth","text":"How do you feel about what will happen to you later in your life?","reverse":False},
            {"id":"SN12","dim":"growth","text":"In the past two weeks, how often have you felt like doing things?","reverse":False},
        ],
    },
}

DIMS = [
    {"key":"physical","label":"Physical","icon":"💪","color":"#1565C0","bg":"#E3F2FD","desc":"rest, movement, nutrition, medical care"},
    {"key":"emotional","label":"Emotional","icon":"💗","color":"#7B1FA2","bg":"#F3E5F5","desc":"naming feelings, coping, support"},
    {"key":"social","label":"Social","icon":"🤝","color":"#2E7D32","bg":"#E8F5E9","desc":"connection, understanding, community"},
    {"key":"daily-life","label":"Daily Life","icon":"📋","color":"#E65100","bg":"#FFF3E0","desc":"home, finances, schedules, advocacy"},
    {"key":"purpose","label":"Purpose","icon":"⭐","color":"#F57F17","bg":"#FFF8E1","desc":"meaning, values, identity, hope"},
    {"key":"growth","label":"Growth","icon":"🌱","color":"#C62828","bg":"#FFEBEE","desc":"learning, creativity, becoming"},
]

# ── Build ────────────────────────────────────────────────────
questions_json = json.dumps(QUESTIONS, ensure_ascii=False)
dims_json = json.dumps(DIMS, ensure_ascii=False)

html = textwrap.dedent(r"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wheel of Wellness Assessment</title>
<meta name="description" content="Find the resources your family needs in 5 minutes. A wellness assessment across six dimensions.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
:root{--primary:#2E7D6F;--primary-dark:#1F5C52;--primary-light:#3A9A88;--secondary:#E8835C;--cream:#FFF8F0;--charcoal:#2D3436;--gray-100:#F7F7F7;--gray-200:#E8E8E8;--gray-300:#D1D1D1;--gray-400:#9E9E9E;--gray-500:#6B6B6B;--green:#4CAF50;--green-light:#E8F5E9;--yellow:#FFC107;--yellow-light:#FFF8E1;--red:#E85C4A;--red-light:#FFEBEE;--shadow-sm:0 1px 3px rgba(0,0,0,.08);--shadow-md:0 4px 12px rgba(0,0,0,.1);--shadow-lg:0 8px 30px rgba(0,0,0,.12)}
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Inter',-apple-system,BlinkMacSystemFont,sans-serif;background:var(--cream);color:var(--charcoal);-webkit-font-smoothing:antialiased;min-height:100vh}
a{color:var(--primary);text-decoration:none}

/* Header */
.site-header{background:linear-gradient(135deg,var(--primary) 0%,var(--primary-dark) 100%);padding:12px 24px;display:flex;align-items:center;justify-content:space-between;color:white;position:sticky;top:0;z-index:50}
.site-header .brand{display:flex;align-items:center;gap:10px;font-size:15px;font-weight:700;letter-spacing:.3px}
.site-header .logo-icon{width:32px;height:32px;background:rgba(255,255,255,.2);border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:18px}
.site-header .nav-links{display:flex;gap:20px;font-size:13px;font-weight:500;opacity:.9}
.site-header .nav-links a{color:white;text-decoration:none;padding:4px 0}
.site-header .nav-links a:hover{opacity:1}

/* Footer */
.site-footer{background:var(--primary-dark);color:rgba(255,255,255,.7);text-align:center;padding:16px 20px;font-size:11px;letter-spacing:.3px;margin-top:auto}
.site-footer a{color:rgba(255,255,255,.9)}

/* Container */
.container{max-width:900px;margin:0 auto;padding:24px 20px}

/* ── Screens ── */
.screen{display:none}
.screen.active{display:block}

/* Landing */
.landing{text-align:center;padding:40px 20px 60px}
.landing .eyebrow{font-size:11px;font-weight:600;letter-spacing:2px;text-transform:uppercase;color:var(--secondary);margin-bottom:8px}
.landing h1{font-size:clamp(28px,5vw,42px);font-weight:800;color:var(--primary-dark);line-height:1.15;margin-bottom:12px}
.landing .subtitle{font-size:17px;color:var(--secondary);font-weight:600;margin-bottom:16px}
.landing .intro{font-size:14px;color:var(--gray-500);line-height:1.7;max-width:560px;margin:0 auto 32px}
.feature-pills{display:flex;gap:10px;justify-content:center;flex-wrap:wrap;margin-bottom:32px}
.feature-pill{display:flex;align-items:center;gap:6px;background:white;border:1px solid var(--gray-200);border-radius:20px;padding:6px 14px;font-size:12px;color:var(--gray-500);font-weight:500;box-shadow:var(--shadow-sm)}

/* Wheel SVG on landing */
.wheel-svg{width:240px;height:240px;margin:0 auto 28px}

/* Audience selector */
.audience-section{margin-bottom:32px}
.audience-section h2{font-size:16px;font-weight:700;color:var(--primary-dark);margin-bottom:12px}
.audience-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:10px;max-width:700px;margin:0 auto}
.audience-card{background:white;border:2px solid var(--gray-200);border-radius:12px;padding:16px 12px;cursor:pointer;transition:all .15s;text-align:center}
.audience-card:hover{border-color:var(--primary);box-shadow:var(--shadow-md)}
.audience-card.selected{border-color:var(--primary);background:rgba(46,125,111,.05)}
.audience-card .aud-icon{font-size:28px;margin-bottom:6px}
.audience-card .aud-title{font-size:13px;font-weight:700;color:var(--charcoal)}
.audience-card .aud-desc{font-size:11px;color:var(--gray-400);margin-top:4px;line-height:1.4}

/* CTA */
.cta-button{display:inline-flex;align-items:center;gap:10px;background:linear-gradient(135deg,var(--secondary) 0%,#D06A42 100%);color:white;font-size:16px;font-weight:700;padding:14px 36px;border-radius:50px;border:none;cursor:pointer;box-shadow:0 4px 16px rgba(232,131,92,.35);letter-spacing:.3px;transition:transform .15s}
.cta-button:hover{transform:translateY(-1px)}
.cta-button:disabled{opacity:.5;cursor:not-allowed;transform:none}
.cta-subtext{font-size:11px;color:var(--gray-400);margin-top:10px}

/* ── Questions ── */
.questions-screen{padding-bottom:40px}
.progress-section{margin-bottom:20px}
.progress-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.progress-header .label{font-size:13px;font-weight:600;color:var(--primary)}
.progress-header .count{font-size:12px;color:var(--gray-400);font-weight:500}
.progress-bar-track{width:100%;height:8px;background:var(--gray-200);border-radius:4px;overflow:hidden}
.progress-bar-fill{height:100%;background:linear-gradient(90deg,var(--primary) 0%,var(--primary-light) 100%);border-radius:4px;transition:width .3s ease}

.dim-indicator{display:flex;gap:6px;margin-bottom:20px;flex-wrap:wrap}
.dim-dot{width:10px;height:10px;border-radius:50%;transition:all .2s}
.dim-dot.active{transform:scale(1.4)}

.question-card{background:white;border-radius:14px;padding:24px 28px;box-shadow:var(--shadow-md);border:1px solid var(--gray-200);position:relative;animation:fadeIn .3s ease}
@keyframes fadeIn{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}
.question-card .q-dim-label{font-size:10px;font-weight:700;letter-spacing:1.5px;text-transform:uppercase;margin-bottom:8px}
.question-card .q-text{font-size:16px;font-weight:600;color:var(--charcoal);line-height:1.5;margin-bottom:20px}
.question-card .q-number{font-size:11px;color:var(--gray-300);font-weight:600;position:absolute;top:24px;right:28px}

.options-list{display:flex;flex-direction:column;gap:10px}
.option-item{display:flex;align-items:center;gap:14px;padding:14px 18px;background:var(--gray-100);border:2px solid var(--gray-200);border-radius:10px;font-size:14px;color:var(--gray-500);cursor:pointer;transition:all .15s;font-weight:500}
.option-item:hover{border-color:var(--gray-300);background:white}
.option-item.selected{background:var(--green-light);border-color:var(--primary);color:var(--primary-dark)}
.option-item .opt-emoji{font-size:20px;width:28px;text-align:center}
.radio-circle{width:20px;height:20px;border-radius:50%;border:2px solid var(--gray-300);flex-shrink:0;display:flex;align-items:center;justify-content:center;transition:all .15s}
.option-item.selected .radio-circle{border-color:var(--primary);background:var(--primary)}
.option-item.selected .radio-circle::after{content:'';width:8px;height:8px;background:white;border-radius:50%}

/* Nav buttons */
.q-nav{display:flex;justify-content:space-between;margin-top:24px}
.q-nav button{padding:10px 28px;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;border:none;transition:all .15s}
.btn-prev{background:var(--gray-100);color:var(--gray-500);border:1px solid var(--gray-200)}
.btn-prev:hover{background:var(--gray-200)}
.btn-next{background:var(--primary);color:white}
.btn-next:hover{background:var(--primary-dark)}
.btn-next:disabled{opacity:.4;cursor:not-allowed}
.btn-submit{background:var(--secondary);color:white;font-size:16px;padding:14px 36px;border-radius:50px}
.btn-submit:hover{background:#D06A42}

/* ── Results ── */
.results-screen{padding-bottom:40px}
.results-header{text-align:center;margin-bottom:28px}
.results-header .completion-badge{display:inline-flex;align-items:center;gap:6px;background:var(--green-light);color:var(--green);font-size:11px;font-weight:600;padding:4px 14px;border-radius:16px;margin-bottom:8px}
.results-header h2{font-size:28px;font-weight:800;color:var(--primary-dark);margin-bottom:6px}
.results-header .summary{font-size:14px;color:var(--gray-500);max-width:500px;margin:0 auto;line-height:1.6}

.results-body{display:flex;gap:32px;align-items:flex-start;flex-wrap:wrap}
.results-wheel-wrap{flex-shrink:0;width:280px;height:280px;margin:0 auto}

.dimensions-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;flex:1;min-width:280px}
.dim-card{background:white;border-radius:12px;padding:16px 18px;box-shadow:var(--shadow-sm);border:1px solid var(--gray-200)}
.dim-card-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
.dim-card-name{font-size:13px;font-weight:700;color:var(--charcoal);display:flex;align-items:center;gap:6px}
.dim-card-name .dim-icon{font-size:16px}
.dim-card .dim-score-text{font-size:24px;font-weight:800;margin-bottom:4px}
.dim-card .dim-desc{font-size:11px;color:var(--gray-400);line-height:1.4}

.status-badge{font-size:10px;font-weight:700;padding:3px 10px;border-radius:10px;letter-spacing:.3px}
.status-badge.strong{background:var(--green-light);color:var(--green)}
.status-badge.moderate{background:var(--yellow-light);color:#F9A825}
.status-badge.needs-attention{background:var(--red-light);color:var(--red)}

.overall-card{background:white;border-radius:14px;padding:20px 24px;box-shadow:var(--shadow-md);border:1px solid var(--gray-200);text-align:center;margin-top:20px}
.overall-card .overall-score{font-size:48px;font-weight:800;color:var(--primary-dark)}
.overall-card .overall-label{font-size:13px;color:var(--gray-400);font-weight:600}

.disclaimer{margin-top:24px;padding:16px 20px;background:rgba(46,125,111,.06);border-radius:10px;font-size:12px;color:var(--gray-500);line-height:1.6;text-align:center}

.btn-retake{margin-top:20px;padding:12px 28px;background:white;border:2px solid var(--gray-200);border-radius:50px;font-size:14px;font-weight:600;color:var(--gray-500);cursor:pointer;transition:all .15s}
.btn-retake:hover{border-color:var(--primary);color:var(--primary)}

@media(max-width:640px){
  .audience-grid{grid-template-columns:1fr 1fr}
  .dimensions-grid{grid-template-columns:1fr}
  .results-body{flex-direction:column;align-items:center}
  .q-nav{flex-direction:column;gap:10px}
  .q-nav button{width:100%}
}
</style>
</head>
<body>

<header class="site-header">
  <div class="brand">
    <div class="logo-icon">♿</div>
    <span>Wheel of Wellness</span>
  </div>
  <nav class="nav-links">
    <a href="#" onclick="showScreen('landing');return false">Home</a>
    <a href="https://helpipedia.org" target="_blank">HELPipedia</a>
    <a href="https://specialneeds.help" target="_blank">SpecialNeeds.help</a>
  </nav>
</header>

<!-- Landing -->
<div id="screen-landing" class="screen active">
  <div class="container landing">
    <div class="eyebrow">HELPipedia / SpecialNeeds.help</div>
    <h1>Wheel of Wellness</h1>
    <p class="subtitle">Find the resources your family needs &mdash; in 5 minutes</p>
    <p class="intro">Whether you are a parent, caregiver, or individual navigating disability, this quick assessment identifies your needs across six wellness areas and connects you to resources.</p>

    <svg class="wheel-svg" viewBox="0 0 240 240" id="landing-wheel"></svg>

    <div class="audience-section">
      <h2>Who are you?</h2>
      <div class="audience-grid" id="audience-grid"></div>
    </div>

    <button class="cta-button" id="btn-start" disabled onclick="startAssessment()">
      Start Your Assessment <span class="arrow">→</span>
    </button>
    <p class="cta-subtext">18 questions &middot; About 5 minutes &middot; Private &amp; anonymous</p>
  </div>
</div>

<!-- Questions -->
<div id="screen-questions" class="screen">
  <div class="container questions-screen">
    <div class="progress-section">
      <div class="progress-header">
        <span class="label" id="dim-label"></span>
        <span class="count" id="q-count"></span>
      </div>
      <div class="progress-bar-track">
        <div class="progress-bar-fill" id="progress-fill"></div>
      </div>
    </div>
    <div class="dim-indicator" id="dim-indicator"></div>
    <div id="question-area"></div>
    <div class="q-nav">
      <button class="btn-prev" id="btn-prev" onclick="prevQuestion()">← Back</button>
      <button class="btn-next" id="btn-next" onclick="nextQuestion()" disabled>Next →</button>
    </div>
  </div>
</div>

<!-- Results -->
<div id="screen-results" class="screen">
  <div class="container results-screen">
    <div class="results-header">
      <div class="completion-badge">✓ Assessment Complete</div>
      <h2>Your Wellness Results</h2>
      <p class="summary" id="results-summary"></p>
    </div>
    <div class="results-body">
      <div class="results-wheel-wrap">
        <svg viewBox="0 0 280 280" id="results-wheel"></svg>
      </div>
      <div class="dimensions-grid" id="results-grid"></div>
    </div>
    <div class="overall-card">
      <div class="overall-score" id="overall-score"></div>
      <div class="overall-label">Overall Wellness Score</div>
    </div>
    <div class="disclaimer">
      This is a screening tool for self-reflection, not a diagnosis. If you have concerns about your wellbeing, please talk to a qualified professional.
    </div>
    <div style="text-align:center">
      <button class="btn-retake" onclick="retake()">← Take Again</button>
    </div>
  </div>
</div>

<footer class="site-footer">
  <div>Powered by <a href="https://helpipedia.org" target="_blank">HELPipedia</a> &nbsp;·&nbsp; <a href="https://specialneeds.help" target="_blank">SpecialNeeds.help</a></div>
</footer>

<script>
const QUESTIONS = """ + questions_json + """;
const DIMS = """ + dims_json + """;

let selectedAudience = null;
let currentQ = 0;
let answers = {};

// ── Audience selector ──
const grid = document.getElementById('audience-grid');
const icons = {'generalized':'👤','parent-caregiver':'👨‍👩‍👧','family-member':'🏠','professional':'🩺','special-needs':'♿'};
Object.entries(QUESTIONS).forEach(([key, q]) => {
  const card = document.createElement('div');
  card.className = 'audience-card';
  card.dataset.key = key;
  card.innerHTML = `<div class="aud-icon">${icons[key]||'👤'}</div><div class="aud-title">${q.title}</div><div class="aud-desc">${q.subtitle}</div>`;
  card.onclick = () => selectAudience(key);
  grid.appendChild(card);
});

function selectAudience(key) {
  selectedAudience = key;
  document.querySelectorAll('.audience-card').forEach(c => c.classList.toggle('selected', c.dataset.key === key));
  document.getElementById('btn-start').disabled = false;
}

// ── Landing wheel SVG ──
function drawLandingWheel() {
  const svg = document.getElementById('landing-wheel');
  const cx = 120, cy = 120, r = 90, inner = 40;
  let paths = '';
  DIMS.forEach((d, i) => {
    const a1 = (i * 60 - 90) * Math.PI / 180;
    const a2 = ((i + 1) * 60 - 90) * Math.PI / 180;
    const x1 = cx + r * Math.cos(a1), y1 = cy + r * Math.sin(a1);
    const x2 = cx + r * Math.cos(a2), y2 = cy + r * Math.sin(a2);
    const ix1 = cx + inner * Math.cos(a1), iy1 = cy + inner * Math.sin(a1);
    const ix2 = cx + inner * Math.cos(a2), iy2 = cy + inner * Math.sin(a2);
    paths += `<path d="M${ix1},${iy1} L${x1},${y1} A${r},${r} 0 0,1 ${x2},${y2} L${ix2},${iy2} A${inner},${inner} 0 0,0 ${ix1},${iy1}" fill="${d.color}" opacity=".8"/>`;
    const mx = cx + (r + inner) / 2 * Math.cos((a1 + a2) / 2);
    const my = cy + (r + inner) / 2 * Math.sin((a1 + a2) / 2);
    paths += `<text x="${mx}" y="${my}" text-anchor="middle" dominant-baseline="central" fill="white" font-size="12" font-weight="700">${d.icon}</text>`;
  });
  svg.innerHTML = paths + `<circle cx="${cx}" cy="${cy}" r="${inner - 4}" fill="var(--cream)"/><text x="${cx}" y="${cy}" text-anchor="middle" dominant-baseline="central" font-size="20">☸</text>`;
}
drawLandingWheel();

// ── Navigation ──
function showScreen(name) {
  document.querySelectorAll('.screen').forEach(s => s.classList.remove('active'));
  document.getElementById('screen-' + name).classList.add('active');
  window.scrollTo(0, 0);
}

function startAssessment() {
  if (!selectedAudience) return;
  currentQ = 0;
  answers = {};
  showScreen('questions');
  renderQuestion();
}

function renderQuestion() {
  const items = QUESTIONS[selectedAudience].items;
  const item = items[currentQ];
  const dim = DIMS.find(d => d.key === item.dim);
  const total = items.length;
  const scale = QUESTIONS[selectedAudience].scale;
  const emojis = QUESTIONS[selectedAudience].emoji;

  document.getElementById('dim-label').textContent = dim.icon + ' ' + dim.label;
  document.getElementById('q-count').textContent = `Question ${currentQ + 1} of ${total}`;
  document.getElementById('progress-fill').style.width = `${((currentQ + 1) / total) * 100}%`;

  // Dim indicator dots
  const di = document.getElementById('dim-indicator');
  di.innerHTML = '';
  DIMS.forEach(d => {
    const dot = document.createElement('div');
    dot.className = 'dim-dot' + (d.key === item.dim ? ' active' : '');
    dot.style.background = d.color;
    dot.title = d.label;
    di.appendChild(dot);
  });

  // Question card
  const area = document.getElementById('question-area');
  let optionsHtml = scale.map((s, i) => {
    const selected = answers[item.id] === i ? ' selected' : '';
    const emoji = emojis ? `<span class="opt-emoji">${emojis[i]}</span>` : '';
    return `<div class="option-item${selected}" onclick="selectOption('${item.id}',${i})"><div class="radio-circle"></div>${emoji}<span>${s}</span></div>`;
  }).join('');

  area.innerHTML = `<div class="question-card"><div class="q-dim-label" style="color:${dim.color}">${dim.label}</div><div class="q-number">${item.id}</div><div class="q-text">${item.text}</div><div class="options-list">${optionsHtml}</div></div>`;

  // Nav buttons
  document.getElementById('btn-prev').style.visibility = currentQ === 0 ? 'hidden' : 'visible';
  const nextBtn = document.getElementById('btn-next');
  if (currentQ === total - 1) {
    nextBtn.outerHTML = `<button class="btn-submit" id="btn-next" onclick="submitAssessment()" ${answers[item.id] === undefined ? 'disabled' : ''}>See My Results →</button>`;
  } else {
    nextBtn.disabled = answers[item.id] === undefined;
  }
}

function selectOption(qId, val) {
  answers[qId] = val;
  renderQuestion();
}

function nextQuestion() {
  const items = QUESTIONS[selectedAudience].items;
  if (currentQ < items.length - 1) { currentQ++; renderQuestion(); }
}

function prevQuestion() {
  if (currentQ > 0) { currentQ--; renderQuestion(); }
}

// ── Scoring ──
function scoreAssessment() {
  const items = QUESTIONS[selectedAudience].items;
  const scaleLen = QUESTIONS[selectedAudience].scale.length;
  const dimScores = {};
  DIMS.forEach(d => { dimScores[d.key] = {sum: 0, count: 0}; });

  items.forEach(item => {
    const val = answers[item.id];
    if (val === undefined) return;
    // Score: highest option = best. Reverse items flip.
    const score = item.reverse ? (scaleLen - 1 - val) : val;
    dimScores[item.dim].sum += score;
    dimScores[item.dim].count += 1;
  });

  const results = DIMS.map(d => {
    const {sum, count} = dimScores[d.key];
    // Scale to 0-100
    const raw = count > 0 ? (sum / count) / (scaleLen - 1) * 100 : 0;
    const score = Math.round(raw);
    let status = 'strong';
    if (score < 40) status = 'needs-attention';
    else if (score < 60) status = 'moderate';
    return {...d, score, status};
  });

  const overall = Math.round(results.reduce((s, r) => s + r.score, 0) / results.length);
  let overallStatus = 'Strong';
  if (overall < 40) overallStatus = 'Needs Attention';
  else if (overall < 60) overallStatus = 'Moderate';
  return {results, overall, overallStatus};
}

// ── Results ──
function submitAssessment() {
  const {results, overall, overallStatus} = scoreAssessment();
  showScreen('results');

  // Summary
  document.getElementById('results-summary').textContent =
    `Based on your answers, here is how you are doing across the six wellness areas. Your overall score is ${overall}/100 (${overallStatus}).`;

  // Dim cards
  const grid = document.getElementById('results-grid');
  grid.innerHTML = results.map(r => `
    <div class="dim-card">
      <div class="dim-card-header">
        <span class="dim-card-name"><span class="dim-icon">${r.icon}</span> ${r.label}</span>
        <span class="status-badge ${r.status}">${r.status.replace('-', ' ')}</span>
      </div>
      <div class="dim-score-text" style="color:${r.color}">${r.score}</div>
      <div class="dim-desc">${r.desc}</div>
    </div>
  `).join('');

  // Overall
  document.getElementById('overall-score').textContent = overall;
  const oc = document.getElementById('overall-score');
  oc.style.color = overall >= 60 ? 'var(--green)' : overall >= 40 ? '#F9A825' : 'var(--red)';

  // Results wheel
  drawResultsWheel(results);
}

function drawResultsWheel(results) {
  const svg = document.getElementById('results-wheel');
  const cx = 140, cy = 140, maxR = 120, inner = 30;
  let paths = '';
  results.forEach((r, i) => {
    const a1 = (i * 60 - 90) * Math.PI / 180;
    const a2 = ((i + 1) * 60 - 90) * Math.PI / 180;
    const segR = inner + (maxR - inner) * (r.score / 100);
    const x1 = cx + segR * Math.cos(a1), y1 = cy + segR * Math.sin(a1);
    const x2 = cx + segR * Math.cos(a2), y2 = cy + segR * Math.sin(a2);
    const ix1 = cx + inner * Math.cos(a1), iy1 = cy + inner * Math.sin(a1);
    const ix2 = cx + inner * Math.cos(a2), iy2 = cy + inner * Math.sin(a2);
    paths += `<path d="M${ix1},${iy1} L${x1},${y1} A${segR},${segR} 0 0,1 ${x2},${y2} L${ix2},${iy2} A${inner},${inner} 0 0,0 ${ix1},${iy1}" fill="${r.color}" opacity=".85"/>`;
    // Label
    const labelR = maxR + 16;
    const mx = cx + labelR * Math.cos((a1 + a2) / 2);
    const my = cy + labelR * Math.sin((a1 + a2) / 2);
    paths += `<text x="${mx}" y="${my}" text-anchor="middle" dominant-baseline="central" font-size="11" font-weight="600" fill="var(--charcoal)">${r.icon} ${r.score}</text>`;
  });
  // Background rings
  let rings = '';
  [25, 50, 75, 100].forEach(pct => {
    const rr = inner + (maxR - inner) * pct / 100;
    rings += `<circle cx="${cx}" cy="${cy}" r="${rr}" fill="none" stroke="var(--gray-200)" stroke-width="1" opacity=".5"/>`;
  });
  svg.innerHTML = rings + paths + `<circle cx="${cx}" cy="${cy}" r="${inner}" fill="var(--cream)"/>`;
}

function retake() {
  answers = {};
  currentQ = 0;
  selectedAudience = null;
  document.querySelectorAll('.audience-card').forEach(c => c.classList.remove('selected'));
  document.getElementById('btn-start').disabled = true;
  showScreen('landing');
}
</script>
</body>
</html>""")

out = "/home/newkirk/Projects/wellnessWheel/site/index.html"
import os
os.makedirs(os.path.dirname(out), exist_ok=True)
with open(out, 'w') as f:
    f.write(html)
print(f"Built: {out}")
print(f"Size: {os.path.getsize(out)} bytes")
