Files
filwordspl-frontend/src/pages/BubbleWordsPage.tsx
T
Drobysh f7389afa4f 🌊 Волна 3: frontend юзабилити топ (4 бага)
- HINT_AUTO_SELECTS_CORRECT: подсказка не засчитывается как ответ
  (PracticeViewPage.tsx, паттерн из LessonViewPage)
- ALERT_IN_TELEGRAM_MINIAPP: alert() → кастомный toast
  (TeacherChatPage.tsx, 3 места)
- BUBBLE_ERROR_MESSAGE_STUCK: errorTimeoutRef + автоскрытие
  (BubbleWordsPage.tsx)
- WORDSEARCH_STREAK_ON_ALREADY_FOUND: инкремент внутри проверки includes
  (WordSearchPage.tsx)

Аудит: Issue #3, frontend 4/34 задач
2026-09-23 15:14:28 +03:00

833 lines
30 KiB
TypeScript

import { useState, useEffect, useCallback, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { fonts, radius } from '../styles/theme';
import { getBubbleLevel, completeBubbleLevel, getBubbleProgress, fetchProgress } from '../api';
import RulesModal from '../components/RulesModal';
import { useAchievements } from '../hooks/useAchievements';
interface BubbleWord {
word_pl: string;
translation: string;
parts: string[];
}
interface Bubble {
text: string;
word_pl: string;
}
const BubbleWordsPage: React.FC = () => {
const navigate = useNavigate();
const { t } = useLanguage();
const [words, setWords] = useState<BubbleWord[]>([]);
const [bubbles, setBubbles] = useState<Bubble[]>([]);
const [loading, setLoading] = useState(true);
const [totalScore, setTotalScore] = useState(0);
const [hintsUsed, setHintsUsed] = useState(0);
const [firstLetterHintsUsed, setFirstLetterHintsUsed] = useState(0);
const [showWordModal, setShowWordModal] = useState(false);
const [selectedBubbles, setSelectedBubbles] = useState<Bubble[]>([]);
const [foundWords, setFoundWords] = useState<string[]>([]);
const [completed, setCompleted] = useState(false);
const [isTransitioning, setIsTransitioning] = useState(false);
const [showRules, setShowRules] = useState(false);
const [message, setMessage] = useState<string | null>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [levelsCompleted, setLevelsCompleted] = useState(0);
const [bubbleLevel, setBubbleLevel] = useState(1);
const [currentLevel, setCurrentLevel] = useState('A1');
const [animationsReady, setAnimationsReady] = useState(false);
const [hintHighlightedBubble, setHintHighlightedBubble] = useState<string | null>(null);
const { activeAchievement, showAchievement, resetAchievements } = useAchievements();
const isMountedRef = useRef(true);
const messageTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const hintTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// 🔧 ФИКС (23.09.2026): BUBBLE_ERROR_MESSAGE_STUCK — добавлен таймер для errorMessage,
// чтобы плашка автоскрывалась (раньше висела бесконечно).
const errorTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const startTimeRef = useRef<number>(0);
const rulesShownRef = useRef(false);
const maxFirstLetterHints = 3;
const brandColor = '#2ECC71';
const palette = { bubble: '#4FA9E8' };
const textColor = '#1A1A2E';
const subColor = '#6B7280';
const bgColor = '#F4F5F7';
const glass = (extra: React.CSSProperties = {}): React.CSSProperties => ({
background: 'rgba(255,255,255,0.55)',
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
border: '1px solid rgba(255,255,255,0.7)',
boxShadow: '0 8px 32px rgba(31,38,73,0.10), inset 0 1px 0 rgba(255,255,255,0.85)',
...extra,
});
useEffect(() => {
isMountedRef.current = true;
// Автопоказ правил при первом входе
if (!rulesShownRef.current) {
rulesShownRef.current = true;
const rulesSeen = localStorage.getItem('filwords_rules_bubble');
if (!rulesSeen) {
setTimeout(() => {
if (isMountedRef.current) {
setShowRules(true);
localStorage.setItem('filwords_rules_bubble', '1');
}
}, 500);
}
}
return () => {
isMountedRef.current = false;
if (messageTimeoutRef.current) clearTimeout(messageTimeoutRef.current);
if (hintTimeoutRef.current) clearTimeout(hintTimeoutRef.current);
// 🔧 ФИКС (23.09.2026): BUBBLE_ERROR_MESSAGE_STUCK — cleanup нового таймера
if (errorTimeoutRef.current) clearTimeout(errorTimeoutRef.current);
};
}, []);
const fetchLevel = useCallback(() => {
setLoading(true);
setSelectedBubbles([]);
setFoundWords([]);
setCompleted(false);
setIsTransitioning(false);
setHintsUsed(0);
setFirstLetterHintsUsed(0);
setShowWordModal(false);
setAnimationsReady(false);
setHintHighlightedBubble(null);
resetAchievements();
startTimeRef.current = Date.now();
getBubbleLevel()
.then((data: any) => {
if (isMountedRef.current) {
setWords(data.words || []);
setBubbles(data.bubbles || []);
setBubbleLevel(data.level || 1);
setTimeout(() => {
if (isMountedRef.current) setAnimationsReady(true);
}, 50);
}
})
.catch(() => {
if (isMountedRef.current) navigate('/menu');
})
.finally(() => {
if (isMountedRef.current) setLoading(false);
});
fetchProgress()
.then((data: any) => {
if (isMountedRef.current) {
setTotalScore(data.total_score || 0);
if (data.current_level) {
setCurrentLevel(data.current_level);
}
}
})
.catch(() => {});
getBubbleProgress()
.then((data: any) => {
if (isMountedRef.current) setLevelsCompleted(data.levels_completed || 0);
})
.catch(() => {});
}, [navigate, resetAchievements]);
useEffect(() => {
fetchLevel();
}, [fetchLevel]);
const showMessage = (msg: string) => {
if (!isMountedRef.current) return;
setMessage(msg);
if (messageTimeoutRef.current) clearTimeout(messageTimeoutRef.current);
messageTimeoutRef.current = setTimeout(() => {
if (isMountedRef.current) setMessage(null);
}, 1500);
};
// 🔧 ФИКС (23.09.2026): BUBBLE_ERROR_MESSAGE_STUCK — helper для errorMessage
// с автоскрытием через 2 секунды (по аналогии с showMessage).
const showError = (msg: string) => {
if (!isMountedRef.current) return;
setErrorMessage(msg);
if (errorTimeoutRef.current) clearTimeout(errorTimeoutRef.current);
errorTimeoutRef.current = setTimeout(() => {
if (isMountedRef.current) setErrorMessage(null);
}, 2000);
};
const handleBubbleClick = useCallback((bubble: Bubble) => {
if (completed || isTransitioning) return;
if (foundWords.includes(bubble.word_pl)) return;
setSelectedBubbles(prev => {
const alreadySelected = prev.find(b => b.text === bubble.text && b.word_pl === bubble.word_pl);
if (alreadySelected) {
return prev.filter(b => !(b.text === bubble.text && b.word_pl === bubble.word_pl));
}
return [...prev, bubble];
});
if (window.Telegram?.WebApp?.HapticFeedback) {
window.Telegram.WebApp.HapticFeedback.impactOccurred('light');
}
}, [completed, isTransitioning, foundWords]);
useEffect(() => {
if (selectedBubbles.length === 0) return;
const grouped: Record<string, string> = {};
selectedBubbles.forEach(b => {
if (!grouped[b.word_pl]) grouped[b.word_pl] = '';
grouped[b.word_pl] += b.text;
});
for (const word of words) {
const assembled = grouped[word.word_pl] || '';
if (assembled === word.word_pl && !foundWords.includes(word.word_pl)) {
const newFoundWords = [...foundWords, word.word_pl];
setFoundWords(newFoundWords);
setSelectedBubbles(prev => prev.filter(b => b.word_pl !== word.word_pl));
showMessage(`✅ ${word.word_pl}`);
if (window.Telegram?.WebApp?.HapticFeedback) {
window.Telegram.WebApp.HapticFeedback.impactOccurred('medium');
}
if (newFoundWords.length === words.length && !isTransitioning) {
setIsTransitioning(true);
setCompleted(true);
const completionTime = Math.floor((Date.now() - startTimeRef.current) / 1000);
if (window.Telegram?.WebApp?.HapticFeedback) {
window.Telegram.WebApp.HapticFeedback.impactOccurred('heavy');
}
completeBubbleLevel(hintsUsed, words.length, completionTime)
.then((data: any) => {
if (isMountedRef.current) {
setTotalScore(prev => prev + (data.score || 0));
setLevelsCompleted(prev => prev + 1);
fetchProgress().catch(() => {});
if (data.new_achievements && data.new_achievements.length > 0) {
data.new_achievements.forEach((ach: any) => {
showAchievement({
id: ach.code,
icon: ach.icon,
name: ach.name,
});
});
}
}
})
.catch(() => {});
setTimeout(() => {
if (isMountedRef.current) fetchLevel();
}, 2000);
}
break;
}
}
}, [selectedBubbles, words, foundWords, isTransitioning, hintsUsed, fetchLevel, showAchievement]);
const handleFirstLetterHint = () => {
if (firstLetterHintsUsed >= maxFirstLetterHints) {
// 🔧 ФИКС (23.09.2026): BUBBLE_ERROR_MESSAGE_STUCK — используем showError
showError('⚠️ ' + (t('noMoreFirstLetterHints') || 'No more hints'));
return;
}
const notFoundWords = words.filter(w => !foundWords.includes(w.word_pl));
if (notFoundWords.length === 0) return;
const randomWord = notFoundWords[Math.floor(Math.random() * notFoundWords.length)];
const firstPart = randomWord.parts[0];
const hintKey = `${firstPart}-${randomWord.word_pl}`;
setHintHighlightedBubble(hintKey);
if (hintTimeoutRef.current) clearTimeout(hintTimeoutRef.current);
hintTimeoutRef.current = setTimeout(() => {
if (isMountedRef.current) setHintHighlightedBubble(null);
}, 2000);
setFirstLetterHintsUsed(prev => prev + 1);
setHintsUsed(prev => prev + 1);
setErrorMessage(null);
};
const handleShowWords = () => {
if (!showWordModal) {
setHintsUsed(prev => prev + 1);
}
setShowWordModal(prev => !prev);
};
const isBubbleSelected = (bubble: Bubble): boolean => {
return selectedBubbles.some(b => b.text === bubble.text && b.word_pl === bubble.word_pl);
};
const isBubbleFound = (bubble: Bubble): boolean => {
return foundWords.includes(bubble.word_pl);
};
const isHintHighlighted = (bubble: Bubble): boolean => {
const key = `${bubble.text}-${bubble.word_pl}`;
return hintHighlightedBubble === key;
};
if (loading) {
return (
<div style={{
minHeight: '100vh',
background: bgColor,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: subColor,
fontFamily: fonts.main,
fontSize: '18px',
}}>
{t('loading')}...
</div>
);
}
return (
<div style={{
minHeight: '100vh',
background: bgColor,
color: textColor,
fontFamily: fonts.main,
padding: '16px',
display: 'flex',
flexDirection: 'column',
position: 'relative',
overflow: 'hidden',
}}>
<div style={{ position: 'fixed', top: '-80px', right: '-60px', width: '260px', height: '260px', borderRadius: '50%', background: palette.bubble, opacity: 0.22, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />
<div style={{ position: 'fixed', bottom: '-50px', left: '-40px', width: '220px', height: '220px', borderRadius: '50%', background: brandColor, opacity: 0.16, filter: 'blur(80px)', pointerEvents: 'none', zIndex: 0 }} />
<style>{`
@keyframes bubbleDrop {
0% { transform: translateY(-70vh) scale(0.3); opacity: 0; }
50% { opacity: 1; }
70% { transform: translateY(6px) scale(1.02); }
85% { transform: translateY(-3px) scale(0.98); }
100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes bubbleWobble {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-6px); }
}
@keyframes hintPulse {
0%, 100% { box-shadow: 0 0 10px rgba(255, 215, 0, 0.6); }
50% { box-shadow: 0 0 25px rgba(255, 215, 0, 1); }
}
@keyframes fadeInUp {
0% { transform: translateY(10px); opacity: 0; }
100% { transform: translateY(0); opacity: 1; }
}
@keyframes messagePopIn {
0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes achievementSlideDown {
0% { transform: translateX(-50%) translateY(-80px); opacity: 0; }
100% { transform: translateX(-50%) translateY(0); opacity: 1; }
}
`}</style>
<div style={{ position: 'relative', zIndex: 1, display: 'flex', flexDirection: 'column', flex: 1 }}>
<RulesModal
isOpen={showRules}
onClose={() => setShowRules(false)}
title={t('bubbleWordsRulesTitle') || '🫧 Bubble Words Rules'}
content={t('bubbleWordsRulesContent') || 'Rules content loading...'}
/>
{activeAchievement && (
<div style={{
position: 'fixed',
top: '16px',
left: '50%',
transform: 'translateX(-50%)',
zIndex: 900,
background: 'linear-gradient(135deg, #FFD700, #FFA500)',
color: '#FFFFFF',
padding: '14px 20px',
borderRadius: radius.lg,
boxShadow: '0 8px 30px rgba(255, 215, 0, 0.5)',
display: 'flex',
alignItems: 'center',
gap: '12px',
minWidth: '250px',
maxWidth: '90vw',
animation: 'achievementSlideDown 0.4s ease',
}}>
<span style={{ fontSize: '28px', flexShrink: 0 }}>{activeAchievement.icon}</span>
<div>
<div style={{ fontSize: '11px', fontWeight: 600, opacity: 0.9, letterSpacing: '1px', textTransform: 'uppercase' }}>
🏆 {t('achievement') || 'Achievement'}
</div>
<div style={{ fontSize: '15px', fontWeight: 800, marginTop: '2px' }}>
{activeAchievement.name}
</div>
</div>
</div>
)}
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '16px',
animation: 'fadeInUp 0.3s ease',
}}>
<div style={{ display: 'flex', gap: '8px', alignItems: 'center' }}>
<button
onClick={() => navigate('/menu')}
style={{
...glass({
padding: '10px 18px',
borderRadius: radius.md,
}),
color: textColor,
fontSize: '14px',
fontWeight: 600,
cursor: 'pointer',
transition: 'transform 0.2s ease',
}}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.95)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
← {t('back')}
</button>
<button
onClick={() => setShowRules(true)}
style={{
...glass({
width: '40px',
height: '40px',
borderRadius: radius.md,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}),
color: textColor,
fontSize: '18px',
fontWeight: 700,
cursor: 'pointer',
transition: 'transform 0.2s ease',
flexShrink: 0,
}}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.95)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
?
</button>
</div>
<div style={{ textAlign: 'center' }}>
<div style={{ fontSize: '14px', color: subColor }}>
{t('level')} {bubbleLevel}
</div>
</div>
<div style={{ textAlign: 'right', display: 'flex', alignItems: 'center', gap: '8px' }}>
<span style={{
fontSize: '12px',
fontWeight: 800,
color: brandColor,
background: `${brandColor}15`,
padding: '4px 8px',
borderRadius: radius.sm,
border: `1px solid ${brandColor}40`,
}}>
{currentLevel}
</span>
<div>
<div style={{ fontSize: '11px', color: subColor, marginBottom: '2px' }}>
{t('score')}
</div>
<div style={{
fontSize: '16px',
fontWeight: 800,
color: brandColor,
}}>
{totalScore}
</div>
</div>
</div>
</div>
{errorMessage && (
<div style={{
position: 'absolute',
top: '60px',
left: '50%',
transform: 'translateX(-50%)',
padding: '10px 20px',
fontSize: '14px',
fontWeight: 600,
color: '#FFFFFF',
background: '#F39C12',
borderRadius: radius.md,
boxShadow: '0 4px 12px rgba(243,156,18,0.4)',
whiteSpace: 'nowrap',
zIndex: 10,
animation: 'messagePopIn 0.25s ease',
}}>
{errorMessage}
</div>
)}
{message && (
<div style={{
position: 'absolute',
top: '60px',
left: '50%',
transform: 'translateX(-50%)',
padding: '10px 20px',
fontSize: '16px',
fontWeight: 700,
color: '#FFFFFF',
background: brandColor,
borderRadius: radius.md,
boxShadow: `0 4px 12px ${brandColor}40`,
whiteSpace: 'nowrap',
zIndex: 10,
animation: 'messagePopIn 0.25s ease',
pointerEvents: 'none',
}}>
{message}
</div>
)}
<div style={{
display: 'flex',
flexWrap: 'wrap',
gap: '6px',
marginBottom: '12px',
minHeight: '24px',
animation: 'fadeInUp 0.3s ease',
}}>
{foundWords.map(w => (
<span key={w} style={{
padding: '4px 10px',
borderRadius: radius.sm,
background: `${brandColor}20`,
color: '#1a7a3a',
fontSize: '12px',
fontWeight: 700,
border: `1px solid ${brandColor}40`,
}}>
✅ {w}
</span>
))}
</div>
<div style={{
flex: 1,
display: 'flex',
flexWrap: 'wrap',
gap: '10px',
justifyContent: 'center',
alignContent: 'flex-start',
padding: '10px 0',
overflow: 'auto',
position: 'relative',
}}>
{bubbles.map((bubble, index) => {
const selected = isBubbleSelected(bubble);
const found = isBubbleFound(bubble);
const hinted = isHintHighlighted(bubble);
if (found) return null;
const totalBubbles = bubbles.length;
const isSmallLevel = totalBubbles <= 12;
const bubbleSize = isSmallLevel
? (bubble.text.length <= 2 ? 70 : bubble.text.length <= 3 ? 80 : 90)
: (bubble.text.length <= 2 ? 55 : bubble.text.length <= 3 ? 65 : 75);
return (
<div
key={`${bubble.text}-${bubble.word_pl}-${index}`}
onClick={() => handleBubbleClick(bubble)}
style={{
width: bubbleSize,
height: bubbleSize,
borderRadius: '50%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: bubbleSize > 70 ? '17px' : bubbleSize > 60 ? '15px' : '14px',
fontWeight: 700,
cursor: 'pointer',
userSelect: 'none',
transition: 'all 0.2s ease',
background: hinted
? 'radial-gradient(circle at 35% 35%, #FFD700, #FFA500)'
: selected
? `radial-gradient(circle at 35% 35%, ${palette.bubble}CC, ${palette.bubble})`
: 'rgba(255,255,255,0.55)',
border: hinted
? '3px solid #FFD700'
: selected
? `2px solid ${palette.bubble}`
: '1px solid rgba(0,0,0,0.06)',
color: hinted ? '#FFFFFF' : selected ? '#FFFFFF' : textColor,
boxShadow: hinted
? '0 0 20px rgba(255, 215, 0, 0.8)'
: selected
? `0 0 15px ${palette.bubble}60`
: '0 4px 12px rgba(31,38,73,0.06)',
animation: hinted
? `bubbleDrop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) ${index * 0.1}s both, hintPulse 0.8s ease-in-out infinite`
: animationsReady
? `bubbleDrop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) ${index * 0.1}s both, bubbleWobble ${2.5 + index * 0.4}s ease-in-out infinite ${0.7 + index * 0.1}s`
: 'none',
opacity: animationsReady ? 1 : 0,
}}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.9)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
{bubble.text}
</div>
);
})}
</div>
{selectedBubbles.length > 0 && (
<div style={{
display: 'flex',
flexWrap: 'wrap',
gap: '6px',
justifyContent: 'center',
padding: '8px',
marginBottom: '8px',
background: 'rgba(0,0,0,0.02)',
borderRadius: radius.md,
border: '1px dashed rgba(0,0,0,0.1)',
animation: 'fadeInUp 0.2s ease',
}}>
{selectedBubbles.map((b, i) => (
<span key={i} style={{
padding: '6px 10px',
borderRadius: radius.sm,
background: `${palette.bubble}20`,
color: palette.bubble,
fontSize: '14px',
fontWeight: 700,
border: `1px solid ${palette.bubble}40`,
}}>
{b.text}
</span>
))}
</div>
)}
<div style={{
display: 'flex',
gap: '10px',
justifyContent: 'center',
padding: '8px 0',
animation: 'fadeInUp 0.3s ease 0.2s both',
}}>
<button
onClick={handleFirstLetterHint}
disabled={firstLetterHintsUsed >= maxFirstLetterHints}
style={{
...glass({
flex: 1,
padding: '12px',
borderRadius: radius.md,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '6px',
}),
opacity: firstLetterHintsUsed >= maxFirstLetterHints ? 0.5 : 1,
cursor: firstLetterHintsUsed >= maxFirstLetterHints ? 'default' : 'pointer',
fontSize: '13px',
fontWeight: 600,
color: textColor,
}}
onTouchStart={(e) => { if (firstLetterHintsUsed < maxFirstLetterHints) e.currentTarget.style.transform = 'scale(0.95)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
<span>💡 {t('firstLetter')}</span>
<div style={{ display: 'flex', gap: '6px' }}>
{Array.from({ length: maxFirstLetterHints }, (_, i) => (
<div key={i} style={{
width: '10px',
height: '10px',
borderRadius: '50%',
background: i < maxFirstLetterHints - firstLetterHintsUsed ? brandColor : 'rgba(0,0,0,0.08)',
border: i < maxFirstLetterHints - firstLetterHintsUsed ? `1px solid ${brandColor}` : '1px solid rgba(0,0,0,0.06)',
boxShadow: i < maxFirstLetterHints - firstLetterHintsUsed ? `0 0 6px ${brandColor}80` : 'inset 0 1px 2px rgba(0,0,0,0.06)',
}} />
))}
</div>
</button>
<button
onClick={handleShowWords}
style={{
...glass({
flex: 1,
padding: '12px',
borderRadius: radius.md,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '6px',
}),
border: showWordModal ? `2px solid ${brandColor}` : '1px solid rgba(255,255,255,0.7)',
fontSize: '13px',
fontWeight: 600,
color: textColor,
cursor: 'pointer',
}}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.95)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
<span>📖 {t('showWords')} {showWordModal ? '▲' : '▼'}</span>
<span style={{ fontSize: '18px', color: brandColor, lineHeight: '1' }}>∞</span>
</button>
</div>
{showWordModal && (
<div
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
background: 'rgba(20,22,35,0.25)',
zIndex: 500,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '20px',
backdropFilter: 'blur(4px)',
WebkitBackdropFilter: 'blur(4px)',
}}
onClick={(e) => { if (e.target === e.currentTarget) setShowWordModal(false); }}
>
<div style={{
...glass({
borderRadius: radius.lg,
padding: '20px',
width: '100%',
maxWidth: '400px',
maxHeight: '70vh',
overflow: 'auto',
}),
boxShadow: '0 20px 60px rgba(31,38,73,0.20), inset 0 1px 0 rgba(255,255,255,0.85)',
}}>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '16px',
paddingBottom: '12px',
borderBottom: '1px solid rgba(0,0,0,0.06)',
}}>
<h3 style={{ margin: 0, fontSize: '18px', fontWeight: 700, color: textColor }}>📖 {t('showWords')}</h3>
<button
onClick={() => setShowWordModal(false)}
style={{
...glass({
padding: '8px 16px',
borderRadius: radius.md,
}),
color: textColor,
fontSize: '14px',
fontWeight: 600,
cursor: 'pointer',
}}
>
✕
</button>
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px', justifyContent: 'center' }}>
{words.map(w => (
<div key={w.word_pl} style={{
padding: '10px 14px',
borderRadius: radius.md,
background: foundWords.includes(w.word_pl) ? `${brandColor}20` : 'rgba(255,255,255,0.55)',
border: `2px solid ${foundWords.includes(w.word_pl) ? brandColor : 'rgba(0,0,0,0.06)'}`,
color: foundWords.includes(w.word_pl) ? '#1a7a3a' : textColor,
fontSize: '14px',
fontWeight: foundWords.includes(w.word_pl) ? 700 : 400,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '4px',
minWidth: '80px',
}}>
<span style={{ fontSize: '16px' }}>{w.word_pl}</span>
{w.translation && (
<span style={{ fontSize: '11px', color: foundWords.includes(w.word_pl) ? brandColor : subColor }}>
{w.translation}
</span>
)}
{foundWords.includes(w.word_pl) && <span style={{ fontSize: '12px' }}>✅</span>}
</div>
))}
</div>
<div style={{
marginTop: '16px',
paddingTop: '12px',
borderTop: '1px solid rgba(0,0,0,0.06)',
textAlign: 'center',
fontSize: '14px',
color: subColor,
}}>
{foundWords.length}/{words.length} {t('foundWords').toLowerCase()}
</div>
</div>
</div>
)}
{completed && (
<div style={{
textAlign: 'center',
padding: '16px',
marginTop: '8px',
background: `${brandColor}15`,
borderRadius: radius.lg,
border: `2px solid ${brandColor}40`,
}}>
<div style={{ fontSize: '28px', marginBottom: '4px' }}>🎉</div>
<div style={{ fontSize: '16px', fontWeight: 700, color: brandColor }}>{t('levelCompleted')}</div>
</div>
)}
<div style={{ textAlign: 'center', marginTop: '8px', color: subColor, fontSize: '12px' }}>
{t('levelsCompleted')}: {levelsCompleted}
</div>
</div>
</div>
);
};
export default BubbleWordsPage;