"; const C = { primary: "#1a1a2e", secondary: "#16213e", card: "#0f3460", accent: "#e94560", gold: "#f5a623", mint: "#00d2a0", text: "#e8e8f0", muted: "#9090b0", }; const SYSTEM_PROMPT = `You are SmartRevision AI, a friendly and brilliant study companion on SmartRevision.blog. Your mission is to help students understand ANY topic in the simplest, most relatable way possible. CORE RULES: 1. Always explain in plain everyday language — like talking to a curious 14-year-old. 2. Use analogies, stories, real-life examples and metaphors to make ideas stick. 3. Break complex concepts into small digestible chunks. 4. When given document content, extract the key ideas and explain them simply. 5. Always end with a "Quick Check" — 2 simple quiz questions. 6. Structure every response with: - 🎯 **The Big Idea** (one sentence summary) - 📖 **Breaking It Down** (simple explanation with examples) - 🌍 **Real World Connection** (how this appears in everyday life) - 💡 **Remember This** (one memorable trick or tip) - ✅ **Quick Check** (2 simple questions) At the very end, on its own line, add: IMAGE_PROMPT: [a description of a simple educational diagram that would visually explain this concept]`; const SUBJECTS = [ { icon:"🔬", label:"Science", color:"#00d2a0" }, { icon:"📐", label:"Maths", color:"#f5a623" }, { icon:"📚", label:"Literature", color:"#e94560" }, { icon:"🌍", label:"Geography", color:"#4ecdc4" }, { icon:"⚗️", label:"Chemistry", color:"#a29bfe" }, { icon:"🧬", label:"Biology", color:"#55efc4" }, { icon:"⚡", label:"Physics", color:"#fdcb6e" }, { icon:"📜", label:"History", color:"#e17055" }, ]; const EXAMPLES = [ "Explain photosynthesis like I'm 10 years old", "What is the Pythagorean theorem and when do I use it?", "How did World War 2 start? Simple version please", "What is DNA and why is it important?", ]; // ── helpers ────────────────────────────────────────────────────────────── function Dots() { return ( {[0,1,2].map(i => ( ))} ); } function callAPI(messages, system) { return fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": API_KEY, "anthropic-version": "2023-06-01", "anthropic-dangerous-direct-browser-access": "true", }, body: JSON.stringify({ model: "claude-sonnet-4-20250514", max_tokens: 1200, system: system || SYSTEM_PROMPT, messages, }), }).then(r => r.json()); } // ── ImageGenerator ──────────────────────────────────────────────────────── function ImageGenerator({ prompt }) { const [svg, setSvg] = React.useState(null); const [busy, setBusy] = React.useState(false); const [err, setErr] = React.useState(null); async function generate() { setBusy(true); setErr(null); try { const data = await callAPI([{ role:"user", content:`Create a simple clean SVG diagram (600×400 viewBox, dark bg #1a1a2e, bright colours, clear labels and arrows) that visually explains: "${prompt}". Return ONLY raw SVG starting with .` }], null); const raw = data.content?.[0]?.text?.trim() ?? ""; const start = raw.indexOf("") + 6; if (start !== -1 && end > start) { setSvg(raw.slice(start, end)); } else { setErr("Could not render a visual — try asking a more specific question."); } } catch { setErr("Network error. Check your API key or connection."); } setBusy(false); } return (

🎨 Visual Aid — generate a diagram for this topic

{!svg && ( )} {err &&

{err}

} {svg && (
)}
); } // ── MessageBubble ───────────────────────────────────────────────────────── function MessageBubble({ msg }) { const isUser = msg.role === "user"; const parts = (msg.content || "").split(/IMAGE_PROMPT:\s*/); const text = parts[0].trim(); const imgP = parts[1]?.trim(); function renderText(t) { return t.split("\n").map((line, i) => { const html = line .replace(/\*\*(.*?)\*\*/g, "$1") .replace(/^(#{1,3})\s(.+)/, (_,h,c) => `${c}`); return

; }); } return (

{!isUser && (
🎓
)}
{msg.loading ?
Thinking…
: renderText(text) }
{imgP && !msg.loading && }
); } // ── Main App ────────────────────────────────────────────────────────────── function App() { const [view, setView] = React.useState("home"); const [messages, setMessages] = React.useState([]); const [input, setInput] = React.useState(""); const [loading, setLoading] = React.useState(false); const [docText, setDocText] = React.useState(""); const [docName, setDocName] = React.useState(""); const fileRef = React.useRef(); const bottomRef = React.useRef(); const taRef = React.useRef(); function scrollDown() { setTimeout(() => bottomRef.current?.scrollIntoView({behavior:"smooth"}), 80); } // auto-resize textarea function handleInput(e) { setInput(e.target.value); const ta = taRef.current; if (ta) { ta.style.height="auto"; ta.style.height = Math.min(ta.scrollHeight,120)+"px"; } } async function handleFile(file) { if (!file) return; setDocName(file.name); if (file.type==="text/plain" || file.name.endsWith(".md") || file.name.endsWith(".txt")) { const t = await file.text(); setDocText(t.slice(0,8000)); } else { // PDF / DOC — we can't parse binary on bare HTML, so we flag it setDocText(`[File uploaded: ${file.name}] — Please ask me questions and I will help you study this topic based on your questions.`); } setView("chat"); } async function send(override) { const text = (override || input).trim(); if (!text || loading) return; setInput(""); if (taRef.current) taRef.current.style.height = "auto"; setView("chat"); const userMsg = { role:"user", content: text }; const apiContent = docText ? `Document uploaded ("${docName}"):\n\n${docText}\n\n---\nStudent question: ${text}` : text; const history = [...messages, userMsg]; setMessages([...history, { role:"assistant", content:"", loading:true }]); scrollDown(); setLoading(true); const apiMessages = history.map((m, i) => (i === history.length-1 && docText) ? { role:"user", content: apiContent } : { role: m.role, content: m.content } ); try { const data = await callAPI(apiMessages); const reply = data.content?.[0]?.text || "Sorry, I couldn't get a response. Please try again."; setMessages([...history, { role:"assistant", content: reply }]); } catch { setMessages([...history, { role:"assistant", content:"⚠️ Error connecting to AI. Check your API key in the HTML file." }]); } setLoading(false); scrollDown(); } function reset() { setMessages([]); setDocText(""); setDocName(""); setView("home"); } function startSubject(s) { setView("chat"); setTimeout(() => send(`I want to study ${s.label}. Give me a simple overview of the most important topics I should know.`), 50); } // ── Header ── const Header = () => (
{docName && (
📄 {docName}
)}
handleFile(e.target.files[0])}/>
); // ── Input bar ── const InputBar = () => (
{docName && view==="chat" && (

📄 Using: {docName}

)}