:root {
    --bg-color: #fcf9f2;
    --text-dark: #4a4a4a;
    --text-light: #ffffff;
    
    --gray: #94a3b8;   
    --blue: #4a90e2;    
    --red: #ef4444;     
    --green: #22c55e;   
    
    --tile-1: #F9F6F2; 
    --tile-2: #FEFEC5; 
    --tile-3: #FFD6A5; 
    --tile-4: #FF9689; 
    --tile-5: #D8796E; 
    
    --gold: linear-gradient(135deg, #ffd700, #ffec8b, #ffd700);
}

body {
    background-color: var(--bg-color);
    transition: background-color 1s ease;
    font-family: 'Quicksand', sans-serif;
    color: var(--text-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100dvh; 
    margin: 0;
    user-select: none;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

.reward-float {
    position: absolute;
    width: 100%;
    left: 0;
    text-align: center;
    color: #000000;
    font-weight: 900;
    font-size: 1.1rem;
    pointer-events: none;
    animation: floatUp 1.5s ease-out forwards;
    z-index: 1000;
    text-shadow: 1px 1px 0px rgba(255,255,255,0.7);
}

#timer { text-align: left; }
#solve-count { text-align: center; }
#score { text-align: right; }

#game-container {
    position: relative; 
    background: white;
    width: 480px; 
    max-width: 95vw; 
    min-height: 75dvh; 
    max-height: 88dvh; 
    border-radius: 24px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box; 
}

#stage {
    flex-grow: 1;
    min-height: 120px; 
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap; 
}

.tile {
    width: 70px;
    height: 70px;
    flex-shrink: 1; 
    min-width: 60px;
    min-height: 60px; 
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.2rem, 5vw, 1.5rem); 
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

#controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

/* --- Top Controls (Skip, Hint, Undo) --- */
.top-controls {
    display: flex;
    justify-content: center; /* Centers the buttons instead of stretching them apart */
    align-items: center;
    gap: 20px; /* Perfectly equal spacing between the squares */
}

#controls .top-controls button {
    flex: 0 0 auto; /* Completely stops them from stretching */
    width: 65px;    /* Matches the visual weight of the number tiles */
    height: 65px;
    padding: 0; 
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 16px; /* Matches the rounded corners of the tiles */
    font-size: 0.95rem; /* Keeps the text legible inside the square */
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); /* Adds a subtle depth to match tiles */
}

.op-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

#controls button {
    width: 100%;
    padding: 15px 0; 
}

.op-btn {
    font-size: clamp(2rem, 8vw, 2.5rem); 
    border-radius: 16px;
    padding: 10px 0;
}

header {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr; 
    align-items: center;
    font-size: clamp(0.9rem, 3.5vw, 1.1rem); 
    font-weight: 700;
    margin-bottom: 20px;
}

.tile.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

@media (max-width: 380px) {
    #stage {
        flex-wrap: wrap; 
        align-content: center;
    }
}

.tile:active { transform: scale(0.95); }
.tile.selected { outline: 3px solid #777; transform: scale(1.05); }

.combo-1 { background-color: var(--tile-1); color: var(--text-dark); }
.combo-2 { background-color: var(--tile-2); color: var(--text-dark); }
.combo-3 { background-color: var(--tile-3); color: var(--text-dark); }
.combo-4 { background-color: var(--tile-4); color: var(--text-dark); } 
.combo-5 { background-color: var(--tile-5); color: var(--text-light); } 

.gold { 
    background: var(--gold); 
    background-size: 200% 200%;
    animation: shine 2s infinite linear, pulse 1s infinite alternate;
    color: #8b6508; 
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.8), inset 0 0 10px rgba(255, 255, 255, 0.5);
    border: 2px solid #fff;
}

@keyframes shine {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

button {
    font-family: inherit;
    font-size: clamp(1rem, 4vw, 1.25rem); 
    font-weight: 700;
    border: none;
    border-radius: 12px;
    background: #f1f5f9;
    color: var(--text-dark);
    padding: 15px 20px;
    cursor: pointer;
}

button.selected-op { background: #cbd5e1; outline: 2px solid #94a3b8; }
button:active { background: #e2e8f0; }

.hidden { display: none !important; }

#game-over-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    z-index: 100;
}

#combo-count { 
    text-align: center; 
    color: #000000; 
}

/* FIX: Top Buttons Coloring */
#skip-btn { background: #FA8072; color: white; }
#hint-btn { background: #ffedd5; color: #c2410c; }
#undo-btn { background: #79BAEC; color: white; }

#skip-btn:hover { transform: scale(1.10); color: var(--red); }
#hint-btn:hover { transform: scale(1.10); color: #ea580c; }
#undo-btn:hover { transform: scale(1.10); }

#skip-btn:active, #hint-btn:active, #undo-btn:active {
    transform: scale(0.95);
}

/* FIX: Grays out unavailable abilities */
#skip-btn:disabled, #hint-btn:disabled {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(100%);
}

#menu-btn, #music-btn {
    position: absolute; 
    top: 20px;
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--gray);
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    z-index: 10;
}
#menu-btn { right: 20px; }
#music-btn { left: 20px; font-family: Arial, sans-serif; }

#music-btn.muted {
    text-decoration: line-through;
    text-decoration-thickness: 3px;
    opacity: 0.6; 
}

#menu-btn:hover, #music-btn:hover {
    transform: scale(1.15);
    color: var(--blue);
}

