:root {
    --header-offset: 104px;
    --bottom-bar-offset: 7rem;
    --fluid-h1: clamp(1.05rem, 2vw + 0.5rem, 1.35rem);
    --fluid-h2: clamp(1.1rem, 2.2vw + 0.45rem, 1.4rem);
    --fluid-word: clamp(1.25rem, 2.5vw + 0.5rem, 1.65rem);
    --fluid-sentence: clamp(0.95rem, 1.4vw + 0.5rem, 1.15rem);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #050811; }
::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: #334155; }

/* Mobile-first thin horizontal scrollbars without layout shift */
.no-scrollbar::-webkit-scrollbar { height: 4px; }
.no-scrollbar { scrollbar-width: thin; scrollbar-color: #1e293b transparent; }

body {
    background-color: #050811;
    background-image:
        radial-gradient(at 0% 0%, rgba(56, 189, 248, 0.09) 0px, transparent 45%),
        radial-gradient(at 100% 0%, rgba(168, 85, 247, 0.09) 0px, transparent 45%),
        radial-gradient(at 50% 100%, rgba(52, 211, 153, 0.06) 0px, transparent 50%);
    background-attachment: scroll; /* Mobile-first fast repaint */
    color: #f1f5f9;
    padding-bottom: var(--bottom-bar-offset);
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

/* Responsive Fluid Media (Images, Videos, Audio, Iframes, SVGs) */
img, video, iframe, canvas, svg {
    max-width: 100%;
    height: auto;
    display: block;
}
.fluid-media-frame {
    width: 100%;
    border-radius: 0.75rem;
    overflow: hidden;
    background: rgba(2, 6, 23, 0.8);
    border: 1px solid rgba(51, 65, 85, 0.5);
}
.fluid-media-frame img,
.fluid-media-frame video {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
}
.fluid-video-embed {
    aspect-ratio: 16 / 9;
    width: 100%;
    border: 0;
}

/* Fluid CSS Grid Layouts (Mobile-First Auto-Fill) */
.fluid-vocab-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.875rem;
}
.fluid-sentence-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.875rem;
}

/* Dynamic Sticky Module Navigation (Prevents Mobile Header Overlap) */
.sticky-module-nav {
    position: sticky;
    top: var(--header-offset, 0px);
    z-index: 30;
    transition: top 0.15s ease-out;
}

/* Memory Blur / Active Recall Flashcard Effect */
.memory-blur {
    filter: blur(9px);
    user-select: none;
    transition: filter 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}
.memory-blur:hover, .memory-blur.revealed {
    filter: blur(0px);
    user-select: auto;
}

/* Grammar SPOK Highlighting */
.spok-token {
    display: inline-block;
    padding: 0.18rem 0.55rem;
    margin: 0.12rem 0.08rem;
    border-radius: 0.5rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: 1px solid transparent;
    max-width: 100%;
}
.spok-S { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; border-color: rgba(56, 189, 248, 0.38); }
.spok-P { background: rgba(251, 113, 133, 0.16); color: #fda4af; border-color: rgba(251, 113, 133, 0.38); }
.spok-O { background: rgba(52, 211, 153, 0.16); color: #6ee7b7; border-color: rgba(52, 211, 153, 0.38); }
.spok-K { background: rgba(251, 191, 36, 0.16); color: #fde047; border-color: rgba(251, 191, 36, 0.38); }

.spok-dimmed { opacity: 0.22; transform: scale(0.96); }
.spok-focused { transform: translateY(-2px) scale(1.06); box-shadow: 0 0 18px currentColor; font-weight: 700; z-index: 10; }

/* Card Subtle Glow & Performance */
.neuro-card {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease;
    min-width: 0;
}
.neuro-card:hover {
    transform: translateY(-2px);
    background: rgba(22, 32, 58, 0.94);
}

/* Animations */
@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
    100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}
.speaking-active {
    animation: pulse-ring 1.2s infinite;
    background-color: rgba(56, 189, 248, 0.25) !important;
    color: #38bdf8 !important;
}

@keyframes pulse-mic {
    0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.75); }
    70% { box-shadow: 0 0 0 12px rgba(244, 63, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}
.mic-listening {
    animation: pulse-mic 1s infinite;
    background-color: rgba(244, 63, 94, 0.3) !important;
    color: #fda4af !important;
    border-color: #f43f5e !important;
}

@keyframes false-friend-glow {
    0%, 100% { box-shadow: 0 0 8px rgba(244, 63, 94, 0.35); }
    50% { box-shadow: 0 0 18px rgba(244, 63, 94, 0.75); }
}
.false-friend-badge {
    animation: false-friend-glow 2s infinite;
}

/* =====================================================================
   CSS MEDIA QUERIES (MOBILE-FIRST BREAKPOINTS & ACCESSIBILITY)
   ===================================================================== */
/* Small Mobile Phones (< 640px) */
@media (max-width: 639px) {
    :root {
        --bottom-bar-offset: 9.5rem;
    }
    .neuro-card {
        backdrop-filter: none; /* Faster mobile GPU compositing */
        -webkit-backdrop-filter: none;
        background: rgba(15, 23, 42, 0.96);
    }
    .sticky-table-col {
        max-width: 125px;
        min-width: 110px;
        font-size: 0.7rem;
    }
    .mobile-collapsible-closed {
        display: none !important;
    }
}

/* Tablets & Medium Screens (>= 640px) */
@media (min-width: 640px) {
    .fluid-vocab-grid {
        grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
        gap: 1rem;
    }
    .fluid-sentence-grid {
        grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
        gap: 1rem;
    }
}

/* Desktops & Large Screens (>= 1024px) */
@media (min-width: 1024px) {
    body {
        background-attachment: fixed;
    }
    .fluid-vocab-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 1.15rem;
    }
    .fluid-sentence-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1.15rem;
    }
}

/* Ultra-Wide Monitors (>= 1536px) */
@media (min-width: 1536px) {
    .fluid-vocab-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Respect User Reduced Motion Preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
