/* ========================================================
   BIBLIOMIND - LORD OF THE RINGS EDITION
   A Biblical puzzle game with Middle-earth aesthetics
   ======================================================== */

/* ========== FONTS ========== */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700;900&family=MedievalSharp&family=Spectral:ital,wght@0,400;0,600;0,700;1,400&display=swap');

/* ========== RESET & BASE ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ========== CSS VARIABLES - MIDDLE-EARTH PALETTE ========== */
:root {
    /* Core Colors */
    --parchment-light: #f4ead5;
    --parchment-dark: #d4c5a9;
    --ink-dark: #2d1810;
    --ink-medium: #4a3525;
    --gold-light: #f4d03f;
    --gold-dark: #c89f3f;
    --mithril: #b0c4de;
    --elven-green: #6b8e23;
    --dwarf-copper: #b87333;

    /* Rank Colors */
    --bronze: #cd7f32;
    --silver: #c0c0c0;
    --gold: #ffd700;
    --mithril-rank: #e0f2ff;
    --elven: #90ee90;

    /* UI Colors */
    --success: #6b8e23;
    --danger: #8b4513;
    --warning: #d4a017;
    --info: #5f9ea0;

    /* Shadows and Effects */
    --shadow-soft: rgba(45, 24, 16, 0.15);
    --shadow-medium: rgba(45, 24, 16, 0.3);
    --shadow-hard: rgba(45, 24, 16, 0.5);
    --glow-gold: rgba(244, 208, 63, 0.6);
    --glow-mithril: rgba(176, 196, 222, 0.6);
}

/* ========== PARCHMENT TEXTURE BACKGROUND ========== */
body {
    font-family: 'Spectral', 'Georgia', serif;
    background:
        /* Texture overlay */
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(45, 24, 16, 0.03) 2px,
            rgba(45, 24, 16, 0.03) 4px
        ),
        /* Aged paper effect */
        radial-gradient(
            ellipse at 30% 40%,
            rgba(244, 234, 213, 0.9) 0%,
            transparent 70%
        ),
        radial-gradient(
            ellipse at 70% 60%,
            rgba(212, 197, 169, 0.8) 0%,
            transparent 70%
        ),
        /* Base gradient */
        linear-gradient(
            135deg,
            #5d4e37 0%,
            #7d6e5d 50%,
            #5d4e37 100%
        );
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--ink-dark);
    padding: 20px;
    position: relative;
    overflow-x: hidden;
}

/* Animated background particles (floating dust) */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(2px 2px at 20% 30%, rgba(255, 255, 255, 0.3), transparent),
        radial-gradient(2px 2px at 60% 70%, rgba(255, 255, 255, 0.3), transparent),
        radial-gradient(1px 1px at 50% 50%, rgba(255, 255, 255, 0.3), transparent),
        radial-gradient(1px 1px at 80% 10%, rgba(255, 255, 255, 0.3), transparent);
    background-size: 200% 200%;
    animation: dustFloat 20s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes dustFloat {
    0%, 100% { background-position: 0% 0%, 100% 100%, 50% 50%, 80% 20%; }
    50% { background-position: 100% 100%, 0% 0%, 30% 70%, 20% 80%; }
}

/* ========== MAIN GAME CONTAINER ========== */
.game-container {
    width: 95%;
    max-width: 1000px;
    background:
        /* Paper texture */
        url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E"),
        linear-gradient(to bottom, var(--parchment-light), var(--parchment-dark));
    border-radius: 15px;
    box-shadow:
        0 0 0 3px var(--ink-dark),
        0 0 0 6px var(--gold-dark),
        0 20px 60px var(--shadow-hard),
        inset 0 0 100px rgba(244, 234, 213, 0.5);
    overflow: hidden;
    position: relative;
    border: 8px solid;
    border-image:
        repeating-linear-gradient(
            45deg,
            var(--gold-dark),
            var(--gold-dark) 10px,
            var(--gold-light) 10px,
            var(--gold-light) 20px
        ) 8;
    z-index: 1;
}

/* Decorative corner ornaments */
.game-container::before,
.game-container::after {
    content: '✦';
    position: absolute;
    font-size: 2rem;
    color: var(--gold-dark);
    z-index: 10;
    animation: glowPulse 3s ease-in-out infinite;
}

