/* General Body and Base Styles */
body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #1a0033; /* Dark purple background */
    color: #e0e0e0; /* Light grey text */
    overflow-x: hidden; /* Prevent horizontal scrollbar */
    font-size: 16px;
}

/* Base variables for default theme (can be overridden by theme classes) */
:root {
    --primary-color: #8a2be2; /* BlueViolet - for highlights, buttons */
    --secondary-color: #4b0082; /* Indigo - for deeper accents */
    --accent-color: #ff00ff; /* Magenta - for neon glow/borders */
    --text-color: #e0e0e0;
    --background-color: #1a0033;
    --card-background: #330066;
    --border-color: #6a0dad;
    --button-bg: var(--primary-color);
    --button-text: #ffffff;
    --neon-glow: 0 0 5px var(--accent-color), 0 0 10px var(--accent-color), 0 0 15px var(--accent-color), 0 0 20px var(--accent-color);
    --text-shadow-glow: 0 0 5px var(--accent-color);
}

/* Screen Management */
.game-screen {
    width: 100%;
    max-width: 480px; /* Standard phone width */
    height: 100vh; /* Full viewport height */
    max-height: 850px; /* Limit height for larger screens */
    background-color: var(--background-color);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    border: 2px solid var(--border-color); /* Subtle border for screens */
    border-radius: 15px;
    overflow-y: auto; /* Enable scrolling if content exceeds height */
}

.game-screen.hidden {
    display: none;
}

/* --- Shared Components --- */
h1, h2, h3 {
    color: var(--accent-color);
    text-shadow: var(--text-shadow-glow);
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 2.5em;
    margin-top: 30px;
}

h2 {
    font-size: 2em;
}

p {
    color: var(--text-color);
    text-align: center;
    line-height: 1.5;
}

/* Buttons General Style */
.main-btn, .menu-btn, .action-btn, .icon-btn, .theme-option, .nav-arrow-btn {
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 8px;
    padding: 12px 25px;
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    box-shadow: var(--neon-glow); /* Apply neon glow to buttons */
}

.main-btn:hover, .menu-btn:hover, .action-btn:hover, .icon-btn:hover, .theme-option:hover, .nav-arrow-btn:hover {
    background-color: #9932cc; /* Darker purple on hover */
    transform: translateY(-2px);
    box-shadow: 0 0 8px var(--accent-color), 0 0 15px var(--accent-color), 0 0 25px var(--accent-color);
}

.main-btn:active, .menu-btn:active, .action-btn:active, .icon-btn:active, .theme-option:active, .nav-arrow-btn:active {
    transform: translateY(0);
    box-shadow: var(--neon-glow);
}

.main-btn:disabled, .menu-btn:disabled, .action-btn:disabled, .icon-btn:disabled, .theme-option:disabled, .nav-arrow-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* Icon Buttons */
.icon-btn {
    background: none;
    border: 1px solid var(--border-color);
    padding: 8px 15px;
    font-size: 1em;
    color: var(--text-color);
    box-shadow: none; /* No neon glow by default for subtle icon buttons */
}

.icon-btn:hover {
    color: var(--accent-color);
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 5px var(--accent-color);
}

.icon-btn i {
    margin-right: 5px;
}

.ecp-display {
    font-size: 1.2em;
    font-weight: bold;
    color: #ffd700; /* Gold for ECP */
    text-shadow: 0 0 5px #ffd700;
    display: flex;
    align-items: center;
    gap: 5px;
}
.ecp-display span {
    color: #fff; /* White for the number itself */
}

/* Header Bar */
.header-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

/* Modals (Achievements, Themes) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 100; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.7); /* Black w/ opacity */
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex; /* Show when active */
}

.modal-content {
    background-color: var(--card-background);
    margin: auto;
    padding: 30px;
    border: 2px solid var(--border-color);
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 0 15px var(--accent-color);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.modal-content h3 {
    margin-top: 0;
    color: var(--accent-color);
    text-shadow: var(--text-shadow-glow);
    font-size: 1.8em;
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: var(--accent-color);
    text-decoration: none;
}

/* --- Intro Page Specific --- */
#intro-screen {
    justify-content: center;
    padding: 20px; /* Ensure consistent padding */
}

.intro-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    flex-grow: 1; /* Allow content to grow and push button down */
    justify-content: center; /* Center content vertically */
}

.intro-container h1 {
    font-size: 3em;
}

.intro-container p {
    font-size: 1.2em;
    max-width: 80%;
}

/* --- Game Menu / Hub Screen Specific --- */
#game-menu-screen .menu-content {
    flex-grow: 1; /* Allows content to take available space */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding-top: 20px;
}

#game-menu-screen .tagline {
    font-style: italic;
    color: var(--text-color);
    margin-bottom: 40px;
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 80%;
    max-width: 300px;
    margin-bottom: 40px;
}

.menu-btn {
    width: 100%;
    padding: 15px 20px;
    font-size: 1.2em;
}

.menu-btn i {
    margin-right: 10px;
}

