:root {
    --bg-color: #0f172a; /* Slate 900 */
    --text-color: #f8fafc; /* Slate 50 */
    --text-muted: #94a3b8; /* Slate 400 */
    --board-bg: #1e293b; /* Slate 800 */
    --cell-empty: #334155; /* Slate 700 */
    --cell-empty-hover: #475569; /* Slate 600 */
    
    --accent: #3b82f6; /* Blue 500 */
    --accent-hover: #2563eb; /* Blue 600 */
    
    /* Vibrant Block Colors */
    --color-1: #ef4444; /* Red */
    --color-2: #f59e0b; /* Amber */
    --color-3: #10b981; /* Emerald */
    --color-4: #3b82f6; /* Blue */
    --color-5: #8b5cf6; /* Violet */
    --color-6: #ec4899; /* Pink */
    --color-7: #06b6d4; /* Cyan */
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --shadow-soft: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.4);
    --shadow-block: inset 0 0 0 2px rgba(255, 255, 255, 0.15), 0 4px 6px rgba(0,0,0,0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Mobile bottom bar fix */
    overflow: hidden;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

/* Typography */
.logo {
    font-size: 4rem;
    font-weight: 800;
    letter-spacing: -2px;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.logo span {
    color: var(--accent);
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 3rem;
    font-weight: 500;
}

/* Buttons */
.primary-btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 1.2rem 3rem;
    font-size: 1.25rem;
    font-weight: 700;
    border-radius: var(--radius-full);
    cursor: pointer;
    box-shadow: var(--shadow-glow);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.primary-btn:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(59, 130, 246, 0.6);
}

.primary-btn:active {
    transform: translateY(2px) scale(0.95);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

/* Game Layout */
.game-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 500px;
    height: 100%;
    padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px);
    justify-content: space-between;
}

.header {
    display: flex;
    justify-content: space-between;
    margin-bottom: auto;
    padding-top: 1rem;
}

.score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--board-bg);
    padding: 0.8rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.score-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 1.5px;
    margin-bottom: 2px;
}

#score, #best-score {
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Board */
.board-wrapper {
    width: 100%;
    aspect-ratio: 1;
    background: var(--board-bg);
    padding: 12px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    margin: 2rem 0;
}

#board {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 4px;
}

.cell {
    background-color: var(--cell-empty);
    border-radius: var(--radius-sm);
    transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.cell.filled {
    box-shadow: var(--shadow-block);
}

.cell.highlight {
    opacity: 0.7;
    transform: scale(0.9);
    box-shadow: var(--shadow-block);
}

.cell.clearing {
    animation: clearLine 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes clearLine {
    0% { transform: scale(1); opacity: 1; filter: brightness(1); }
    40% { transform: scale(1.15); opacity: 0.9; filter: brightness(1.5); }
    100% { transform: scale(0); opacity: 0; filter: brightness(2); }
}

/* Pieces Area */
.pieces-container {
    width: 100%;
    height: 140px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 15px;
    margin-bottom: 1rem;
}

.piece-slot {
    flex: 1;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: rgba(30, 41, 59, 0.5); /* Semi-transparent slot bg */
    border-radius: var(--radius-md);
}

.piece {
    display: grid;
    gap: 2px;
    cursor: grab;
    touch-action: none;
    z-index: 100;
    transition: opacity 0.2s ease;
    animation: popInPiece 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

/* Stagger animations for piece generation */
.piece-slot:nth-child(1) .piece { animation-delay: 0.1s; }
.piece-slot:nth-child(2) .piece { animation-delay: 0.2s; }
.piece-slot:nth-child(3) .piece { animation-delay: 0.3s; }

.piece:active {
    cursor: grabbing;
}

.piece.dragging {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    transition: none;
    /* Transform applied via JS during drag, using scale and translate */
    filter: drop-shadow(0 15px 20px rgba(0,0,0,0.4));
}

.piece-block {
    border-radius: 4px; /* Slightly smaller radius in preview */
    box-shadow: var(--shadow-block);
}

/* Modal */
.modal {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    z-index: 2000;
}

.modal-content {
    background: var(--board-bg);
    padding: 3.5rem 2.5rem;
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255,255,255,0.05);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.screen.active .modal-content {
    transform: translateY(0);
    opacity: 1;
}

.modal-content h2 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, #fff, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.final-score {
    display: flex;
    flex-direction: column;
    margin-bottom: 2.5rem;
    background: rgba(0,0,0,0.2);
    padding: 1.5rem;
    border-radius: var(--radius-md);
}

.final-score span:first-child {
    color: var(--text-muted);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

#final-score-val {
    font-size: 4rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

/* Animations */
@keyframes popInPiece {
    0% { transform: scale(0.5); opacity: 0; }
    80% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

#confetti {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Responsive adjustments */
@media (max-width: 450px) {
    .board-wrapper {
        padding: 8px;
    }
    #board {
        gap: 3px;
    }
    .score-box {
        padding: 0.6rem 1.2rem;
    }
    .pieces-container {
        height: 120px;
        gap: 8px;
    }
}

.game-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 5px;
    font-weight: 500;
    opacity: 0.5;
    letter-spacing: 0.5px;
}

/* New Leaderboard UI and Floating Text */
.secondary-btn {
    background-color: transparent;
    color: var(--text-color);
    border: 2px solid var(--cell-empty);
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}
.secondary-btn:hover {
    background-color: var(--cell-empty);
    transform: translateY(-2px);
}
.secondary-btn:active {
    transform: translateY(2px) scale(0.95);
}

.small-btn {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
}

#player-name {
    width: 100%;
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 2px solid var(--cell-empty);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1.1rem;
    font-family: inherit;
    margin-bottom: 15px;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}
#player-name:focus {
    border-color: var(--accent);
}

