@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;700&display=swap');


:root {
    --pink: #F72585;
    --purple-1: #7209B7;
    --purple-2: #560BAD;
    --purple-3: #480CA8;
    --blue-1: #3F37C9;
    --blue-2: #4361EE;
    --blue-3: #4CC9F0;
    --bg-dark: #120038;
    --bg-light: #120038;
    --text-light: #e0fbfc;
    --shadow-light: rgba(255, 255, 255, 0.2);
    --shadow-dark: rgba(0, 0, 0, 0.3);
}

/* --- Global & Mobile Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: 'Poppins', sans-serif; /* <-- UPDATED FONT */
    background: var(--bg-dark);
    color: var(--text-light);
    overflow: hidden;
    -webkit-user-select: none; /* Safari */
    -ms-user-select: none; /* IE 10+ */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none; /* Lock page on mobile */
}

/* --- Login/Register Page --- */
.login-register {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}
.form-container {
    background: var(--bg-light);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px var(--shadow-dark);
}
.form-container .logo { width: 150px; margin-bottom: 20px; }
.form-container h1 { margin-bottom: 20px; color: var(--blue-3); }
.form-container input {
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    border: none;
    background: var(--bg-dark);
    color: var(--text-light);
    font-size: 16px;
}
.form-container button {
    width: 100%;
    padding: 15px;
    border-radius: 8px;
    border: none;
    background: var(--pink);
    color: white;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.2s;
}
.form-container button:hover { transform: scale(1.05); }
.form-container a { color: var(--blue-3); text-decoration: none; display: block; margin-top: 15px; }
.form-container .error { color: var(--pink); margin-bottom: 15px; }

/* --- Loading Screen --- */
#loading-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.5s ease;
}
#loading-screen .logo {
    width: 200px;
    animation: zoomIn 0.8s ease-out forwards;
}
#loading-screen .tagline {
    margin: 20px 0;
    font-style: italic;
    color: var(--blue-3);
    font-size: 16px;
    letter-spacing: 1px;
    opacity: 0;
    animation: fadeIn 1s ease-out 0.5s forwards;
    max-width: 90%;
    text-align: center;
    line-height: 1.4;
    padding: 0 15px;
}
.spinner {
    border: 4px solid var(--shadow-light);
    border-top: 4px solid var(--pink);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- Game Layout --- */
#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 10px;
}
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 5px;
    padding-top: max(10px, env(safe-area-inset-top));
}
.game-logo { 
    width: 120px;
}

.score-box-link {
    text-decoration: none;
    color: inherit;
}
.score-box {
    background: var(--bg-light);
    padding: 10px 20px;
    border-radius: 10px;
    text-align: center;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s ease;
}
.score-box:hover {
    transform: scale(1.05);
}
.score-box div:first-child { font-size: 12px; color: var(--blue-3); }
.score-box div:last-child { font-size: 24px; color: white; }

main {
    flex-grow: 1;
    display: flex;
    align-items: flex-end; /* Pushes grid down to the bottom of this container */
    justify-content: center;
    padding-bottom: 15px; /* Adds spacing between grid and pieces */
}
#grid-container {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 95vw;
    height: 95vw;
    max-width: 480px;
    max-height: 480px;
    background: #2c2a4a;
    border: 2px solid var(--blue-1);
    border-radius: 10px;
}
.grid-cell {
    position: relative;
    border: 1px solid var(--bg-dark);
}

