:root {
    --primary-hue: 250;

    /* DARK MODE (Default) - Strictly Dark Backgrounds */
    --lightness-bg: 10%;
    --lightness-text: 95%;

    --primary-color: hsl(var(--primary-hue), 80%, 65%);
    --secondary-color: hsl(calc(var(--primary-hue) + 60), 80%, 60%);

    /* Using specific lightness for deep dark mode feel */
    --bg-gradient: linear-gradient(135deg,
            hsl(var(--primary-hue), 60%, 12%) 0%,
            hsl(calc(var(--primary-hue) + 50), 60%, 10%) 100%);

    --glass-bg: rgba(0, 0, 0, 0.3);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);

    --text-main: hsl(0, 0%, 95%);
    --text-muted: hsl(0, 0%, 80%);

    --card-radius: 25px;
    --btn-radius: 20px;

    --font-family: 'Outfit', sans-serif;

    --success: #34D399;
    --error: #F87171;
    --warning: #FBBF24;
}

[data-theme="light"] {
    /* LIGHT MODE - Strictly Light Backgrounds */

    --bg-gradient: linear-gradient(120deg,
            hsl(var(--primary-hue), 90%, 96%) 0%,
            hsl(calc(var(--primary-hue) + 40), 90%, 92%) 100%);

    --primary-color: hsl(var(--primary-hue), 90%, 55%);
    --secondary-color: hsl(calc(var(--primary-hue) + 60), 90%, 50%);

    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 8px 32px 0 rgba(100, 100, 200, 0.05);

    --text-main: hsl(var(--primary-hue), 60%, 20%);
    --text-muted: hsl(var(--primary-hue), 40%, 40%);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-main);
    overflow-x: hidden;
    transition: background 0.5s ease;
    font-size: 18px;
    /* Increased base size */
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 15px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0 30px;
}

.logo {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -1px;
}

.logo span {
    color: var(--warning);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.score-pill {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 5px 15px;
    border-radius: 50px;
    font-weight: 500;
    backdrop-filter: blur(4px);
    transition: transform 0.2s;
}

.score-pill:hover {
    transform: scale(1.05);
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(15deg);
}

.icon-btn.mini {
    width: 32px;
    height: 32px;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.2);
}

.icon-btn.mini:hover {
    background: rgba(0, 0, 0, 0.4);
}

.icon-btn.mini:hover {
    background: rgba(0, 0, 0, 0.4);
}

/* Screens */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    animation: fadeIn 0.5s ease-out;
}

.screen.hidden {
    display: none;
}

/* Cards */
.card,
.hero-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--card-radius);
    padding: 30px;
    box-shadow: var(--glass-shadow);
    width: 100%;
}

.hero-card {
    text-align: center;
}

.hero-card h1 {
    margin-bottom: 10px;
    font-size: 2.5rem;
    line-height: 1.2;
}

.hero-card p {
    color: var(--text-muted);
    margin-bottom: 30px;
}

/* Mode Selection */
.mode-selection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.mode-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--btn-radius);
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    color: var(--text-main);
}

.mode-card:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-5px);
    border-color: var(--warning);
}

.mode-card .icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.mode-card h3 {
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.mode-card p {
    font-size: 0.8rem;
    margin: 0;
    opacity: 0.7;
}

/* Difficulty Selector */
.difficulty-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.toggle-group {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50px;
    padding: 4px;
}

[data-theme="light"] .toggle-group {
    background: rgba(255, 255, 255, 0.5);
}

.diff-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 8px 20px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.diff-btn.active {
    background: var(--text-main);
    color: var(--primary-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .diff-btn.active {
    background: var(--primary-color);
    color: white;
}

/* Game Screen */
.game-hud {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-weight: 700;
    font-size: 1.2rem;
}

.timer-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--glass-bg);
    padding: 5px 12px;
    border-radius: 20px;
    color: var(--text-main);
    /* Better contrast */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.timer-icon {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2.5px;
    fill: none;
    animation: pulse 1s infinite alternate;
}

.puzzle-area {
    width: 100%;
    margin: 10px 0 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.letter-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-bottom: 35px;
    min-height: 90px;
}

.letter-card {
    width: 60px;
    height: 70px;
    background: var(--glass-bg);
    border: 2px solid var(--glass-border);
    /* Thicker border */
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-main);
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.1);
    /* Chunky bottom shadow */
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s;
}

.letter-card:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
}

.input-area {
    width: 100%;
    max-width: 350px;
    position: relative;
    margin-bottom: 25px;
}

input[type="text"] {
    width: 100%;
    background: rgba(255, 255, 255, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: var(--btn-radius);
    padding: 18px 20px;
    font-size: 1.5rem;
    color: var(--text-main);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 4px;
    outline: none;
    transition: all 0.3s ease;
    font-weight: 700;
}

[data-theme="light"] input[type="text"] {
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-main);
    border-color: var(--primary-color);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

#header-home-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: rotate(0) scale(1.1);
    box-shadow: 0 0 15px var(--primary-color);
    border-color: transparent;
}

input[type="text"]:focus {
    background: var(--glass-bg);
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(118, 75, 162, 0.3);
}

input[type="text"].shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
    border-color: var(--error);
}

input[type="text"].success {
    border-color: var(--success);
    color: var(--success);
}

.message-area {
    height: 24px;
    font-size: 0.9rem;
    color: var(--warning);
    margin-bottom: 10px;
    text-align: center;
}

.game-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    margin-bottom: 10px;
}

#submit-btn {
    grid-column: span 2;
}

.game-btn,
.btn {
    border: none;
    padding: 15px;
    border-radius: var(--btn-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary {
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}

.game-btn:hover,
.btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.game-btn:active,
.btn:active {
    transform: translateY(0);
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    margin-top: 15px;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: underline;
    opacity: 0.7;
}

.text-btn:hover {
    opacity: 1;
}

.cost {
    font-size: 0.8em;
    opacity: 0.8;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal {
    max-width: 400px;
    width: 90%;
    padding: 40px;
    text-align: center;
    transform: translateY(0);
    animation: slideUp 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.modal h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 30px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
}

.stat-item label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.stat-item .value {
    font-size: 1.2rem;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

@keyframes pulse {
    from {
        opacity: 0.6;
    }

    to {
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .logo {
        font-size: 1.5rem;
    }

    .hero-card h1 {
        font-size: 2rem;
    }

    .letter-card {
        width: 40px;
        height: 50px;
        font-size: 1.2rem;
    }
}

/* Guide Modal */
.guide-card {
    max-width: 500px;
    text-align: left;
}

.guide-card h2 {
    text-align: center;
    margin-bottom: 30px;
}

.guide-steps {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
}

.step {
    display: flex;
    align-items: center;
    gap: 20px;
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 15px;
    transition: transform 0.2s;
}

.step:hover {
    transform: translateX(5px);
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .step {
    background: rgba(255, 255, 255, 0.4);
}

.step .icon {
    font-size: 2.5rem;
    min-width: 60px;
    text-align: center;
}

.step h3 {
    margin-bottom: 5px;
    color: var(--primary-color);
}

.step p {
    font-size: 0.9rem;
    opacity: 0.9;
    line-height: 1.4;
}