/* ========================================
   Phrasal Verbs Lab - Flashcards Activity
   Travel & Navigation Theme
   Â© Cool English 2026
   ======================================== */

/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    
    --teal-50: #f0fdfa;
    --teal-100: #ccfbf1;
    --teal-200: #99f6e4;
    --teal-300: #5eead4;
    --teal-400: #2dd4bf;
    --teal-500: #14b8a6;
    --teal-600: #0d9488;
    --teal-700: #0f766e;
    
    --cyan-400: #22d3ee;
    --cyan-500: #06b6d4;
    
    --amber-400: #fbbf24;
    --amber-500: #f59e0b;
    --amber-600: #d97706;
    
    --emerald-400: #34d399;
    --emerald-500: #10b981;
    
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
}

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #ecfeff 0%, #f0fdfa 50%, #e0f2fe 100%);
    color: var(--slate-800);
}

.app {
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Header
   ======================================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 4px solid transparent;
    border-image: linear-gradient(90deg, #FF6B35, #F59E0B, #22C55E, #06B6D4, #8B5CF6, #EC4899) 1;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 0.75rem;
    background: var(--slate-100);
    color: var(--slate-600);
    text-decoration: none;
    transition: all 0.3s ease;
    border: 2px solid var(--slate-200);
}

.back-btn:hover {
    background: var(--teal-500);
    border-color: var(--teal-500);
    color: white;
    transform: translateX(-3px);
}

.logo {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 1rem;
    background: linear-gradient(135deg, var(--teal-400), var(--cyan-500));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-lg);
}

.title-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.main-title {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--slate-800);
}

.theme-badge {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    font-size: 1rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* Control Buttons */
.control-buttons {
    display: flex;
    gap: 0.5rem;
    background: var(--slate-100);
    padding: 0.375rem;
    border-radius: 1rem;
    border: 2px solid var(--slate-200);
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    background: transparent;
    color: var(--slate-500);
}

.control-btn:hover {
    background: var(--slate-200);
    color: var(--slate-700);
}

.control-btn.active {
    background: white;
    color: var(--teal-600);
    box-shadow: var(--shadow-md);
}

.flip-all-btn {
    background: linear-gradient(135deg, var(--amber-400), var(--amber-500)) !important;
    color: white !important;
}

.flip-all-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.done-btn {
    background: linear-gradient(135deg, var(--emerald-400), var(--emerald-500)) !important;
    color: white !important;
}

.done-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg), 0 0 15px rgba(16, 185, 129, 0.4);
}

/* Progress */
.progress-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: white;
    padding: 0.75rem 1.25rem;
    border-radius: 1rem;
    border: 2px solid var(--teal-200);
}

.progress-count {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--teal-600);
}

.progress-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--slate-500);
}

/* ========================================
   Main Content
   ======================================== */
.main-content {
    flex: 1;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.instruction {
    text-align: center;
    font-size: 1.5rem;
    color: var(--slate-500);
    font-weight: 600;
}

/* ========================================
   Flashcards Grid
   ======================================== */
.flashcards-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 1.25rem;
}

/* ========================================
   FLASHCARD - 3D FLIP CARD
   ======================================== */

/* Outer wrapper - creates the clickable area */
.flashcard {
    perspective: 1000px;
    cursor: pointer;
    min-height: 200px;
}

/* Inner container that actually flips */
.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 200px;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

/* When flipped */
.flashcard.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

/* Both card faces */
.card-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 1.25rem;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    border: 3px solid;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Front - Image side */
.card-front {
    background: linear-gradient(145deg, #ffffff, var(--teal-50));
    border-color: var(--teal-300);
    z-index: 2;
}

/* Back - Word side (starts rotated) */
.card-back {
    background: linear-gradient(135deg, var(--teal-500), var(--cyan-500));
    border-color: var(--teal-400);
    transform: rotateY(180deg);
    -webkit-transform: rotateY(180deg);
    color: white;
    z-index: 1;
}

/* Cycle through 4 colour variants so cards aren't all identical */
.flashcard:nth-child(4n+1) .card-back { background: linear-gradient(135deg, #0d9488, #06b6d4); border-color: #0d9488; }
.flashcard:nth-child(4n+2) .card-back { background: linear-gradient(135deg, #0284c7, #0ea5e9); border-color: #0284c7; }
.flashcard:nth-child(4n+3) .card-back { background: linear-gradient(135deg, #0f766e, #14b8a6); border-color: #0f766e; }
.flashcard:nth-child(4n+0) .card-back { background: linear-gradient(135deg, #0369a1, #06b6d4); border-color: #0369a1; }

/* Hover effect */
.flashcard:hover .flashcard-inner {
    transform: scale(1.03);
}

.flashcard.flipped:hover .flashcard-inner {
    transform: rotateY(180deg) scale(1.03);
}

/* ========================================
   Card Content
   ======================================== */

/* Image container */
.card-image {
    width: 100%;
    flex: 1;
    border-radius: 1rem;
    overflow: hidden;
    background: linear-gradient(135deg, var(--teal-100), var(--cyan-100));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Placeholder */
.card-image-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--teal-400);
    gap: 0.5rem;
}

.card-image-placeholder svg {
    width: 3rem;
    height: 3rem;
}

.card-image-placeholder span {
    font-size: 1rem;
    font-weight: 600;
}

/* Tap hint */
.card-hint {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--teal-600);
    text-align: center;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tap-icon {
    animation: tapPulse 1.5s ease-in-out infinite;
}

@keyframes tapPulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.2); opacity: 1; }
}

/* Word on back */
.card-word {
    font-size: clamp(1.75rem, 3.5vw, 4rem);
    font-weight: 900;
    text-align: center;
    margin-bottom: 1rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
    line-height: 1.15;
    word-break: break-word;
    hyphens: none;
}

/* Audio button */
.card-audio-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 3px solid rgba(255,255,255,0.5);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.card-audio-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.15);
    border-color: white;
}

.card-audio-btn.playing {
    animation: audioPulse 0.5s ease infinite;
}

@keyframes audioPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ========================================
   Footer
   ======================================== */
.footer {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.95);
    border-top: 2px solid var(--teal-200);
    text-align: center;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.footer p {
    font-size: 1rem;
    color: var(--slate-500);
    font-weight: 600;
}

/* ========================================
   Completion Overlay
   ======================================== */
.completion-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.completion-overlay.visible {
    display: flex;
    opacity: 1;
}

.completion-content {
    background: white;
    border-radius: 2rem;
    padding: 3rem 4rem;
    text-align: center;
    box-shadow: var(--shadow-xl);
    transform: scale(0.8);
    transition: transform 0.3s ease;
    max-width: 90%;
}

.completion-overlay.visible .completion-content {
    transform: scale(1);
    animation: completionBounceIn 0.5s ease;
}

@keyframes completionBounceIn {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.completion-emoji {
    font-size: 5rem;
    margin-bottom: 1rem;
}

.completion-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--slate-800);
    margin-bottom: 1rem;
}

.completion-message {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--slate-600);
    margin-bottom: 2rem;
}

.completion-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.completion-buttons .retry-btn,
.completion-buttons .home-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 2rem;
    border-radius: 1rem;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.completion-buttons .retry-btn {
    background: linear-gradient(135deg, var(--teal-400), var(--teal-600));
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
}

.completion-buttons .retry-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-xl);
}

