File size: 8,520 Bytes
4e3ac7f
 
 
 
 
 
 
 
 
 
 
 
 
 
d30c8ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e3ac7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d30c8ef
c7faf5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d30c8ef
 
c7faf5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d30c8ef
 
 
 
 
 
4e3ac7f
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mathaí — Irish Maths AI Tutor</title>
    <link rel="stylesheet" href="/static/styles.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <!-- KaTeX for maths rendering -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
</head>
<body>

<!-- ── PIN Auth Overlay ─────────────────────────────────────────── -->
<div id="pinOverlay" class="pin-overlay">
    <div class="pin-card">
        <div class="pin-icon">🔒</div>
        <h2>Enter Access Code</h2>
        <p>This app is currently in private preview.</p>
        <div class="pin-input-row">
            <input type="text" id="pinInput" maxlength="4" placeholder="····" autocomplete="off" autofocus>
        </div>
        <button class="pin-submit" onclick="checkPin()">Unlock</button>
        <p id="pinError" class="pin-error"></p>
    </div>
</div>

<!-- ── Welcome Screen ─────────────────────────────────────────── -->
    <div id="welcomeScreen" class="welcome-screen">
        <div class="welcome-content">
            <div class="welcome-hero">
                <div class="hero-icon">🧮</div>
                <h1>Mathaí</h1>
                <p class="hero-sub">Your Irish Maths AI Tutor</p>
                <p class="hero-desc">Get help with any maths topic from the Irish curriculum.<br>Primary, Junior Cycle &amp; Leaving Cert.</p>
            </div>

            <div class="role-picker">
                <h3>I am a...</h3>
                <div class="role-cards">
                    <button class="role-card" data-role="student" id="pickStudent">
                        <span class="role-icon">🎒</span>
                        <span class="role-label">Student</span>
                        <span class="role-hint">Get help with homework &amp; study</span>
                    </button>
                    <button class="role-card" data-role="teacher" id="pickTeacher">
                        <span class="role-icon">👩‍🏫</span>
                        <span class="role-label">Teacher</span>
                        <span class="role-hint">Lesson plans, worksheets &amp; ideas</span>
                    </button>
                </div>
            </div>

            <!-- Level picker (shown after student is picked) -->
            <div class="level-picker" id="levelPicker" style="display:none;">
                <h3>What level are you?</h3>
                <div class="level-cards">
                    <button class="level-card" data-level="primary">
                        <span class="level-emoji">🏫</span>
                        <span class="level-name">Primary</span>
                        <span class="level-detail">Junior Infants – 6th Class</span>
                    </button>
                    <button class="level-card" data-level="junior_cycle">
                        <span class="level-emoji">📚</span>
                        <span class="level-name">Junior Cycle</span>
                        <span class="level-detail">1st – 3rd Year</span>
                    </button>
                    <button class="level-card" data-level="senior_cycle">
                        <span class="level-emoji">🎓</span>
                        <span class="level-name">Senior Cycle</span>
                        <span class="level-detail">5th & 6th Year / Leaving Cert</span>
                    </button>
                </div>
            </div>

            <!-- Class picker for primary (shown after primary is picked) -->
            <div class="class-picker" id="classPicker" style="display:none;">
                <h3>What class are you in?</h3>
                <div class="class-grid" id="classGrid"></div>
            </div>
        </div>
    </div>

    <!-- ── Chat Screen ────────────────────────────────────────────── -->
    <div id="chatScreen" class="chat-screen" style="display:none;">
        <header class="chat-header">
            <div class="header-left">
                <button class="btn-back" id="backBtn" title="Back to start">←</button>
                <div class="header-brand">
                    <span class="brand-icon">🧮</span>
                    <div>
                        <span class="brand-name">Mathaí</span>
                        <span class="brand-level" id="headerLevel"></span>
                    </div>
                </div>
            </div>
            <div class="header-right">
                <button class="btn-topics" id="topicsBtn" title="Browse topics">📖 Topics</button>
                <button class="btn-new-chat" id="newChatBtn" title="New conversation">+ New Chat</button>
            </div>
        </header>

        <main class="chat-main" id="chatMain">
            <!-- Quick topic buttons -->
            <div class="quick-topics" id="quickTopics"></div>

            <!-- Messages appear here -->
            <div class="messages" id="messages"></div>
        </main>

        <div class="chat-input-area">
            <div class="input-row">
                <textarea id="chatInput" placeholder="Ask me anything about maths..." rows="1"></textarea>
                <button class="btn-send" id="sendBtn" title="Send">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
                </button>
            </div>
            <div class="input-hint">
                Mathaí follows the Irish curriculum. Answers may not always be perfect — always check with your teacher!
            </div>
        </div>

        <!-- Topics sidebar -->
        <div class="topics-sidebar" id="topicsSidebar">
            <div class="sidebar-header">
                <h3>📖 Browse Topics</h3>
                <button class="sidebar-close" id="sidebarClose">&times;</button>
            </div>
            <div class="sidebar-content" id="sidebarContent"></div>
        </div>
    </div>

    <script>

(async function() {

    var overlay = document.getElementById('pinOverlay');

    var stored = localStorage.getItem('mathai_pin_token');

    if (stored) {

        try {

            var r = await fetch('/api/pin/check', {

                method: 'POST',

                headers: {'Content-Type': 'application/json'},

                body: JSON.stringify({token: stored})

            });

            var d = await r.json();

            if (d.ok) { overlay.style.display = 'none'; return; }

        } catch(e) {}

        localStorage.removeItem('mathai_pin_token');

    }

})();

function checkPin() {

    var pin = document.getElementById('pinInput').value.trim();

    fetch('/api/pin/verify', {

        method: 'POST',

        headers: {'Content-Type': 'application/json'},

        body: JSON.stringify({pin: pin})

    }).then(function(r) { return r.json(); }).then(function(d) {

        if (d.ok) {

            localStorage.setItem('mathai_pin_token', d.token);

            document.getElementById('pinOverlay').style.display = 'none';

        } else {

            document.getElementById('pinError').textContent = 'Incorrect code. Try again.';

            document.getElementById('pinInput').value = '';

            document.getElementById('pinInput').focus();

        }

    }).catch(function() {

        document.getElementById('pinError').textContent = 'Connection error. Try again.';

    });

}

document.getElementById('pinInput').addEventListener('keydown', function(e) {

    if (e.key === 'Enter') checkPin();

});

</script>
<script src="/static/app.js"></script>
</body>
</html>