Spaces:
Running

File size: 35,826 Bytes
64378fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30247fe
 
64378fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cecfe55
 
64378fa
 
 
 
cecfe55
64378fa
 
cecfe55
 
 
64378fa
 
cecfe55
 
 
 
 
64378fa
 
 
 
cecfe55
 
 
64378fa
 
cecfe55
64378fa
 
 
 
 
 
 
 
cecfe55
64378fa
 
 
 
 
 
 
30247fe
cecfe55
64378fa
 
 
 
 
 
 
30247fe
 
 
 
64378fa
 
 
30247fe
 
64378fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30247fe
64378fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cecfe55
64378fa
cecfe55
64378fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cecfe55
64378fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Setting up Explication — the picture guide</title>
<style>
  :root {
    --ink:#111114; --secondary:#56575e; --faint:#8c8d95; --hairline:#e8e8ec;
    --accent:#1b6b4f; --accent-soft:#edf5f0; --accent-deep:#124a37;
    --warning:#a9662f; --warning-soft:#f9eee0; --danger:#a3403f; --danger-soft:#f9e7e5;
    --surface:#fff; --sunken:#f4f4f7; --deep:#f7f7f9;
    --serif:"Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;
    --sans:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    --mono:ui-monospace,SFMono-Regular,Menlo,monospace;
  }
  *{box-sizing:border-box}
  body{margin:0;font-family:var(--sans);color:var(--ink);background:#fff;font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}
  a{color:var(--accent)}
  .wrap{max-width:960px;margin:0 auto;padding:0 22px 90px}
  header.hero{padding:54px 0 4px;border-bottom:1px solid var(--hairline);background:linear-gradient(180deg,#f3f8f4, #fff)}
  header.hero .wrap{padding-bottom:28px}
  .badge{display:inline-flex;align-items:center;gap:6px;background:#fff;border:1px solid #dde8e0;color:var(--accent-deep);border-radius:999px;padding:5px 11px;font-size:10.5px;font-weight:700;letter-spacing:.04em;text-transform:uppercase}
  h1{font-family:var(--serif);font-size:44px;line-height:1.05;letter-spacing:-.03em;margin:14px 0 0;max-width:700px}
  .lede{font-size:15px;color:var(--secondary);max-width:620px;margin:12px 0 0;line-height:1.6}
  .meta{display:flex;gap:16px;flex-wrap:wrap;margin-top:16px;font-size:11.5px;color:var(--faint);font-weight:600}
  .meta span{display:inline-flex;align-items:center;gap:5px}
  .dot{width:6px;height:6px;border-radius:50%;background:var(--accent)}

  .step{margin-top:34px;border-top:1px solid var(--hairline);padding-top:26px}
  .step:first-of-type{border-top:0;margin-top:0;padding-top:0}
  .step-head{display:flex;gap:14px;align-items:flex-start}
  .num{flex:0 0 34px;height:34px;border-radius:50%;background:var(--ink);color:#fff;display:grid;place-items:center;font-weight:700;font-size:14px}
  .step h2{font-family:var(--serif);font-size:24px;letter-spacing:-.02em;margin:0;line-height:1.2}
  .step .why{color:var(--secondary);font-size:13px;margin:5px 0 0;max-width:640px;line-height:1.55}
  .body{padding-left:48px;margin-top:16px}

  .window{border:1px solid var(--hairline);border-radius:12px;overflow:hidden;background:#fff;box-shadow:0 8px 26px rgba(11,12,14,.06)}
  .chrome{display:flex;align-items:center;gap:6px;padding:8px 10px;background:var(--deep);border-bottom:1px solid var(--hairline)}
  .chrome i{width:8px;height:8px;border-radius:50%;background:#d9d9df;display:block}
  .chrome .url{margin-left:8px;font-family:var(--mono);font-size:10px;color:var(--faint);background:#fff;border:1px solid var(--hairline);border-radius:6px;padding:3px 8px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
  .pane{display:flex;min-height:120px}
  .rail{flex:0 0 168px;border-right:1px solid var(--hairline);padding:12px;background:#fbfbfc}
  .rail .item{display:flex;align-items:center;gap:7px;font-size:11px;color:var(--secondary);padding:6px 7px;border-radius:7px;margin-bottom:2px}
  .rail .item.on{background:var(--accent-soft);color:var(--accent-deep);font-weight:700}
  .rail .item .ic{width:14px;height:14px;border-radius:4px;border:1px solid #cfcfd6;display:grid;place-items:center;font-size:8px;font-weight:700;color:var(--faint);background:#fff}
  .canvas{flex:1;padding:16px;min-width:0}
  .canvas h4{margin:0 0 4px;font-size:13px}
  .canvas p{margin:0;font-size:11.5px;color:var(--secondary)}
  .field{border:1px solid var(--hairline);border-radius:8px;padding:8px 10px;font-size:11.5px;color:var(--ink);background:#fff;display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:8px}
  .field .lab{color:var(--faint);font-size:10px;display:block;margin-bottom:2px}
  .field code{font-family:var(--mono);font-size:10.5px;color:var(--secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:340px}
  .btn{display:inline-flex;align-items:center;gap:6px;background:var(--ink);color:#fff;border:0;border-radius:7px;padding:7px 11px;font-size:11.5px;font-weight:600}
  .btn.green{background:var(--accent)}
  .btn.ghost{background:#fff;color:var(--ink);border:1px solid var(--hairline)}
  .row{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px}
  .toggle{width:30px;height:17px;border-radius:999px;background:var(--accent);position:relative;display:inline-block;flex:0 0 30px}
  .toggle::after{content:"";position:absolute;right:2px;top:2px;width:13px;height:13px;border-radius:50%;background:#fff}
  .listline{display:flex;align-items:center;justify-content:space-between;gap:10px;border-top:1px solid var(--hairline);padding:9px 0;font-size:11.5px}
  .listline:first-child{border-top:0}
  .pin{display:inline-grid;place-items:center;width:17px;height:17px;border-radius:50%;background:var(--ink);color:#fff;font-size:9.5px;font-weight:700;vertical-align:middle;margin-right:4px}

  .do{margin-top:12px;background:var(--accent-soft);border:1px solid #d9eae1;border-radius:10px;padding:12px 14px;font-size:12.5px;color:var(--accent-deep);line-height:1.6}
  .do b{font-weight:700}
  .warn{margin-top:12px;background:var(--warning-soft);border:1px solid #f0dcc5;border-radius:10px;padding:12px 14px;font-size:12.5px;color:#7d4a1f;line-height:1.6}
  .tip{margin-top:10px;font-size:11.5px;color:var(--faint)}
  code.inline{font-family:var(--mono);font-size:11.5px;background:var(--deep);border:1px solid var(--hairline);border-radius:5px;padding:1px 5px}
  .copy{font-family:var(--sans);cursor:pointer}

  table.where{width:100%;border-collapse:collapse;margin-top:10px;font-size:12px}
  table.where th{text-align:left;font-size:9.5px;letter-spacing:.07em;text-transform:uppercase;color:var(--faint);font-weight:700;padding:0 0 6px}
  table.where td{padding:8px 10px 8px 0;border-top:1px solid var(--hairline);vertical-align:top;color:var(--secondary)}
  table.where td:first-child{color:var(--ink);font-weight:600;width:38%}

  footer{margin-top:44px;border-top:1px solid var(--hairline);padding-top:18px;font-size:11.5px;color:var(--faint)}
  @media (max-width:720px){
    h1{font-size:33px}.body{padding-left:0}.pane{flex-direction:column}.rail{flex:none;border-right:0;border-bottom:1px solid var(--hairline)}
    .field code{max-width:180px}
  }
</style>
</head>
<body>
<header class="hero">
  <div class="wrap">
    <span class="badge">● Explication setup</span>
    <h1>From an empty folder to taking payments.</h1>
    <p class="lede">Nine screens. Each one tells you exactly where to click, what to copy and where to paste it. No terminal, no code, no guessing.</p>
    <div class="meta"><span><i class="dot"></i> About 20 minutes</span><span><i class="dot"></i> Free tiers are enough</span><span><i class="dot"></i> Test mode first, real money later</span></div>
  </div>
</header>

<div class="wrap">

  <section class="step">
    <div class="step-head">
      <div class="num">1</div>
      <div>
        <h2>Make a Supabase project</h2>
        <p class="why">Supabase is the free service that holds the accounts, the plans and the page wording. One project is all you need.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com/dashboard</span></div>
        <div class="pane">
          <div class="rail">
            <div class="item on"><span class="ic">+</span> New project</div>
            <div class="item"><span class="ic">▦</span> All projects</div>
            <div class="item"><span class="ic">?</span> Help</div>
          </div>
          <div class="canvas">
            <h4>Create a new project</h4>
            <p>Free. Pick the region closest to you.</p>
            <div class="field"><span><span class="lab">Name</span><code>explication</code></span></div>
            <div class="field"><span><span class="lab">Database password</span><code>••••••••••••</code></span><span class="pin">1</span></div>
            <div class="field"><span><span class="lab">Region</span><code>Europe (London)</code></span></div>
            <div class="row"><button class="btn green">Create new project</button></div>
          </div>
        </div>
      </div>
      <div class="do"><b>Do this:</b> go to <a href="https://supabase.com/dashboard" target="_blank" rel="noreferrer">supabase.com/dashboard</a>, sign in, click <b>New project</b>. Name it <b>explication</b>, save the database password somewhere safe <span class="pin">1</span> (you will not need it in this guide), pick the closest region, and press <b>Create new project</b>. Wait about two minutes while it builds.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">2</div>
      <div>
        <h2>Paste in the database file</h2>
        <p class="why">This creates every table the site needs, fills in the seven plans, and locks all editing to your developer email.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → your project → SQL Editor</span></div>
        <div class="pane">
          <div class="rail">
            <div class="item"><span class="ic">▦</span> Table editor</div>
            <div class="item on"><span class="ic">&gt;_</span> SQL Editor</div>
            <div class="item"><span class="ic">⚿</span> Authentication</div>
            <div class="item"><span class="ic">⚙</span> Project Settings</div>
          </div>
          <div class="canvas">
            <h4>New query</h4>
            <p>Paste the whole file, then press Run.</p>
            <div class="field" style="min-height:74px;align-items:flex-start"><code style="white-space:pre-line;max-width:100%">create extension if not exists pgcrypto;<br/>create table public.explication_plans ( … );</code></div>
            <div class="row"><button class="btn green">▷ Run</button><button class="btn ghost">Save</button><span class="pin">2</span></div>
          </div>
        </div>
      </div>
      <div class="do">
        <b>Do this:</b> in the left sidebar click <b>SQL Editor</b> <span class="pin">2</span>, then <b>New query</b>.
        Click the button below to copy the file, paste it into the big box, and press <b>Run</b>.
        You should see <code class="inline">Success. No rows returned</code>.
        <div class="row"><button class="btn copy" data-copy-sql="1">Copy the database file</button><span class="tip" id="copy-sql-note"></span></div>
      </div>
      <div class="warn">If you later change the plans, come back here and run the same file again — it updates the shop front in place without wiping anything.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">3</div>
      <div>
        <h2>Turn on email sign-in</h2>
        <p class="why">Students sign in with an email and password. While you are testing, switch confirmation off so you can sign in instantly.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → Authentication → Providers</span></div>
        <div class="pane">
          <div class="rail">
            <div class="item on"><span class="ic">⚿</span> Providers</div>
            <div class="item"><span class="ic">@</span> Emails</div>
            <div class="item"><span class="ic">↗</span> URL Configuration</div>
          </div>
          <div class="canvas">
            <h4>Email</h4>
            <p>The simplest way in.</p>
            <div class="listline"><span>Enable email provider</span><span class="toggle"></span></div>
            <div class="listline"><span>Confirm email <em style="color:var(--faint)">(off while testing)</em></span><span class="toggle" style="background:#dfe0e6"></span></div>
            <div class="row"><button class="btn">Save</button><span class="pin">3</span></div>
          </div>
        </div>
      </div>
      <div class="do">        <b>Do this:</b> click <b>Authentication → Providers</b> <span class="pin">3</span>, open <b>Email</b>, make sure it is <b>enabled</b>. Turn <b>Confirm email</b> off for now — turn it back on before real students arrive. Press <b>Save</b>.<br><br>The branded email templates are in <code class="inline">emails/auth-emails.html</code> — one paste-ready block per email — with subject lines in <code class="inline">emails/auth-emails.txt</code>. Those templates only reach real students once a real sender is connected: that is <b>Make email actually arrive</b>, after step 9.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">4</div>
      <div>
        <h2>Copy two values into the site</h2>
        <p class="why">The site needs the project's address and its public key. Nothing secret goes in the browser.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → Project Settings → API</span></div>
        <div class="pane">
          <div class="rail">
            <div class="item"><span class="ic">⚙</span> General</div>
            <div class="item on"><span class="ic">⚙</span> API</div>
            <div class="item"><span class="ic">⚿</span> Database</div>
          </div>
          <div class="canvas">
            <h4>Project API keys</h4>
            <p>Copy these two. Ignore <b>service_role</b> for ever.</p>
            <div class="field"><span><span class="lab">Project URL</span><code>https://abcdefgh.supabase.co</code></span><button class="btn ghost copy" data-copy="0">Copy</button></div>
            <div class="field"><span><span class="lab">anon public</span><code>eyJhbGciOiJIUzI1NiIs…</code></span><button class="btn ghost copy" data-copy="1">Copy</button></div>
          </div>
        </div>
      </div>
      <div class="do"><b>Do this:</b> in Supabase click <b>Project Settings → API</b>. Copy <b>Project URL</b> and the <b>anon public</b> key. Then open the Explication site, click <b>Connect Supabase</b> on the green bar, paste one into each box, and press <b>Connect this site</b>.</div>
      <div class="warn"><b>Never</b> paste the <b>service_role</b> key into the site. If it ever leaks, rotate it in the same screen.</div>
      <div class="tip">Want every visitor to skip this step? Open <code class="inline">js/config.js</code> in the Explication Web folder and paste the same two values there.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">5</div>
      <div>
        <h2>Make yourself the developer</h2>
        <p class="why">One address gets the console: <b>lucas.owen13@icloud.com</b>. Nobody else, ever.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">your site → Account</span></div>
        <div class="pane">
          <div class="canvas">
            <h4>Create account</h4>
            <div class="field"><span><span class="lab">Email</span><code>lucas.owen13@icloud.com</code></span></div>
            <div class="field"><span><span class="lab">Password</span><code>••••••••</code></span></div>
            <div class="row"><button class="btn green">Create account</button><span class="pin">4</span></div>
          </div>
        </div>
      </div>
      <div class="do"><b>Do this:</b> on the site click <b>Account → Create account</b> <span class="pin">4</span> and use exactly <b>lucas.owen13@icloud.com</b>. Sign in. A <b>Developer</b> item appears in the sidebar — that is your console.</div>
      <div class="warn">Using any other address gives a normal account with no console. That is the point: the database itself refuses edits from everyone else.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">6</div>
      <div>
        <h2>Give a model its API key</h2>
        <p class="why">Offline models and students' own keys work without this. This is only if you want to host the big models yourself.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">your site → Developer → Models &amp; keys</span></div>
        <div class="pane">
          <div class="canvas">
            <h4>Qwen2.5 7B</h4>
            <div class="field"><span><span class="lab">Endpoint base URL</span><code>https://openrouter.ai/api/v1</code></span></div>
            <div class="field"><span><span class="lab">Model name at the host</span><code>qwen/qwen-2.5-7b-instruct</code></span></div>
            <div class="field"><span><span class="lab">API key</span><code>sk-or-v1-…</code></span><span class="pin">5</span></div>
            <div class="row"><button class="btn green">Save model</button></div>
          </div>
        </div>
      </div>
      <div class="do"><b>Do this:</b> in your model provider's dashboard create an API key. On the site open <b>Developer → Models &amp; keys</b>, edit a model, paste the endpoint and the key <span class="pin">5</span>, and press <b>Save model</b>. Repeat per model.</div>
      <div class="tip">The key is write-only: it goes into a table no browser can read, and only the site's server function uses it.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">7</div>
      <div>
        <h2>Connect PayPal to the plans</h2>
        <p class="why">Two routes: the PayPal API unlocks purchases automatically; payment links need no keys but one click per sale.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">developer.paypal.com → Apps &amp; Credentials</span></div>
        <div class="pane">
          <div class="rail">
            <div class="item on"><span class="ic">▦</span> Apps &amp; Credentials</div>
            <div class="item"><span class="ic">◍</span> Live</div>
            <div class="item"><span class="ic">↗</span> Webhooks</div>
          </div>
          <div class="canvas">
            <h4>Create a PayPal app</h4>
            <p>Copy the Client ID and Secret into Supabase secrets.</p>
            <div class="field"><span><span class="lab">Client ID</span><code>AeA1…your-client-id</code></span></div>
            <div class="field"><span><span class="lab">Secret</span><code>••••••••••••</code></span><span class="pin">6</span></div>
            <div class="row"><button class="btn green">Create app</button><span class="pin">7</span></div>
          </div>
        </div>
      </div>
      <div class="do">
        <b>Do this:</b> in PayPal open <b>Developer → Apps &amp; Credentials</b>, choose <b>Live</b> (or <b>Sandbox</b> to test), create an app, and copy the <b>Client ID</b> and <b>Secret</b> <span class="pin">6</span>. Add them as <code class="inline">PAYPAL_CLIENT_ID</code> and <code class="inline">PAYPAL_CLIENT_SECRET</code> in Supabase → <b>Edge Functions → Secrets</b> <span class="pin">7</span>.
        Add a webhook at <code class="inline">https://YOUR-PROJECT.supabase.co/functions/v1/paypal-webhook</code> with the six payment events listed in <code class="inline">supabase/SETUP.md</code>, then put its <b>Webhook ID</b> into <code class="inline">PAYPAL_WEBHOOK_ID</code>.
        On the site open <b>Developer → PayPal</b>, paste the <b>Client ID</b>, set <b>Live</b> and <b>PayPal API</b>, and save.
      </div>
      <table class="where">
        <tr><th>Product name</th><th>Price</th><th>Type</th></tr>
        <tr><td>Paragraph Lite</td><td>£4.00</td><td>One-off</td></tr>
        <tr><td>Model Library</td><td>£14.00</td><td>One-off</td></tr>
        <tr><td>Exam Season</td><td>£24.00</td><td>One-off</td></tr>
        <tr><td>AI Booster</td><td>£6.00</td><td>One-off</td></tr>
        <tr><td>Student</td><td>£4.00</td><td>Monthly, recurring</td></tr>
        <tr><td>Scholar</td><td>£9.00</td><td>Monthly, recurring</td></tr>
        <tr><td>Examiner</td><td>£19.00</td><td>Monthly, recurring</td></tr>
      </table>
      <div class="tip">No terminal? Use <b>PayPal payment links</b> instead: create a link per plan in PayPal, paste it into <b>Developer → Plans → PayPal payment link</b>, switch the checkout mode to <b>Payment links</b>, and grant each buyer in <b>People</b>. The API route is the one that unlocks automatically.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">8</div>
      <div>
        <h2>Try it, then give yourself the plan</h2>
        <p class="why">With payment links, PayPal takes the money but the site does not hear about it automatically. You approve the buyer by hand — one click.</p>
      </div>
    </div>
    <div class="body">
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">your site → Developer → People</span></div>
        <div class="pane">
          <div class="canvas">
            <h4>Give someone a plan</h4>
            <div class="field"><span><span class="lab">Buyer's email</span><code>lucas.owen13@icloud.com</code></span></div>
            <div class="field"><span><span class="lab">Plan</span><code>Student · £4.00</code></span></div>
            <div class="row"><button class="btn green">Grant access</button><span class="pin">8</span></div>
          </div>
        </div>
      </div>
      <div class="do"><b>Do this:</b> buy your own plan with test card <code class="inline">4242 4242 4242 4242</code>, any future date, any CVC. Then on the site open <b>Developer → People</b>, type the buyer's email, pick the plan and press <b>Grant access</b> <span class="pin">8</span>. The plan shows on their Account page immediately.</div>
      <div class="warn">Want purchases to unlock themselves? That is the optional checkout-function route in <code class="inline">supabase/SETUP.md</code>, step 3. It needs five terminal commands. Everything works without it — you just approve each sale.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">9</div>
      <div>
        <h2>Publish it</h2>
        <p class="why">Any static host works. Supabase stays the backend, so there is nothing to run.</p>
      </div>
    </div>
    <div class="body">
      <div class="do">
        <b>Before you upload:</b> open <code class="inline">js/config.js</code> in a text editor and paste your Project URL and anon key into the two empty quotes (the same two values from step 4). That is what makes the plans, wording and prices identical for every visitor — without it, each visitor is asked to connect their own project.
        <b>Then:</b> upload the <b>dist</b> folder — it is the upload copy of the site, with the Supabase function files left out so hosts do not think a build is needed. On Cloudflare go to <b>Workers &amp; Pages → Create → Upload and deploy</b>; on Netlify drag it onto <a href="https://app.netlify.com/drop" target="_blank" rel="noreferrer">app.netlify.com/drop</a>. You get an address like <code class="inline">explication.netlify.app</code> or <code class="inline">explication.you.workers.dev</code>.
        Go back to Supabase → <b>Authentication → URL Configuration</b> and add that address to <b>Redirect URLs</b>.
        Finally set the same address in the iPhone and Mac apps (see <code class="inline">supabase/SETUP.md</code>) so their plan buttons open the right site.
      </div>
      <div class="warn">Local files (<code class="inline">file://</code>) cannot sign in. Always open the site through <code class="inline">Start Explication.command</code> or the published address.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">✉</div>
      <div>
        <h2>Make email actually arrive</h2>
        <p class="why">Supabase's built-in sender only delivers to your own team and allows a couple of messages an hour. Real students need a real sender. Three jobs, three services: Resend sends, Cloudflare receives, Apple Mail reads it.</p>
      </div>
    </div>
    <div class="body">
      <div class="do">
        <b>A · Sending: Resend.</b> You need a domain you own — buy one at Cloudflare → <b>Domain Registration</b> (about £8–10 a year) if you do not have one. Then sign up at <a href="https://resend.com" target="_blank" rel="noreferrer">resend.com</a>; the free plan is 3,000 emails a month, 100 a day.<br><br>
        <b>1.</b> Resend → <b>Domains → Add domain</b> → type the domain → pick a region → <b>Add</b>.<br>
        <b>2.</b> It lists three or four DNS records. In Cloudflare open the domain → <b>DNS → Records</b> and add each one exactly as shown. Leave the proxy switch <b>off</b> (grey cloud, “DNS only”) — a proxied MX or TXT record will not verify. Then press <b>Verify</b> in Resend; usually a few minutes.<br>
        <b>3.</b> Resend → <b>API Keys → Create API key</b>, permission <b>Sending access</b>, and copy the <code class="inline">re_…</code> value. It is shown once.
      </div>
      <div class="window">
        <div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → Authentication → Emails → SMTP Settings</span></div>
        <div class="pane">
          <div class="canvas">
            <h4>Enable custom SMTP</h4>
            <p>Six values. Only the sender is yours.</p>
            <div class="field"><span><span class="lab">Sender email</span><code>no-reply@yourdomain.com</code></span></div>
            <div class="field"><span><span class="lab">Sender name</span><code>Explication</code></span></div>
            <div class="field"><span><span class="lab">Host</span><code>smtp.resend.com</code></span></div>
            <div class="field"><span><span class="lab">Port</span><code>465</code></span></div>
            <div class="field"><span><span class="lab">Username</span><code>resend</code></span></div>
            <div class="field"><span><span class="lab">Password</span><code>re_… (your API key)</code></span></div>
            <div class="row"><button class="btn green">Save</button></div>
          </div>
        </div>
      </div>
      <div class="do" style="margin-top:12px">
        <b>4.</b> In Supabase open <b>Authentication → Emails → SMTP Settings</b>, turn on <b>Enable custom SMTP</b> and paste the six values above. The username really is the word <code class="inline">resend</code>, and the password is the API key, not your Resend login.<br>
        <b>5.</b> Trigger a password reset from the site. It should arrive from <code class="inline">no-reply@yourdomain.com</code> within seconds, and Resend → <b>Emails</b> shows whether it was delivered. Supabase starts you at 30 messages an hour — raise it in <b>Authentication → Rate Limits</b> once it works. The branded templates from step 3 are what gets sent; nothing else to change.
      </div>
      <div class="tip">If Resend offers a DMARC record as well, add it: it is one TXT record at <code class="inline">_dmarc</code> and it keeps your mail out of spam folders.</div>
      <div class="do">
        <b>B · Receiving: Cloudflare Email Routing.</b> Free, and receiving only — Cloudflare has no inbox and no SMTP server, so it can never be the thing that sends.<br><br>
        <b>1.</b> The domain has to be on Cloudflare, using Cloudflare's nameservers.<br>
        <b>2.</b> Dashboard → <b>Email → Email Routing → Onboard domain → Add records and enable</b>. That adds the MX, SPF and DKIM records for you.<br>
        <b>3.</b> <b>Destination addresses</b> → add your iCloud address → open the verification email → verify.<br>
        <b>4.</b> <b>Routing rules → Custom addresses → Create address</b>: <code class="inline">hello</code> (or <code class="inline">support</code>) → action <b>Send to</b> → your iCloud address → <b>Save</b>.<br>
        <b>5.</b> Email it from another account. It should land in iCloud within seconds, and the original address stays hidden.
      </div>
      <div class="warn">Never switch Email Routing on for a domain that already receives mail somewhere else — Google, Microsoft, or iCloud+. It replaces the MX records, so that other inbox stops getting mail. One receiver per domain.</div>
      <div class="do">
        <b>C · Reading it: Apple Mail.</b> On the iPhone: <b>Settings → Apps → Mail → Accounts → Add Account → iCloud</b>. On the Mac: <b>Mail → Settings → Accounts → +</b> → iCloud.<br><br>
        Mail sent to <code class="inline">hello@yourdomain.com</code> is forwarded into that iCloud inbox, so it arrives like any other message. Replies go out from your iCloud address unless you do D.
      </div>
      <div class="do">
        <b>D · Replying as hello@yourdomain.com (optional).</b> Two honest routes.<br><br>
        <b>iCloud+ custom domain</b> — paid with iCloud+ (about 79p a month): <b>Settings → Apple Account → iCloud → Custom Email Domain</b> → use a domain you own. Apple then hosts the mailbox, Apple Mail sends and receives natively as <code class="inline">hello@yourdomain.com</code>, and Cloudflare is only DNS. It takes over the MX records, so switch Cloudflare Email Routing off for that domain first — and then part B is not needed at all.<br><br>
        <b>Send-as through Resend</b> — free, fine for the occasional reply: <b>Mail → Settings → Accounts → your iCloud account → Account Information → Edit Email Addresses</b> → add <code class="inline">hello@yourdomain.com</code>. Then <b>Server Settings → Outgoing Mail Server → Edit SMTP Server List</b> → add <code class="inline">smtp.resend.com</code>, port <code class="inline">465</code>, user <code class="inline">resend</code>, your API key, TLS on. It sends, but Resend is not a mailbox: there is no Sent folder on a server and the message is logged as app mail. Good enough to answer a student; not a replacement for a real inbox.
      </div>
      <table class="where">
        <tr><th>Job</th><th>Who does it</th><th>Cost</th></tr>
        <tr><td>Send sign-in and password emails</td><td>Resend → Supabase custom SMTP</td><td>Free to 3,000 a month</td></tr>
        <tr><td>Receive mail at your domain</td><td>Cloudflare Email Routing → forwards to iCloud</td><td>Free</td></tr>
        <tr><td>Read it and reply</td><td>Apple Mail, on the iCloud account</td><td>Free</td></tr>
        <tr><td>Reply <i>as</i> your domain, natively</td><td>iCloud+ custom domain (replaces Email Routing)</td><td>iCloud+ subscription</td></tr>
      </table>
      <div class="warn">Resend cannot receive email. Never point MX records at Resend, and never put the <code class="inline">re_…</code> key in the website — it belongs only in Supabase's SMTP settings.</div>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">☰</div>
      <div>
        <h2>Where everything lives</h2>
        <p class="why">One table to come back to when you forget.</p>
      </div>
    </div>
    <div class="body">
      <table class="where">
        <tr><th>What you want to change</th><th>Where to click</th></tr>
        <tr><td>Prices, plan names, wording of a plan</td><td>Site → <b>Developer → Plans → Edit</b></td></tr>
        <tr><td>Any sentence on any page</td><td>Site → <b>Developer → Wording → edit mode</b>, then click the words</td></tr>
        <tr><td>Model keys and endpoints</td><td>Site → <b>Developer → Models &amp; keys</b></td></tr>
        <tr><td>Payment links</td><td>Site → <b>Developer → Plans</b> → PayPal payment link field</td></tr>
        <tr><td>Who has a plan</td><td>Site → <b>Developer → People</b></td></tr>
        <tr><td>PayPal keys (advanced)</td><td>Supabase → <b>Edge Functions → Secrets</b></td></tr>
        <tr><td>The project address and key</td><td>Supabase → <b>Project Settings → API</b>; site → <b>Developer → Supabase</b></td></tr>
        <tr><td>Emails students receive</td><td>Supabase → <b>Authentication → Emails</b></td></tr>
        <tr><td>Which address students see as the sender</td><td>Supabase → <b>Authentication → Emails → SMTP Settings</b></td></tr>
        <tr><td>Mail sent to hello@yourdomain</td><td>Cloudflare → <b>Email → Email Routing</b></td></tr>
      </table>
    </div>
  </section>

  <section class="step">
    <div class="step-head">
      <div class="num">?</div>
      <div>
        <h2>If something looks wrong</h2>
        <p class="why">The four things that actually go wrong.</p>
      </div>
    </div>
    <div class="body">
      <table class="where">
        <tr><th>Symptom</th><th>Fix</th></tr>
        <tr><td>No developer console in the sidebar</td><td>You are signed in as a different email. Sign out, sign in as lucas.owen13@icloud.com.</td></tr>
        <tr><td>"Supabase could not be reached"</td><td>Project URL or anon key pasted wrong. Developer → Supabase → paste again from Project Settings → API.</td></tr>
        <tr><td>Plans page is empty</td><td>Step 2 did not run. Supabase → SQL Editor → paste the file → Run.</td></tr>
        <tr><td>"This plan has no PayPal payment link yet"</td><td>Add the link to that plan in Developer → Plans, or you are in live mode with a test link.</td></tr>
        <tr><td>Sign-up says "check your email" but nothing arrives</td><td>Confirmation is on and Supabase's built-in sender only reaches your own team. Connect Resend (last section), or turn Confirm email off in Authentication → Providers → Email.</td></tr>
      </table>
    </div>
  </section>

  <footer>
    Explication · the full technical version, including webhooks and edge functions, is in <code class="inline">supabase/SETUP.md</code>.
  </footer>
</div>

<script>
  const sqlButton = document.querySelector("[data-copy-sql]");
  const sqlNote = document.getElementById("copy-sql-note");
  if (sqlButton) {
    sqlButton.addEventListener("click", async () => {
      try {
        let text = "";
        for (const path of ["schema.sql", "supabase/schema.sql"]) {
          const res = await fetch(path);
          if (res.ok) {
            text = await res.text();
            break;
          }
        }
        if (!text) throw new Error("schema not found");
        await navigator.clipboard.writeText(text);
        sqlButton.textContent = "Copied — now paste it into Supabase";
        sqlNote.textContent = "Includes the tables and all seven plans.";
        setTimeout(() => { sqlButton.textContent = "Copy the database file"; }, 4000);
      } catch (error) {
        sqlNote.textContent = "Could not copy. Open supabase/schema.sql and copy it by hand.";
      }
    });
  }

  document.querySelectorAll(".copy[data-copy]").forEach((button) => {
    button.addEventListener("click", () => {
      const field = button.closest(".field");
      const value = field ? field.querySelector("code").textContent : "";
      navigator.clipboard.writeText(value).catch(() => {});
      button.textContent = "Copied";
      setTimeout(() => { button.textContent = "Copy"; }, 2000);
    });
  });
</script>
</body>
</html>