#menu-btn:active, #music-btn:active {
    transform: scale(0.95);
}

#hint-display {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--blue);
    text-align: center;
    margin-bottom: 10px;
    min-height: 1.5rem;
}

.modal-content ul { 
    list-style: none; 
    padding: 0; 
    margin-bottom: 20px; 
    text-align: left;
}

.modal-content li {
    padding: 5px 0;
    border-bottom: 1px solid #eee;
}

#header-titles {
    text-align: center;
    margin-bottom: 15px;
}

#header-titles h1 {
    margin: 0 0 5px 0;
    font-size: clamp(1.8rem, 6vw, 2.2rem);
    color: var(--text-dark);
}

.modal-content {
    background: white;
    padding: 25px; 
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 90%;            
    max-width: 450px;      
    max-height: 90dvh; 
    display: flex;
    flex-direction: column;
    overflow: hidden; 
}

.modal-scroll-area {
    flex: 1; 
    overflow-y: auto; 
    padding-right: 5px; 
    margin-bottom: 15px; 
    scrollbar-width: thin; 
}

.modal-scroll-area::-webkit-scrollbar { width: 6px; }
.modal-scroll-area::-webkit-scrollbar-thumb {
    background-color: var(--gray);
    border-radius: 10px;
}

#mode-selector {
    display: flex;
    flex-wrap: wrap;       
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

#leaderboard-list {
    flex: 1; 
    min-height: 50px; 
    overflow-y: auto; 
    padding-right: 10px; 
    margin-bottom: 20px;
}

#leaderboard-list::-webkit-scrollbar { width: 6px; }
#leaderboard-list::-webkit-scrollbar-thumb {
    background-color: var(--gray);
    border-radius: 10px;
}

.mode-btn {
    padding: 8px 16px;
    font-size: clamp(0.8rem, 3vw, 0.9rem);
    border-radius: 20px;
    background: #e2e8f0;
    color: var(--text-dark);
    border: 2px solid transparent;
}

.mode-btn.active {
    background: var(--blue);
    color: var(--text-light);
    border-color: #5c85b5;
    transform: scale(1.05);
}

#score-submission {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

#player-name {
    padding: 12px;
    border-radius: 12px;
    border: 2px solid var(--gray);
    font-family: inherit;
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

#player-name:focus { border-color: var(--blue); }
#submit-score-btn { background: var(--green); color: white; }
#submit-score-btn:active { background: #3a7a4d; }

#solution-display {
    background: #fff0f0;
    color: var(--red);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin: 15px 0;
    border: 1px dashed var(--red);
}

#solution-display strong {
    font-size: 1.1rem;
    letter-spacing: 1px;
    display: inline-block;
    margin-top: 5px;
}

body.tutorial-mode {
    background-color: #d1fae5 !important; 
    transition: background-color 1s ease;
}

.menu-actions {
    display: flex;
    flex-direction: row; 
    gap: 12px;
    margin-top: 25px;
    flex-shrink: 0;
}

.menu-actions button {
    flex: 1; 
    padding: 12px 10px;
    font-size: clamp(0.9rem, 3.5vw, 1.1rem);
}

#close-info-btn { background: var(--blue); color: white; }
#close-info-btn:active { background: #5c85b5; }
#quit-save-btn {
    background: #fff0f0;
    color: var(--red);
    border: 2px solid var(--red);
    font-size: 1rem;
}
#quit-save-btn:active { background: var(--red); color: white; }

footer {
    position: absolute;
    bottom: 15px;
    font-size: 0.85rem;
    color: #999;
    text-align: center;
    width: 100%;
    font-weight: 500;
}

#info-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    z-index: 200; 
}

.info-content { text-align: left; }
.info-content h2 { text-align: center; margin-top: 0; color: var(--text-dark); }
.info-content ul { padding-left: 20px; margin-bottom: 25px; list-style-type: disc; }
.info-content li {
    font-size: 0.95rem;
    margin-bottom: 12px;
    border-bottom: none; 
    color: #555;
    line-height: 1.4;
}

@keyframes floatUp {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(-50px); opacity: 0; }
}

#instruction-overlay {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--blue);
    text-align: center;
    margin-bottom: 10px;
}

#solution-display {
    background: #f8fafc; 
    padding: 15px;
    border-radius: 12px;
    margin: 15px 0;
    border: 2px solid #e2e8f0;
}

#solution-text {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.solution-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mini-tile {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.solution-op {
    color: var(--text-dark);
    font-weight: 900;
    font-size: 1.2rem;
    width: 15px; 
    text-align: center;
}

.end-game-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-shrink: 0; 
}

.end-game-actions button {
    flex: 1; 
    margin-top: 0; 
    padding: 12px 10px; 
    font-size: clamp(0.85rem, 3.5vw, 1.1rem); 
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

#restart-btn { background: var(--blue); color: white; }
#restart-btn:active { background: #5c85b5; }

#screenshot-btn {
    background: var(--tile-2); 
    color: var(--text-dark); 
    border: 2px solid #fef3c7; 
}
#screenshot-btn:active { background: #fef08a; }

#message-zone {
    min-height: 40px; 
    display: flex;
    flex-direction: column;
    justify-content: center;
}

body.challenge-mode {
    background: radial-gradient(circle at center, #a81640 0%, #150b16 50%, #000000 100%) !important;
}