Flashcards

A flashcard study session on a skewed pile with the next two cards peeking behind: tap a card and it turns over in 3D with its face swapping at 90 degrees, drag it right for Know it or left for Still learning with a tilt, an edge glow and a label tab in the matching colour, then let go to fling it out or spring it back short of the line. The answer buttons fill as you drag towards them and throw the card the same way, the counters roll and fill from the outside in, undo flies the last card back, shuffle fans the pile out and deals a new order, and the deck ends on a summary ring that draws known against learning, with time spent, a review of only the missed cards and a restart.

flashcardsstudylanguage learningspaced repetitionswipeflipanimationreanimated
Paste into Claude Code Cursor Codex Lovable RapidNative
Live preview · follows the site themeOpen full screen

Details

File
components/patterns/flashcards.tsx
Lines
1401
Stack
React Native, StyleSheet
Packages
expo-linear-gradient, lucide-react-native, react-native-reanimated, react-native-safe-area-context, react-native-svg, react-native-worklets
Platforms
iOS, Android, Web

Using gluestack-ui?

Optional. The screen is plain React Native; these components can stand in for its primitives.

components/patterns/flashcards.tsx
1import { useEffect, useRef, useState, type ReactNode } from 'react';
2import {
3 PanResponder,
4 Platform,
5 Pressable,
6 ScrollView,
7 StyleSheet,
8 Text,
9 View,
10 useColorScheme,
11 useWindowDimensions,
12 type GestureResponderEvent,
13 type LayoutChangeEvent,
14 type PanResponderGestureState,
15 type StyleProp,
16 type TextStyle,
17 type ViewStyle,
18} from 'react-native';
19import Animated, {
20 cancelAnimation,
21 Easing,
22 FadeIn,
23 FadeInDown,
24 FadeOut,
25 interpolate,
26 useAnimatedProps,
27 useAnimatedStyle,
28 useDerivedValue,
29 useSharedValue,
30 withDelay,
31 withRepeat,
32 withSequence,
33 withSpring,
34 withTiming,
35 type SharedValue,
36} from 'react-native-reanimated';
37import { LinearGradient } from 'expo-linear-gradient';
38import { useSafeAreaInsets } from 'react-native-safe-area-context';
39import Svg, { Circle } from 'react-native-svg';
40import {
41 ArrowLeft,
42 ArrowRight,
43 Check,
44 Clock,
45 Coffee,
46 Flame,
47 Layers,
48 Lightbulb,
49 MapPin,
50 MessageCircle,
51 RotateCcw,
52 RotateCw,
53 Shuffle,
54 ShoppingBag,
55 Timer,
56 Undo2,
57 Volume2,
58 X,
59} from 'lucide-react-native';
60
61// ─── Brand ──────────────────────────────────────────────────────────────────
62// The study app's accent and name. Every accent colour below derives from these, so changing them rebrands the screen.
63// "Know it" green and "Still learning" coral mean something on their own, so they stay literal.
64
65const ACCENT = '#C99A2E';
66const ACCENT_DARK = '#DCAF47'; // the accent on dark backgrounds
67const ON_ACCENT = '#1C1405'; // text and icons on an accent fill
68const APP_NAME = 'Margin';
69
70/** `hex` at `alpha` opacity, as rgba(). */
71function tint(hex: string, alpha: number) {
72 const n = parseInt(hex.slice(1), 16);
73 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
74}
75
76/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */
77function shade(hex: string, amount: number) {
78 const n = parseInt(hex.slice(1), 16);
79 const target = amount < 0 ? 255 : 0;
80 const p = Math.abs(amount);
81 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');
82 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();
83}
84
85/** `hex` with its hue turned by `deg` degrees and its HSL lightness and saturation moved by `light` / `sat` (-1 to 1).
86 * For accent-related colours of a different hue (an amber-to-coral gradient from one accent). */
87function spin(hex: string, deg: number, light = 0, sat = 0) {
88 const n = parseInt(hex.slice(1), 16);
89 const r = ((n >> 16) & 255) / 255;
90 const g = ((n >> 8) & 255) / 255;
91 const b = (n & 255) / 255;
92 const max = Math.max(r, g, b);
93 const min = Math.min(r, g, b);
94 const d = max - min;
95 const s = Math.min(1, Math.max(0, (d === 0 ? 0 : d / (1 - Math.abs(max + min - 1))) + sat));
96 const l = Math.min(1, Math.max(0, (max + min) / 2 + light));
97 const h0 = d === 0 ? 0 : max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
98 const h = (((h0 * 60 + deg) % 360) + 360) % 360;
99 const a = s * Math.min(l, 1 - l);
100 const f = (m: number) => {
101 const k = (m + h / 30) % 12;
102 return Math.round(255 * (l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)))).toString(16).padStart(2, '0');
103 };
104 return `#${f(0)}${f(8)}${f(4)}`.toUpperCase();
105}
106
107/** `hex` with its hue turned by `deg` and saturation moved by `sat`, at an exact HSL `lightness` (0 to 1).
108 * For surfaces that must stay as dark or as pale as designed whatever the accent: dark-theme backdrops, pale washes,
109 * cards on them and the ink that sits on them. */
110function tone(hex: string, deg: number, lightness: number, sat = 0) {
111 const n = parseInt(hex.slice(1), 16);
112 const r = (n >> 16) & 255; const g = (n >> 8) & 255; const b = n & 255;
113 return spin(hex, deg, lightness - (Math.max(r, g, b) + Math.min(r, g, b)) / 510, sat);
114}
115
116// ─── Sample data ────────────────────────────────────────────────────────────
117
118const DECK = { title: 'Paris on foot', language: 'French', kind: 'travel phrases' };
119
120type Result = 'know' | 'learn';
121type Topic = 'around' | 'cafe' | 'shop' | 'talk';
122
123const TOPICS: Record<Topic, { label: string; Icon: typeof MapPin }> = {
124 around: { label: 'Getting around', Icon: MapPin },
125 cafe: { label: 'Café and table', Icon: Coffee },
126 shop: { label: 'Shopping', Icon: ShoppingBag },
127 talk: { label: 'Small talk', Icon: MessageCircle },
128};
129
130// `past` is how the card went in earlier sessions, oldest first.
131type Card = { id: string; term: string; hint: string; meaning: string; say: string; example: string; exampleEn: string; topic: Topic; past: Result[] };
132
133// French sets a space before ? and !; a non-breaking one keeps the mark on the same line.
134const CARDS: Card[] = [
135 { id: 'billet', term: 'Je voudrais un billet', hint: 'billet = ticket', meaning: 'I would like a ticket', say: 'zhuh voo-DREH uhn bee-YEH', example: 'Je voudrais un billet pour Lyon, s’il vous plaît.', exampleEn: 'I’d like a ticket to Lyon, please.', topic: 'around', past: ['learn', 'know', 'know'] },
136 { id: 'table', term: 'Une table pour deux', hint: 'deux = two', meaning: 'A table for two', say: 'oon TAH-bluh poor DUH', example: 'Bonsoir, une table pour deux, s’il vous plaît.', exampleEn: 'Good evening, a table for two, please.', topic: 'cafe', past: ['know', 'know'] },
137 { id: 'combien', term: 'C’est combien\u00A0?', hint: 'You ask it at a market stall', meaning: 'How much is it?', say: 'seh kohm-BYAN', example: 'Ce fromage, c’est combien\u00A0?', exampleEn: 'How much is this cheese?', topic: 'shop', past: ['learn', 'learn', 'know'] },
138 { id: 'creme', term: 'Un café crème', hint: 'crème = cream', meaning: 'A coffee with milk', say: 'uhn kah-FAY KREM', example: 'Un café crème et un croissant, merci.', exampleEn: 'A coffee with milk and a croissant, thanks.', topic: 'cafe', past: ['know', 'know', 'know'] },
139 { id: 'comprends', term: 'Je ne comprends pas', hint: 'ne … pas wraps the verb to say “not”', meaning: 'I don’t understand', say: 'zhuh nuh kohm-PRAHN pah', example: 'Désolé, je ne comprends pas. Plus lentement\u00A0?', exampleEn: 'Sorry, I don’t understand. More slowly?', topic: 'talk', past: ['learn', 'know'] },
140 { id: 'gare', term: 'Où est la gare\u00A0?', hint: 'gare = station', meaning: 'Where is the train station?', say: 'oo eh lah GAHR', example: 'Pardon, où est la gare, s’il vous plaît\u00A0?', exampleEn: 'Excuse me, where is the train station, please?', topic: 'around', past: ['learn', 'know', 'learn'] },
141 { id: 'addition', term: 'L’addition, s’il vous plaît', hint: 'You ask for it when the meal is over', meaning: 'The bill, please', say: 'lah-dee-SYOHN, seel voo PLEH', example: 'C’était délicieux. L’addition, s’il vous plaît\u00A0!', exampleEn: 'That was delicious. The bill, please!', topic: 'cafe', past: ['know', 'learn'] },
142 { id: 'perdu', term: 'Je suis perdu', hint: 'perdu = lost', meaning: 'I’m lost', say: 'zhuh swee pehr-DOO', example: 'Je suis perdu. Vous pouvez m’aider\u00A0?', exampleEn: 'I’m lost. Can you help me?', topic: 'around', past: ['learn'] },
143 { id: 'heure', term: 'À quelle heure\u00A0?', hint: 'heure = hour', meaning: 'At what time?', say: 'ah kel UHR', example: 'Le musée ferme à quelle heure\u00A0?', exampleEn: 'What time does the museum close?', topic: 'talk', past: ['know', 'learn', 'know'] },
144 { id: 'taille', term: 'Vous avez ma taille\u00A0?', hint: 'taille = size', meaning: 'Do you have my size?', say: 'voo zah-VAY mah TIE', example: 'J’aime cette veste. Vous avez ma taille\u00A0?', exampleEn: 'I like this jacket. Do you have my size?', topic: 'shop', past: [] },
145 { id: 'beau', term: 'Il fait beau', hint: 'beau = fine, lovely', meaning: 'The weather is nice', say: 'eel feh BOH', example: 'Il fait beau, on mange en terrasse\u00A0?', exampleEn: 'It’s nice out, shall we eat outside?', topic: 'talk', past: ['know'] },
146 { id: 'later', term: 'À tout à l’heure', hint: 'You will see them again today', meaning: 'See you later', say: 'ah too tah LUHR', example: 'Je reviens vite. À tout à l’heure\u00A0!', exampleEn: 'I’ll be right back. See you later!', topic: 'talk', past: ['learn', 'learn'] },
147];
148const CARD_BY_ID: Record<string, Card> = Object.fromEntries(CARDS.map((card) => [card.id, card]));
149
150// The session opens five cards in, as if the warm-up is already behind you.
151const HEAD_START: Result[] = ['know', 'know', 'learn', 'know', 'learn'];
152const SECONDS_BEFORE = 156;
153
154// ─── Palette ────────────────────────────────────────────────────────────────
155
156const KNOW = '#2E9E6A';
157const LEARN = '#E2583E';
158const SERIF = Platform.select({ ios: 'Georgia', android: 'serif', default: 'Georgia, "Times New Roman", serif' });
159const COLUMN = 520; // widest the screen gets on tablets and the web
160const SHRINK = 0.055; // how much smaller each card behind is
161const PEEK = 13; // how far each card behind shows above the one in front
162const PEEK_ROOM = 40;
163const FILL = { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 } as const;
164const SETTLE = { damping: 19, stiffness: 190, mass: 0.9 };
165const PRESS = { damping: 16, stiffness: 320, mass: 0.6 };
166const FLIP = { damping: 15, stiffness: 105, mass: 0.9 };
167const WEB_NOSELECT = Platform.OS === 'web' ? ({ userSelect: 'none' } as object) : null;
168const KNOW_EDGE = [tint(KNOW, 0), tint(KNOW, 0.3)] as const;
169const LEARN_EDGE = [tint(LEARN, 0.3), tint(LEARN, 0)] as const;
170
171function usePalette() {
172 const dark = useColorScheme() === 'dark';
173 return {
174 dark,
175 bg: dark ? tone(ACCENT, 0, 0.055, -0.45) : tone(ACCENT, 0, 0.945, -0.22),
176 surface: dark ? tone(ACCENT, 0, 0.1, -0.47) : tone(ACCENT, 0, 0.99, -0.2),
177 card: dark ? tone(ACCENT, 0, 0.13, -0.47) : tone(ACCENT, 0, 0.995, -0.2),
178 cardBack: dark ? tone(ACCENT, 0, 0.115, -0.42) : tone(ACCENT, 0, 0.975, -0.15),
179 example: dark ? tone(ACCENT, 0, 0.155, -0.45) : tone(ACCENT, 0, 0.995, -0.2),
180 fg: dark ? tone(ACCENT, 0, 0.94, -0.4) : tone(ACCENT, 0, 0.11, -0.4),
181 muted: dark ? tone(ACCENT, 0, 0.62, -0.5) : tone(ACCENT, 0, 0.4, -0.5),
182 faint: dark ? tone(ACCENT, 0, 0.38, -0.5) : tone(ACCENT, 0, 0.66, -0.45),
183 line: dark ? tone(ACCENT, 0, 0.21, -0.45) : tone(ACCENT, 0, 0.87, -0.32),
184 track: dark ? tone(ACCENT, 0, 0.18, -0.45) : tone(ACCENT, 0, 0.87, -0.3),
185 rule: dark ? tint(ACCENT_DARK, 0.08) : tint(ACCENT, 0.12),
186 accent: dark ? ACCENT_DARK : ACCENT,
187 accentText: dark ? ACCENT_DARK : shade(ACCENT, 0.34),
188 accentSoft: dark ? tint(ACCENT_DARK, 0.14) : tint(ACCENT, 0.14),
189 accentLine: dark ? tint(ACCENT_DARK, 0.45) : tint(ACCENT, 0.55),
190 knowText: dark ? '#56D69A' : '#1D7A4F',
191 knowSoft: dark ? tint(KNOW, 0.2) : tint(KNOW, 0.13),
192 knowLine: dark ? tint(KNOW, 0.42) : tint(KNOW, 0.32),
193 learnText: dark ? '#FF8E74' : '#BF3E27',
194 learnSoft: dark ? tint(LEARN, 0.2) : tint(LEARN, 0.12),
195 learnLine: dark ? tint(LEARN, 0.42) : tint(LEARN, 0.32),
196 veil: dark ? '#000000' : tone(ACCENT, 0, 0.3, -0.5),
197 veilMax: dark ? 0.12 : 0.05,
198 sheen: dark ? (['rgba(255,255,255,0.05)', 'rgba(255,255,255,0)'] as const) : ([tint(ACCENT, 0), tint(ACCENT, 0.045)] as const),
199 scrim: dark ? 'rgba(0,0,0,0.62)' : 'rgba(34,28,14,0.4)',
200 };
201}
202type Palette = ReturnType<typeof usePalette>;
203
204// ─── Helpers ────────────────────────────────────────────────────────────────
205
206const pad2 = (n: number) => String(n).padStart(2, '0');
207const clock = (s: number) => `${Math.floor(s / 60)}:${pad2(Math.round(s) % 60)}`;
208const clamp01 = (v: number) => {
209 'worklet';
210 return Math.max(0, Math.min(1, v));
211};
212
213/** The example sentence split around the phrase, so the phrase can be set in the accent. */
214function splitExample(card: Card): [string, string, string] {
215 const phrase = card.term.replace(/[\s\u00A0]*[?!]$/, '');
216 const at = card.example.toLowerCase().indexOf(phrase.toLowerCase());
217 if (at < 0) return [card.example, '', ''];
218 return [card.example.slice(0, at), card.example.slice(at, at + phrase.length), card.example.slice(at + phrase.length)];
219}
220
221/** The cards left, in a new order that never keeps the same card on top. */
222function mix(ids: string[]) {
223 const next = [...ids];
224 for (let i = next.length - 1; i > 0; i--) {
225 const j = Math.floor(Math.random() * (i + 1));
226 [next[i], next[j]] = [next[j], next[i]];
227 }
228 if (next.length > 1 && next[0] === ids[0]) [next[0], next[1]] = [next[1], next[0]];
229 return next;
230}
231
232function longestRun(results: Result[]) {
233 let best = 0;
234 let run = 0;
235 for (const r of results) {
236 run = r === 'know' ? run + 1 : 0;
237 best = Math.max(best, run);
238 }
239 return best;
240}
241
242// ─── Small pieces ───────────────────────────────────────────────────────────
243
244function Tap({ label, onPress, style, flex, to = 0.92, children }: { label: string; onPress?: () => void; style?: StyleProp<ViewStyle>; flex?: boolean; to?: number; children: ReactNode }) {
245 const s = useSharedValue(1);
246 const press = useAnimatedStyle(() => ({ transform: [{ scale: s.value }] }));
247 return (
248 <Pressable
249 role="button"
250 aria-label={label}
251 onPress={onPress}
252 onPressIn={() => (s.value = withSpring(to, PRESS))}
253 onPressOut={() => (s.value = withSpring(1, PRESS))}
254 style={flex ? styles.flex : null}
255 >
256 <Animated.View style={[style, press]}>{children}</Animated.View>
257 </Pressable>
258 );
259}
260
261/** A number that rolls: the old value slides out as the new one slides in, up when counting up, down on undo. */
262function Ticker({ value, style }: { value: number; style: StyleProp<TextStyle> }) {
263 const [shown, setShown] = useState({ now: value, was: value });
264 const t = useSharedValue(1);
265 const dir = useSharedValue(1);
266 useEffect(() => {
267 if (value === shown.now) return;
268 dir.value = value > shown.now ? 1 : -1;
269 setShown({ now: value, was: shown.now });
270 t.value = 0;
271 t.value = withTiming(1, { duration: 420, easing: Easing.out(Easing.back(1.7)) });
272 // eslint-disable-next-line react-hooks/exhaustive-deps
273 }, [value]);
274 const enter = useAnimatedStyle(() => ({ opacity: clamp01(t.value * 1.6), transform: [{ translateY: (1 - t.value) * 20 * dir.value }] }));
275 const leave = useAnimatedStyle(() => ({ opacity: clamp01(1 - t.value * 1.6), transform: [{ translateY: -t.value * 20 * dir.value }] }));
276 return (
277 <View style={styles.ticker}>
278 <Animated.Text style={[style, styles.tickerGhost, leave]}>{shown.was}</Animated.Text>
279 <Animated.Text style={[style, enter]}>{shown.now}</Animated.Text>
280 </View>
281 );
282}
283
284// ─── Header: one segment per card, coloured by how it went ──────────────────
285
286type SegState = 'know' | 'learn' | 'now' | 'todo';
287
288function Segment({ state, w, delay, c }: { state: SegState; w: number; delay: number; c: Palette }) {
289 const done = useSharedValue(0);
290 const now = useSharedValue(0);
291 const first = useRef(true);
292 // The result colour stays put while it slides away on undo.
293 const [color, setColor] = useState(state === 'learn' ? LEARN : KNOW);
294 useEffect(() => {
295 if (state === 'know' || state === 'learn') setColor(state === 'know' ? KNOW : LEARN);
296 const wait = first.current ? delay : state === 'now' ? 240 : 0;
297 first.current = false;
298 done.value = withDelay(wait, withTiming(state === 'know' || state === 'learn' ? 1 : 0, { duration: 420, easing: Easing.out(Easing.cubic) }));
299 now.value = withDelay(wait, withTiming(state === 'now' ? 1 : 0, { duration: 260 }));
300 // eslint-disable-next-line react-hooks/exhaustive-deps
301 }, [state]);
302 const fill = useAnimatedStyle(() => ({ transform: [{ translateX: (done.value - 1) * (w + 2) }] }));
303 const current = useAnimatedStyle(() => ({ opacity: now.value, transform: [{ scaleY: 0.6 + now.value * 0.4 }] }));
304 return (
305 <View style={[styles.segment, { backgroundColor: c.track }]}>
306 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: c.accent }, current]} />
307 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: color }, fill]} />
308 </View>
309 );
310}
311
312function Progress({ results, total, c }: { results: Result[]; total: number; c: Palette }) {
313 const [w, setW] = useState(0);
314 const segW = w ? (w - (total - 1) * 4) / total : 0;
315 return (
316 <View
317 role="progressbar"
318 aria-label={`${Math.min(results.length, total)} of ${total} cards studied`}
319 style={styles.progress}
320 onLayout={(e: LayoutChangeEvent) => setW(e.nativeEvent.layout.width)}
321 >
322 {Array.from({ length: total }, (_, k) => (
323 <Segment key={`${total}-${k}`} state={results[k] ?? (k === results.length ? 'now' : 'todo')} w={segW} delay={260 + k * 45} c={c} />
324 ))}
325 </View>
326 );
327}
328
329// ─── Counters: they fill from the outside in and lean towards a drag ────────
330
331function Counter({ kind, value, total, lean, c }: { kind: Result; value: number; total: number; lean: SharedValue<number>; c: Palette }) {
332 const know = kind === 'know';
333 const label = know ? 'Know it' : 'Still learning';
334 const Icon = know ? Check : X;
335 const [w, setW] = useState(0);
336 const fill = useSharedValue(0);
337 const bump = useSharedValue(0);
338 const last = useRef(value);
339 useEffect(() => {
340 fill.value = withSpring(total ? value / total : 0, { damping: 18, stiffness: 120 });
341 if (value > last.current) bump.value = withSequence(withTiming(1, { duration: 120 }), withTiming(0, { duration: 420, easing: Easing.out(Easing.quad) }));
342 last.current = value;
343 }, [value, total, fill, bump]);
344 const pill = useAnimatedStyle(() => ({ transform: [{ scale: 1 + clamp01(lean.value) * 0.05 + bump.value * 0.05 }] }));
345 const ring = useAnimatedStyle(() => ({ opacity: Math.max(bump.value, clamp01(lean.value)) }));
346 const bar = useAnimatedStyle(() => ({ width: fill.value * w, opacity: fill.value > 0.002 ? 1 : 0 }));
347 return (
348 <Animated.View
349 aria-label={`${label}: ${value} of ${total}`}
350 onLayout={(e: LayoutChangeEvent) => setW(e.nativeEvent.layout.width)}
351 style={[styles.counter, { backgroundColor: c.surface, borderColor: c.line }, pill]}
352 >
353 <Animated.View style={[styles.counterFill, know ? styles.fillFromRight : styles.fillFromLeft, { backgroundColor: know ? c.knowSoft : c.learnSoft, borderColor: know ? c.knowLine : c.learnLine }, bar]} />
354 <Animated.View pointerEvents="none" style={[styles.counterRing, { borderColor: know ? KNOW : LEARN }, ring]} />
355 <View style={[styles.counterRow, know && styles.rowReverse]}>
356 {/* On narrow phones the label keeps the room and the icon steps aside. */}
357 {w >= 166 && (
358 <View style={[styles.counterIcon, { backgroundColor: know ? KNOW : LEARN }]}>
359 <Icon size={12} color="#FFFFFF" strokeWidth={3.4} />
360 </View>
361 )}
362 <Text numberOfLines={1} style={[styles.counterLabel, { color: c.fg }]}>
363 {label}
364 </Text>
365 <View style={styles.flex} />
366 <Ticker value={value} style={[styles.counterNum, { color: know ? c.knowText : c.learnText }]} />
367 </View>
368 </Animated.View>
369 );
370}
371
372// ─── Card faces ─────────────────────────────────────────────────────────────
373
374/** How the card went in earlier sessions: one dot per session, newest on the right. */
375function History({ past, c }: { past: Result[]; c: Palette }) {
376 if (!past.length) {
377 return (
378 <View style={[styles.newBadge, { borderColor: c.line }]}>
379 <Text style={[styles.newText, { color: c.muted }]}>NEW</Text>
380 </View>
381 );
382 }
383 const missed = past.filter((r) => r === 'learn').length;
384 return (
385 <View style={styles.history} aria-label={`Seen ${past.length} times before, missed ${missed}`}>
386 <Text style={[styles.historyText, { color: c.muted }]}>Seen {past.length}×</Text>
387 <View style={styles.historyDots}>
388 {past.map((r, k) => (
389 <View key={k} style={[styles.historyDot, { backgroundColor: r === 'know' ? KNOW : LEARN }]} />
390 ))}
391 </View>
392 </View>
393 );
394}
395
396function CardFront({ card, width, hint, onHint, c }: { card: Card; width: number; hint: boolean; onHint: () => void; c: Palette }) {
397 const topic = TOPICS[card.topic];
398 // Short phrases stay on one line on narrow cards; longer ones wrap at a smaller size.
399 const size = card.term.length > 22 ? 33 : card.term.length > 16 ? 37 : Math.max(32, Math.min(42, Math.floor((width - 52) / (card.term.length * 0.43))));
400 return (
401 <View style={styles.faceBody}>
402 <View style={styles.faceTop}>
403 <View style={[styles.topic, { backgroundColor: c.accentSoft }]}>
404 <topic.Icon size={13} color={c.accentText} strokeWidth={2.4} />
405 <Text style={[styles.topicText, { color: c.accentText }]}>{topic.label}</Text>
406 </View>
407 <History past={card.past} c={c} />
408 </View>
409 <View style={[styles.frontRule, { backgroundColor: c.accentLine }]} />
410
411 <View style={styles.frontMid}>
412 <Text style={[styles.lang, { color: c.muted }]}>{DECK.language.toUpperCase()}</Text>
413 <Text style={[styles.term, { color: c.fg, fontFamily: SERIF, fontSize: size, lineHeight: Math.round(size * 1.18) }]}>{card.term}</Text>
414 <View style={[styles.dash, { backgroundColor: c.accent }]} />
415 <Pressable
416 role="button"
417 aria-label={hint ? 'Hide hint' : 'Show hint'}
418 aria-expanded={hint}
419 onPress={onHint}
420 style={({ pressed }) => [styles.hintPill, { borderColor: hint ? c.accentLine : c.line, backgroundColor: hint ? c.accentSoft : c.card }, pressed && styles.pressed]}
421 >
422 <Lightbulb size={14} color={c.accentText} fill={hint ? c.accentText : 'transparent'} strokeWidth={2.2} />
423 <Text style={[styles.hintLabel, { color: c.accentText }]}>{hint ? 'Hide hint' : 'Hint'}</Text>
424 </Pressable>
425 <View style={styles.hintSlot}>
426 {hint && (
427 <Animated.Text entering={FadeInDown.duration(260)} style={[styles.hintText, { color: c.muted }]}>
428 {card.hint}
429 </Animated.Text>
430 )}
431 </View>
432 </View>
433
434 <View style={styles.frontFoot}>
435 <RotateCw size={13} color={c.faint} strokeWidth={2.4} />
436 <Text style={[styles.footText, { color: c.muted }]}>Tap to flip</Text>
437 </View>
438 </View>
439 );
440}
441
442function Bar({ k, playing, color }: { k: number; playing: boolean; color: string }) {
443 const v = useSharedValue(0);
444 useEffect(() => {
445 if (playing) {
446 v.value = withDelay(k * 80, withRepeat(withSequence(withTiming(1, { duration: 200 + k * 50 }), withTiming(0.25, { duration: 240 + k * 30 })), -1, false));
447 } else {
448 cancelAnimation(v);
449 v.value = withTiming(0, { duration: 200 });
450 }
451 }, [playing, k, v]);
452 const style = useAnimatedStyle(() => ({ height: 4 + v.value * 14, opacity: 0.35 + v.value * 0.65 }));
453 return <Animated.View style={[styles.bar, { backgroundColor: color }, style]} />;
454}
455
456const RULES = [0, 1, 2, 3, 4, 5, 6, 7, 8];
457const LINE = 34; // ruled line spacing, also the meaning's line height
458const LINE_TOP = 12;
459
460function CardBack({ card, number, total, c }: { card: Card; number: number; total: number; c: Palette }) {
461 const [playing, setPlaying] = useState(false);
462 const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
463 useEffect(() => () => void (timer.current && clearTimeout(timer.current)), []);
464 // Replace with your audio clip; the bars dance for about as long as the phrase takes to say.
465 const play = () => {
466 if (timer.current) clearTimeout(timer.current);
467 setPlaying(true);
468 timer.current = setTimeout(() => setPlaying(false), 1700);
469 };
470 const [before, match, after] = splitExample(card);
471 return (
472 <View style={styles.faceBody}>
473 <View style={styles.faceTop}>
474 <Text style={[styles.eyebrow, { color: c.accentText }]}>MEANING</Text>
475 <Text style={[styles.cardNo, { color: c.muted }]}>
476 {pad2(number)} <Text style={{ color: c.faint }}>/ {pad2(total)}</Text>
477 </Text>
478 </View>
479 <View style={[styles.backRule, { backgroundColor: c.accentLine }]} />
480 {/* Ruled like an index card: the meaning and the pronunciation sit on the lines. */}
481 <View style={styles.lined}>
482 <View pointerEvents="none" style={styles.rules}>
483 {RULES.map((k) => (
484 <View key={k} style={[styles.ruleLine, { top: LINE_TOP + (k + 1) * LINE - 1, backgroundColor: c.rule }]} />
485 ))}
486 </View>
487 <Text style={[styles.meaning, { color: c.fg }]}>{card.meaning}</Text>
488 <View style={styles.sayRow}>
489 <Pressable
490 role="button"
491 aria-label={`Hear “${card.term}”`}
492 onPress={play}
493 style={({ pressed }) => [styles.sayButton, { backgroundColor: playing ? c.accent : c.accentSoft }, pressed && styles.pressed]}
494 >
495 <Volume2 size={15} color={playing ? ON_ACCENT : c.accentText} strokeWidth={2.3} />
496 </Pressable>
497 <Text style={[styles.say, { color: c.fg }]}>/ {card.say} /</Text>
498 <View style={styles.bars}>
499 {[0, 1, 2, 3].map((k) => (
500 <Bar key={k} k={k} playing={playing} color={c.accentText} />
501 ))}
502 </View>
503 </View>
504 </View>
505
506 <View style={[styles.example, { backgroundColor: c.example, borderColor: c.line }]}>
507 <Text style={[styles.eyebrow, { color: c.muted }]}>IN A SENTENCE</Text>
508 <Text style={[styles.exampleText, { color: c.fg, fontFamily: SERIF }]}>
509 {before}
510 <Text style={[styles.exampleMatch, { color: c.accentText }]}>{match}</Text>
511 {after}
512 </Text>
513 <Text style={[styles.exampleEn, { color: c.muted }]}>{card.exampleEn}</Text>
514 </View>
515
516 <View style={styles.backFoot}>
517 <View style={styles.backFootSide}>
518 <ArrowLeft size={13} color={c.learnText} strokeWidth={2.6} />
519 <Text style={[styles.backFootText, { color: c.learnText }]}>Still learning</Text>
520 </View>
521 <View style={styles.backFootSide}>
522 <Text style={[styles.backFootText, { color: c.knowText }]}>Know it</Text>
523 <ArrowRight size={13} color={c.knowText} strokeWidth={2.6} />
524 </View>
525 </View>
526 </View>
527 );
528}
529
530// ─── A card in the stack: tap to flip, drag to sort, flings out ─────────────
531
532type CardProps = {
533 card: Card;
534 i: number;
535 total: number;
536 top: boolean;
537 fate: Result | null;
538 flipped: boolean;
539 pos: SharedValue<number>;
540 dragX: SharedValue<number>;
541 riffle: SharedValue<number>;
542 w: number;
543 h: number;
544 deal: number | null;
545 onFlip: () => void;
546 onSwipe: (r: Result) => void;
547};
548
549function StudyCard({ card, i, total, top, fate, flipped, pos, dragX, riffle, w, h, deal, onFlip, onSwipe }: CardProps) {
550 const c = usePalette();
551 const { width: W } = useWindowDimensions();
552 const limit = w * 0.3;
553 const out = W * 0.6 + w;
554 const x = useSharedValue(fate === 'know' ? out : fate === 'learn' ? -out : 0);
555 const y = useSharedValue(0);
556 const flip = useSharedValue(flipped ? 1 : 0);
557 const enter = useSharedValue(deal === null ? 1 : 0);
558 const flying = useRef<Result | null>(fate);
559 const [hint, setHint] = useState(false);
560
561 // The first cards of a round are dealt onto the table, back to front.
562 useEffect(() => {
563 if (deal !== null) enter.value = withDelay(deal, withSpring(1, { damping: 17, stiffness: 150, mass: 0.9 }));
564 // eslint-disable-next-line react-hooks/exhaustive-deps
565 }, []);
566 useEffect(() => {
567 flip.value = withSpring(flipped ? 1 : 0, FLIP);
568 }, [flipped, flip]);
569 useEffect(() => {
570 if (!top) setHint(false);
571 }, [top]);
572
573 // A fling keeps its own speed. A button press leans the card to its side first, so the colour is seen, then throws it.
574 const fly = (to: Result, vx: number, vy: number) => {
575 flying.current = to;
576 const side = to === 'know' ? 1 : -1;
577 if (vx === 0 && vy === 0) {
578 x.value = withSequence(withTiming(side * limit * 1.05, { duration: 190, easing: Easing.out(Easing.quad) }), withTiming(side * out, { duration: 300, easing: Easing.in(Easing.quad) }));
579 y.value = withSequence(withTiming(-8, { duration: 190 }), withTiming(-46, { duration: 300 }));
580 dragX.value = withSequence(withTiming(side * limit, { duration: 190 }), withTiming(0, { duration: 320 }));
581 return;
582 }
583 const duration = Math.max(180, Math.min(380, (out - Math.abs(x.value)) / Math.max(Math.abs(vx), 1.4)));
584 x.value = withTiming(side * out, { duration, easing: Easing.out(Easing.quad) });
585 y.value = withTiming(y.value + vy * duration * 0.35, { duration });
586 dragX.value = withTiming(0, { duration: 260 });
587 };
588
589 // The buttons and undo change a card's fate from outside; a drag has already started its own flight.
590 useEffect(() => {
591 if (fate && flying.current !== fate) fly(fate, 0, 0);
592 if (!fate && flying.current) {
593 flying.current = null;
594 x.value = withSpring(0, SETTLE);
595 y.value = withSpring(0, SETTLE);
596 }
597 // eslint-disable-next-line react-hooks/exhaustive-deps
598 }, [fate]);
599
600 const live = useRef({ top: false, release: (_g: PanResponderGestureState, _moved: boolean) => {} });
601 live.current.top = top && !fate;
602 live.current.release = (g, moved) => {
603 if (!moved) {
604 onFlip();
605 return;
606 }
607 const know = g.dx > limit || (g.vx > 0.55 && g.dx > 40);
608 const learn = g.dx < -limit || (g.vx < -0.55 && g.dx < -40);
609 if (know || learn) {
610 const to: Result = know ? 'know' : 'learn';
611 fly(to, g.vx, g.vy);
612 onSwipe(to);
613 return;
614 }
615 // Short of the line: it springs back and the card behind settles again.
616 x.value = withSpring(0, SETTLE);
617 y.value = withSpring(0, SETTLE);
618 pos.value = withSpring(i, SETTLE);
619 dragX.value = withSpring(0, SETTLE);
620 };
621 const moved = useRef(false);
622 const pan = useRef(
623 PanResponder.create({
624 onStartShouldSetPanResponder: () => live.current.top,
625 onMoveShouldSetPanResponder: (_e: GestureResponderEvent, g: PanResponderGestureState) => live.current.top && Math.abs(g.dx) + Math.abs(g.dy) > 4,
626 onPanResponderTerminationRequest: () => false,
627 onPanResponderGrant: () => {
628 moved.current = false;
629 cancelAnimation(x);
630 cancelAnimation(y);
631 },
632 onPanResponderMove: (_e: GestureResponderEvent, g: PanResponderGestureState) => {
633 if (Math.abs(g.dx) + Math.abs(g.dy) > 6) moved.current = true;
634 x.value = g.dx;
635 y.value = g.dy * 0.3;
636 dragX.value = g.dx;
637 pos.value = i + Math.min(1, Math.abs(g.dx) / (w * 1.1)) * 0.6;
638 },
639 onPanResponderRelease: (_e: GestureResponderEvent, g: PanResponderGestureState) => live.current.release(g, moved.current),
640 onPanResponderTerminate: (_e: GestureResponderEvent, g: PanResponderGestureState) => live.current.release(g, moved.current),
641 })
642 ).current;
643
644 // Cards behind sit smaller and higher with a slight skew, like a real pile, and straighten as they come forward.
645 const veilMax = c.veilMax;
646 const slot = useAnimatedStyle(() => {
647 const depth = Math.max(0, i - pos.value);
648 const d = Math.min(depth, 2);
649 const r = Math.sin(riffle.value * Math.PI);
650 const side = i % 2 === 0 ? -1 : 1;
651 const fan = r * side * (36 + d * 18);
652 const e = enter.value;
653 return {
654 opacity: interpolate(depth, [2, 2.7], [1, 0], 'clamp') * clamp01(e * 1.5),
655 transform: [
656 { translateX: x.value + fan },
657 { translateY: y.value - d * (h * SHRINK * 0.5 + PEEK) - r * 12 + (1 - e) * (h * 0.45 + 90) },
658 { rotate: `${(x.value / w) * 13 + interpolate(d, [0, 1, 2], [0, -2.6, 2.2]) + r * side * 5 + (1 - e) * 7}deg` },
659 { scale: 1 - d * SHRINK },
660 ],
661 };
662 });
663 const veil = useAnimatedStyle(() => ({ opacity: Math.min(2, Math.max(0, i - pos.value)) * veilMax }));
664 const knowGlow = useAnimatedStyle(() => ({ opacity: interpolate(x.value, [8, limit], [0, 1], 'clamp') }));
665 const learnGlow = useAnimatedStyle(() => ({ opacity: interpolate(-x.value, [8, limit], [0, 1], 'clamp') }));
666 const knowTag = useAnimatedStyle(() => {
667 const p = interpolate(x.value, [18, limit], [0, 1], 'clamp');
668 return { opacity: p, transform: [{ translateY: (1 - p) * 12 }, { scale: 0.8 + p * 0.2 }] };
669 });
670 const learnTag = useAnimatedStyle(() => {
671 const p = interpolate(-x.value, [18, limit], [0, 1], 'clamp');
672 return { opacity: p, transform: [{ translateY: (1 - p) * 12 }, { scale: 0.8 + p * 0.2 }] };
673 });
674 // The face swaps at 90 degrees; the card lifts a little at the midpoint of the turn.
675 const front = useAnimatedStyle(() => ({
676 opacity: flip.value < 0.5 ? 1 : 0,
677 transform: [{ perspective: 1100 }, { rotateY: `${flip.value * 180}deg` }, { scale: 1 + Math.sin(clamp01(flip.value) * Math.PI) * 0.04 }],
678 }));
679 const back = useAnimatedStyle(() => ({
680 opacity: flip.value < 0.5 ? 0 : 1,
681 transform: [{ perspective: 1100 }, { rotateY: `${flip.value * 180 - 180}deg` }, { scale: 1 + Math.sin(clamp01(flip.value) * Math.PI) * 0.04 }],
682 }));
683
684 const shadow = c.dark ? styles.faceDark : styles.faceLight;
685 return (
686 <Animated.View
687 role="group"
688 aria-hidden={!top}
689 aria-label={top ? (flipped ? `${card.term}. Means: ${card.meaning}. Tap to flip back` : `${card.term}. Tap to see the meaning`) : undefined}
690 style={[styles.slot, { width: w, height: h }, WEB_NOSELECT, slot]}
691 {...pan.panHandlers}
692 >
693 <Animated.View pointerEvents="none" style={[styles.halo, { backgroundColor: c.card }, styles.haloKnow, knowGlow]} />
694 <Animated.View pointerEvents="none" style={[styles.halo, { backgroundColor: c.card }, styles.haloLearn, learnGlow]} />
695
696 <Animated.View pointerEvents={flipped ? 'none' : 'auto'} style={[styles.face, { backgroundColor: c.card, borderColor: c.line }, shadow, front]}>
697 <View pointerEvents="none" style={styles.faceClip}>
698 <LinearGradient colors={c.sheen} style={StyleSheet.absoluteFill} />
699 </View>
700 <CardFront card={card} width={w} hint={hint} onHint={() => setHint((v) => !v)} c={c} />
701 </Animated.View>
702 <Animated.View pointerEvents={flipped ? 'auto' : 'none'} style={[styles.face, { backgroundColor: c.cardBack, borderColor: c.line }, shadow, back]}>
703 <View pointerEvents="none" style={styles.faceClip}>
704 <LinearGradient colors={c.sheen} style={StyleSheet.absoluteFill} />
705 </View>
706 <CardBack card={card} number={i + 1} total={total} c={c} />
707 </Animated.View>
708
709 {/* Edge glow, ring and veil sit over whichever face is up. */}
710 <View pointerEvents="none" style={styles.edge}>
711 <Animated.View style={[styles.edgeRight, knowGlow]}>
712 <LinearGradient colors={KNOW_EDGE} start={{ x: 0, y: 0.5 }} end={{ x: 1, y: 0.5 }} style={StyleSheet.absoluteFill} />
713 </Animated.View>
714 <Animated.View style={[styles.edgeLeft, learnGlow]}>
715 <LinearGradient colors={LEARN_EDGE} start={{ x: 0, y: 0.5 }} end={{ x: 1, y: 0.5 }} style={StyleSheet.absoluteFill} />
716 </Animated.View>
717 <Animated.View style={[styles.edgeRing, styles.ringKnow, knowGlow]} />
718 <Animated.View style={[styles.edgeRing, styles.ringLearn, learnGlow]} />
719 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: c.veil }, veil]} />
720 </View>
721 <Animated.View pointerEvents="none" style={[styles.tagWrap, styles.tagWrapKnow, knowTag]}>
722 <View style={[styles.tag, styles.tagKnow]}>
723 <Check size={15} color="#FFFFFF" strokeWidth={3.2} />
724 <Text style={styles.tagText}>Know it</Text>
725 </View>
726 </Animated.View>
727 <Animated.View pointerEvents="none" style={[styles.tagWrap, styles.tagWrapLearn, learnTag]}>
728 <View style={[styles.tag, styles.tagLearn]}>
729 <RotateCcw size={14} color="#FFFFFF" strokeWidth={3} />
730 <Text style={styles.tagText}>Still learning</Text>
731 </View>
732 </Animated.View>
733 </Animated.View>
734 );
735}
736
737// ─── Answer buttons: they fill as the card is dragged their way ─────────────
738
739function Choice({ kind, lean, compact, onPress, c }: { kind: Result; lean: SharedValue<number>; compact: boolean; onPress: () => void; c: Palette }) {
740 const know = kind === 'know';
741 const label = know ? 'Know it' : 'Still learning';
742 const Icon = know ? Check : X;
743 const s = useSharedValue(1);
744 const press = useAnimatedStyle(() => ({ transform: [{ scale: s.value * (1 + clamp01(lean.value) * 0.04) }] }));
745 const solid = useAnimatedStyle(() => ({ opacity: clamp01(lean.value) }));
746 const inner = (ink: string) => (
747 <View style={styles.choiceRow}>
748 {!compact && <Icon size={18} color={ink} strokeWidth={3} />}
749 <Text numberOfLines={1} style={[styles.choiceLabel, { color: ink }]}>
750 {label}
751 </Text>
752 </View>
753 );
754 return (
755 <Pressable
756 role="button"
757 aria-label={`${label}, swipe ${know ? 'right' : 'left'}`}
758 onPress={onPress}
759 onPressIn={() => (s.value = withSpring(0.95, PRESS))}
760 onPressOut={() => (s.value = withSpring(1, PRESS))}
761 style={styles.flex}
762 >
763 <Animated.View style={[styles.choice, { backgroundColor: know ? c.knowSoft : c.learnSoft, borderColor: know ? c.knowLine : c.learnLine }, press]}>
764 {inner(know ? c.knowText : c.learnText)}
765 <Animated.View pointerEvents="none" style={[styles.choiceSolid, { backgroundColor: know ? KNOW : LEARN }, solid]}>
766 {inner('#FFFFFF')}
767 </Animated.View>
768 </Animated.View>
769 </Pressable>
770 );
771}
772
773// ─── Summary: a ring of known against learning, then what to do next ────────
774
775const AnimatedCircle = Animated.createAnimatedComponent(Circle);
776const RING = 156;
777const STROKE = 14;
778
779function Arc({ length, start, delay, duration, color }: { length: number; start: number; delay: number; duration: number; color: string }) {
780 const r = (RING - STROKE) / 2;
781 const C = 2 * Math.PI * r;
782 const t = useSharedValue(0);
783 useEffect(() => {
784 t.value = withDelay(delay, withTiming(1, { duration, easing: Easing.out(Easing.cubic) }));
785 }, [t, delay, duration]);
786 const props = useAnimatedProps(() => ({ strokeDashoffset: length * (1 - t.value), strokeOpacity: t.value > 0.01 ? 1 : 0 }));
787 if (length <= 0) return null;
788 return (
789 <AnimatedCircle
790 cx={RING / 2}
791 cy={RING / 2}
792 r={r}
793 stroke={color}
794 strokeWidth={STROKE}
795 strokeLinecap="round"
796 fill="none"
797 strokeDasharray={`${length} ${C}`}
798 transform={`rotate(${start} ${RING / 2} ${RING / 2})`}
799 animatedProps={props}
800 />
801 );
802}
803
804function Ring({ known, learn, total, c }: { known: number; learn: number; total: number; c: Palette }) {
805 const r = (RING - STROKE) / 2;
806 const C = 2 * Math.PI * r;
807 const both = known > 0 && learn > 0;
808 // Round caps reach past each end, so the arcs are trimmed to leave a clean gap between them.
809 const gap = both ? STROKE + 7 : 0;
810 const kLen = known === total ? C : Math.max(0, (known / total) * C - gap);
811 const lLen = learn === total ? C : Math.max(0, (learn / total) * C - gap);
812 const gapDeg = (gap / C) * 180;
813 return (
814 <Svg width={RING} height={RING}>
815 <Circle cx={RING / 2} cy={RING / 2} r={r} stroke={c.track} strokeWidth={STROKE} fill="none" />
816 <Arc length={kLen} start={-90 + gapDeg} delay={260} duration={820} color={KNOW} />
817 <Arc length={lLen} start={-90 + (known / total) * 360 + gapDeg} delay={known ? 1000 : 260} duration={520} color={LEARN} />
818 </Svg>
819 );
820}
821
822function useCountUp(target: number, delay: number) {
823 const [v, setV] = useState(0);
824 useEffect(() => {
825 let raf = 0;
826 let start = 0;
827 const tick = (now: number) => {
828 if (!start) start = now;
829 const p = Math.min(1, (now - start) / 900);
830 setV(Math.round(target * (1 - Math.pow(1 - p, 3))));
831 if (p < 1) raf = requestAnimationFrame(tick);
832 };
833 const wait = setTimeout(() => (raf = requestAnimationFrame(tick)), delay);
834 return () => {
835 clearTimeout(wait);
836 cancelAnimationFrame(raf);
837 };
838 }, [target, delay]);
839 return v;
840}
841
842type SummaryProps = {
843 order: string[];
844 results: Result[];
845 review: boolean;
846 ended: boolean;
847 seconds: number;
848 bottom: number;
849 onReview: () => void;
850 onRestart: () => void;
851 onBack: () => void;
852 c: Palette;
853};
854
855function Summary({ order, results, review, ended, seconds, bottom, onReview, onRestart, onBack, c }: SummaryProps) {
856 const total = order.length;
857 const known = results.filter((r) => r === 'know').length;
858 const learn = results.length - known;
859 const skipped = total - results.length;
860 const missed = order.filter((_, k) => results[k] === 'learn').map((id) => CARD_BY_ID[id]);
861 const pct = total ? Math.round((known / total) * 100) : 0;
862 const shown = useCountUp(pct, 300);
863 const perCard = results.length ? Math.round(seconds / results.length) : 0;
864 const badge = ended ? 'SESSION ENDED' : review ? 'REVIEW DONE' : 'DECK COMPLETE';
865 const headline = ended ? `${results.length} of ${total} cards studied` : known === total ? 'Every card stuck' : `${known} of ${total} cards stuck`;
866 const stats = [
867 { Icon: Clock, value: clock(seconds), label: 'Time spent' },
868 { Icon: Timer, value: `${perCard}s`, label: 'Per card' },
869 { Icon: Flame, value: String(longestRun(results)), label: 'Best streak' },
870 ];
871 return (
872 <ScrollView style={[styles.flex, { backgroundColor: c.bg }]} contentContainerStyle={[styles.summary, { paddingBottom: bottom + 20 }]} showsVerticalScrollIndicator={false}>
873 <Animated.View entering={FadeInDown.duration(380)} style={styles.summaryHead}>
874 <View style={[styles.badge, { backgroundColor: c.accentSoft }]}>
875 <Text style={[styles.badgeText, { color: c.accentText }]}>{badge}</Text>
876 </View>
877 <Text style={[styles.summaryTitle, { color: c.fg, fontFamily: SERIF }]}>{headline}</Text>
878 <Text style={[styles.summarySub, { color: c.muted }]}>
879 {DECK.title} · {review ? 'missed cards' : `${DECK.language} ${DECK.kind}`}
880 </Text>
881 </Animated.View>
882
883 <Animated.View entering={FadeIn.delay(100).duration(420)} style={styles.ringRow}>
884 <View style={styles.ringWrap}>
885 <Ring known={known} learn={learn} total={total} c={c} />
886 <View pointerEvents="none" style={styles.ringCenter}>
887 <Text style={[styles.ringPct, { color: c.fg, fontFamily: SERIF }, styles.tabular]}>
888 {shown}
889 <Text style={styles.ringPctMark}>%</Text>
890 </Text>
891 <Text style={[styles.ringLabel, { color: c.muted }]}>known</Text>
892 </View>
893 </View>
894 <View style={styles.legend}>
895 <LegendRow color={KNOW} label="Know it" value={known} c={c} />
896 <LegendRow color={LEARN} label="Still learning" value={learn} c={c} />
897 {skipped > 0 && <LegendRow color={c.track} label="Not studied" value={skipped} c={c} />}
898 </View>
899 </Animated.View>
900
901 <Animated.View entering={FadeInDown.delay(260).duration(380)} style={[styles.stats, { backgroundColor: c.surface, borderColor: c.line }]}>
902 {stats.map((s, k) => (
903 <View key={s.label} style={[styles.stat, k > 0 && [styles.statDivider, { borderLeftColor: c.line }]]}>
904 <View style={styles.statTop}>
905 <s.Icon size={15} color={c.accentText} strokeWidth={2.4} />
906 <Text style={[styles.statValue, { color: c.fg }, styles.tabular]}>{s.value}</Text>
907 </View>
908 <Text style={[styles.statLabel, { color: c.muted }]}>{s.label}</Text>
909 </View>
910 ))}
911 </Animated.View>
912
913 {missed.length > 0 && (
914 <Animated.View entering={FadeInDown.delay(340).duration(380)} style={styles.missed}>
915 <Text style={[styles.eyebrow, { color: c.muted }]}>TO REVIEW</Text>
916 <View style={styles.chips}>
917 {missed.map((card) => (
918 <View key={card.id} style={[styles.chip, { backgroundColor: c.learnSoft, borderColor: c.learnLine }]}>
919 <Text style={[styles.chipText, { color: c.fg, fontFamily: SERIF }]}>{card.term}</Text>
920 </View>
921 ))}
922 </View>
923 </Animated.View>
924 )}
925
926 <Animated.View entering={FadeInDown.delay(420).duration(380)} style={styles.summaryActions}>
927 {missed.length > 0 ? (
928 <>
929 <Tap label={`Review ${missed.length} missed cards`} onPress={onReview} to={0.97} style={[styles.primary, { backgroundColor: c.accent }]}>
930 <RotateCcw size={18} color={ON_ACCENT} strokeWidth={2.6} />
931 <Text style={styles.primaryText}>
932 Review {missed.length} missed card{missed.length === 1 ? '' : 's'}
933 </Text>
934 </Tap>
935 </>
936 ) : (
937 <Tap label="Restart deck" onPress={onRestart} to={0.97} style={[styles.primary, { backgroundColor: c.accent }]}>
938 <RotateCcw size={18} color={ON_ACCENT} strokeWidth={2.6} />
939 <Text style={styles.primaryText}>Restart deck</Text>
940 </Tap>
941 )}
942 <View style={styles.secondaryRow}>
943 {missed.length > 0 && (
944 <Tap label="Restart deck" onPress={onRestart} to={0.96} flex style={[styles.secondary, { borderColor: c.line, backgroundColor: c.surface }]}>
945 <Layers size={16} color={c.fg} strokeWidth={2.3} />
946 <Text style={[styles.secondaryText, { color: c.fg }]}>Restart deck</Text>
947 </Tap>
948 )}
949 {results.length > 0 && (
950 <Tap label={ended ? 'Resume the deck' : 'Undo the last card'} onPress={onBack} to={0.96} flex style={[styles.secondary, { borderColor: c.line, backgroundColor: c.surface }]}>
951 <Undo2 size={16} color={c.fg} strokeWidth={2.3} />
952 <Text style={[styles.secondaryText, { color: c.fg }]}>{ended ? 'Resume deck' : 'Undo last'}</Text>
953 </Tap>
954 )}
955 </View>
956 </Animated.View>
957
958 <Text style={[styles.footnote, { color: c.faint }]}>{`${APP_NAME} brings missed cards back tomorrow, then in three days.`}</Text>
959 </ScrollView>
960 );
961}
962
963function LegendRow({ color, label, value, c }: { color: string; label: string; value: number; c: Palette }) {
964 return (
965 <View style={styles.legendRow}>
966 <View style={[styles.legendDot, { backgroundColor: color }]} />
967 <Text style={[styles.legendLabel, { color: c.muted }]}>{label}</Text>
968 <Text style={[styles.legendValue, { color: c.fg }, styles.tabular]}>{value}</Text>
969 </View>
970 );
971}
972
973// ─── Leave sheet ────────────────────────────────────────────────────────────
974
975function LeaveSheet({ open, studied, total, width, bottom, onStay, onEnd, c }: { open: boolean; studied: number; total: number; width: number; bottom: number; onStay: () => void; onEnd: () => void; c: Palette }) {
976 const [mounted, setMounted] = useState(open);
977 const t = useSharedValue(0);
978 useEffect(() => {
979 if (open) {
980 setMounted(true);
981 t.value = withSpring(1, { damping: 22, stiffness: 230, mass: 0.8 });
982 return;
983 }
984 t.value = withTiming(0, { duration: 200, easing: Easing.in(Easing.quad) });
985 const done = setTimeout(() => setMounted(false), 220);
986 return () => clearTimeout(done);
987 }, [open, t]);
988 const scrim = useAnimatedStyle(() => ({ opacity: clamp01(t.value) }));
989 const sheet = useAnimatedStyle(() => ({ transform: [{ translateY: (1 - t.value) * 320 }] }));
990 if (!mounted) return null;
991 return (
992 <View style={[StyleSheet.absoluteFill, styles.sheetHost]}>
993 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: c.scrim }, scrim]}>
994 <Pressable role="button" aria-label="Dismiss" onPress={onStay} style={styles.flex} />
995 </Animated.View>
996 <Animated.View role="dialog" aria-label="End this session?" style={[styles.sheet, { width, backgroundColor: c.surface, paddingBottom: bottom + 16 }, sheet]}>
997 <View style={[styles.grabber, { backgroundColor: c.line }]} />
998 <Text style={[styles.sheetTitle, { color: c.fg, fontFamily: SERIF }]}>End this session?</Text>
999 <Text style={[styles.sheetBody, { color: c.muted }]}>
1000 {`You have been through ${studied} of ${total} cards. ${APP_NAME} keeps your place, so you can pick this deck up again later.`}
1001 </Text>
1002 <Tap label="Keep studying" onPress={onStay} to={0.97} style={[styles.primary, { backgroundColor: c.accent }]}>
1003 <Text style={styles.primaryText}>Keep studying</Text>
1004 </Tap>
1005 <Tap label="End and see summary" onPress={onEnd} to={0.97} style={[styles.secondary, { borderColor: c.line, backgroundColor: c.surface }]}>
1006 <Text style={[styles.secondaryText, { color: c.learnText }]}>End and see summary</Text>
1007 </Tap>
1008 </Animated.View>
1009 </View>
1010 );
1011}
1012
1013// ─── Screen ─────────────────────────────────────────────────────────────────
1014
1015type Session = { round: number; review: boolean; order: string[]; results: Result[]; base: number; startedAt: number };
1016
1017export default function FlashcardsScreen() {
1018 const c = usePalette();
1019 const insets = useSafeAreaInsets();
1020 const { width } = useWindowDimensions();
1021 const column = Math.min(width, COLUMN);
1022 const cardW = Math.min(column - 40, 440);
1023
1024 const [session, setSession] = useState<Session>(() => ({ round: 0, review: false, order: CARDS.map((card) => card.id), results: HEAD_START, base: SECONDS_BEFORE, startedAt: Date.now() }));
1025 const [flipped, setFlipped] = useState(false);
1026 const [summary, setSummary] = useState<{ seconds: number; ended: boolean } | null>(null);
1027 const [leaving, setLeaving] = useState(false);
1028 const [dealing, setDealing] = useState(true);
1029 const [booted, setBooted] = useState(false);
1030 const [areaH, setAreaH] = useState(0);
1031 const [toast, setToast] = useState<{ id: number; text: string } | null>(null);
1032 const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
1033 const later = (fn: () => void, ms: number) => void timers.current.push(setTimeout(fn, ms));
1034 useEffect(() => () => timers.current.forEach(clearTimeout), []);
1035
1036 const { order, results } = session;
1037 const index = results.length;
1038 const total = order.length;
1039 const done = index >= total;
1040 const known = results.filter((r) => r === 'know').length;
1041 const learn = index - known;
1042 const cardH = Math.round(Math.max(300, Math.min(areaH - PEEK_ROOM - 12, cardW * 1.42)));
1043
1044 const pos = useSharedValue(index);
1045 const dragX = useSharedValue(0);
1046 const riffle = useSharedValue(0);
1047 const turn = useSharedValue(0);
1048 const nudge = useSharedValue(0);
1049 useEffect(() => {
1050 pos.value = withSpring(index, SETTLE);
1051 }, [index, pos]);
1052
1053 // Counters and segments fill in once the deck has been dealt.
1054 useEffect(() => {
1055 later(() => setBooted(true), 520);
1056 later(() => setDealing(false), 1300);
1057 // eslint-disable-next-line react-hooks/exhaustive-deps
1058 }, []);
1059
1060 // The last card leaves before the summary comes in.
1061 useEffect(() => {
1062 if (!done || summary) return;
1063 const t = setTimeout(() => setSummary({ seconds: Math.round(session.base + (Date.now() - session.startedAt) / 1000), ended: false }), 480);
1064 return () => clearTimeout(t);
1065 }, [done, summary, session]);
1066
1067 const limit = cardW * 0.3;
1068 const knowLean = useDerivedValue(() => dragX.value / limit);
1069 const learnLean = useDerivedValue(() => -dragX.value / limit);
1070 const shuffleIcon = useAnimatedStyle(() => ({ transform: [{ rotate: `${turn.value * 180}deg` }] }));
1071 const shake = useAnimatedStyle(() => ({ transform: [{ translateX: nudge.value }] }));
1072
1073 const say = (text: string) => {
1074 setToast({ id: Date.now(), text });
1075 later(() => setToast((t) => (t && t.text === text ? null : t)), 1700);
1076 };
1077 const jolt = () => {
1078 nudge.value = withSequence(withTiming(-6, { duration: 50 }), withTiming(6, { duration: 80 }), withTiming(-3, { duration: 70 }), withTiming(0, { duration: 60 }));
1079 };
1080
1081 const swipe = (r: Result) => {
1082 if (done || summary) return;
1083 setFlipped(false);
1084 setSession((s) => (s.results.length === index ? { ...s, results: [...s.results, r] } : s));
1085 };
1086 const undo = () => {
1087 if (!index) {
1088 jolt();
1089 say('Nothing to undo yet');
1090 return;
1091 }
1092 setSummary(null);
1093 setFlipped(false);
1094 setSession((s) => ({ ...s, results: s.results.slice(0, -1) }));
1095 };
1096 const shuffle = () => {
1097 const rest = total - index;
1098 if (summary || rest < 2) {
1099 jolt();
1100 say(rest === 1 ? 'Only one card left' : 'Nothing left to shuffle');
1101 return;
1102 }
1103 riffle.value = 0;
1104 riffle.value = withTiming(1, { duration: 640, easing: Easing.inOut(Easing.quad) });
1105 turn.value = withTiming(Math.round(turn.value) + 1, { duration: 640, easing: Easing.inOut(Easing.cubic) });
1106 setFlipped(false);
1107 // The order changes while the cards are fanned out, so the swap is hidden in the motion.
1108 later(() => setSession((s) => ({ ...s, order: [...s.order.slice(0, s.results.length), ...mix(s.order.slice(s.results.length))] })), 300);
1109 say(`Shuffled the ${rest} cards left`);
1110 };
1111 const startRound = (ids: string[], review: boolean) => {
1112 pos.value = 0;
1113 dragX.value = 0;
1114 setFlipped(false);
1115 setSummary(null);
1116 setDealing(true);
1117 setSession((s) => ({ round: s.round + 1, review, order: ids, results: [], base: 0, startedAt: Date.now() }));
1118 later(() => setDealing(false), 1300);
1119 };
1120 const reviewMissed = () => startRound(order.filter((_, k) => results[k] === 'learn'), true);
1121 const restart = () => startRound(CARDS.map((card) => card.id), false);
1122 const endSession = () => {
1123 setLeaving(false);
1124 setFlipped(false);
1125 setSummary({ seconds: Math.round(session.base + (Date.now() - session.startedAt) / 1000), ended: true });
1126 };
1127 const close = () => {
1128 if (summary) {
1129 say('Your progress is saved');
1130 return;
1131 }
1132 setLeaving(true);
1133 };
1134
1135 // Back to front: two cards behind, the top card, then the one that just left (kept for undo).
1136 const visible: number[] = [];
1137 for (let k = Math.min(total - 1, index + 2); k >= Math.max(0, index - 1); k--) visible.push(k);
1138 const subtitle = summary
1139 ? summary.ended
1140 ? 'Session ended'
1141 : 'Session complete'
1142 : `${session.review ? 'Review' : `${DECK.language} ${DECK.kind}`} · card ${Math.min(index + 1, total)} of ${total}`;
1143
1144 return (
1145 <View style={[styles.screen, { backgroundColor: c.bg }]}>
1146 <View style={[styles.column, { paddingTop: insets.top + 8 }]}>
1147 {/* Header */}
1148 <Animated.View entering={FadeIn.duration(420)} style={styles.header}>
1149 <Tap label="Close session" onPress={close} style={[styles.iconButton, { backgroundColor: c.surface, borderColor: c.line }]}>
1150 <X size={20} color={c.fg} strokeWidth={2.3} />
1151 </Tap>
1152 <View style={styles.headerTitle}>
1153 <Text numberOfLines={1} style={[styles.title, { color: c.fg }]}>
1154 {DECK.title}
1155 </Text>
1156 <Text numberOfLines={1} style={[styles.subtitle, { color: c.muted }]}>
1157 {subtitle}
1158 </Text>
1159 </View>
1160 <Animated.View style={shake}>
1161 <Tap label="Shuffle the cards left" onPress={shuffle} style={[styles.iconButton, { backgroundColor: c.surface, borderColor: c.line }]}>
1162 <Animated.View style={shuffleIcon}>
1163 <Shuffle size={18} color={c.fg} strokeWidth={2.3} />
1164 </Animated.View>
1165 </Tap>
1166 </Animated.View>
1167 </Animated.View>
1168
1169 <Progress results={results} total={total} c={c} />
1170
1171 <View style={styles.flex}>
1172 {/* Counters */}
1173 <View style={styles.counters}>
1174 <Counter kind="learn" value={booted ? learn : 0} total={total} lean={learnLean} c={c} />
1175 <Counter kind="know" value={booted ? known : 0} total={total} lean={knowLean} c={c} />
1176 </View>
1177
1178 <View style={styles.body}>
1179 {/* The pile */}
1180 <View style={styles.stackArea} onLayout={(e: LayoutChangeEvent) => setAreaH(e.nativeEvent.layout.height)}>
1181 {areaH > 0 && (
1182 <View style={[styles.stack, { width: cardW, height: cardH, marginTop: PEEK_ROOM }]}>
1183 {visible.map((k) => (
1184 <StudyCard
1185 key={`${session.round}-${order[k]}`}
1186 card={CARD_BY_ID[order[k]]}
1187 i={k}
1188 total={total}
1189 top={k === index && !summary}
1190 fate={results[k] ?? null}
1191 flipped={k === index && flipped}
1192 pos={pos}
1193 dragX={dragX}
1194 riffle={riffle}
1195 w={cardW}
1196 h={cardH}
1197 deal={dealing && k >= index ? 120 + (2 - (k - index)) * 120 : null}
1198 onFlip={() => setFlipped((f) => !f)}
1199 onSwipe={swipe}
1200 />
1201 ))}
1202 </View>
1203 )}
1204 {toast && (
1205 <Animated.View key={toast.id} entering={FadeInDown.duration(220)} exiting={FadeOut.duration(200)} pointerEvents="none" style={[styles.toast, { backgroundColor: c.fg }]}>
1206 <Text style={[styles.toastText, { color: c.bg }]}>{toast.text}</Text>
1207 </Animated.View>
1208 )}
1209 </View>
1210
1211 {/* Answers */}
1212 <Animated.View entering={FadeInDown.delay(380).duration(420)} style={[styles.actions, { paddingBottom: Math.max(insets.bottom, 14) + 6 }]}>
1213 <Choice kind="learn" lean={learnLean} compact={column < 380} onPress={() => swipe('learn')} c={c} />
1214 <Tap label="Undo last card" onPress={undo} style={[styles.undo, { backgroundColor: c.surface, borderColor: c.line, opacity: index ? 1 : 0.45 }]}>
1215 <Undo2 size={20} color={c.fg} strokeWidth={2.3} />
1216 </Tap>
1217 <Choice kind="know" lean={knowLean} compact={column < 380} onPress={() => swipe('know')} c={c} />
1218 </Animated.View>
1219 </View>
1220
1221 {/* The summary covers the pile and the counters; the segments above stay as the record. */}
1222 {summary && (
1223 <Animated.View entering={FadeIn.duration(260)} style={[StyleSheet.absoluteFill, { backgroundColor: c.bg }]}>
1224 <Summary
1225 order={order}
1226 results={results}
1227 review={session.review}
1228 ended={summary.ended}
1229 seconds={summary.seconds}
1230 bottom={Math.max(insets.bottom, 14)}
1231 onReview={reviewMissed}
1232 onRestart={restart}
1233 onBack={summary.ended ? () => setSummary(null) : undo}
1234 c={c}
1235 />
1236 </Animated.View>
1237 )}
1238 </View>
1239 </View>
1240
1241 <LeaveSheet open={leaving} studied={index} total={total} width={column} bottom={Math.max(insets.bottom, 12)} onStay={() => setLeaving(false)} onEnd={endSession} c={c} />
1242 </View>
1243 );
1244}
1245
1246// ─── Styles ─────────────────────────────────────────────────────────────────
1247
1248const styles = StyleSheet.create({
1249 screen: { flex: 1, overflow: 'hidden' },
1250 column: { flex: 1, width: '100%', maxWidth: COLUMN, alignSelf: 'center' },
1251 flex: { flex: 1 },
1252 rowReverse: { flexDirection: 'row-reverse' },
1253 tabular: { fontVariant: ['tabular-nums'] },
1254 pressed: { opacity: 0.6 },
1255
1256 // Header
1257 header: { height: 48, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16, gap: 12 },
1258 iconButton: { width: 42, height: 42, borderRadius: 21, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },
1259 headerTitle: { flex: 1, alignItems: 'center' },
1260 title: { fontSize: 17, fontWeight: '700', letterSpacing: -0.3 },
1261 subtitle: { marginTop: 2, fontSize: 12.5, fontWeight: '500' },
1262 progress: { flexDirection: 'row', gap: 4, marginTop: 14, marginHorizontal: 20, height: 6 },
1263 segment: { flex: 1, height: 6, borderRadius: 3, overflow: 'hidden' },
1264
1265 // Counters
1266 counters: { flexDirection: 'row', gap: 10, marginTop: 16, paddingHorizontal: 20 },
1267 counter: { flex: 1, height: 50, borderRadius: 16, borderWidth: 1, overflow: 'hidden', justifyContent: 'center' },
1268 counterFill: { position: 'absolute', top: 0, bottom: 0 },
1269 fillFromLeft: { left: 0, borderRightWidth: 1.5 },
1270 fillFromRight: { right: 0, borderLeftWidth: 1.5 },
1271 counterRing: { ...FILL, borderRadius: 16, borderWidth: 2 },
1272 counterRow: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 12 },
1273 counterIcon: { width: 22, height: 22, borderRadius: 11, alignItems: 'center', justifyContent: 'center' },
1274 counterLabel: { fontSize: 13.5, fontWeight: '600', letterSpacing: -0.1, flexShrink: 1 },
1275 counterNum: { fontSize: 22, lineHeight: 28, fontWeight: '800', letterSpacing: -0.5, fontVariant: ['tabular-nums'] },
1276 ticker: { height: 28, overflow: 'hidden', justifyContent: 'center' },
1277 tickerGhost: { position: 'absolute', left: 0, right: 0, top: 0, textAlign: 'center' },
1278
1279 // Pile
1280 body: { flex: 1 },
1281 stackArea: { flex: 1, alignItems: 'center', justifyContent: 'center' },
1282 stack: {},
1283 slot: { position: 'absolute', top: 0, left: 0 },
1284 face: { ...FILL, borderRadius: 28, borderWidth: 1 },
1285 faceLight: { shadowColor: '#3A2C0C', shadowOpacity: 0.13, shadowRadius: 22, shadowOffset: { width: 0, height: 12 } },
1286 faceDark: { shadowColor: '#000000', shadowOpacity: 0.55, shadowRadius: 22, shadowOffset: { width: 0, height: 12 } },
1287 faceClip: { ...FILL, borderRadius: 27, overflow: 'hidden' },
1288 halo: { ...FILL, borderRadius: 28 },
1289 haloKnow: { shadowColor: KNOW, shadowOpacity: 0.75, shadowRadius: 30, shadowOffset: { width: 0, height: 0 } },
1290 haloLearn: { shadowColor: LEARN, shadowOpacity: 0.75, shadowRadius: 30, shadowOffset: { width: 0, height: 0 } },
1291 edge: { ...FILL, borderRadius: 28, overflow: 'hidden' },
1292 edgeRight: { position: 'absolute', top: 0, bottom: 0, right: 0, width: '55%' },
1293 edgeLeft: { position: 'absolute', top: 0, bottom: 0, left: 0, width: '55%' },
1294 edgeRing: { ...FILL, borderRadius: 28, borderWidth: 2.5 },
1295 ringKnow: { borderColor: KNOW },
1296 ringLearn: { borderColor: LEARN },
1297 tagWrap: { position: 'absolute', top: -17 },
1298 tagWrapKnow: { left: 22 },
1299 tagWrapLearn: { right: 22 },
1300 tag: { flexDirection: 'row', alignItems: 'center', gap: 6, height: 34, paddingHorizontal: 14, borderRadius: 17 },
1301 tagKnow: { backgroundColor: KNOW, shadowColor: KNOW, shadowOpacity: 0.45, shadowRadius: 12, shadowOffset: { width: 0, height: 6 } },
1302 tagLearn: { backgroundColor: LEARN, shadowColor: LEARN, shadowOpacity: 0.45, shadowRadius: 12, shadowOffset: { width: 0, height: 6 } },
1303 tagText: { color: '#FFFFFF', fontSize: 14, fontWeight: '800', letterSpacing: 0.1 },
1304
1305 // Faces
1306 faceBody: { flex: 1, padding: 22, paddingTop: 20 },
1307 faceTop: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', minHeight: 28 },
1308 topic: { flexDirection: 'row', alignItems: 'center', gap: 6, height: 28, paddingHorizontal: 11, borderRadius: 14 },
1309 topicText: { fontSize: 12.5, fontWeight: '700' },
1310 history: { flexDirection: 'row', alignItems: 'center', gap: 7 },
1311 historyText: { fontSize: 12.5, fontWeight: '600' },
1312 historyDots: { flexDirection: 'row', gap: 4 },
1313 historyDot: { width: 7, height: 7, borderRadius: 4 },
1314 newBadge: { height: 24, paddingHorizontal: 9, borderRadius: 12, borderWidth: 1, justifyContent: 'center' },
1315 newText: { fontSize: 10.5, fontWeight: '800', letterSpacing: 1.4 },
1316 cardNo: { fontSize: 13, fontWeight: '700', fontVariant: ['tabular-nums'], letterSpacing: 0.5 },
1317 frontRule: { height: 1, marginTop: 14, marginHorizontal: -22, opacity: 0.6 },
1318 frontMid: { flex: 1, alignItems: 'center', justifyContent: 'center', paddingTop: 12 },
1319 lang: { fontSize: 11.5, fontWeight: '700', letterSpacing: 2.4 },
1320 term: { marginTop: 14, textAlign: 'center', letterSpacing: -0.6, fontWeight: '400', paddingHorizontal: 4 },
1321 dash: { width: 28, height: 3, borderRadius: 2, marginTop: 22, marginBottom: 22 },
1322 hintPill: { flexDirection: 'row', alignItems: 'center', gap: 6, height: 34, paddingHorizontal: 14, borderRadius: 17, borderWidth: 1 },
1323 hintLabel: { fontSize: 13.5, fontWeight: '700' },
1324 hintSlot: { height: 44, justifyContent: 'center' },
1325 hintText: { fontSize: 15, fontStyle: 'italic', textAlign: 'center' },
1326 frontFoot: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6 },
1327 footText: { fontSize: 13, fontWeight: '600' },
1328
1329 rules: { ...FILL },
1330 ruleLine: { position: 'absolute', left: 0, right: 0, height: 1 },
1331 eyebrow: { fontSize: 11, fontWeight: '800', letterSpacing: 1.8 },
1332 backRule: { height: 2, borderRadius: 1, marginTop: 14, marginHorizontal: -22 },
1333 lined: { flex: 1, marginHorizontal: -22, paddingHorizontal: 22, paddingTop: LINE_TOP, overflow: 'hidden', marginBottom: 14 },
1334 meaning: { fontSize: 26, lineHeight: LINE, fontWeight: '800', letterSpacing: -0.7 },
1335 sayRow: { flexDirection: 'row', alignItems: 'center', gap: 10, height: LINE },
1336 sayButton: { width: 28, height: 28, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
1337 say: { fontSize: 15.5, fontWeight: '600', fontStyle: 'italic', flexShrink: 1 },
1338 bars: { flexDirection: 'row', alignItems: 'center', gap: 3, height: 18 },
1339 bar: { width: 3, borderRadius: 2 },
1340 example: { borderRadius: 18, borderWidth: 1, padding: 16, gap: 8 },
1341 exampleText: { fontSize: 18, lineHeight: 25, fontStyle: 'italic' },
1342 exampleMatch: { fontWeight: '700' },
1343 exampleEn: { fontSize: 14, lineHeight: 20 },
1344 backFoot: { flexDirection: 'row', justifyContent: 'space-between', marginTop: 16 },
1345 backFootSide: { flexDirection: 'row', alignItems: 'center', gap: 5 },
1346 backFootText: { fontSize: 12.5, fontWeight: '700' },
1347
1348 // Answers
1349 actions: { flexDirection: 'row', alignItems: 'center', gap: 10, paddingHorizontal: 20, paddingTop: 12 },
1350 choice: { height: 56, borderRadius: 28, borderWidth: 1, overflow: 'hidden', justifyContent: 'center' },
1351 choiceSolid: { ...FILL, justifyContent: 'center' },
1352 choiceRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6, paddingHorizontal: 8 },
1353 choiceLabel: { fontSize: 15, fontWeight: '700', letterSpacing: -0.2, flexShrink: 1 },
1354 undo: { width: 48, height: 48, borderRadius: 24, borderWidth: 1, alignItems: 'center', justifyContent: 'center' },
1355 toast: { position: 'absolute', top: 2, alignSelf: 'center', paddingHorizontal: 16, height: 38, borderRadius: 19, justifyContent: 'center' },
1356 toastText: { fontSize: 14, fontWeight: '600' },
1357
1358 // Summary
1359 summary: { paddingHorizontal: 20, paddingTop: 14, gap: 16 },
1360 summaryHead: { alignItems: 'center' },
1361 badge: { height: 24, paddingHorizontal: 11, borderRadius: 12, justifyContent: 'center' },
1362 badgeText: { fontSize: 10.5, fontWeight: '800', letterSpacing: 1.6 },
1363 summaryTitle: { marginTop: 10, fontSize: 29, lineHeight: 34, letterSpacing: -0.7, textAlign: 'center' },
1364 summarySub: { marginTop: 3, fontSize: 14, fontWeight: '500', textAlign: 'center' },
1365 ringRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 26 },
1366 ringWrap: { width: RING, height: RING, alignItems: 'center', justifyContent: 'center' },
1367 ringCenter: { ...FILL, alignItems: 'center', justifyContent: 'center' },
1368 ringPct: { fontSize: 40, lineHeight: 44, letterSpacing: -1.4 },
1369 ringPctMark: { fontSize: 21 },
1370 ringLabel: { fontSize: 12.5, fontWeight: '600', marginTop: 1 },
1371 legend: { gap: 12 },
1372 legendRow: { flexDirection: 'row', alignItems: 'center', gap: 8 },
1373 legendDot: { width: 10, height: 10, borderRadius: 5 },
1374 legendLabel: { fontSize: 13.5, fontWeight: '600', minWidth: 92 },
1375 legendValue: { fontSize: 17, fontWeight: '800' },
1376 stats: { flexDirection: 'row', borderRadius: 18, borderWidth: 1, paddingVertical: 12 },
1377 stat: { flex: 1, alignItems: 'center', gap: 3 },
1378 statDivider: { borderLeftWidth: 1 },
1379 statTop: { flexDirection: 'row', alignItems: 'center', gap: 6 },
1380 statValue: { fontSize: 19, fontWeight: '800', letterSpacing: -0.4 },
1381 statLabel: { fontSize: 12, fontWeight: '600' },
1382 missed: { gap: 9 },
1383 chips: { flexDirection: 'row', flexWrap: 'wrap', gap: 7 },
1384 chip: { borderRadius: 13, borderWidth: 1, paddingHorizontal: 11, paddingVertical: 6 },
1385 chipText: { fontSize: 14.5, fontStyle: 'italic' },
1386 summaryActions: { gap: 10 },
1387 primary: { height: 56, borderRadius: 28, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8, backgroundColor: ACCENT },
1388 primaryText: { color: ON_ACCENT, fontSize: 16, fontWeight: '800', letterSpacing: -0.2 },
1389 secondaryRow: { flexDirection: 'row', gap: 10 },
1390 secondary: { height: 50, borderRadius: 25, borderWidth: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 7 },
1391 secondaryText: { fontSize: 15, fontWeight: '700' },
1392 footnote: { fontSize: 12.5, lineHeight: 18, textAlign: 'center', paddingHorizontal: 12 },
1393
1394 // Leave sheet
1395 sheetHost: { alignItems: 'center' },
1396 sheet: { position: 'absolute', bottom: 0, borderTopLeftRadius: 28, borderTopRightRadius: 28, paddingHorizontal: 20, paddingTop: 10, gap: 12 },
1397 grabber: { alignSelf: 'center', width: 40, height: 5, borderRadius: 3, marginBottom: 6 },
1398 sheetTitle: { fontSize: 26, lineHeight: 32, letterSpacing: -0.5 },
1399 sheetBody: { fontSize: 15, lineHeight: 22, marginBottom: 8 },
1400});

More screens like this.

All Learning