/* ======= PREMIUM DESIGN TOKENS ======= */
:root {
    --primary: #58cc02; /* Duolingo Green */
    --primary-hover: #46a302;
    --secondary: #1cb0f6; /* Duolingo Blue */
    --secondary-hover: #1899d6;
    --accent: #ffc800; /* Duolingo Yellow */
    --accent-hover: #e5b300;
    --error: #ea2b2b;
    --text-dark: #3c3c3c;
    --text-muted: #777777;
    --border-color: #e5e5e5;
    
    --bg-gradient: #ffffff;
    --card-bg: #ffffff;
    
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: #e5e5e5;
    --glass-shadow: 0 4px 0 0 #e5e5e5; /* Duolingo style "tab" shadows */

    --card-radius: 16px;
    --btn-radius: 12px;
    --transition: all 0.2s ease;
    
    /* Skeleton Palette */
    --skeleton-bg: #f2f2f2;
    --skeleton-shimmer: linear-gradient(90deg, #f2f2f2 25%, #e6e6e6 50%, #f2f2f2 75%);
}

.main-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 32px;
    max-width: 1400px;
    margin: 40px auto;
    padding: 0 32px;
    align-items: start;
}

html {
    scroll-behavior: smooth;
}

/* ======= RESET & TYPOGRAPHY ======= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-dark);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
}

button {
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    border: none;
    outline: none;
    transition: var(--transition);
}

/* ======= ANIMATED BACKGROUND ======= */
.bg-animated {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 10s infinite ease-in-out alternate;
}

.blob-1 {
    top: -10%;
    left: -10%;
    width: 600px;
    height: 600px;
    background: rgba(79, 70, 229, 0.3);
    /* Primary */
    animation-delay: 0s;
}

.blob-2 {
    bottom: -10%;
    right: -10%;
    width: 500px;
    height: 500px;
    background: rgba(236, 72, 153, 0.3);
    /* Secondary */
    animation-delay: -2s;
}

.blob-3 {
    top: 40%;
    left: 40%;
    width: 400px;
    height: 400px;
    background: rgba(245, 158, 11, 0.2);
    /* Accent */
    animation-delay: -4s;
    animation-duration: 15s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(30px, 50px) scale(1.1);
    }
}

/* ======= SKELETON ANIMATIONS ======= */
.skeleton {
    background: #f5f5f5; /* Clean light grey */
    border-radius: 4px;
    display: block;
}

/* Thumbnail Fade-in Fix */
.thumb-img {
    opacity: 0;
    transition: opacity 0.35s ease;
}

.thumb-img.loaded {
    opacity: 1;
}

.skeleton-card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
}

.skeleton-thumb {
    width: 100%;
    aspect-ratio: 245/160;
    border-radius: 8px;
    display: block;
}

.skeleton-title {
    height: 18px;
    width: 80%;
}

.skeleton-subtitle {
    height: 14px;
    width: 50%;
}

/* ======= LANDING SECTIONS ======= */
.landing-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 64px auto;
    padding: 0 32px;
    gap: 64px;
}

.hero-text {
    flex: 1;
}

.hero-text h1 {
    font-size: 48px;
    line-height: 1.1;
    margin-bottom: 24px;
    color: var(--text-dark);
}

.hero-text p {
    font-size: 20px;
    color: var(--text-muted);
    margin-bottom: 32px;
    line-height: 1.5;
}

.hero-image-container {
    flex: 1.2;
    display: flex;
    justify-content: center;
}

.hero-image-container img {
    width: 100%;
    max-width: 600px;
    height: auto;
    filter: drop-shadow(0 20px 40px rgba(0,0,0,0.05));
}

.hero-actions {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.btn-duo {
    padding: 16px 32px;
    border-radius: 16px;
    font-size: 17px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 4px solid rgba(0,0,0,0.2);
    transition: all 0.1s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-duo:active {
    transform: translateY(2px);
    border-bottom-width: 0;
    margin-bottom: 4px;
}

.btn-duo-primary {
    background: var(--primary);
    color: white;
    border-color: #46a302;
}

.btn-duo-secondary {
    background: white;
    color: var(--secondary);
    border: 2px solid var(--border-color);
    border-bottom: 4px solid var(--border-color);
}

.features-section {
    background: #f7f7f7;
    padding: 80px 32px;
    border-top: 2px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
}

.features-container {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 48px;
}

.feature-item {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.feature-item img {
    width: 120px;
    height: 120px;
    margin-bottom: 24px;
}

.feature-item h3 {
    font-size: 20px;
    margin-bottom: 12px;
    color: var(--text-dark);
}

.feature-item p {
    color: var(--text-muted);
    line-height: 1.5;
}

/* ======= MODIFIED UI COMPONENTS ======= */
.glass-sidebar {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    box-shadow: none;
    position: sticky;
    top: 100px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.sidebar-header h3 {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-dark);
}

.accordion-item {
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    margin-bottom: 12px;
}

.accordion-item:last-child {
    border-bottom: none;
}

.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    cursor: pointer;
    transition: var(--transition);
}

.accordion-header h4 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dark);
}