/* --- "Sexy" Shading on Blocks (UPDATED) --- */
.block {
    border-radius: 4px; /* Slightly more rounded */
    transform: scale(1.05); /* Make blocks slightly larger than cell */
    /* New box-shadow for a 3D effect */
    box-shadow: inset 2px 2px 4px rgba(255, 255, 255, 0.4), 
                inset -2px -2px 4px rgba(0, 0, 0, 0.4),
                0 0 10px var(--shadow-dark);
    transition: transform 0.1s ease;
}
/* More vibrant gradients and new colors */
.color-1 { background: linear-gradient(145deg, #ff54a2, #F72585); } /* Pink */
.color-2 { background: linear-gradient(145deg, #9b2de5, #7209B7); } /* Purple */
.color-3 { background: linear-gradient(145deg, #5c1de5, #480CA8); } /* Indigo */
.color-4 { background: linear-gradient(145deg, #4f46e5, #3F37C9); } /* Blue */
.color-5 { background: linear-gradient(145deg, #34d399, #10b981); } /* Emerald Green */
.color-6 { background: linear-gradient(145deg, #f59e0b, #d97706); } /* Amber */
.color-7 { background: linear-gradient(145deg, #60a5fa, #3b82f6); } /* Sky Blue */

/* --- Piece Container --- */
footer {
    height: 180px; /* Increased height for more space */
    display: flex;
    align-items: flex-start; /* Aligns pieces to the top of the footer area */
    justify-content: center;
    padding-top: 10px;
}
#pieces-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
}
.piece-preview {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    cursor: grab;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.piece-preview:active {
    cursor: grabbing;
    transform: scale(1.2);
}
.piece-preview-cell {
    width: 24px;
    height: 24px;
}
.piece-preview-cell.block {
    border-radius: 2px;
}

/* --- Animations & Effects --- */
.line-clear-flash {
    animation: flash 0.5s ease-out;
}
@keyframes flash {
    0% { transform: scale(1.1); background-color: white; }
    100% { transform: scale(1.0); }
}

/* --- Upgraded Combo Effect (Resized) --- */
.combo-text {
    position: absolute;
    top: 50%;
    left: 50%;
    font-weight: bold;
    color: var(--pink);
    -webkit-text-stroke: 2px white;
    text-shadow: 0 0 30px var(--pink);
    opacity: 0;
    animation: combo-pop 1.2s ease-out;
    pointer-events: none;
    white-space: nowrap;
    /* NEW: Use clamp() for responsive but controlled font size */
    font-size: clamp(3.5rem, 16vw, 5.5rem);
}


@keyframes combo-pop {
    0% { transform: translate(-50%, -50%) scale(0.5) rotate(-15deg); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.3) rotate(10deg); opacity: 1; }
    80% { transform: translate(-50%, -50%) scale(1.1) rotate(0deg); opacity: 1; }
    100% { transform: translate(-50%, -150%) scale(1.1) rotate(5deg); opacity: 0; }
}


/* --- Modals & Buttons --- */
.hidden { display: none !important; }

#game-over-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal-content {
    background: var(--bg-light);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    animation: modal-appear 0.3s ease;
    width: 90%;
    max-width: 350px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-content .button, .modal-content #restart-button {
    width: 100%;
    margin-top: 0;
}

@keyframes modal-appear { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1.0); } }

.modal-content h2 { font-size: 32px; color: var(--pink); margin-bottom: 10px; }
.modal-content p { font-size: 20px; margin-bottom: 20px; }
.button, #restart-button {
    display: block;
    text-decoration: none;
    background: var(--blue-2);
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    margin-top: 10px;
    cursor: pointer;
    transition: transform 0.2s;
}
#restart-button { background: var(--pink); }
.button.logout { background: var(--purple-2); }
.button:hover, #restart-button:hover { transform: scale(1.05); }

#install-pwa-button {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--blue-3);
    color: var(--bg-dark);
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: bold;
    box-shadow: 0 4px 15px var(--shadow-dark);
}

/* --- High Score Page --- */
.highscore-page { padding: 20px; }
.highscore-container {
    background: var(--bg-light);
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    position: relative; /* For back button positioning */
}
.highscore-container h1 { margin-bottom: 20px; }
.highscore-container .logo { width: 120px; margin-bottom: 10px; }

/* UPDATED: Back button style with explicit width and height */
.back-button {
    position: absolute;
    top: 50px;
    left: 15px;
    background: var(--blue-2);
    color: white;
    
    /* --- ADJUST SIZE HERE --- */
    width: 60px;   /* Set the desired width */
    height: 40px;  /* Set the desired height */

    /* NOTE: Padding has been removed to allow width/height to take full control */
    
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 24px;
    font-weight: bold;
    transition: transform 0.2s;
    border: none;
}

.back-button:hover {
    transform: scale(1.1);
}


/* UPDATED: Table styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    table-layout: fixed; /* Prevents long names from breaking layout */
}
th, td { padding: 10px; }
th { 
    color: var(--blue-3);
    text-align: center; /* Center table headers */
}
tbody tr:nth-child(odd) { background: var(--bg-dark); }

/* Center Rank/Score, left-align Player name */
td:nth-child(1),
td:nth-child(3) {
    text-align: center;
}
td:nth-child(2) {
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* Use '...' for very long names */
}

@keyframes zoomIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- NEW Glowing Shadow Styles --- */
.preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    z-index: 5;
}
.preview-overlay.color-1 { background: rgba(247, 37, 133, 0.4); box-shadow: 0 0 12px rgba(247, 37, 133, 0.6); }
.preview-overlay.color-2 { background: rgba(114, 9, 183, 0.4); box-shadow: 0 0 12px rgba(114, 9, 183, 0.6); }
.preview-overlay.color-3 { background: rgba(72, 12, 168, 0.4); box-shadow: 0 0 12px rgba(72, 12, 168, 0.6); }
.preview-overlay.color-4 { background: rgba(63, 55, 201, 0.4); box-shadow: 0 0 12px rgba(63, 55, 201, 0.6); }
.preview-overlay.color-5 { background: rgba(16, 185, 129, 0.4); box-shadow: 0 0 12px rgba(16, 185, 129, 0.6); }
.preview-overlay.color-6 { background: rgba(217, 119, 6, 0.4); box-shadow: 0 0 12px rgba(217, 119, 6, 0.6); }
.preview-overlay.color-7 { background: rgba(59, 130, 246, 0.4); box-shadow: 0 0 12px rgba(59, 130, 246, 0.6); }


.plop-animation { animation: plop 0.2s ease-out; }
@keyframes plop {
    0% { transform: scale(1.3); }
    100% { transform: scale(1.0); }
}

/* --- PWA Install Overlay Styles --- */
#pwa-install-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    z-index: 200;
}

.overlay-content .logo { width: 150px; margin-bottom: 20px; }
.overlay-content h2 { color: var(--pink); margin-bottom: 10px; }
.overlay-content p { margin-bottom: 25px; line-height: 1.5; }
.overlay-content .small { font-size: 14px; color: var(--blue-3); opacity: 0.8; }

#install-pwa-button {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 0 auto 20px auto;
    font-size: 18px;
    font-weight: bold;
    padding: 15px;
    border-radius: 10px;
    border: none;
    background: var(--pink);
    color: white;
}
#install-pwa-button .icon { margin-right: 10px; }

@media all and (display-mode: browser) and (max-width: 768px) {
    #pwa-install-overlay { display: flex; }
    #game-container, #loading-screen { display: none !important; }
}

@media all and (display-mode: standalone) {
    #pwa-install-overlay { display: none !important; }
}

.particle-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}
.particle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    z-index: 10;
    animation: particle-burst 0.6s ease-out forwards;
}

@keyframes particle-burst {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}
.swoosh-out { animation: swoosh-out 0.4s ease-in forwards; }
@keyframes swoosh-out {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}


#loading-progress {
    margin-top: 15px;
    font-size: 16px;
    color: var(--blue-3);
}
