/* CSS Variables for Theming */
:root {
    /* 70s Light Theme */
    --bg-primary: #F5E6D3;
    --bg-secondary: #E8D5B7;
    --bg-card: #FEFAE0;
    --bg-card-selected: #F4A460;
    --bg-card-solved: #DEB887;
    
    --text-primary: #4A4A4A;
    --text-secondary: #6B6B6B;
    --text-on-accent: #FFFFFF;
    
    --accent-primary: #D2691E;
    --accent-secondary: #CD853F;
    --accent-success: #8B7355;
    --accent-error: #A0522D;
    
    --border-color: #D2B48C;
    --shadow-color: rgba(139, 69, 19, 0.2);
    
    /* Difficulty Colors */
    --difficulty-light: #F0E68C;
    --difficulty-moderate: #FFB347;
    --difficulty-advanced: #FF6B6B;

    /* 70s Retro Palette for Solved Groups - Diverse Colors */
    --solved-color-1: #012D4E;  /* Deep Navy Blue */
    --solved-color-2: #028391;  /* Teal */
    --solved-color-3: #FAA698;  /* Coral Pink */
    --solved-color-4: #F85525;  /* Orange-Red */

    /* Font Families */
    --font-retro: 'Righteous', cursive;
    --font-casual: 'Kalam', cursive;
}

/* 80s Neon Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0F0F23;
    --bg-secondary: #1A1A2E;
    --bg-card: #16213E;
    --bg-card-selected: #E94560;
    --bg-card-solved: #533483;
    
    --text-primary: #FFFFFF;
    --text-secondary: #C9C9C9;
    --text-on-accent: #FFFFFF;
    
    --accent-primary: #F72585;
    --accent-secondary: #7209B7;
    --accent-success: #06FFA5;
    --accent-error: #FF006E;
    
    --border-color: #3A0CA3;
    --shadow-color: rgba(247, 37, 133, 0.4);
    
    --difficulty-light: #06FFA5;
    --difficulty-moderate: #FFBE0B;
    --difficulty-advanced: #FF006E;

    /* 80s Neon Bright Colors for Solved Groups - Diverse Colors */
    --solved-color-1: #FF006E;  /* Hot Pink */
    --solved-color-2: #7209B7;  /* Purple */
    --solved-color-3: #3A0CA3;  /* Deep Blue */
    --solved-color-4: #06FFA5;  /* Neon Green */
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: var(--font-casual);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    flex-direction: column;
}

#app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header Styles */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1.25rem;
    background-color: var(--bg-secondary);
    box-shadow: 0 2px 10px var(--shadow-color);
    flex-shrink: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.game-title {
    font-family: var(--font-retro);
    font-size: 1.4rem;
    color: var(--accent-primary);
    text-shadow: 2px 2px 4px var(--shadow-color);
    white-space: nowrap;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 50%;
    transition: background-color 0.3s ease;
    line-height: 1;
}

.icon-btn:hover {
    background-color: var(--bg-primary);
}

/* Daily progress — compact pills inline in header */
.daily-progress {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.daily-progress .progress-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.85rem;
    line-height: 1;
}

.daily-progress .progress-label {
    font-weight: 700;
    color: var(--text-primary);
}

.daily-progress .progress-status {
    font-size: 0.95rem;
}

/* Mode selector kept around for JS hooks only */
.mode-selector[hidden] { display: none !important; }

/* Game Container — fills remaining viewport, owns its own flex column */
.game-container {
    flex: 1;
    min-height: 0;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Game Info Bar */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: 10px;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.difficulty-badge {
    padding: 0.25rem 0.75rem;
    background-color: var(--difficulty-light);
    color: var(--text-primary);
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.9rem;
}

.lives-container {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.lives-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.lives-dots {
    display: flex;
    gap: 0.2rem;
}

.life-dot {
    font-size: 1.1rem;
    color: var(--text-secondary);
    transition: color 0.3s ease;
    line-height: 1;
}

.life-dot.active {
    color: var(--accent-error);
}

.score-display {
    font-size: 1rem;
    font-weight: bold;
}

.score-label {
    color: var(--text-secondary);
    margin-right: 0.4rem;
    font-weight: normal;
}

/* Play Area: solved groups stack above the grid, together filling available height */
.play-area {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Solved Groups */
.solved-groups {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex-shrink: 0;
}

.solved-group {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 1rem;
    border-radius: 10px;
    animation: slideDown 0.5s ease-out;
    box-shadow: 0 2px 8px var(--shadow-color);
    text-align: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Different colors for each solved group */
.solved-group:nth-child(1) {
    background-color: var(--solved-color-1);
}

.solved-group:nth-child(2) {
    background-color: var(--solved-color-2);
}

.solved-group:nth-child(3) {
    background-color: var(--solved-color-3);
}

.solved-group:nth-child(4) {
    background-color: var(--solved-color-4);
}

.solved-group-title {
    font-weight: bold;
    color: var(--text-on-accent);
    text-transform: uppercase;
    font-size: 0.85rem;
    white-space: nowrap;
}

.solved-group-words {
    color: var(--text-on-accent);
    opacity: 0.95;
    font-size: 0.78rem;
}

/* Game Grid — fills remaining vertical space in play-area; auto rows redistribute
   when groups are solved and cards removed (12 cards → 3 rows, etc.) */
.game-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 1fr;
    gap: 0.5rem;
}

.word-card {
    min-height: 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    font-size: clamp(0.7rem, 1.6vw, 1rem);
    font-weight: 600;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    word-break: break-word;
}

.word-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px var(--shadow-color);
}

.word-card.selected {
    color: var(--text-on-accent);
    transform: scale(1.05);
}

/* Preview color for ALL selected cards - shows next available solution color */
.word-card.selected.preview-color-1 {
    background-color: var(--solved-color-1);
    border-color: var(--solved-color-1);
}

.word-card.selected.preview-color-2 {
    background-color: var(--solved-color-2);
    border-color: var(--solved-color-2);
}

.word-card.selected.preview-color-3 {
    background-color: var(--solved-color-3);
    border-color: var(--solved-color-3);
}

.word-card.selected.preview-color-4 {
    background-color: var(--solved-color-4);
    border-color: var(--solved-color-4);
}

.word-card.shake {
    animation: shake 0.5s ease-out;
}

/* Action Buttons */
.game-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
    position: relative;
}

/* New Puzzle (casual mode) sits far left so it can't be hit by accident
   while reaching for Submit. Absolute so it doesn't shift the centered group. */
#new-puzzle-btn {
    position: absolute;
    left: 0;
}