.accordion-header .chevron {
    font-size: 20px;
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.accordion-item.active .chevron {
    transform: rotate(180deg);
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.accordion-item.active .accordion-content {
    max-height: 1000px;
    padding-bottom: 16px;
}

/* Custom Circle Checkboxes - Moved to index.html */


/* Grade Grid Styling */
.grade-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding-top: 8px;
}

.grade-btn {
    border: 1px solid #E2E8F0;
    background: white;
    padding: 10px 4px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.grade-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(79, 70, 229, 0.03);
}

.grade-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

.grade-btn.full-width {
    grid-column: 1 / -1;
}


.filter-sub {
    margin-left: 20px;
}

/* ======= MAIN CONTENT AREA ======= */
.glass-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 32px;
}

.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1.5px solid var(--primary);
    background: white;
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
}

.filter-badge span.material-icons-outlined {
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
}

.filter-badge span.material-icons-outlined:hover {
    color: var(--secondary);
    transform: scale(1.1);
}

.view-header h2 {
    font-size: 32px;
    margin-bottom: 4px;
    color: var(--text-dark);
}

.view-header p {
    color: var(--text-muted);
    font-size: 16px;
}

.search-wrapper {
    position: relative;
    width: 300px;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input {
    width: 100%;
    padding: 14px 16px 14px 48px;
    border-radius: 100px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    font-family: 'Nunito', sans-serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    box-shadow: var(--glass-shadow);
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

/* ======= GRID & CARDS ======= */
.premium-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.glass-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--card-radius);
    padding: 16px;
    box-shadow: 0 2px 0 0 var(--border-color);
    transition: var(--transition);
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
}

.glass-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 0 0 var(--border-color);
    background: #fcfcfc;
}

.card-media {
    width: 100%;
    height: 180px;
    border-radius: 16px;
    object-fit: cover;
    background: #fff;
    margin-bottom: 16px;
}

.card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    line-height: 1.3;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
}

.tag {
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.tag-primary {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
}

.tag-accent {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent);
}

/* Obsolete game styles removed */

.play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: var(--transition);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.glass-card:hover .play-overlay {
    opacity: 1;
}

.play-btn-glass {
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transform: scale(0.8) translateY(10px);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.play-btn-glass span {
    font-size: 36px;
    margin-left: 4px;
    /* Optical optical centering for play arrow */
}

.glass-card:hover .play-btn-glass {
    transform: scale(1) translateY(0);
}

/* ======= MODALS ======= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 24px;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.glass-modal {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

.modal-overlay.active .glass-modal {
    transform: translateY(0) scale(1);
}

/* Worksheet Modal Layout */
.worksheet-modal-content {
    max-width: 900px;
    padding: 40px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
}

.img-frame {
    background: white;
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: center;
}

.img-frame img {
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
}

.modal-info-col {
    display: flex;
    flex-direction: column;
}

.tags-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.modal-title {
    font-size: 32px;
    line-height: 1.2;
    margin-bottom: 16px;
    color: var(--text-dark);
}

.modal-desc {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-muted);
    flex: 1;
    margin-bottom: 32px;
}

.modal-actions {
    display: flex;
    gap: 16px;
}

