:root {
    --primary: #FF6B6B;
    --primary-hover: #FF5252;
    --secondary: #4ECDC4;
    --secondary-hover: #45b7ae;
    --accent: #FFE66D;
    --bg-color: #F7F9FC;
    --text-color: #2D3436;
    --card-bg: rgba(255, 255, 255, 0.95);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    --radius: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background: #F7F9FC url('bg.png');
    background-size: 300px;
    background-repeat: repeat;
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10px 10px;
    /* Minimal padding */
    position: relative;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.1), rgba(78, 205, 196, 0.1));
    z-index: -1;
}

.app-container {
    width: 100%;
    max-width: 800px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius);
    padding: 20px;
    /* Reduced container padding */
    box-shadow: var(--shadow);
    text-align: center;
}

.topics-section {
    margin-bottom: 20px;
    animation: fadeIn 0.8s ease;
}

.topic-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #454d5d;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#topicsContainer {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    padding: 10px;
}

.topic-category-card {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 16px;
    padding: 10px;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.3);
    height: fit-content;
}

.topic-category-card:hover {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
}

.category-title {
    width: 100%;
    text-align: left;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    margin: 0 0 10px 0;
    padding: 12px 15px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.category-title:hover {
    background: white;
    border-color: rgba(0, 0, 0, 0.05);
    transform: none;
    /* Reset transform as card handles it */
}

.category-title::after {
    content: '+';
    font-size: 1.4rem;
    font-weight: 400;
    color: #999;
}

.category-title.active::after {
    content: '-';
    color: var(--primary);
}

.topics-grid.hidden {
    display: none !important;
}

.topics-grid {
    display: flex;
    justify-content: flex-start;
    /* Changed from center to align with text */
    gap: 8px;
    /* Slightly tighter gap */
    flex-wrap: wrap;
    padding: 0 5px 5px 5px;
}

.topic-bubble {
    background: white;
    padding: 6px 14px;
    /* Slightly smaller padding */
    border-radius: 50px;
    font-size: 0.95rem;
    /* Slightly smaller font */
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(0, 0, 0, 0.03);
    user-select: none;
}

.topic-bubble:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.08);
    /* Reduced shadow intensity */
    background: var(--accent);
    color: #444;
}

.topic-bubble:active {
    transform: translateY(0) scale(0.95);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

header {
    margin-bottom: 5px;
    position: relative;
}

.top-nav {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    margin-bottom: 20px;
    flex-wrap: wrap;
    width: 100%;
    z-index: 100;
}

@media (max-width: 600px) {
    .top-nav {
        justify-content: center;
    }
}

.lang-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.7);
    padding: 4px;
    border-radius: 50px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.lang-btn {
    border: none;
    background: transparent;
    padding: 8px 16px;
    border-radius: 40px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #666;
    white-space: nowrap;
}

.lang-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.about-link {
    background: rgba(255, 255, 255, 0.8);
    padding: 10px 20px;
    border-radius: 50px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 800;
    font-size: 0.85rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    white-space: nowrap;
}

.about-link:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    color: var(--primary-hover);
}

.title {
    font-size: 1.5rem;
    /* Even smaller title */
    font-weight: 800;
    color: white;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    margin-bottom: 5px;
}

.subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 20px;
}

#magicBtn {
    position: relative;
    z-index: 1;
}

#magicBtn::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    background: linear-gradient(135deg, #FF6B6B, #FFE66D, #4ECDC4);
    border-radius: 54px;
    z-index: -1;
    opacity: 0.4;
    filter: blur(12px);
    animation: glow 4s linear infinite;
    transition: opacity 0.3s ease;
}

#magicBtn:hover::after {
    opacity: 0.7;
    filter: blur(16px);
}

@keyframes glow {
    0% { filter: blur(10px); opacity: 0.4; }
    50% { filter: blur(20px); opacity: 0.6; }
    100% { filter: blur(10px); opacity: 0.4; }
}

.magic-btn {
    padding: 0 40px;
    height: 56px;
    background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 1.15rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(255, 107, 107, 0.4);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.magic-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        120deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    transition: all 0.6s;
}

.magic-btn:hover {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 12px 30px rgba(255, 107, 107, 0.5);
}

.magic-btn:hover::before {
    left: 100%;
}

.magic-btn:active {
    transform: translateY(-1px) scale(0.97);
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
}

#wordInput {
    width: 100%;
    min-height: 60px;
    /* Reduced from 120px */
    padding: 10px 15px;
    /* Reduced padding */
    border: 3px solid #eee;
    border-radius: 20px;
    font-size: 1.1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s ease;
    resize: vertical;
}

#wordInput:focus {
    border-color: var(--secondary);
}

.controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.styled-select {
    padding: 0 45px 0 25px;
    height: 56px;
    border-radius: 50px;
    border: 3px solid #f0f0f0;
    background: white;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    color: #444;
    outline: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23FF6B6B' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 20px center;
    background-size: 18px;
}