.action-btn {
    font-family: var(--font-casual);
    font-size: 1rem;
    font-weight: bold;
    padding: 0.5rem 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: 22px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.action-btn.primary {
    background-color: var(--accent-primary);
    color: var(--text-on-accent);
    border-color: var(--accent-primary);
}

.action-btn.primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-btn.secondary {
    background-color: var(--bg-card);
    color: var(--text-primary);
}

.action-btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.3s ease-out;
}

.modal.show {
    display: block;
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 10% auto;
    padding: 2rem;
    border-radius: 20px;
    max-width: 500px;
    position: relative;
    animation: slideUp 0.3s ease-out;
    box-shadow: 0 10px 30px var(--shadow-color);
}

.close-modal {
    position: absolute;
    right: 1.5rem;
    top: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.close-modal:hover {
    color: var(--accent-error);
}

/* Auth Styles */
.auth-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
}

.auth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    border: 2px solid var(--border-color);
    background-color: var(--bg-card);
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

.divider {
    text-align: center;
    color: var(--text-secondary);
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

/* Leaderboard Styles */
.leaderboard-content {
    max-width: 600px;
}

.leaderboard-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 1.5rem 0;
}

.leaderboard-tab {
    padding: 0.5rem 1.5rem;
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.leaderboard-tab.active {
    background-color: var(--accent-primary);
    color: var(--text-on-accent);
    border-color: var(--accent-primary);
}

.leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background-color: var(--bg-card);
    border-radius: 8px;
    transition: background-color 0.3s ease;
}

.leaderboard-entry:hover {
    background-color: var(--bg-card-selected);
}

.leaderboard-entry.current-user {
    background-color: var(--accent-secondary);
    color: var(--text-on-accent);
}

.leaderboard-rank {
    font-weight: bold;
    min-width: 2rem;
}

.leaderboard-name {
    flex: 1;
    margin: 0 1rem;
}

.leaderboard-score {
    font-weight: bold;
    color: var(--accent-primary);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-header {
        padding: 0.4rem 0.6rem;
        gap: 0.5rem;
    }

    .game-title {
        font-size: 1.1rem;
    }

    .daily-progress {
        gap: 0.25rem;
    }

    .daily-progress .progress-item {
        padding: 0.2rem 0.45rem;
        font-size: 0.75rem;
        gap: 0.2rem;
    }

    .icon-btn {
        font-size: 1.1rem;
        padding: 0.25rem;
    }

    .game-container {
        padding: 0.5rem 0.6rem;
        gap: 0.5rem;
    }

    .game-info {
        padding: 0.35rem 0.6rem;
        font-size: 0.85rem;
    }

    .difficulty-badge {
        font-size: 0.8rem;
        padding: 0.2rem 0.55rem;
    }

    .lives-label, .score-label {
        font-size: 0.75rem;
    }

    .life-dot {
        font-size: 0.95rem;
    }

    .solved-group {
        padding: 0.4rem 0.6rem;
        gap: 0.4rem;
    }

    .solved-group-title {
        font-size: 0.7rem;
    }

    .solved-group-words {
        font-size: 0.65rem;
    }

    .game-grid {
        gap: 0.35rem;
    }

    .word-card {
        font-size: clamp(0.6rem, 3vw, 0.85rem);
        padding: 0.25rem;
        border-width: 1px;
    }

    .action-btn {
        font-size: 0.9rem;
        padding: 0.4rem 1rem;
    }
}

/* Narrow phones — let header wrap title above buttons */
@media (max-width: 420px) {
    .game-header {
        flex-wrap: wrap;
        justify-content: center;
    }

    .game-title {
        flex: 1 1 100%;
        text-align: center;
    }
}

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

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --bg-primary: #FFFFFF;
        --bg-secondary: #F0F0F0;
        --text-primary: #000000;
        --accent-primary: #0066CC;
    }
}