.start-game-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-top: auto; /* Pushes to bottom */
    width: 100%;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.start-game-section p {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-color);
}

/* Achievements List */
#achievements-list {
    list-style: none;
    padding: 0;
    width: 100%;
    max-height: 300px; /* Limit height for scrolling */
    overflow-y: auto;
    background-color: #1a0033; /* Darker background for the list itself */
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

#achievements-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 1.1em;
}

#achievements-list li:last-child {
    border-bottom: none;
}

.achievement-text {
    color: var(--text-color);
}

.lock-icon, .check-icon {
    font-size: 1.4em;
    margin-left: 10px;
}

.lock-icon {
    color: #ffcc00; /* Yellow for lock */
}

.check-icon {
    color: #00ff00; /* Green for check */
}

/* Theme Options Grid */
#theme-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 columns */
    gap: 15px;
    width: 100%;
    padding: 10px;
}

.theme-option {
    padding: 15px;
    font-size: 1em;
    font-weight: bold;
    text-align: center;
    text-transform: capitalize;
    background-color: var(--primary-color);
    color: var(--button-text);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--neon-glow);
}

.theme-option:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px var(--accent-color);
}

/* --- Level & Puzzle Selection Screen Specific --- */
#level-selection-screen {
    justify-content: flex-start; /* Align content to top */
}

#level-selection-screen .header-bar {
    justify-content: space-between; /* ECP on left, Achievements on right */
}

#level-selection-screen .header-bar .ecp-display {
    margin-right: auto; /* Pushes achievements button to the right */
}

.level-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 20px 0;
    gap: 15px;
}

.level-navigation h2 {
    margin: 0;
    font-size: 2.2em;
    white-space: nowrap; /* Prevent "LEVEL 1" from wrapping */
}

.nav-arrow-btn {
    background: none;
    border: 2px solid var(--border-color);
    padding: 10px 15px;
    font-size: 1.5em;
    color: var(--accent-color);
    box-shadow: var(--neon-glow);
}

.nav-arrow-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 5 columns of puzzles */
    gap: 10px;
    width: 100%;
    padding: 10px;
    background-color: var(--card-background);
    border-radius: 10px;
    border: 2px solid var(--border-color);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    flex-grow: 1; /* Take up available space */
    overflow-y: auto; /* Enable scrolling if grid is too tall */
    max-height: 450px; /* Adjust as needed */
}

.puzzle-box {
    background-color: rgba(0,0,0,0.4); /* Darker background for uncompleted */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    height: 60px; /* Fixed height for boxes */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5em;
    font-weight: bold;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: inset 0 0 5px rgba(255,255,255,0.1);
}

.puzzle-box:hover:not(.locked):not(.completed) {
    background-color: rgba(var(--primary-color), 0.5);
    box-shadow: 0 0 8px var(--accent-color);
}

.puzzle-box.completed {
    background-color: #008000; /* Green for completed */
    color: #ffffff;
    border-color: #00ff00;
    box-shadow: 0 0 5px #00ff00, inset 0 0 8px #00ff00;
}

.puzzle-box.locked {
    background-color: #555; /* Grey for locked */
    color: #aaa;
    cursor: not-allowed;
    border-color: #777;
    position: relative;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

.puzzle-box.locked::after {
    content: '\f023'; /* Font Awesome lock icon */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    font-size: 2em;
    color: rgba(0,0,0,0.5);
    text-shadow: 1px 1px 2px rgba(255,255,255,0.2);
    z-index: 1;
}

.footer-buttons {
    margin-top: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
}

/* --- Game Play Screen Specific --- */
#game-play-screen {
    justify-content: flex-start; /* Align content to top */
    gap: 15px;
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.timer-display {
    font-size: 1.2em;
    font-weight: bold;
    color: #ff6347; /* Tomato Red for timer */
    text-shadow: 0 0 5px #ff6347;
}
.timer-display span {
    color: #fff;
}

.question-info {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding: 0 5px;
}

#question-counter {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-color);
}

.small-icon-btn {
    padding: 5px 10px;
    font-size: 0.9em;
    background-color: rgba(var(--primary-color), 0.5);
    border: 1px solid var(--border-color);
    box-shadow: none;
}
.small-icon-btn:hover {
    background-color: var(--primary-color);
    box-shadow: 0 0 5px var(--accent-color);
}

.puzzle-box-large {
    background-color: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 20px;
    width: 100%;
    min-height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 1.4em;
    font-weight: bold;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5), var(--neon-glow); /* Outer neon glow */
    margin: 20px 0;
}

#puzzle-sentence {
    margin: 0;
    color: var(--text-color);
}

.guess-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.guess-section label {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-color);
}

#guess-input {
    width: calc(100% - 40px);
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background-color: #220044;
    color: #fff;
    font-size: 1.2em;
    text-align: center;
    outline: none;
    box-shadow: inset 0 0 5px var(--accent-color);
}

#guess-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#submit-guess-btn {
    width: 100%;
    padding: 15px 0;
    font-size: 1.2em;
}