.btn-primary,
.btn-secondary {
    padding: 14px 24px;
    border-radius: var(--btn-radius);
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.flex-btn {
    flex: 1;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-bottom: 4px solid #46a302;
}

.btn-primary:hover {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

.btn-secondary {
    background: white;
    color: var(--secondary);
    border: 2px solid var(--border-color);
    border-bottom: 4px solid var(--border-color);
}

.btn-secondary:hover {
    background: #f7f7f7;
}

.close-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.close-btn:hover {
    color: var(--secondary);
    transform: rotate(90deg);
}

.related-section {
    margin-top: 40px;
    padding-top: 32px;
    border-top: 1px solid var(--glass-border);
}

.related-section h3 {
    margin-bottom: 24px;
    font-size: 20px;
}

.related-scroller {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    padding-bottom: 16px;
}

.related-scroller::-webkit-scrollbar {
    height: 8px;
}

.related-scroller::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 10px;
}

.mini-card {
    min-width: 180px;
    width: 180px;
    padding: 12px;
}

.mini-card .card-media {
    height: 120px;
    margin-bottom: 12px;
}

.mini-card .card-title {
    font-size: 14px;
    margin: 0;
}

/* Game Modal Layout */
.game-modal-content {
    max-width: 1000px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.game-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
    background: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid var(--glass-border);
}

.game-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.game-icon {
    width: 40px;
    height: 40px;
    background: var(--accent);
    color: white;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-title-group h3 {
    font-size: 24px;
    color: var(--text-dark);
}

.game-modal-header .close-btn {
    position: static;
}

.iframe-container {
    flex: 1;
    background: #000;
}

.iframe-container iframe {
    width: 100%;
    height: 100%;
}

/* ======= EMPTY STATE ======= */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon-wrapper {
    width: 80px;
    height: 80px;
    background: rgba(226, 232, 240, 0.5);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    font-size: 40px;
    margin-bottom: 24px;
}

.empty-icon-wrapper span {
    font-size: 40px;
}

.empty-state h3 {
    font-size: 24px;
    margin-bottom: 12px;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 16px;
}

/* Responsiveness */
@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .glass-sidebar {
        position: static;
        margin-bottom: 24px;
    }

    .header-container {
        padding: 16px 20px;
    }

    .brand h1 {
        display: none;
    }

    .modal-grid {
        grid-template-columns: 1fr;
    }
}

/* --- NEW DETAIL PAGE REDESIGN --- */
.detail-back-btn-circle {
    width: 44px; height: 44px; border-radius: 50%; background: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08); border: 1px solid #eee;
    cursor: pointer; transition: all 0.2s; color: #666; margin-bottom: 24px;
}
.detail-back-btn-circle:hover { background: #f9f9f9; transform: scale(1.05); color: #333; }

.detail-breadcrumb-trail { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #888; margin-bottom: 24px; flex-wrap: wrap; }
.breadcrumb-cat { cursor: pointer; transition: color 0.2s; }
.breadcrumb-cat:hover { color: #514099; }
.breadcrumb-sep { color: #ccc; }
.breadcrumb-current { color: var(--primary); font-weight: 700; text-decoration: none; }

.detail-type-banner { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.detail-type-banner span.material-icons-outlined { font-size: 20px; color: #444; }
.detail-type-banner span.type-name { font-size: 16px; font-weight: 600; color: #444; }

.detail-main-title-large { font-size: 48px; font-weight: 800; color: #00BFA5; margin-bottom: 30px; letter-spacing: -1px; }

.detail-layout-grid { display: grid; grid-template-columns: 420px 1fr; gap: 50px; }
.detail-img-side { position: relative; }
.detail-img-frame { border-radius: 20px; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.1); border: 1px solid #f0f0f0; background: #fff; }
.detail-img-frame img { width: 100%; display: block; }

.detail-content-side { display: flex; flex-direction: column; gap: 24px; }
.detail-desc-text { font-size: 15px; color: #555; line-height: 1.6; }

.detail-action-row { display: flex; gap: 16px; margin: 10px 0; }
.btn-detail { padding: 14px 28px; border-radius: 50px; font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; border: 2px solid #514099; }
.btn-detail-outline { background: #fff; color: #514099; }
.btn-detail-outline:hover { background: #f0f4ff; }
.btn-detail-solid { background: #514099; color: #fff; }
.btn-detail-solid:hover { background: #2855b3; box-shadow: 0 4px 12px rgba(51, 102, 204, 0.2); }

.detail-meta-group { display: flex; flex-direction: column; gap: 12px; }
.meta-heading { font-size: 14px; font-weight: 600; color: #222; }
.pill-container { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-item { padding: 6px 16px; border-radius: 20px; font-size: 13px; font-weight: 500; color: #4a5568; background: #fff; border: 1.5px solid #e2e8f0; cursor: pointer; transition: all 0.2s; }
.pill-item:hover { border-color: #cbd5e0; background: #f8fafc; }

.related-header { font-size: 24px; font-weight: 700; color: #333; margin-bottom: 24px; }
.related-carousel-wrapper { 
    position: relative; 
    width: 100%;
    margin-top: 10px;
}
.carousel-track { 
    display: flex; 
    gap: 20px; 
    overflow-x: auto; 
    scroll-behavior: smooth; 
    padding: 10px 5px 30px; 
    scrollbar-width: none; 
    flex-wrap: nowrap; /* Ensure items stay in a row */
}
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-arrow { 
    width: 44px; 
    height: 44px; 
    border-radius: 50%; 
    background: #fff; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.15); 
    border: 1px solid #eee; 
    cursor: pointer; 
    position: absolute; 
    top: 50%; 
    z-index: 100; 
    transform: translateY(-50%); 
    transition: all 0.2s; 
    color: #514099; 
}
.carousel-arrow.prev { left: -22px; }
.carousel-arrow.next { right: -22px; }
.carousel-arrow:hover { background: #f0f4ff; transform: translateY(-50%) scale(1.1); }
.carousel-arrow:active { transform: translateY(-50%) scale(0.95); }

.related-item-card { width: 220px; flex-shrink: 0; background: #fff; border-radius: 16px; border: 1px solid #eee; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.04); transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); cursor: pointer; isolation: isolate; }
.related-item-card:hover { transform: translateY(-6px); box-shadow: 0 15px 30px rgba(0,0,0,0.1); }
.related-thumb { width: 100%; aspect-ratio: 4/3; background: #f7f7f7; overflow: hidden; display: flex; align-items: center; justify-content: center; position: relative; }
.related-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; }
.related-item-card:hover .related-thumb img { transform: scale(1.1); }
.related-info { padding: 16px; }
.related-title-text { font-size: 14px; font-weight: 700; color: #111; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.related-badge { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; color: #666; }
.related-badge .material-icons-outlined { font-size: 14px; color: #514099; }

@media (max-width: 900px) {
    .detail-layout-grid { grid-template-columns: 1fr; }
    .detail-img-side { max-width: 500px; margin: 0 auto; }
}

/* ======= CARD HOVER EFFECTS (USER PANEL) ======= */

/* ======= GRID & CARDS LAYOUT ======= */
.cards-row { 
    display: flex; 
    gap: 24px; 
    overflow-x: auto; 
    padding: 10px 0 20px; 
    scrollbar-width: none; 
}
.cards-row::-webkit-scrollbar { display: none; }

.ws-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); 
    gap: 24px; 
    padding-bottom: 30px; 
}

@media (max-width: 600px) {
    .ws-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

.ws-card,
.game-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    isolation: isolate;
    background: #fff;
    border: 1px solid #f0f0f5;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), 
                box-shadow 0.4s ease, 
                border-color 0.4s ease;
    cursor: pointer;
}

.game-card {
    width: 100%;
}

.ws-card {
    width: 100%;
}

@media (hover: hover) {
    .ws-card:hover,
    .game-card:hover {
        transform: translateY(-8px) scale(1.01);
        box-shadow: 0 25px 50px -12px rgba(81, 64, 153, 0.18),
                    0 10px 20px -5px rgba(0, 0, 0, 0.08);
        border-color: rgba(81, 64, 153, 0.1);
        z-index: 10;
    }
}

.ws-thumb,
.game-thumb {
    width: 100%;
    aspect-ratio: 3/2; /* Default aspect ratio for mobile/touch devices */
    position: relative;
    overflow: hidden;
    background: #f8f9fb;
}

.thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1),
                filter 0.4s ease;
    will-change: transform;
}

.ws-thumb .thumb-img {
    object-position: top center;
}

.game-thumb .thumb-img {
    object-position: center center;
}

@media (hover: hover) {
    .ws-card:hover .thumb-img,
    .game-card:hover .thumb-img {
        transform: scale(1.12);
        filter: brightness(1.05) saturate(1.05);
    }

    /* Premium Gradient Overlay on Hover */
    .ws-thumb::after,
    .game-thumb::after {
        content: '';
        position: absolute;
        inset: 0;
        background: linear-gradient(180deg, rgba(81, 64, 153, 0) 40%, rgba(81, 64, 153, 0.1) 100%);
        opacity: 0;
        transition: opacity 0.4s ease;
    }

    .ws-card:hover .ws-thumb::after,
    .game-card:hover .game-thumb::after {
        opacity: 1;
    }

    /* -- Shimmer Edge Accent -- */
    .ws-card::before,
    .game-card::before {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0;
        height: 4px;
        background: linear-gradient(90deg, #514099, #9b8fd4, #514099);
        background-size: 200% 100%;
        opacity: 0;
        transition: opacity 0.3s ease;
        z-index: 30;
        animation: premium-shimmer 2s linear infinite;
    }

    .ws-card:hover::before,
    .game-card:hover::before {
        opacity: 1;
    }
}

/* /* -- Action Badge Removed -- */
.ws-card::after,
.game-card::after {
    display: none !important;
}

@keyframes premium-shimmer {
    0%   { background-position: 200% center; }
    100% { background-position: -200% center; }
}

/* -- Info Section Polish -- */
.ws-info, .game-info {
    padding: 16px;
    background: #fff;
    transition: background 0.4s ease;
}

@media (hover: hover) {
    .ws-card:hover .ws-info,
    .game-card:hover .game-info {
        background: linear-gradient(to bottom, #f9f8ff, #fff);
    }

    .game-card:hover .game-title,
    .ws-card:hover .ws-title {
        color: #514099;
    }
}

.game-title, .ws-title {
    font-size: 15px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.4;
    margin-bottom: 4px;
    transition: color 0.3s ease;
    /* Limit to 2 lines for games, worksheets stay 1 line due to .ws-title class */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ws-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 1; /* Override the 2-line clamp from the shared class */
}

.game-sub, .ws-sub {
    font-size: 12.5px;
    color: #6b7280;
    line-height: 1.4;
}

/* ======= DETAIL PAGE SYSTEM (PREMIUM) ======= */
:root {
    --pref-purple: #5140a0;
    --pref-purple-light: #ede9ff;
    --pref-purple-border: rgba(81,64,160,0.15);
    --pref-gray: #6b7280;
    --pref-gray-light: #f3f4f6;
    --pref-bg: #ffffff;
    --pref-text: #111827;
}

#detail-page-view {
    display: none;
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
}

#detail-page-view.active {
    display: block;
}

.content-inner-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 48px 80px;
}

/* Back Button */
.detail-back-btn-circle {
    width: 42px;
    height: 42px;
    background: #e5e7eb;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-bottom: 24px;
    transition: all 0.2s;
    color: #4b5563;
}

.detail-back-btn-circle:hover {
    background: #d1d5db;
    transform: scale(1.05);
}

/* Breadcrumb */
.detail-breadcrumb-trail {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.breadcrumb-cat {
    cursor: pointer;
    transition: color 0.2s;
}

.breadcrumb-cat:hover {
    color: #514099;
    text-decoration: underline;
}

.breadcrumb-sep {
    color: #9ca3af;
    margin: 0 4px;
}

.breadcrumb-current {
    font-weight: 500;
}

/* Header Section */
.page-header {
    margin-bottom: 36px;
    animation: fadeUp 0.5s 0.15s ease both;
}

.page-header .category {
    font-size: 18px;
    font-weight: 500;
    color: #6b7280;
    margin-bottom: 4px;
}

.page-header .title {
    font-size: 44px;
    font-weight: 700;
    color: #514099;
    letter-spacing: -0.01em;
    line-height: 1.15;
    font-family: 'Nunito', sans-serif;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Content Grid */
.detail-content-grid {
    display: grid;
    grid-template-columns: 450px 1fr;
    gap: 64px;
    align-items: start;
    animation: fadeUp 0.5s 0.2s ease both;
    position: relative;
}

.detail-preview-col {
    width: 100%;
}

.detail-info-col {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.detail-preview-wrap {
    width: 100%;
    /* aspect-ratio: 692/547; Removed to allow dynamic height */
    background: #f8f9fb;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

.detail-preview-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e8e4f8 0%, #d5cff2 50%, #c9c2ee 100%);
}

.detail-preview-wrap img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.detail-description {
    font-size: 15px;
    color: #4b5563;
    line-height: 1.6;
}

.detail-description ul {
    padding-left: 1rem;
    margin-top: 12px;
    margin-bottom: 12px;
    list-style-type: disc;
}

.detail-description li {
    margin-bottom: 8px;
}

.detail-description li::marker {
    color: #514099; /* Match the purple theme */
}

.detail-description strong {
    color: #1f2937;
    font-weight: 700;
}

/* Meta Row */
.detail-meta-row {
    display: flex;
    gap: 32px;
    align-items: center;
    padding-top: 16px;
    flex-wrap: wrap;
}

.detail-meta-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.detail-meta-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--pref-gray);
}

.detail-meta-badge {
    border: 1px solid #e5e7eb;
    border-radius: 50px;
    padding: 6px 20px;
    font-size: 13px;
    color: var(--pref-purple);
    letter-spacing: 0.02em;
    background: #f5f3ff;
    transition: all 0.2s;
    cursor: default;
    font-weight: 600;
}

.detail-meta-badge:hover {
    background: #ede9fe;
    border-color: var(--pref-purple-border);
}

/* Action Buttons */
.detail-action-row {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.btn-detail-premium {
    padding: 14px 28px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
}

.btn-detail-solid {
    background: #514099;
    color: #fff;
    border: none;
    cursor: pointer;
}

.btn-detail-solid:hover {
    background: #433481;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(81, 64, 153, 0.3);
}

.btn-detail-outline {
    background: #fff;
    border: 1.5px solid #514099;
    color: #514099;
    cursor: pointer;
}

.btn-detail-outline:hover {
    background: #f5f3ff;
    transform: translateY(-2px);
}

.btn-detail-save {
    background: #fff;
    border: 1.5px solid #514099;
    color: #514099;
}

.btn-detail-save.saved {
    background: #514099;
    color: #fff;
}

.btn-detail-premium:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 25px -5px rgba(81, 64, 160, 0.3);
}

/* Right Column (Ads) */
.detail-right-col {
    display: flex;
    flex-direction: column;
    gap: 32px;
    position: sticky;
    top: 24px;
    align-self: start;
}

.detail-ad-block {
    width: 100%;
    height: 260px;
    background: var(--pref-gray-light);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}


.ad-label-design {
    position: relative;
    font-size: 20px;
    color: rgba(0,0,0,0.35);
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    letter-spacing: 0.05em;
    z-index: 1;
}

/* Related Resources */
.related-section {
    margin-top: 80px;
    padding-top: 40px;
    border-top: 1px solid var(--pref-gray-light);
}

.related-header {
    font-size: 22px;
    font-weight: 700;
    color: #333;
    margin-bottom: 32px;
}

.related-carousel-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 10px;
}

.carousel-track {
    display: flex;
    gap: 24px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    padding: 10px 0 20px;
    flex: 1;
    min-width: 0;
}

.carousel-track::-webkit-scrollbar { display: none; }

.related-item-card {
    flex: 0 0 280px;
    height: 320px;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    border: 1px solid #f0f0f0;
}

.related-item-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.1);
}

.carousel-arrow {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: #666;
    z-index: 25;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.carousel-arrow:hover {
    background: #f8f8f8;
    color: var(--pref-purple);
    border-color: var(--pref-purple);
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Adjustments */
@media (max-width: 900px) {
    .detail-content-grid {
        grid-template-columns: 1fr;
    }
    .detail-right-col {
        display: none;
    }
    .content-inner-wrapper {
        padding: 24px 20px;
    }
    .page-header .title {
        font-size: 32px;
    }
    .detail-action-row {
        gap: 12px;
    }
    .detail-meta-row {
        gap: 16px;
    }
    .btn-detail-premium {
        width: 100%; /* Stack on very small screens */
        justify-content: center;
        padding: 14px 20px;
    }
}

/* ======= SCROLL TO TOP ======= */
.scroll-top-btn {
    position: fixed;
    bottom: 36px;
    right: 36px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #e6e4dc;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    z-index: 2000;
}

.scroll-top-btn:hover {
    background: #d8d5c8;
    transform: translateY(-2px);
}

.scroll-top-btn svg {
    width: 18px;
    height: 22px;
    stroke: #6a6a6a;
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --- Playing Mode --- */
.playing-game .detail-breadcrumb-trail,
.playing-game .page-header,
.playing-game .detail-info-col,
.playing-game .related-section,
.playing-game #ad-carousel-container-bottom {
    display: none !important;
}

.playing-game .detail-content-grid {
    grid-template-columns: 1fr;
    gap: 0;
    margin: 0;
    padding: 0;
}

.playing-game .content-inner-wrapper {
    padding: 0px;
    max-width: 100%;
}

.playing-game .detail-preview-wrap {
    border-radius: 0px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    background: #000 !important;
    border: none !important;
}

#exit-game-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

/* --- Desktop Hover Effects --- */
@media (hover: hover) {
    .ws-info, .game-info {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 16px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
        transform: translateY(calc(100% - 85px));
        z-index: 10;
    }

    .ws-card:hover .ws-info,
    .game-card:hover .game-info {
        transform: translateY(0);
    }

    .card-hover-content {
        opacity: 0;
        transition: opacity 0.3s ease 0.1s;
        margin-top: 12px;
    }

    .ws-card:hover .card-hover-content,
    .game-card:hover .card-hover-content {
        opacity: 1;
    }

    .ws-card, .game-card {
        height: 320px;
        display: block;
        overflow: hidden;
        border-radius: 16px;
    }

    .ws-thumb, .game-thumb {
        width: 100%;
        height: 100% !important;
        aspect-ratio: auto !important;
    }
}

/* --- Mobile / Small Screen Behavior --- */
@media (max-width: 600px) {
    .ws-info, .game-info {
        position: relative;
        padding: 12px;
        background: #fff;
        transform: none !important;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .card-hover-content {
        display: none; /* Hide detailed hover info on mobile */
    }

    .ws-card, .game-card {
        height: auto !important;
        display: flex;
        flex-direction: column;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    }

    .ws-thumb, .game-thumb {
        height: auto !important;
        width: 100%;
        aspect-ratio: 3/2 !important; /* Force same 3:2 ratio on mobile */
        padding-top: 0 !important;
    }

    .ws-info, .game-info {
        padding: 10px;
    }

    .ws-title, .game-title {
        font-size: 14px;
        margin-bottom: 2px;
        line-height: 1.3;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ws-cat-label {
        font-size: 11px;
    }
}

.ws-cat-label {
    font-size: 13px;
    font-weight: 500;
    color: #5c6c7b;
    margin-bottom: 4px;
}

.card-short-desc {
    font-size: 12px;
    color: #718096;
    line-height: 1.5;
    margin-bottom: 12px;
}

.card-badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f5;
}

.card-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 800;
    color: #514099;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-badge.pages {
    color: #514099;
}

.card-badge span.material-icons-outlined {
    font-size: 16px;
    color: inherit;
}

.thumb-img {
    height: 100%;
}

/* PDF Dynamic Thumbnails Styles */
.pdf-thumbnails-container {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px dashed #e5e7eb;
}

.pdf-thumbnails-title {
    font-size: 13px;
    font-weight: 700;
    color: #4b5563;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pdf-thumbnails-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 4px 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(81, 64, 160, 0.2) transparent;
}

.pdf-thumbnails-list::-webkit-scrollbar {
    height: 6px;
}

.pdf-thumbnails-list::-webkit-scrollbar-track {
    background: transparent;
}

.pdf-thumbnails-list::-webkit-scrollbar-thumb {
    background-color: rgba(81, 64, 160, 0.2);
    border-radius: 3px;
}

.pdf-thumbnails-list::-webkit-scrollbar-thumb:hover {
    background-color: rgba(81, 64, 160, 0.4);
}

.pdf-thumbnail-item {
    position: relative;
    flex: 0 0 90px;
    aspect-ratio: 1 / 1.414; /* Portrait page ratio */
    border-radius: 8px;
    border: 2px solid #e5e7eb;
    background: #f9fafb;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.pdf-thumbnail-item:hover {
    transform: translateY(-4px);
    border-color: rgba(81, 64, 160, 0.4);
    box-shadow: 0 8px 16px rgba(81, 64, 160, 0.12);
}

.pdf-thumbnail-item.active {
    border-color: #514099;
    box-shadow: 0 0 0 2px rgba(81, 64, 160, 0.2), 0 8px 20px rgba(81, 64, 160, 0.16);
    transform: scale(1.02) translateY(-2px);
}

.pdf-thumbnail-canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pdf-thumbnail-canvas.loaded {
    opacity: 1;
}

.pdf-thumbnail-number {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(17, 24, 39, 0.7);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    backdrop-filter: blur(2px);
    z-index: 2;
}

.pdf-thumbnail-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: pdf-shimmer 1.5s infinite;
    z-index: 1;
}

@keyframes pdf-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.pdf-thumbnail-item.canvas-loaded .pdf-thumbnail-shimmer {
    display: none;
}