.styled-select:hover {
    border-color: var(--secondary);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.styled-select:focus {
    border-color: var(--primary);
}


.workbook-line {
    display: none;
    width: 80%;
    border-bottom: 2px dashed #ccc;
    height: 2rem;
    margin-top: 10px;
}

.workbook-active .voca-term {
    opacity: 0.3;
    /* Faint in browser, hidden in print */
}

@media print {
    .workbook-active .voca-term {
        display: none !important;
    }

    .workbook-active .workbook-line {
        display: block !important;
    }
}

.primary-btn {
    padding: 0 45px;
    height: 56px;
    background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(255, 107, 107, 0.4);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

.primary-btn:hover {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 12px 30px rgba(255, 107, 107, 0.5);
    filter: brightness(1.1);
}

.primary-btn:active {
    transform: translateY(0) scale(0.97);
}

.secondary-btn,
.game-btn {
    padding: 0 30px;
    height: 56px;
    border: none;
    border-radius: 50px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.secondary-btn {
    background: var(--secondary);
    color: white;
    box-shadow: 0 6px 15px rgba(78, 205, 196, 0.3);
}

.game-btn {
    background: #FF9F43;
    color: white;
    box-shadow: 0 6px 15px rgba(255, 159, 67, 0.3);
}

.secondary-btn:hover,
.game-btn:hover {
    transform: translateY(-3px);
    filter: brightness(1.05);
}



.game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-container {
    width: 90%;
    max-width: 600px;
    position: relative;
    padding: 40px !important;
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    font-size: 2rem;
    color: #999;
    cursor: pointer;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.game-image-wrapper {
    width: 200px;
    height: 200px;
    margin: 0 auto 30px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.game-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.letters-container,
.answer-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.letter-bubble {
    width: 50px;
    height: 50px;
    background: white;
    border: 3px solid var(--secondary);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.letter-bubble:hover {
    transform: scale(1.1);
    background: var(--secondary);
    color: white;
}

.answer-bubble {
    width: 50px;
    height: 50px;
    border-bottom: 4px solid var(--primary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    cursor: pointer;
    transition: background 0.2s;
}

.answer-bubble:hover {
    background: rgba(255, 107, 107, 0.05);
}

.clear-btn-bubble {
    border-color: #ff6b6b !important;
    background: #fff5f5;
}

.clear-btn-bubble:hover {
    background: #ff6b6b !important;
    color: white !important;
}

.game-feedback {
    min-height: 40px;
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 20px;
}

.feedback-success {
    color: #2ecc71;
    animation: bounce 0.5s ease;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.score-board {
    background: var(--accent);
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 800;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    margin-top: 30px;
}

.voca-card {
    background: white;
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: cardAppear 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes cardAppear {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.voca-card:hover {
    transform: translateY(-8px) rotate(1deg);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

.voca-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 15px;
    margin-bottom: 15px;
}

.voca-term {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-color);
    text-transform: capitalize;
    display: flex;
    align-items: center;
    gap: 10px;
}

.speaker-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
    line-height: 1;
}

.speaker-btn:hover {
    background: #f0f0f0;
}

@media print {
    .speaker-btn {
        display: none !important;
    }
}

.error-card {
    border: 2px dashed #ff6b6b;
    opacity: 0.8;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.error-reason {
    font-size: 0.8rem;
    color: #ff6b6b;
    margin-top: 10px;
}

/* Print Styles */
@media print {
    body {
        background: white !important;
        padding: 0;
    }

    .app-container {
        max-width: none;
        padding: 0;
        box-shadow: none;
        background: transparent;
        backdrop-filter: none;
    }

    .top-nav,
    header,
    .input-section,
    .topics-section,
    .result-actions,
    .history-section,
    footer {
        display: none !important;
    }

    .image-grid {
        display: grid !important;
        grid-template-columns: repeat(5, 1fr) !important;
        /* 5 columns for maximum density */
        gap: 8px !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .voca-card {
        page-break-inside: avoid;
        border: 1px solid #eee;
        border-radius: 6px;
        box-shadow: none;
        margin: 0;
        padding: 6px !important;
        /* Minimal padding */
        height: auto !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .voca-card img {
        width: 100% !important;
        max-height: 3.5cm;
        /* Limit image height to fit more rows */
        height: auto !important;
        margin-bottom: 2px !important;
        object-fit: contain;
    }

    .voca-term {
        font-size: 0.9rem !important;
        /* Compact text */
        margin-top: 2px !important;
    }
}

.hidden {
    display: none !important;
}

.result-section {
    margin-bottom: 50px;
    animation: fadeIn 0.5s ease-out;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-actions {
    margin-top: 30px;
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    animation: fadeIn 0.8s ease;
}

.loader {
    text-align: center;
}

/* Magic loader sparkles */
.sparkles {
    width: 50px;
    height: 50px;
    margin: 0 auto 15px;
    border: 5px solid rgba(78, 205, 196, 0.2);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: rotate 1s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.history-section h3 {
    color: white;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
}

.history-item {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease;
    aspect-ratio: 1;
}

.history-item:hover {
    transform: scale(1.05);
}

.history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

footer {
    margin-top: 40px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
}

.source-tag {
    display: inline-block;
    padding: 5px 12px;
    background: var(--accent);
    color: #555;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 5px;
}