.feedback-message {
    font-size: 1.1em;
    font-weight: bold;
    margin-top: 10px;
    min-height: 20px; /* Reserve space to prevent layout shifts */
}

/* Feedback message colors (will be set by JS) */
.feedback-message.correct { color: #00ff00; text-shadow: 0 0 5px #00ff00; }
.feedback-message.wrong { color: #ff0000; text-shadow: 0 0 5px #ff0000; }
.feedback-message.hint { color: #ffff00; text-shadow: 0 0 5px #ffff00; }

.game-action-buttons {
    width: 100%;
    display: flex;
    justify-content: space-around;
    gap: 10px;
    margin-top: auto; /* Pushes to bottom */
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.action-btn {
    flex: 1 1 30%; /* Allow buttons to grow/shrink, minimum 30% width */
    padding: 12px 10px;
    font-size: 0.9em;
    white-space: nowrap; /* Prevent text wrapping inside button */
}

/* --- THEME STYLES (JavaScript will add these classes to the body) --- */

/* Dark Mode Theme */
body.theme-dark {
    --primary-color: #3f007d;
    --secondary-color: #2a0050;
    --accent-color: #00ffff; /* Cyan neon */
    --text-color: #f0f0f0;
    --background-color: #0d001a;
    --card-background: #1c0038;
    --border-color: #008080;
    --neon-glow: 0 0 5px var(--accent-color), 0 0 10px var(--accent-color);
    --text-shadow-glow: 0 0 3px var(--accent-color);
}

/* Light Mode Theme */
body.theme-light {
    --primary-color: #87cefa; /* LightSkyBlue */
    --secondary-color: #add8e6; /* LightBlue */
    --accent-color: #4169e1; /* RoyalBlue */
    --text-color: #333333;
    --background-color: #f0f8ff; /* AliceBlue */
    --card-background: #ffffff;
    --border-color: #87cefa;
    --button-bg: var(--primary-color);
    --button-text: #ffffff;
    --neon-glow: none; /* No neon glow in light mode */
    --text-shadow-glow: none;
}

/* Neon Theme (Exaggerated initial theme) */
body.theme-neon {
    --primary-color: #ff00ff; /* Magenta */
    --secondary-color: #00ffff; /* Cyan */
    --accent-color: #00ff00; /* Lime green neon */
    --text-color: #e0e0e0;
    --background-color: #000000; /* Pure black */
    --card-background: #1a001a;
    --border-color: #ff00ff;
    --button-bg: var(--primary-color);
    --button-text: #ffffff;
    --neon-glow: 0 0 10px var(--accent-color), 0 0 20px var(--accent-color), 0 0 30px var(--accent-color), 0 0 40px var(--accent-color);
    --text-shadow-glow: 0 0 5px var(--accent-color);
}

/* Forest Theme */
body.theme-forest {
    --primary-color: #228b22; /* ForestGreen */
    --secondary-color: #006400; /* DarkGreen */
    --accent-color: #a27c00; /* DarkGoldenrod (for text/highlights) */
    --text-color: #f5f5dc; /* Beige */
    --background-color: #0e2a0e; /* Very dark green */
    --card-background: #1c3c1c;
    --border-color: #2e8b57; /* SeaGreen */
    --button-bg: var(--primary-color);
    --button-text: #ffffff;
    --neon-glow: 0 0 5px var(--accent-color);
    --text-shadow-glow: 0 0 3px var(--accent-color);
}

/* Ocean Theme */
body.theme-ocean {
    --primary-color: #4682b4; /* SteelBlue */
    --secondary-color: #1e90ff; /* DodgerBlue */
    --accent-color: #00ced1; /* DarkTurquoise */
    --text-color: #e0f2f7; /* Light cyan */
    --background-color: #0a1f2e; /* Very dark blue */
    --card-background: #1c3855;
    --border-color: #6a5acd; /* SlateBlue */
    --button-bg: var(--primary-color);
    --button-text: #ffffff;
    --neon-glow: 0 0 5px var(--accent-color);
    --text-shadow-glow: 0 0 3px var(--accent-color);
}


/* Responsive Adjustments */
@media (max-width: 600px) {
    .game-screen {
        padding: 15px;
        border-radius: 0; /* Full width on smaller screens */
        max-width: 100%;
        min-height: 100vh;
        max-height: unset;
    }

    h1 {
        font-size: 2em;
    }

    h2 {
        font-size: 1.8em;
    }

    .main-btn, .menu-btn, .action-btn {
        font-size: 1em;
        padding: 10px 20px;
    }

    .puzzle-grid {
        grid-template-columns: repeat(4, 1fr); /* 4 columns on small screens */
        gap: 8px;
    }

    .puzzle-box {
        height: 55px;
        font-size: 1.3em;
    }

    .action-btn {
        flex: 1 1 45%; /* Max two buttons per row */
        padding: 10px 8px;
        font-size: 0.85em;
    }

    .modal-content {
        width: 95%;
        padding: 20px;
    }
}

@media (max-height: 700px) {
    .game-screen {
        max-height: unset; /* Allow full height on shorter screens */
        overflow-y: auto;
    }
}