.game-container::before {
    top: 10px;
    left: 10px;
}

.game-container::after {
    top: 10px;
    right: 10px;
}

@keyframes glowPulse {
    0%, 100% {
        text-shadow: 0 0 5px var(--glow-gold), 0 0 10px var(--glow-gold);
        transform: scale(1);
    }
    50% {
        text-shadow: 0 0 10px var(--glow-gold), 0 0 20px var(--glow-gold);
        transform: scale(1.1);
    }
}

/* ========== HEADER ========== */
.header {
    background:
        linear-gradient(to bottom, rgba(45, 24, 16, 0.9), rgba(74, 53, 37, 0.95)),
        url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpattern id='wood' width='100' height='100' patternUnits='userSpaceOnUse'%3E%3Crect fill='%234a3525' width='100' height='100'/%3E%3Cpath d='M0,50 Q25,45 50,50 T100,50' stroke='%233a2515' fill='none' stroke-width='1'/%3E%3C/pattern%3E%3Crect fill='url(%23wood)' width='100' height='100'/%3E%3C/svg%3E");
    color: var(--gold-light);
    padding: 30px;
    text-align: center;
    position: relative;
    border-bottom: 4px solid var(--gold-dark);
    box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.3);
}

.header h1 {
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    font-weight: 900;
    margin-bottom: 10px;
    text-shadow:
        2px 2px 0 var(--ink-dark),
        4px 4px 10px rgba(0, 0, 0, 0.5),
        0 0 20px var(--glow-gold);
    letter-spacing: 4px;
    animation: titleShine 5s ease-in-out infinite;
}

@keyframes titleShine {
    0%, 100% { text-shadow: 2px 2px 0 var(--ink-dark), 4px 4px 10px rgba(0, 0, 0, 0.5), 0 0 20px var(--glow-gold); }
    50% { text-shadow: 2px 2px 0 var(--ink-dark), 4px 4px 10px rgba(0, 0, 0, 0.5), 0 0 30px var(--glow-gold), 0 0 40px var(--gold-light); }
}

.header .subtitle {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.1rem;
    opacity: 0.95;
    font-style: italic;
    color: var(--parchment-light);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
}

/* ========== STATS BAR WITH RANK AND GEMS ========== */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
    padding: 20px;
    background:
        linear-gradient(to bottom, rgba(212, 197, 169, 0.7), rgba(244, 234, 213, 0.7)),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 10px,
            rgba(45, 24, 16, 0.03) 10px,
            rgba(45, 24, 16, 0.03) 20px
        );
    border-bottom: 3px solid var(--gold-dark);
}

.stat-item {
    text-align: center;
    padding: 12px;
    background:
        linear-gradient(135deg, rgba(244, 234, 213, 0.9), rgba(212, 197, 169, 0.9));
    border-radius: 10px;
    border: 2px solid var(--ink-medium);
    box-shadow:
        0 4px 6px var(--shadow-soft),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    position: relative;
}

.stat-item::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, var(--gold-dark), var(--gold-light));
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.stat-item:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 12px var(--shadow-medium);
}

.stat-item:hover::before {
    opacity: 0.3;
}

.stat-label {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-medium);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.6rem;
    font-weight: bold;
    color: var(--ink-dark);
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
}

.hearts {
    font-size: 1.5rem;
    filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.3));
}

/* Gem Counter */
.gems-counter {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.gem-icon {
    font-size: 1.3rem;
    animation: gemSparkle 2s ease-in-out infinite;
}

@keyframes gemSparkle {
    0%, 100% { transform: scale(1) rotate(0deg); filter: brightness(1); }
    50% { transform: scale(1.15) rotate(5deg); filter: brightness(1.3); }
}

/* Rank Badge */
.rank-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: linear-gradient(135deg, var(--bronze), var(--gold));
    border-radius: 20px;
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ink-dark);
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.4);
    border: 2px solid var(--ink-dark);
}

