Sreehitha-V commited on
Commit
b969342
Β·
verified Β·
1 Parent(s): 00188d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +575 -0
app.py CHANGED
@@ -0,0 +1,575 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from auth_token import login, initiate_signup, complete_signup
3
+ import streamlit.components.v1 as components
4
+ import os
5
+
6
+ st.set_page_config(page_title="FitPlan Pro", page_icon="⚑", layout="wide")
7
+
8
+ # ── Already logged in β†’ go to profile ────────────────────────────────────────
9
+ if st.session_state.get("logged_in"):
10
+ st.switch_page("pages/1_Profile.py")
11
+
12
+ # ── State init ────────────────────────────────────────────────────────────────
13
+ for k, v in [("page_mode","login"),("signup_step","form"),("pending_signup",{})]:
14
+ if k not in st.session_state:
15
+ st.session_state[k] = v
16
+
17
+ # ── Hide Streamlit chrome, make iframe full screen ───────────────────────────
18
+ st.markdown("""
19
+ <style>
20
+ #MainMenu,footer,header,[data-testid="stToolbar"],[data-testid="stDecoration"],
21
+ [data-testid="stSidebarNav"],section[data-testid="stSidebar"]{display:none!important;}
22
+ html,body,.stApp,[data-testid="stAppViewContainer"]{
23
+ background:#0d0d1a!important;margin:0!important;padding:0!important;
24
+ height:100%!important;overflow:hidden!important;}
25
+ [data-testid="stAppViewContainer"]>section{padding:0!important;margin:0!important;}
26
+ [data-testid="stAppViewContainer"]>section>div.block-container{
27
+ padding:0!important;max-width:100%!important;margin:0!important;height:100vh!important;}
28
+ iframe{border:none!important;display:block!important;width:100vw!important;
29
+ height:100vh!important;position:fixed!important;top:0!important;left:0!important;z-index:9999!important;}
30
+ </style>
31
+ """, unsafe_allow_html=True)
32
+
33
+ # ══════════════════════════════════════════════════════════════════════════════
34
+ # ACTION HANDLERS (query params set by JS window.location.href inside iframe)
35
+ # ══════════════════════════════════════════════════════════════════════════════
36
+ params = st.query_params
37
+ action = params.get("action", "")
38
+
39
+ # ── STEP 5: LOGIN ─────────────────────────────────────────────────────────────
40
+ if action == "login":
41
+ u = params.get("u", ""); p = params.get("p", "")
42
+ if u and p:
43
+ ok, token, msg = login(u, p)
44
+ if ok:
45
+ st.session_state.logged_in = True
46
+ st.session_state.username = u.strip()
47
+ st.session_state.auth_token = token
48
+ st.query_params.clear()
49
+ st.switch_page("pages/1_Profile.py") # β†’ STEP 6: Profile
50
+ else:
51
+ st.session_state.login_error = msg
52
+ st.query_params.clear(); st.rerun()
53
+
54
+ # ── STEP 2a: SEND OTP ─────────────────────────────────────────────────────────
55
+ if action == "send_otp":
56
+ su = params.get("u",""); se = params.get("e","")
57
+ sp = params.get("p",""); sp2 = params.get("p2","")
58
+ if sp != sp2:
59
+ st.session_state.signup_error = "Passwords don't match."
60
+ elif "@" not in se or "." not in se:
61
+ st.session_state.signup_error = "Enter a valid email address."
62
+ elif len(sp) < 6:
63
+ st.session_state.signup_error = "Password must be at least 6 characters."
64
+ elif not su.strip():
65
+ st.session_state.signup_error = "Username is required."
66
+ else:
67
+ with st.spinner(""):
68
+ ok, msg = initiate_signup(su.strip(), se.strip().lower(), sp)
69
+ if ok:
70
+ if msg == "__NO_OTP__":
71
+ # Brevo not configured β€” user saved directly, redirect to login
72
+ st.session_state.signup_success = "βœ“ Account created! Please sign in."
73
+ st.session_state.page_mode = "login"
74
+ st.session_state.signup_step = "form"
75
+ st.session_state.pending_signup = {}
76
+ else:
77
+ # OTP sent β€” go to verification step
78
+ st.session_state.pending_signup = {"username": su.strip(), "email": se.strip().lower(), "password": sp}
79
+ st.session_state.signup_step = "otp"
80
+ st.session_state.signup_error = ""
81
+ st.session_state.page_mode = "signup"
82
+ else:
83
+ st.session_state.signup_error = msg
84
+ st.session_state.page_mode = "signup"
85
+ st.query_params.clear(); st.rerun()
86
+
87
+ # ── STEP 2b: VERIFY OTP β†’ STEP 3: CREATE ACCOUNT ────────────────────────────
88
+ if action == "verify_otp":
89
+ otp_val = params.get("otp", "")
90
+ # Data travels in URL β€” never relies on session_state (iframe boundary safe)
91
+ su = params.get("u", "").strip()
92
+ se = params.get("e", "").strip()
93
+ sp = params.get("p", "").strip()
94
+ if not su: # fallback (same-origin reload)
95
+ pd = st.session_state.get("pending_signup", {})
96
+ su = pd.get("username",""); se = pd.get("email",""); sp = pd.get("password","")
97
+ ok, token, msg = complete_signup(su, se, sp, otp_val)
98
+ if ok:
99
+ # STEP 4: redirect to login after account created
100
+ st.session_state.signup_success = "βœ“ Account created! Please sign in."
101
+ st.session_state.signup_step = "form"
102
+ st.session_state.page_mode = "login"
103
+ st.session_state.pending_signup = {}
104
+ else:
105
+ st.session_state.otp_error = msg
106
+ st.session_state.signup_step = "otp"
107
+ st.session_state.page_mode = "signup"
108
+ st.query_params.clear(); st.rerun()
109
+
110
+ # ── NAV ───────────────────────────────────────────────────────────────────────
111
+ if action == "go_signup":
112
+ st.session_state.page_mode = "signup"; st.session_state.signup_step = "form"
113
+ st.query_params.clear(); st.rerun()
114
+ if action == "go_login":
115
+ st.session_state.page_mode = "login"
116
+ st.query_params.clear(); st.rerun()
117
+ if action == "go_back":
118
+ st.session_state.signup_step = "form"
119
+ st.session_state.pending_signup = {}
120
+ st.session_state.page_mode = "signup"
121
+ st.query_params.clear(); st.rerun()
122
+
123
+ # ── Pop flash messages ────────────────────────────────────────────────────────
124
+ login_error = st.session_state.pop("login_error", "")
125
+ signup_error = st.session_state.pop("signup_error", "")
126
+ otp_error = st.session_state.pop("otp_error", "")
127
+ signup_success = st.session_state.pop("signup_success", "")
128
+ mode = st.session_state.page_mode
129
+ signup_step = st.session_state.signup_step
130
+ pending = st.session_state.pending_signup
131
+ pending_email = pending.get("email", "")
132
+ pending_u = pending.get("username", "")
133
+ pending_e = pending.get("email", "")
134
+ pending_p = pending.get("password", "")
135
+ is_signup = mode == "signup"
136
+
137
+ def err(msg): return f"<div class='msg err'><span>⚠</span>{msg}</div>" if msg else ""
138
+ def good(msg): return f"<div class='msg ok'><span>βœ“</span>{msg}</div>" if msg else ""
139
+
140
+ # ── Config status (shown on signup page) ─────────────────────────────────────
141
+ _brevo_ok = bool(os.environ.get("BREVO_API_KEY","")) and bool(os.environ.get("EMAIL_SENDER",""))
142
+ _supabase_ok = bool(os.environ.get("SUPABASE_URL","")) and bool(os.environ.get("SUPABASE_KEY",""))
143
+
144
+ def cfg_banner():
145
+ lines = []
146
+ if not _supabase_ok:
147
+ lines.append("⚠ SUPABASE_URL/SUPABASE_KEY not set β€” accounts reset on restart")
148
+ if not _brevo_ok:
149
+ lines.append("⚠ BREVO_API_KEY/EMAIL_SENDER not set β€” OTP email disabled, direct signup used")
150
+ if not lines: return ""
151
+ return ("<div style='background:rgba(232,124,3,.13);border-left:3px solid #e87c03;"
152
+ "color:#e87c03;font-size:.7rem;padding:8px 12px;border-radius:4px;"
153
+ "margin-bottom:14px;line-height:1.9'>" + "<br>".join(lines) + "</div>")
154
+
155
+ # ══════════════════════════════════════════════════════════════════════════════
156
+ # SVG TILE ICONS
157
+ # ══════════════════════════════════════════════════════════════════════════════
158
+ SVG_ICONS = {
159
+ "barbell": '<rect x="4" y="28" width="56" height="8" rx="4" fill="currentColor"/><rect x="2" y="21" width="9" height="22" rx="3" fill="currentColor"/><rect x="53" y="21" width="9" height="22" rx="3" fill="currentColor"/><rect x="0" y="25" width="5" height="14" rx="2" fill="currentColor" opacity=".55"/><rect x="59" y="25" width="5" height="14" rx="2" fill="currentColor" opacity=".55"/>',
160
+ "dumbbell": '<rect x="16" y="28" width="32" height="8" rx="4" fill="currentColor"/><rect x="7" y="20" width="11" height="24" rx="3" fill="currentColor"/><rect x="46" y="20" width="11" height="24" rx="3" fill="currentColor"/><rect x="3" y="25" width="7" height="14" rx="2" fill="currentColor" opacity=".55"/><rect x="54" y="25" width="7" height="14" rx="2" fill="currentColor" opacity=".55"/>',
161
+ "runner": '<circle cx="40" cy="9" r="6" fill="currentColor"/><path d="M38 16 L28 30 L16 43" stroke="currentColor" stroke-width="4.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/><path d="M28 30 L40 41 L46 56" stroke="currentColor" stroke-width="4.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/><path d="M20 19 L42 24 L54 15" stroke="currentColor" stroke-width="4" stroke-linecap="round" fill="none"/>',
162
+ "pullup": '<rect x="4" y="4" width="56" height="7" rx="3.5" fill="currentColor"/><line x1="20" y1="11" x2="20" y2="26" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><line x1="44" y1="11" x2="44" y2="26" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><circle cx="32" cy="33" r="7" fill="currentColor"/><path d="M19 27 Q32 20 45 27" stroke="currentColor" stroke-width="4" fill="none" stroke-linecap="round"/><path d="M25 40 L21 56 M39 40 L43 56" stroke="currentColor" stroke-width="4" stroke-linecap="round"/>',
163
+ "bicycle": '<circle cx="15" cy="45" r="13" stroke="currentColor" stroke-width="3.5" fill="none"/><circle cx="49" cy="45" r="13" stroke="currentColor" stroke-width="3.5" fill="none"/><path d="M15 45 L32 20 L49 45" stroke="currentColor" stroke-width="3.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/><circle cx="15" cy="45" r="3.5" fill="currentColor"/><circle cx="49" cy="45" r="3.5" fill="currentColor"/>',
164
+ "yoga": '<circle cx="32" cy="8" r="6.5" fill="currentColor"/><line x1="32" y1="15" x2="32" y2="34" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><path d="M8 22 Q20 32 32 28 Q44 32 56 22" stroke="currentColor" stroke-width="4" stroke-linecap="round" fill="none"/><path d="M32 34 L17 52 M32 34 L47 52" stroke="currentColor" stroke-width="4" stroke-linecap="round"/>',
165
+ "kettlebell": '<path d="M23 24 Q18 14 24 8 Q32 1 40 8 Q46 14 41 24" stroke="currentColor" stroke-width="4" fill="none" stroke-linecap="round"/><path d="M23 24 Q14 26 13 37 Q11 50 24 56 Q32 60 40 56 Q53 50 51 37 Q49 26 41 24Z" stroke="currentColor" stroke-width="3" fill="currentColor" opacity=".18"/><path d="M23 24 Q14 26 13 37 Q11 50 24 56 Q32 60 40 56 Q53 50 51 37 Q49 26 41 24Z" stroke="currentColor" stroke-width="3" fill="none"/>',
166
+ "pushup": '<circle cx="47" cy="10" r="6" fill="currentColor"/><path d="M47 17 L47 31 L8 31" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none"/><path d="M8 31 L4 46" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><line x1="0" y1="46" x2="10" y2="46" stroke="currentColor" stroke-width="4" stroke-linecap="round"/>',
167
+ "stopwatch": '<circle cx="32" cy="37" r="22" stroke="currentColor" stroke-width="3.5" fill="none"/><line x1="32" y1="37" x2="32" y2="21" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><line x1="32" y1="37" x2="45" y2="29" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><line x1="26" y1="6" x2="38" y2="6" stroke="currentColor" stroke-width="3.5" stroke-linecap="round"/><line x1="32" y1="6" x2="32" y2="15" stroke="currentColor" stroke-width="3.5" stroke-linecap="round"/>',
168
+ "medal": '<path d="M22 4 L42 4 L50 20 L32 29 L14 20Z" fill="currentColor" opacity=".22" stroke="currentColor" stroke-width="2.5"/><circle cx="32" cy="45" r="17" stroke="currentColor" stroke-width="3.5" fill="none"/><path d="M32 37 L34.8 42.5 L41 43.4 L36.5 47.8 L37.6 54 L32 51 L26.4 54 L27.5 47.8 L23 43.4 L29.2 42.5Z" fill="currentColor"/>',
169
+ "heartrate": '<path d="M32 54 Q9 39 9 24 Q9 12 20 11 Q28 9 32 19 Q36 9 44 11 Q55 12 55 24 Q55 39 32 54Z" stroke="currentColor" stroke-width="3" fill="currentColor" opacity=".15"/><path d="M32 54 Q9 39 9 24 Q9 12 20 11 Q28 9 32 19 Q36 9 44 11 Q55 12 55 24 Q55 39 32 54Z" stroke="currentColor" stroke-width="3" fill="none"/><path d="M5 33 L15 33 L21 22 L28 44 L34 27 L38 37 L44 33 L59 33" stroke="currentColor" stroke-width="2.8" stroke-linecap="round" stroke-linejoin="round" fill="none"/>',
170
+ "squat": '<circle cx="32" cy="8" r="6" fill="currentColor"/><line x1="32" y1="14" x2="32" y2="29" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><line x1="13" y1="20" x2="51" y2="20" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><path d="M32 29 L19 46 L15 60 M32 29 L45 46 L49 60" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>',
171
+ "plank": '<circle cx="55" cy="12" r="6" fill="currentColor"/><path d="M55 19 L46 29 L8 29" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" fill="none"/><line x1="8" y1="29" x2="4" y2="42" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><line x1="46" y1="29" x2="51" y2="42" stroke="currentColor" stroke-width="4" stroke-linecap="round"/><line x1="0" y1="42" x2="58" y2="42" stroke="currentColor" stroke-width="3.5" stroke-linecap="round"/>',
172
+ "boxing": '<path d="M15 23 Q11 16 14 9 Q20 2 30 8 L48 21 Q56 29 52 39 Q48 45 38 42 L23 37 Q13 34 15 24Z" fill="currentColor" opacity=".18" stroke="currentColor" stroke-width="3"/><path d="M23 37 L19 52 M38 42 L43 56" stroke="currentColor" stroke-width="3.5" stroke-linecap="round"/>',
173
+ "flame": '<path d="M32 60 Q12 50 12 33 Q12 17 26 9 Q22 21 32 24 Q24 12 36 3 Q33 16 43 20 Q54 26 54 40 Q54 53 32 60Z" fill="currentColor" opacity=".2" stroke="currentColor" stroke-width="3"/><path d="M32 60 Q12 50 12 33 Q12 17 26 9 Q22 21 32 24 Q24 12 36 3 Q33 16 43 20 Q54 26 54 40 Q54 53 32 60Z" fill="none" stroke="currentColor" stroke-width="3"/><path d="M32 52 Q20 44 22 35 Q24 28 32 31 Q40 28 42 35 Q44 44 32 52Z" fill="currentColor" opacity=".55"/>',
174
+ "target": '<circle cx="32" cy="32" r="27" stroke="currentColor" stroke-width="3" fill="none"/><circle cx="32" cy="32" r="17" stroke="currentColor" stroke-width="3" fill="none"/><circle cx="32" cy="32" r="7" fill="currentColor"/><line x1="32" y1="3" x2="32" y2="10" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/><line x1="32" y1="54" x2="32" y2="61" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/><line x1="3" y1="32" x2="10" y2="32" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/><line x1="54" y1="32" x2="61" y2="32" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/>',
175
+ }
176
+ TILE_DATA = [
177
+ ("barbell","BARBELL","#2a1f3d","#c4b5fd"),("runner","RUNNING","#1e2d45","#93c5fd"),
178
+ ("dumbbell","DUMBBELL","#2a1f3d","#e0aaff"),("heartrate","CARDIO","#3a1a2a","#fca5a5"),
179
+ ("bicycle","CYCLING","#1a2e2a","#6ee7b7"),("yoga","YOGA","#2a1f3d","#d8b4fe"),
180
+ ("pullup","PULL-UPS","#1a2e25","#86efac"),("kettlebell","KETTLEBELL","#1d2e36","#5eead4"),
181
+ ("stopwatch","INTERVALS","#1e2d45","#7dd3fc"),("pushup","PUSH-UPS","#32210f","#fdba74"),
182
+ ("squat","SQUATS","#1f2040","#a5b4fc"),("plank","PLANK","#2a1f3d","#f0abfc"),
183
+ ("boxing","BOXING","#3a1a1e","#fda4af"),("medal","CHAMPION","#30280e","#fde68a"),
184
+ ("flame","HIIT","#351808","#fed7aa"),("target","GOALS","#1e2d45","#7dd3fc"),
185
+ ]
186
+ def make_tile(i):
187
+ key, label, bg, accent = TILE_DATA[i % len(TILE_DATA)]
188
+ d = round((i * 0.4) % 4, 1)
189
+ dur = round(3 + (i * 0.3) % 2, 1)
190
+ border = "border-bottom:2px solid rgba(229,9,20,0.45);" if i % 7 == 0 else ""
191
+ return (
192
+ f'<div class="tile" style="background:{bg};animation-delay:{d}s;animation-duration:{dur}s;{border}">'
193
+ f'<svg viewBox="0 0 64 64" fill="none" style="color:{accent};width:clamp(22px,3vw,38px);height:clamp(22px,3vw,38px)">'
194
+ + SVG_ICONS[key] +
195
+ f'</svg><div class="tile-label" style="color:{accent}bb">{label}</div></div>'
196
+ )
197
+ tiles_html = "".join(make_tile(i) for i in range(60))
198
+
199
+ # ══════════════════════════════════════════════════════════════════════════════
200
+ # BUILD CARD HTML (no nested f-strings β€” plain concatenation)
201
+ # ══════════════════════════════════════════════════════════════════════════════
202
+ if not is_signup:
203
+ # STEP 4 / STEP 5 β€” Login page
204
+ card_html = (
205
+ "<div class='card-title'>Sign In</div>"
206
+ + err(login_error) + good(signup_success)
207
+ + """<form id="fLogin">
208
+ <div class="f"><input type="text" id="li_u" placeholder="x" autocomplete="username"><label>Email or Username</label></div>
209
+ <div class="f"><input type="password" id="li_p" placeholder="x" autocomplete="current-password"><label>Password</label></div>
210
+ <button class="btn-main" type="submit">Sign In</button>
211
+ </form>
212
+ <div class="or-row"><span>OR</span></div>
213
+ <div class="switch-row">New here? <a onclick="goSignup()">Create an account.</a></div>
214
+ <div class="legal">Your data is encrypted and never shared with third parties.</div>"""
215
+ )
216
+
217
+ elif signup_step == "otp":
218
+ # STEP 2b β€” OTP verification
219
+ card_html = (
220
+ "<div class='card-title'>Verify Email</div>"
221
+ + err(otp_error)
222
+ + "<div class='otp-info'><p>We sent a 6-digit code to</p><strong>" + pending_email + "</strong><p style='margin-top:6px;font-size:.68rem'>Check your inbox and spam folder</p></div>"
223
+ + '<form id="fOtp">'
224
+ + '<input type="hidden" id="h_u" value="' + pending_u + '">'
225
+ + '<input type="hidden" id="h_e" value="' + pending_e + '">'
226
+ + '<input type="hidden" id="h_p" value="' + pending_p + '">'
227
+ + """<div class="f"><input class="otp" type="text" id="otp_val" placeholder="000000" maxlength="6" autocomplete="one-time-code" inputmode="numeric"></div>
228
+ <button class="btn-main" type="submit">Verify &amp; Create Account</button>
229
+ </form>
230
+ <div class="back-link"><button id="backBtn">&#8592; Wrong email? Start over</button></div>
231
+ <div class="switch-row">Already a member? <a onclick="goLogin()">Sign in.</a></div>"""
232
+ )
233
+
234
+ else:
235
+ # STEP 1 β€” Signup form
236
+ card_html = (
237
+ "<div class='card-title'>Create Account</div>"
238
+ + cfg_banner()
239
+ + err(signup_error)
240
+ + """<form id="fSignup">
241
+ <div class="f"><input type="text" id="su_u" placeholder="x" autocomplete="username"><label>Username</label></div>
242
+ <div class="f"><input type="email" id="su_e" placeholder="x" autocomplete="email"><label>Email Address</label></div>
243
+ <div class="f"><input type="password" id="su_p" placeholder="x" autocomplete="new-password"><label>Password (min 6 chars)</label></div>
244
+ <div class="f"><input type="password" id="su_p2" placeholder="x" autocomplete="new-password"><label>Confirm Password</label></div>
245
+ <button class="btn-main" type="submit">Send Verification Code</button>
246
+ </form>
247
+ <div class="switch-row">Already a member? <a onclick="goLogin()">Sign in.</a></div>"""
248
+ )
249
+
250
+ # ══════════════════════════════════════════════════════════════════════════════
251
+ # FULL HTML
252
+ # ══════════════════════════════════════════════════════════════════════════════
253
+ HTML = f"""<!DOCTYPE html>
254
+ <html lang="en">
255
+ <head>
256
+ <meta charset="UTF-8">
257
+ <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
258
+ <link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600&display=swap" rel="stylesheet">
259
+ <style>
260
+ :root{{
261
+ --red:#E50914;--red-h:#f40612;
262
+ --white:#fff;
263
+ --ease:cubic-bezier(0.22,1,0.36,1);
264
+ --spring:cubic-bezier(0.34,1.56,0.64,1);
265
+ }}
266
+ *,*::before,*::after{{box-sizing:border-box;margin:0;padding:0;}}
267
+ html,body{{
268
+ width:100%;height:100%;overflow:hidden;
269
+ font-family:'DM Sans',sans-serif;
270
+ background:radial-gradient(ellipse 140% 100% at 50% 0%,#1a1040 0%,#0d0d1a 55%,#080810 100%);
271
+ color:#fff;-webkit-font-smoothing:antialiased;
272
+ }}
273
+
274
+ /* ━━ MOSAIC ━━ */
275
+ .mosaic{{
276
+ position:fixed;inset:0;z-index:0;overflow:hidden;
277
+ display:grid;grid-template-columns:repeat(10,1fr);grid-template-rows:repeat(6,1fr);
278
+ gap:4px;
279
+ transform:perspective(800px) rotateX(5deg) rotateZ(-6deg) scale(1.5);
280
+ animation:mosaic-pan 40s linear infinite alternate;
281
+ }}
282
+ @keyframes mosaic-pan{{
283
+ 0% {{transform:perspective(800px) rotateX(5deg) rotateZ(-6deg) scale(1.5) translate(0,0);}}
284
+ 100%{{transform:perspective(800px) rotateX(5deg) rotateZ(-6deg) scale(1.5) translate(-3%,4%);}}
285
+ }}
286
+ .tile{{
287
+ position:relative;display:flex;flex-direction:column;
288
+ align-items:center;justify-content:center;gap:6px;
289
+ border-radius:6px;overflow:hidden;
290
+ animation:tile-breathe ease-in-out infinite alternate;
291
+ cursor:default;user-select:none;
292
+ transition:transform 0.15s var(--spring),filter 0.15s,opacity 0.15s;
293
+ }}
294
+ @keyframes tile-breathe{{
295
+ from{{opacity:0.52;filter:brightness(0.75) saturate(0.8);}}
296
+ to {{opacity:0.82;filter:brightness(1.2) saturate(1.3);}}
297
+ }}
298
+ .tile::after{{
299
+ content:'';position:absolute;inset:0;
300
+ background:linear-gradient(135deg,rgba(255,255,255,0) 0%,rgba(255,255,255,0.04) 50%,rgba(255,255,255,0) 100%);
301
+ animation:tile-shimmer 6s ease-in-out infinite;animation-delay:inherit;
302
+ }}
303
+ @keyframes tile-shimmer{{0%,100%{{opacity:0;}}50%{{opacity:1;}}}}
304
+ .tile-label{{font-family:'Bebas Neue',sans-serif;font-size:clamp(0.34rem,0.65vw,0.55rem);letter-spacing:3px;}}
305
+
306
+ /* ━━ OVERLAY ━━ */
307
+ .overlay{{
308
+ position:fixed;inset:0;z-index:1;pointer-events:none;
309
+ background:
310
+ radial-gradient(ellipse 80% 65% at 50% 50%,rgba(13,13,26,.05) 0%,rgba(13,13,26,.55) 60%,rgba(8,8,16,.92) 100%),
311
+ linear-gradient(to bottom,rgba(8,8,16,.55) 0%,rgba(8,8,16,0) 18%,rgba(8,8,16,0) 80%,rgba(8,8,16,.72) 100%);
312
+ }}
313
+
314
+ /* ━━ LOGO ━━ */
315
+ .site-logo{{
316
+ position:fixed;top:28px;left:36px;z-index:10;
317
+ font-family:'Bebas Neue',sans-serif;
318
+ font-size:clamp(1.6rem,3vw,2.4rem);letter-spacing:4px;
319
+ color:var(--red);text-shadow:0 0 30px rgba(229,9,20,0.5);
320
+ animation:logo-in 0.8s var(--ease) 0.2s both;
321
+ }}
322
+ @keyframes logo-in{{from{{opacity:0;transform:translateX(-20px)}}to{{opacity:1;transform:none}}}}
323
+
324
+ /* ━━ CARD ━━ */
325
+ .page{{position:fixed;inset:0;z-index:10;display:flex;align-items:center;justify-content:center;padding:16px;overflow-y:auto;}}
326
+ .card{{
327
+ width:100%;max-width:450px;
328
+ background:rgba(12,10,28,0.88);
329
+ border-radius:8px;
330
+ padding:clamp(32px,5vw,52px) clamp(28px,5vw,64px);
331
+ box-shadow:0 8px 48px rgba(0,0,0,0.75),0 0 0 1px rgba(140,100,255,0.06);
332
+ border:1px solid rgba(180,150,255,0.10);
333
+ backdrop-filter:blur(18px);-webkit-backdrop-filter:blur(18px);
334
+ animation:card-in 0.7s var(--ease) 0.1s both;
335
+ flex-shrink:0;
336
+ }}
337
+ @keyframes card-in{{from{{opacity:0;transform:translateY(24px)}}to{{opacity:1;transform:none}}}}
338
+ .card-title{{
339
+ font-family:'Bebas Neue',sans-serif;
340
+ font-size:clamp(1.8rem,3.5vw,2.4rem);
341
+ letter-spacing:1px;color:var(--white);margin-bottom:24px;
342
+ }}
343
+
344
+ /* ━━ FLOATING LABEL INPUTS ━━ */
345
+ .f{{margin-bottom:14px;position:relative;}}
346
+ .f input{{
347
+ width:100%;height:52px;padding:22px 16px 8px;
348
+ background:rgba(255,255,255,0.09);
349
+ border:1.5px solid rgba(255,255,255,0.18);
350
+ border-radius:4px;font-family:'DM Sans',sans-serif;
351
+ font-size:1rem;color:#fff;outline:none;
352
+ transition:background .2s,border-color .2s,box-shadow .2s;
353
+ -webkit-appearance:none;caret-color:#fff;
354
+ }}
355
+ .f input::placeholder{{color:transparent;}}
356
+ .f label{{
357
+ position:absolute;left:16px;top:50%;transform:translateY(-50%);
358
+ font-size:0.88rem;font-weight:400;color:rgba(255,255,255,0.52);
359
+ pointer-events:none;transition:all 0.2s var(--ease);
360
+ }}
361
+ .f input:focus+label,
362
+ .f input:not(:placeholder-shown)+label{{
363
+ top:10px;transform:none;font-size:0.66rem;
364
+ letter-spacing:0.8px;text-transform:uppercase;
365
+ color:rgba(255,255,255,0.65);font-weight:600;
366
+ }}
367
+ .f input:focus{{
368
+ background:rgba(255,255,255,0.13);
369
+ border-color:rgba(255,255,255,0.7);
370
+ box-shadow:0 0 0 2px rgba(255,255,255,0.06);
371
+ }}
372
+ /* OTP input */
373
+ .f input.otp{{
374
+ height:68px;padding:0;
375
+ font-family:'Bebas Neue',sans-serif;
376
+ font-size:2.6rem;letter-spacing:20px;
377
+ text-align:center;color:var(--red);
378
+ border-color:rgba(229,9,20,0.35);
379
+ background:rgba(229,9,20,0.05);
380
+ caret-color:var(--red);
381
+ }}
382
+ .f input.otp:focus{{border-color:var(--red);background:rgba(229,9,20,0.09);box-shadow:0 0 0 2px rgba(229,9,20,0.15);}}
383
+
384
+ /* ━━ BUTTON ━━ */
385
+ .btn-main{{
386
+ width:100%;height:52px;background:var(--red);border:none;border-radius:4px;
387
+ font-family:'DM Sans',sans-serif;font-size:1rem;font-weight:700;
388
+ letter-spacing:0.5px;color:#fff;cursor:pointer;
389
+ position:relative;overflow:hidden;
390
+ transition:background .2s,transform .15s,box-shadow .2s;
391
+ margin-top:8px;box-shadow:0 2px 12px rgba(229,9,20,0.35);
392
+ }}
393
+ .btn-main::before{{
394
+ content:'';position:absolute;top:0;bottom:0;left:-80%;width:50%;
395
+ background:linear-gradient(90deg,transparent,rgba(255,255,255,0.18),transparent);
396
+ transform:skewX(-15deg);transition:left .5s var(--ease);
397
+ }}
398
+ .btn-main:hover{{background:var(--red-h);transform:translateY(-1px);box-shadow:0 4px 22px rgba(229,9,20,0.5);}}
399
+ .btn-main:hover::before{{left:130%;}}
400
+ .btn-main:active{{transform:translateY(0);}}
401
+ .btn-main:disabled{{opacity:0.55;cursor:not-allowed;transform:none;box-shadow:none;}}
402
+
403
+ /* ━━ OR / switch / forgot ━━ */
404
+ .or-row{{display:flex;align-items:center;gap:12px;margin:14px 0;}}
405
+ .or-row::before,.or-row::after{{content:'';flex:1;height:1px;background:rgba(255,255,255,0.15);}}
406
+ .or-row span{{font-size:0.78rem;color:rgba(255,255,255,0.4);letter-spacing:1px;}}
407
+ .switch-row{{margin-top:18px;font-size:0.88rem;color:rgba(255,255,255,0.5);text-align:center;}}
408
+ .switch-row a{{color:#fff;font-weight:600;cursor:pointer;text-decoration:none;}}
409
+ .switch-row a:hover{{text-decoration:underline;}}
410
+ .legal{{font-size:0.65rem;color:rgba(255,255,255,0.22);margin-top:14px;line-height:1.7;}}
411
+
412
+ /* ━━ MESSAGES ━━ */
413
+ .msg{{
414
+ display:flex;align-items:flex-start;gap:7px;
415
+ padding:10px 13px;border-radius:4px;
416
+ font-size:0.8rem;font-weight:500;margin-bottom:14px;
417
+ line-height:1.5;animation:msg-in 0.35s var(--spring) both;
418
+ }}
419
+ @keyframes msg-in{{from{{opacity:0;transform:translateY(-5px)}}to{{opacity:1;transform:none}}}}
420
+ .err{{background:rgba(229,9,20,0.12);border-left:3px solid var(--red);color:#ff8090;}}
421
+ .ok {{background:rgba(0,200,90,0.1);border-left:3px solid #00c85a;color:#3ddc84;}}
422
+
423
+ /* ━━ OTP INFO BADGE ━━ */
424
+ .otp-info{{
425
+ background:rgba(229,9,20,0.07);border:1px solid rgba(229,9,20,0.2);
426
+ border-radius:6px;padding:14px 16px;margin-bottom:18px;text-align:center;
427
+ }}
428
+ .otp-info p{{font-size:0.72rem;color:rgba(255,255,255,0.45);margin-bottom:2px;}}
429
+ .otp-info strong{{color:var(--red);font-size:0.9rem;display:block;margin:4px 0 2px;}}
430
+ .back-link{{text-align:center;margin-top:12px;}}
431
+ .back-link button{{font-size:0.72rem;color:rgba(255,255,255,0.35);background:none;border:none;cursor:pointer;font-family:'DM Sans',sans-serif;transition:color 0.2s;}}
432
+ .back-link button:hover{{color:rgba(255,255,255,0.75);}}
433
+
434
+ /* ━━ MOBILE ━━ */
435
+ @media(max-width:480px){{
436
+ .site-logo{{top:18px;left:20px;font-size:1.6rem;}}
437
+ .card{{padding:32px 22px;border-radius:6px;max-width:100%;}}
438
+ .mosaic{{grid-template-columns:repeat(5,1fr);grid-template-rows:repeat(8,1fr);}}
439
+ }}
440
+ </style>
441
+ </head>
442
+ <body>
443
+
444
+ <div class="mosaic">{tiles_html}</div>
445
+ <div class="overlay"></div>
446
+ <div class="site-logo">⚑ FitPlan Pro</div>
447
+
448
+ <div class="page">
449
+ <div class="card">
450
+ {card_html}
451
+ </div>
452
+ </div>
453
+
454
+ <script>
455
+ function goSignup(){{setTimeout(function(){{window.location.href='?action=go_signup';}},50);}}
456
+ function goLogin() {{setTimeout(function(){{window.location.href='?action=go_login';}},50);}}
457
+
458
+ function shake(el){{
459
+ el.animate([
460
+ {{transform:'translateX(0)'}},{{transform:'translateX(-7px)'}},
461
+ {{transform:'translateX(7px)'}},{{transform:'translateX(-4px)'}},
462
+ {{transform:'translateX(4px)'}},{{transform:'translateX(0)'}}
463
+ ],{{duration:400,easing:'ease-in-out'}});
464
+ }}
465
+
466
+ /* ━━ MAGNETIC HOVER + CLICK BOUNCE ━━ */
467
+ (function(){{
468
+ var tiles=[],centres=[],mx=innerWidth/2,my=innerHeight/2,raf=null,R=220,P=22;
469
+ function init(){{
470
+ tiles=Array.from(document.querySelectorAll('.tile'));
471
+ if(!tiles.length){{setTimeout(init,300);return;}}
472
+ cache();
473
+ addEventListener('resize',cache,{{passive:true}});
474
+ document.addEventListener('mousemove',function(e){{
475
+ mx=e.clientX;my=e.clientY;
476
+ if(!raf)raf=requestAnimationFrame(tick);
477
+ }},{{passive:true}});
478
+ tiles.forEach(function(t){{
479
+ t.addEventListener('click',function(){{
480
+ var el=this;el.style.animationPlayState='paused';
481
+ el.animate([
482
+ {{transform:'scale(1.22)',filter:'brightness(2.2) saturate(2)'}},
483
+ {{transform:'scale(0.86)',filter:'brightness(0.9)'}},
484
+ {{transform:'scale(1.06)',filter:'brightness(1.35)'}},
485
+ {{transform:'scale(1)', filter:'brightness(1)'}}
486
+ ],{{duration:480,easing:'cubic-bezier(.34,1.56,.64,1)'}})
487
+ .onfinish=function(){{el.style.animationPlayState='';}};
488
+ }});
489
+ }});
490
+ }}
491
+ function cache(){{
492
+ centres=tiles.map(function(t){{
493
+ var r=t.getBoundingClientRect();
494
+ return{{x:r.left+r.width*.5,y:r.top+r.height*.5,el:t}};
495
+ }});
496
+ }}
497
+ function tick(){{
498
+ raf=null;
499
+ centres.forEach(function(c){{
500
+ var dx=mx-c.x,dy=my-c.y,d=Math.sqrt(dx*dx+dy*dy);
501
+ if(d<R&&d>0){{
502
+ var s=(1-d/R),mag=s*s*P;
503
+ c.el.style.transform='translate('+(-(dx/d)*mag)+'px,'+(-(dy/d)*mag)+'px) scale('+(1+s*.13)+')';
504
+ c.el.style.filter='brightness('+(1+s*.65)+') saturate('+(1+s*.55)+')';
505
+ c.el.style.opacity=(0.5+s*.5)+'';
506
+ c.el.style.animationPlayState='paused';
507
+ }}else{{
508
+ c.el.style.transform=c.el.style.filter=c.el.style.opacity='';
509
+ c.el.style.animationPlayState='';
510
+ }}
511
+ }});
512
+ }}
513
+ setTimeout(init,300);
514
+ }})();
515
+
516
+ /* ━━ LOGIN FORM ━━ */
517
+ var fL=document.getElementById('fLogin');
518
+ if(fL) fL.addEventListener('submit',function(e){{
519
+ e.preventDefault();
520
+ var u=document.getElementById('li_u').value.trim();
521
+ var p=document.getElementById('li_p').value;
522
+ if(!u||!p){{shake(fL);return;}}
523
+ var b=fL.querySelector('.btn-main');b.disabled=true;b.textContent='Signing in\u2026';
524
+ window.location.href='?action=login&u='+encodeURIComponent(u)+'&p='+encodeURIComponent(p);
525
+ }});
526
+
527
+ /* ━━ SIGNUP FORM ━━ */
528
+ var fS=document.getElementById('fSignup');
529
+ if(fS) fS.addEventListener('submit',function(e){{
530
+ e.preventDefault();
531
+ var u=document.getElementById('su_u').value.trim();
532
+ var em=document.getElementById('su_e').value.trim();
533
+ var p=document.getElementById('su_p').value;
534
+ var p2=document.getElementById('su_p2').value;
535
+ if(!u||!em||!p||!p2){{shake(fS);return;}}
536
+ if(p!==p2){{shake(fS);return;}}
537
+ var b=fS.querySelector('.btn-main');b.disabled=true;b.textContent='Sending code\u2026';
538
+ window.location.href='?action=send_otp&u='+encodeURIComponent(u)+'&e='+encodeURIComponent(em)+'&p='+encodeURIComponent(p)+'&p2='+encodeURIComponent(p2);
539
+ }});
540
+
541
+ /* ━━ OTP FORM ━━ */
542
+ var fO=document.getElementById('fOtp');
543
+ if(fO) fO.addEventListener('submit',function(e){{
544
+ e.preventDefault();
545
+ var otp=document.getElementById('otp_val').value.trim();
546
+ if(!otp||otp.length<6){{shake(fO);return;}}
547
+ var b=fO.querySelector('.btn-main');b.disabled=true;b.textContent='Verifying\u2026';
548
+ var hu=document.getElementById('h_u').value;
549
+ var he=document.getElementById('h_e').value;
550
+ var hp=document.getElementById('h_p').value;
551
+ window.location.href='?action=verify_otp&otp='+encodeURIComponent(otp)
552
+ +'&u='+encodeURIComponent(hu)+'&e='+encodeURIComponent(he)+'&p='+encodeURIComponent(hp);
553
+ }});
554
+
555
+ /* OTP auto-submit at 6 digits */
556
+ var otpEl=document.getElementById('otp_val');
557
+ if(otpEl){{
558
+ otpEl.addEventListener('input',function(){{
559
+ this.value=this.value.replace(/[^0-9]/g,'');
560
+ if(this.value.length===6){{
561
+ setTimeout(function(){{
562
+ var b=document.querySelector('#fOtp .btn-main');
563
+ if(b&&!b.disabled)b.click();
564
+ }},350);
565
+ }}
566
+ }});
567
+ }}
568
+
569
+ var bb=document.getElementById('backBtn');
570
+ if(bb) bb.addEventListener('click',function(){{window.location.href='?action=go_back';}});
571
+ </script>
572
+ </body>
573
+ </html>"""
574
+
575
+ components.html(HTML, height=900, scrolling=False)