.completion-buttons .home-btn {
    background: white;
    color: var(--slate-700);
    border: 3px solid var(--slate-300);
}

.completion-buttons .home-btn:hover {
    border-color: var(--teal-400);
    color: var(--teal-600);
    transform: scale(1.05);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 1200px) {
    .control-btn span {
        display: none;
    }
    
    .control-btn {
        padding: 0.75rem;
    }
    
    .card-word {
        font-size: 3.25rem;
    }
}

@media (max-width: 1024px) {
    .flashcards-grid {
        gap: 1rem;
    }
    
    .card-word {
        font-size: 3rem;
    }
    
    .card-hint {
        font-size: 1rem;
    }
}

@media (max-width: 768px) {
    /* Mobile: allow scroll so all 10 cards are reachable */
    html, body {
        height: auto;
        overflow-y: auto;
    }

    .app {
        min-height: 100dvh;
    }

    .header {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        position: sticky;
        top: 0;
    }
    
    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-right {
        flex-shrink: 0;
        justify-content: flex-end;
    }
    
    .main-title {
        font-size: 1.5rem;
    }

    .theme-badge {
        font-size: 0.8rem;
        padding: 0.35rem 0.75rem;
    }
    
    .flashcards-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: auto;
        gap: 0.75rem;
    }

    .flashcard {
        min-height: 160px;
    }

    .flashcard-inner {
        min-height: 160px;
    }
    
    .card-word {
        font-size: clamp(1.5rem, 6vw, 2.25rem);
    }

    .progress-container {
        padding: 0.5rem 1rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 1rem;
    }
    
    .flashcards-grid {
        gap: 0.5rem;
    }
    
    .card-face {
        padding: 0.75rem;
    }
    
    .card-word {
        font-size: clamp(1.25rem, 5vw, 2rem);
    }
    
    .card-audio-btn {
        width: 3rem;
        height: 3rem;
    }
}

/* ========================================
   V4 RESPONSIVE CLIP/SCROLL SAFETY PATCH
   Same principle as Definitions V4:
   shrink first, then scroll the real content area instead of clipping.
   This patch is intentionally last so it wins the cascade.
   ======================================== */
@media (min-width: 900px) {
    html,
    body {
        min-height: 100dvh;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app {
        min-height: 100dvh;
    }

    .main-content {
        min-height: 0;
        overflow: visible;
    }

    .flashcards-grid {
        min-height: 0;
    }

    .header,
    .footer {
        flex-shrink: 0;
    }
}

/* Flashcards already had page scrolling; this only compresses the grid on short classroom screens. */
@media (min-width: 900px) and (max-height: 1100px) {
    .header {
        padding-top: clamp(0.6rem, 0.9vh, 1rem);
        padding-bottom: clamp(0.6rem, 0.9vh, 1rem);
    }

    .main-content {
        padding-top: clamp(0.75rem, 1.2vh, 1.25rem);
        padding-bottom: clamp(0.75rem, 1.2vh, 1.25rem);
        gap: clamp(0.6rem, 1vh, 0.9rem);
    }

    .flashcards-grid {
        gap: clamp(0.75rem, 1vw, 1.15rem);
    }

    .flashcard {
        min-height: clamp(145px, 19vh, 200px);
    }

    .card-face {
        padding: clamp(0.85rem, 1.5vh, 1.2rem);
    }

    .card-word {
        font-size: clamp(1.4rem, 3.4vh, 2.75rem);
        line-height: 1;
    }

    .card-hint {
        font-size: clamp(0.8rem, 1.6vh, 1rem);
    }
}

@media (min-width: 900px) and (max-height: 820px) {
    .flashcard {
        min-height: 125px;
    }

    .flashcards-grid {
        gap: 0.65rem;
    }

    .footer {
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }
}

@media (min-width: 900px) and (max-height: 720px) {
    .main-content {
        padding: 0.5rem 1.25rem;
    }

    .flashcard {
        min-height: 105px;
    }

    .card-word {
        font-size: clamp(1.2rem, 4vh, 2rem);
    }
}