.rank-badge.bronze { background: linear-gradient(135deg, #cd7f32, #e89654); }
.rank-badge.silver { background: linear-gradient(135deg, #c0c0c0, #e8e8e8); }
.rank-badge.gold { background: linear-gradient(135deg, #ffd700, #ffed4e); }
.rank-badge.mithril { background: linear-gradient(135deg, #b0c4de, #e0f2ff); }
.rank-badge.elven { background: linear-gradient(135deg, #90ee90, #c8ffc8); }

/* ========== GAME AREA ========== */
.game-area {
    padding: 30px;
    min-height: 450px;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 25px,
            rgba(45, 24, 16, 0.02) 25px,
            rgba(45, 24, 16, 0.02) 26px
        );
}

.screen {
    display: none;
    animation: fadeInParchment 0.6s ease-in-out;
}

.screen.active {
    display: block;
}

@keyframes fadeInParchment {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========== MENU SCREEN ========== */
.menu-screen {
    text-align: center;
}

.menu-screen h2 {
    font-family: 'Cinzel', serif;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--ink-dark);
    text-shadow: 2px 2px 4px var(--shadow-soft);
}

.menu-screen p {
    font-family: 'Spectral', serif;
    font-size: 1.15rem;
    margin-bottom: 30px;
    color: var(--ink-medium);
    line-height: 1.8;
}

/* ========== LEVEL MAP (ARCADE MODE) ========== */
.level-map {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
    margin: 30px 0;
    padding: 20px;
    background: rgba(212, 197, 169, 0.3);
    border-radius: 15px;
    border: 2px solid var(--ink-medium);
}

.level-node {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto;
    cursor: pointer;
    transition: all 0.3s ease;
}

.level-node-inner {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--parchment-dark), var(--parchment-light));
    border: 3px solid var(--ink-dark);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 1.3rem;
    box-shadow: 0 4px 8px var(--shadow-medium);
    transition: all 0.3s ease;
}

.level-node:hover .level-node-inner {
    transform: scale(1.15);
    box-shadow: 0 6px 15px var(--shadow-hard);
}

.level-node.completed .level-node-inner {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold-light));
    border-color: var(--gold-dark);
    box-shadow: 0 0 20px var(--glow-gold);
}

.level-node.completed::after {
    content: '✓';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 25px;
    height: 25px;
    background: var(--success);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    border: 2px solid var(--ink-dark);
}

.level-node.current .level-node-inner {
    background: linear-gradient(135deg, var(--mithril), var(--mithril-rank));
    border-color: var(--info);
    animation: currentLevelPulse 2s ease-in-out infinite;
}

@keyframes currentLevelPulse {
    0%, 100% {
        box-shadow: 0 0 10px var(--glow-mithril), 0 4px 8px var(--shadow-medium);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 25px var(--glow-mithril), 0 6px 12px var(--shadow-hard);
        transform: scale(1.05);
    }
}

.level-node.locked .level-node-inner {
    background: linear-gradient(135deg, #888, #aaa);
    border-color: #666;
    cursor: not-allowed;
    opacity: 0.6;
}

.level-node.locked::before {
    content: '🔒';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    z-index: 10;
}

.level-node.expert .level-node-inner {
    background: linear-gradient(135deg, #8b0000, #ff4500);
    border-color: #8b0000;
    box-shadow: 0 0 15px rgba(139, 0, 0, 0.6);
}

.level-node.expert::after {
    content: '⚔️';
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 1.2rem;
}

/* Path connector between nodes */
.level-node::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    width: 20px;
    height: 3px;
    background: var(--ink-medium);
    transform: translateY(-50%);
    z-index: -1;
}

.level-node:nth-child(5n)::before {
    display: none;
}

/* ========== BUTTONS ========== */
.btn {
    display: inline-block;
    padding: 15px 40px;
    margin: 10px;
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: 700;
    border: 3px solid var(--ink-dark);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow:
        0 4px 6px var(--shadow-medium),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.5s, height 0.5s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold-light));
    color: var(--ink-dark);
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow:
        0 8px 15px var(--shadow-hard),
        0 0 20px var(--glow-gold);
}

.btn-primary:active {
    transform: translateY(-1px) scale(1.02);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--dwarf-copper), #d4a76a);
    color: var(--parchment-light);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.btn-secondary:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow:
        0 8px 15px var(--shadow-hard),
        0 0 15px rgba(184, 115, 51, 0.6);
}

.btn-small {
    padding: 10px 25px;
    font-size: 0.95rem;
}

.btn-expert {
    background: linear-gradient(135deg, #8b0000, #ff4500);
    color: var(--parchment-light);
    border-color: #8b0000;
    animation: expertGlow 2s ease-in-out infinite;
}

@keyframes expertGlow {
    0%, 100% { box-shadow: 0 4px 6px var(--shadow-medium), 0 0 10px rgba(139, 0, 0, 0.5); }
    50% { box-shadow: 0 4px 6px var(--shadow-medium), 0 0 25px rgba(255, 69, 0, 0.8); }
}

/* ========== PUZZLE SCREEN ========== */
.puzzle-header {
    text-align: center;
    margin-bottom: 30px;
}

.puzzle-type {
    display: inline-block;
    padding: 10px 25px;
    background: linear-gradient(135deg, var(--gold-dark), var(--gold-light));
    color: var(--ink-dark);
    border-radius: 25px;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    margin-bottom: 15px;
    border: 2px solid var(--ink-dark);
    box-shadow: 0 4px 8px var(--shadow-medium);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.puzzle-question {
    font-family: 'Spectral', serif;
    font-size: 1.35rem;
    color: var(--ink-dark);
    margin: 20px 0;
    line-height: 1.7;
    padding: 20px;
    background: rgba(244, 234, 213, 0.6);
    border-left: 5px solid var(--gold-dark);
    border-radius: 5px;
    box-shadow: inset 0 1px 3px var(--shadow-soft);
}

.cipher-text {
    font-family: 'Courier New', monospace;
    font-size: 1.5rem;
    background:
        linear-gradient(135deg, var(--ink-dark), var(--ink-medium));
    color: var(--gold-light);
    padding: 25px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: center;
    letter-spacing: 3px;
    box-shadow:
        inset 0 2px 10px rgba(0, 0, 0, 0.5),
        0 4px 8px var(--shadow-medium);
    border: 3px solid var(--gold-dark);
}

.morse-text {
    font-family: 'Courier New', monospace;
    font-size: 2rem;
    background: linear-gradient(135deg, #34495e, #2c3e50);
    color: var(--gold-light);
    padding: 25px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: center;
    letter-spacing: 5px;
    box-shadow:
        inset 0 2px 10px rgba(0, 0, 0, 0.5),
        0 4px 8px var(--shadow-medium);
    border: 3px solid var(--gold-dark);
}

/* ========== MEMORY GRID ========== */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin: 20px 0;
}

.memory-card {
    padding: 20px;
    background: linear-gradient(135deg, var(--parchment-light), var(--parchment-dark));
    border: 3px solid var(--ink-dark);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 600;
    font-family: 'Spectral', serif;
    box-shadow: 0 4px 6px var(--shadow-soft);
}

.memory-card:hover {
    background: linear-gradient(135deg, #e8f4f8, var(--mithril));
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 6px 12px var(--shadow-medium);
}

.memory-card.matched {
    background: linear-gradient(135deg, var(--success), var(--elven-green));
    color: var(--parchment-light);
    border-color: var(--success);
    cursor: default;
    box-shadow: 0 0 15px rgba(107, 142, 35, 0.5);
}

/* ========== TRIVIA OPTIONS ========== */
.trivia-options {
    display: grid;
    gap: 15px;
    margin: 20px 0;
}

.trivia-option {
    padding: 18px 25px;
    background: linear-gradient(135deg, var(--parchment-light), var(--parchment-dark));
    border: 3px solid var(--ink-dark);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    font-size: 1.1rem;
    font-family: 'Spectral', serif;
    font-weight: 600;
    box-shadow: 0 3px 6px var(--shadow-soft);
}

.trivia-option:hover {
    background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
    transform: translateX(10px) scale(1.02);
    box-shadow: 0 5px 15px var(--shadow-medium);
    color: var(--ink-dark);
}

/* ========== INPUT FIELDS ========== */
.input-group {
    margin: 30px 0;
    text-align: center;
}

.answer-input {
    width: 100%;
    max-width: 550px;
    padding: 18px 25px;
    font-family: 'Spectral', serif;
    font-size: 1.3rem;
    border: 4px solid var(--ink-dark);
    border-radius: 10px;
    text-align: center;
    font-weight: 600;
    background: linear-gradient(to bottom, var(--parchment-light), white);
    transition: all 0.3s ease;
    box-shadow:
        inset 0 2px 4px var(--shadow-soft),
        0 2px 8px var(--shadow-soft);
}

.answer-input:focus {
    outline: none;
    border-color: var(--gold-dark);
    box-shadow:
        0 0 0 4px var(--glow-gold),
        inset 0 2px 4px var(--shadow-soft);
    transform: scale(1.02);
}

/* ========== TIMER ========== */
.timer {
    font-family: 'MedievalSharp', cursive;
    font-size: 2.2rem;
    font-weight: bold;
    color: var(--danger);
    text-align: center;
    margin: 20px 0;
    padding: 18px;
    background:
        linear-gradient(135deg, rgba(255, 228, 196, 0.8), rgba(255, 218, 185, 0.9));
    border-radius: 12px;
    border: 3px solid var(--danger);
    box-shadow: 0 4px 8px var(--shadow-medium);
    text-shadow: 2px 2px 4px var(--shadow-soft);
}

.timer.warning {
    animation: timerPulse 0.8s infinite;
}

@keyframes timerPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 8px var(--shadow-medium);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 6px 15px rgba(139, 69, 19, 0.6), 0 0 25px rgba(255, 0, 0, 0.4);
    }
}

/* ========== FEEDBACK OVERLAY ========== */
.feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    padding: 50px 70px;
    border-radius: 20px;
    font-family: 'Cinzel', serif;
    font-size: 2.5rem;
    font-weight: 900;
    z-index: 1000;
    box-shadow: 0 15px 50px var(--shadow-hard);
    transition: transform 0.4s ease;
    border: 4px solid;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.feedback.show {
    transform: translate(-50%, -50%) scale(1);
    animation: feedbackBounce 0.6s ease;
}

@keyframes feedbackBounce {
    0% { transform: translate(-50%, -50%) scale(0); }
    60% { transform: translate(-50%, -50%) scale(1.15); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

.feedback.correct {
    background: linear-gradient(135deg, var(--success), var(--elven-green));
    color: var(--parchment-light);
    border-color: var(--success);
    box-shadow: 0 15px 50px var(--shadow-hard), 0 0 30px rgba(107, 142, 35, 0.7);
}

.feedback.wrong {
    background: linear-gradient(135deg, var(--danger), #a0522d);
    color: var(--parchment-light);
    border-color: var(--danger);
    box-shadow: 0 15px 50px var(--shadow-hard), 0 0 30px rgba(139, 69, 19, 0.7);
}

/* ========== GAME OVER SCREEN ========== */
.game-over-screen {
    text-align: center;
}

.game-over-screen h2 {
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    font-weight: 900;
    color: var(--ink-dark);
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px var(--shadow-soft);
}

.final-score {
    font-family: 'MedievalSharp', cursive;
    font-size: 5rem;
    font-weight: bold;
    color: var(--gold-dark);
    margin: 25px 0;
    text-shadow:
        3px 3px 0 var(--ink-dark),
        5px 5px 15px var(--shadow-hard);
    animation: scoreReveal 1s ease-out;
}

@keyframes scoreReveal {
    from {
        opacity: 0;
        transform: scale(0.5) rotate(-10deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

.medal {
    font-size: 6rem;
    margin: 25px 0;
    animation: medalFloat 2s ease-in-out infinite;
    filter: drop-shadow(0 10px 20px var(--shadow-hard));
}

@keyframes medalFloat {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 35px 0;
}

.summary-item {
    padding: 25px;
    background: linear-gradient(135deg, rgba(244, 234, 213, 0.8), rgba(212, 197, 169, 0.8));
    border-radius: 12px;
    border: 3px solid var(--ink-medium);
    box-shadow: 0 4px 10px var(--shadow-soft);
}

.summary-label {
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink-medium);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.summary-value {
    font-family: 'MedievalSharp', cursive;
    font-size: 2rem;
    font-weight: bold;
    color: var(--ink-dark);
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
}

/* ========== CONTROLS ========== */
.controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 12px;
    z-index: 100;
}

.icon-btn {
    width: 45px;
    height: 45px;
    border: 3px solid var(--gold-dark);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--parchment-light), var(--parchment-dark));
    color: var(--ink-dark);
    cursor: pointer;
    font-size: 1.3rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px var(--shadow-medium);
}

.icon-btn:hover {
    background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
    transform: scale(1.15) rotate(10deg);
    box-shadow: 0 6px 15px var(--shadow-hard), 0 0 15px var(--glow-gold);
}

.icon-btn:active {
    transform: scale(1.05) rotate(5deg);
}

.lang-btn {
    width: 55px;
    height: 45px;
    border: 3px solid var(--gold-dark);
    border-radius: 10px;
    background: linear-gradient(135deg, var(--parchment-light), var(--parchment-dark));
    cursor: pointer;
    font-size: 1.6rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px var(--shadow-medium);
}

.lang-btn:hover {
    background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
    transform: scale(1.15);
    box-shadow: 0 6px 15px var(--shadow-hard), 0 0 15px var(--glow-gold);
}

.lang-btn:active {
    transform: scale(1.05);
}

/* ========== PARTICLES ========== */
.particle {
    position: fixed;
    pointer-events: none;
    font-size: 2rem;
    animation: particleFloat 2.5s ease-out forwards;
    z-index: 9999;
}

@keyframes particleFloat {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-150px) rotate(360deg) scale(0.5);
    }
}

/* Enhanced particle types */
.particle.star { content: '⭐'; }
.particle.sparkle { content: '✨'; }
.particle.magic { content: '🌟'; }
.particle.gem { content: '💎'; }
.particle.ring { content: '💍'; }
.particle.sword { content: '⚔️'; }
.particle.shield { content: '🛡️'; }

/* ========== HINT SYSTEM ========== */
.hint-box {
    background:
        linear-gradient(135deg, rgba(255, 243, 205, 0.9), rgba(255, 235, 180, 0.9));
    border-left: 5px solid var(--warning);
    border-radius: 8px;
    padding: 18px;
    margin: 20px 0;
    display: none;
    font-family: 'Spectral', serif;
    font-style: italic;
    box-shadow: 0 3px 10px var(--shadow-soft);
}

.hint-box.show {
    display: block;
    animation: hintSlide 0.4s ease-out;
}

@keyframes hintSlide {
    from {
        opacity: 0;
        transform: translateY(-15px);
        max-height: 0;
    }
    to {
        opacity: 1;
        transform: translateY(0);
        max-height: 200px;
    }
}

/* ========== COMBO INDICATOR ========== */
.combo-indicator {
    position: fixed;
    top: 25%;
    right: 30px;
    background: linear-gradient(135deg, var(--gold-dark), var(--gold-light));
    color: var(--ink-dark);
    padding: 18px 30px;
    border-radius: 50px;
    font-family: 'Cinzel', serif;
    font-weight: 900;
    font-size: 1.7rem;
    border: 3px solid var(--ink-dark);
    box-shadow:
        0 6px 20px var(--shadow-hard),
        0 0 30px var(--glow-gold);
    transform: translateX(250px);
    transition: transform 0.4s ease;
    z-index: 100;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.combo-indicator.show {
    transform: translateX(0);
    animation: comboShake 0.5s ease;
}

@keyframes comboShake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(0) rotate(-5deg); }
    75% { transform: translateX(0) rotate(5deg); }
}

/* ========== MODAL ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(45, 24, 16, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background:
        linear-gradient(to bottom, var(--parchment-light), var(--parchment-dark)),
        url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
    border-radius: 20px;
    padding: 45px;
    max-width: 550px;
    width: 90%;
    box-shadow:
        0 0 0 4px var(--ink-dark),
        0 0 0 8px var(--gold-dark),
        0 25px 70px var(--shadow-hard);
    transform: scale(0.8) translateY(-30px);
    transition: transform 0.4s ease;
    position: relative;
    border: 6px solid var(--gold-dark);
}

.modal-overlay.show .modal {
    transform: scale(1) translateY(0);
}

.modal-icon {
    font-size: 5rem;
    text-align: center;
    margin-bottom: 25px;
    animation: modalIconBounce 1s ease-in-out infinite;
}

@keyframes modalIconBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.modal-title {
    font-family: 'Cinzel', serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--ink-dark);
    text-align: center;
    margin-bottom: 18px;
    text-shadow: 1px 1px 2px var(--shadow-soft);
}

.modal-message {
    font-family: 'Spectral', serif;
    font-size: 1.15rem;
    color: var(--ink-medium);
    text-align: center;
    line-height: 1.7;
    margin-bottom: 35px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.modal-btn {
    padding: 14px 35px;
    font-family: 'Cinzel', serif;
    font-size: 1.05rem;
    font-weight: 700;
    border: 3px solid var(--ink-dark);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px var(--shadow-medium);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal-btn-primary {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold-light));
    color: var(--ink-dark);
}

.modal-btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px var(--shadow-hard), 0 0 20px var(--glow-gold);
}

.modal-btn-secondary {
    background: linear-gradient(135deg, #95a5a6, #bdc3c7);
    color: var(--ink-dark);
}

.modal-btn-secondary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px var(--shadow-hard);
}

/* ========== SCROLLBAR STYLING ========== */
::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: var(--parchment-dark);
    border-left: 2px solid var(--ink-medium);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, var(--gold-dark), var(--gold-light));
    border-radius: 6px;
    border: 2px solid var(--ink-dark);
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(to bottom, var(--gold-light), var(--gold-dark));
}

/* ========== RESPONSIVE DESIGN ========== */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .header h1 {
        font-size: 2rem;
        letter-spacing: 2px;
    }

    .header .subtitle {
        font-size: 0.95rem;
    }

    .stats-bar {
        padding: 15px;
        gap: 10px;
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-item {
        padding: 10px;
    }

    .stat-value {
        font-size: 1.3rem;
    }

    .game-area {
        padding: 20px;
        min-height: 350px;
    }

    .btn {
        padding: 12px 30px;
        font-size: 1rem;
        margin: 8px;
    }

    .puzzle-question {
        font-size: 1.15rem;
        padding: 15px;
    }

    .cipher-text,
    .morse-text {
        font-size: 1.2rem;
        padding: 18px;
    }

    .final-score {
        font-size: 3.5rem;
    }

    .medal {
        font-size: 4rem;
    }

    .level-map {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }

    .level-node {
        width: 60px;
        height: 60px;
    }

    .level-node-inner {
        font-size: 1rem;
    }

    .combo-indicator {
        right: 10px;
        font-size: 1.3rem;
        padding: 12px 20px;
    }

    .modal {
        padding: 30px 20px;
    }

    .modal-title {
        font-size: 1.6rem;
    }

    .modal-message {
        font-size: 1rem;
    }

    .controls {
        top: 15px;
        right: 15px;
        gap: 8px;
    }

    .icon-btn {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .lang-btn {
        width: 45px;
        height: 40px;
        font-size: 1.4rem;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.6rem;
    }

    .stats-bar {
        grid-template-columns: 1fr 1fr;
    }

    .level-map {
        grid-template-columns: repeat(2, 1fr);
    }

    .memory-grid {
        grid-template-columns: 1fr;
    }

    .answer-input {
        font-size: 1.1rem;
        padding: 14px 20px;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    body {
        background: white;
    }

    .game-container {
        box-shadow: none;
        border: 2px solid black;
    }

    .controls,
    .btn,
    .timer,
    .combo-indicator {
        display: none;
    }
}

/* ========== ANIMATIONS LIBRARY ========== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInFromBottom {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-3deg); }
    75% { transform: rotate(3deg); }
}

/* ========== ACCESSIBILITY ========== */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus styles for keyboard navigation */
button:focus,
.btn:focus,
.trivia-option:focus,
.memory-card:focus,
input:focus {
    outline: 3px solid var(--gold-light);
    outline-offset: 3px;
}

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

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --parchment-light: #ffffff;
        --parchment-dark: #f0f0f0;
        --ink-dark: #000000;
        --gold-dark: #000000;
    }

    .btn,
    .stat-item,
    .puzzle-type {
        border-width: 4px;
    }
}

/* ========== END OF STYLES ========== */
