Real Caffeine Calculator applies pharmacokinetic exponential decay math to give users a real-time view of caffeine in their bloodstream. Users log any combination of drinks from a 30+ item database spanning Starbucks, energy drinks, teas, and custom entries, then the tool calculates current mg, projects a 24-hour SVG decay chart with color-coded risk zones, and computes the latest safe caffeine cut-off time before bed. Metabolism is fully adjustable for five profiles (normal, fast, slow, pregnant, smoker) driven by CYP1A2 half-life data from NIH research. Built with Astro 6 as a fully static site, styled with Tailwind CSS v4, written in TypeScript and vanilla JS, and deployed on Cloudflare Workers Assets — no server, no account, no data ever leaves the browser.

The core input panel lets users log one or more drinks consumed at any time of day. Each row has a drink selector (grouped by category as optgroups), a time picker that auto-fills the current time, and a remove button. A custom "enter mg" option is available for unlisted drinks.
The drink database includes 30+ real-world entries: 12 coffee drinks (including Starbucks sizes, Death Wish, cold brew), 12 energy drinks (Bang 300mg, Reign 300mg, Monster, Celsius, Red Bull in three sizes), teas, sodas, and a freeform custom entry. All drinks use size-specific names and fixed mg values for accuracy.

The outputs card shows a large hero number for current mg in system, a status badge that reads "Log a drink to start / Safe to sleep / Cutting it close / Too much for sleep," and a "You can have caffeine until" hero timestamp that dynamically inverts from the bedtime to find the latest safe intake window.
Below the chart, three stat rows show: when caffeine clears below 50mg ("caffeine clears at"), sleep disruption risk badge with mg-at-bedtime ("Low impact / Moderate impact / High impact"), and optional mg/kg load. A red warning banner appears when total intake exceeds the FDA's 400mg daily limit.

An inline SVG chart renders a 24-hour caffeine decay curve starting from the first drink. It samples 240 data points and draws a blue polyline with a gradient fill underneath. Three background color bands show safe (<50mg, green), moderate (50–150mg, amber), and high (>150mg, red) zones.
Vertical dashed markers for "now" (white) and "bedtime" (purple) are plotted on the chart. A dot with a white center marks the current position on the curve. The chart re-renders on every calculation tick and whenever the theme changes (dark/light mode), swapping axis and grid colors accordingly.

A structured editorial section below the calculator explains the science in six headed paragraphs: what caffeine half-life is, how CYP1A2 genetics affect clearance, how the calculator formula works, why timing matters for sleep (citing Drake et al. 2013 JCSM), FDA daily limits, and a comparison of caffeine content across popular drink brands.

A five-question accordion FAQ uses native HTML <details>/<summary> elements for no-JS expand/collapse. Each question also maps to a FAQPage schema.org JSON-LD block injected into <head> for rich result eligibility in Google Search.

A numbered citation list beneath the FAQ links to the five authoritative sources the calculator's science is based on: NIH StatPearls on caffeine half-life range, FDA consumer guidance on the 400mg limit, Drake et al. 2013 in the Journal of Clinical Sleep Medicine, AASM sleep timing recommendations, and USDA FoodData Central for drink caffeine content.

The site ships dark-first. A sun/moon icon button in the sticky header toggles a `.light` class on <html>, which overrides all CSS custom properties. Theme preference is persisted to localStorage. An inline script in <head> applies the class before first paint, preventing any flash of unstyled content (FOUC).
The calculator's SVG chart listens for a custom `theme-change` DOM event dispatched on toggle and re-renders with the correct axis/grid colors for the active theme.

The sticky header collapses to a hamburger menu on screens narrower than 640px. Clicking the hamburger reveals a dropdown nav with all three links. The hamburger icon swaps to an X when open. Clicking outside the header or any nav link closes the menu.

A single-column editorial page explains what the tool is, how it works, and who it's for. A "Key facts" card lists five bullet points about the science and privacy model in a styled dark card with checkmarks.

A clean contact form with Name, Email, Subject, and Message fields submits via the Formspree API using `fetch` with `FormData`. On success, the form resets and shows a green confirmation message. On failure, a red error message appears. The submit button shows "Sending…" while in-flight and "Sent" on success.