.save-score-section {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
}

.leaderboard-list {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 20px;
    text-align: left;
    background: rgba(0,0,0,0.2);
    border-radius: var(--radius-md);
    padding: 15px;
}
.leaderboard-list::-webkit-scrollbar {
    width: 6px;
}
.leaderboard-list::-webkit-scrollbar-thumb {
    background-color: var(--cell-empty);
    border-radius: 10px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.leaderboard-item:last-child {
    border-bottom: none;
}
.leaderboard-rank {
    font-weight: bold;
    color: var(--accent);
    width: 35px;
}
.leaderboard-name {
    flex: 1;
    font-weight: 600;
}
.leaderboard-score {
    font-weight: bold;
    color: var(--color-2);
}

.floating-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(2rem, 8vw, 3.5rem);
    font-weight: 800;
    color: #fff;
    text-transform: uppercase;
    text-align: center;
    pointer-events: none;
    z-index: 1000;
    text-shadow: 0 5px 15px rgba(0,0,0,0.5), 0 0 20px var(--accent);
    animation: floatUpFade 1.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    width: 100%;
}

@keyframes floatUpFade {
    0% { transform: translate(-50%, -20%) scale(0.5) rotate(-5deg); opacity: 0; }
    20% { transform: translate(-50%, -50%) scale(1.1) rotate(5deg); opacity: 1; }
    70% { transform: translate(-50%, -60%) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(-50%, -80%) scale(0.9); opacity: 0; }
}

/* Neon Theme Additions */
body.neon-theme {
    --bg-color: #000;
    --board-bg: #09090b;
    --cell-empty: #101014;
    --shadow-soft: 0 0 20px rgba(59, 130, 246, 0.1);
    background-image: radial-gradient(circle at center, #12121a 0%, #000 100%);
}

body.neon-theme .cell.filled, body.neon-theme .piece-block {
    box-shadow: 0 0 15px currentColor, inset 0 0 8px rgba(255,255,255,0.4);
    border: 1px solid rgba(255,255,255,0.5);
    border-radius: 6px;
}

body.neon-theme .board-wrapper {
    box-shadow: 0 0 25px rgba(236, 72, 153, 0.15), 0 0 40px rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(255,255,255,0.05);
}

body.neon-theme .floating-text {
    text-shadow: 0 0 10px currentColor, 0 0 20px currentColor, 0 0 40px currentColor;
    font-weight: 900;
}
