:root {
    --bg-color: #0d0d12;
    --grid-bg: #1a1a24;
    --cell-empty: #252533;
    --primary-color: #00ffff;
    --secondary-color: #ff00ff;
    --text-color: #ffffff;
    --accent-color: #ffe600;

    --cell-size: 40px;
    --gap-size: 4px;

    --font-main: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    touch-action: none;
    /* Prevent default touch actions like scrolling */
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#game-container {
    width: 100%;
    max-width: 500px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    position: relative;
}

header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px 20px;
    position: relative;
}

.icon-btn {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 165, 0, 0.2));
    border: 2px solid rgba(255, 215, 0, 0.5);
    color: #ffd700;
    font-size: 1.5rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.icon-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.icon-btn:active {
    transform: scale(0.95);
}

.score-container {
    text-align: center;
}

.score-label {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 2px;
}

.score-value {
    font-size: 1.8rem;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* Combo Display */
#combo-display {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 20px;
    border-radius: 15px;
    text-align: center;
    z-index: 100;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 15px rgba(255, 0, 255, 0.4);
    animation: comboAppear 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    backdrop-filter: blur(2px);
}

#combo-display.hidden {
    display: none;
}

.combo-text {
    font-size: 1rem;
    font-weight: 300;
    letter-spacing: 3px;
    margin-bottom: 5px;
    color: rgba(255, 255, 255, 0.8);
}

.combo-value {
    font-size: 3rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    animation: pulseCombo 0.5s ease-in-out infinite;
}

.combo-multiplier {
    font-size: 1.2rem;
    font-weight: 500;
    color: #ffe600;
    margin-top: 5px;
    text-shadow: 0 0 10px rgba(255, 230, 0, 0.8);
}

@keyframes comboAppear {
    from {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes pulseCombo {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

#game-area {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

#grid-container {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: var(--gap-size);
    background-color: var(--grid-bg);
    padding: 8px;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: var(--cell-empty);
    border-radius: 6px;
    transition: background-color 0.2s, transform 0.1s;
}

.cell.filled {
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.cell.highlight {
    background-color: rgba(255, 255, 255, 0.2);
}

#hand-container {
    width: 100%;
    height: 120px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 10px;
}

.hand-slot {
    width: 30%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Block Styles (used in hand and drag) */
.block-shape {
    display: grid;
    gap: var(--gap-size);
    pointer-events: none;
    /* Let events pass through to underlying elements during drag check if needed, but we handle drag on container */
}

.block-cell {
    width: calc(var(--cell-size) * 0.6);
    /* Smaller in hand */
    height: calc(var(--cell-size) * 0.6);
    border-radius: 4px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}


#game-over-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: linear-gradient(135deg, #2a2a35, #15151e);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.2);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: var(--secondary-color);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.modal-content p {
    font-size: 1.5rem;
    margin-bottom: 30px;
}

#leaderboard-list {
    text-align: left;
    margin-bottom: 20px;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 10px;
}

#leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

#leaderboard-list::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

#leaderboard-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

#restart-btn {
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border: none;
    padding: 15px 40px;
    border-radius: 30px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s, box-shadow 0.1s;
}

#restart-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Start Screen */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    /* Removed !important so JS can hide it */
    justify-content: center;
    align-items: center;
    z-index: 9999;
    /* Highest priority */
    backdrop-filter: blur(10px);
    transition: opacity 0.5s;
}

.start-content {
    min-width: 300px;
    max-width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Center vertically */
    padding-bottom: 20px;
}

.start-content::-webkit-scrollbar {
    width: 0px;
    /* Hide scrollbar just in case */
}

.start-content::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.neon-text {
    font-size: 3rem;
    color: #fff;
    text-shadow: 0 0 10px var(--primary-color), 0 0 20px var(--primary-color), 0 0 30px var(--secondary-color);
    margin-bottom: 5px;
    /* Reduced margin */
}

.sub-title {
    color: var(--secondary-color);
    font-size: 1.2rem;
    margin-bottom: 10px;
    /* Reduced margin */
    letter-spacing: 2px;
}

#start-leaderboard-list {
    text-align: left;
    margin-bottom: 15px;
    /* height: 330px; Removed fixed height */
    min-height: 100px;
    /* Allow it to shrink if needed, but maintain structure */
    width: 100%;
    max-width: 400px;
    padding-right: 0;
}

/* Pagination (Shared Class) */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.pulse-btn {
    background: linear-gradient(90deg, #ff00de, #00e5ff);
    border: none;
    padding: 15px 50px;
    border-radius: 30px;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(255, 0, 222, 0.5);
    animation: pulse 1.5s infinite;
    transition: transform 0.2s;
}

.pulse-btn:hover {
    transform: scale(1.05);
}

.pulse-btn:active {
    transform: scale(0.95);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 0, 222, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(255, 0, 222, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 0, 222, 0);
    }
}

/* Leaderboard Modal */
.leaderboard-content {
    min-width: 350px;
    max-width: 450px;
}

#leaderboard-list {
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    margin: 8px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
    color: #ffffff;
    /* Enforce white text */
}

.leaderboard-entry .player-name {
    color: #ffffff;
}

.leaderboard-entry .player-score {
    color: var(--primary-color);
}

.leaderboard-entry:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(5px);
}

.leaderboard-entry.rank-1 {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.2), rgba(255, 215, 0, 0.05));
    border-color: rgba(255, 215, 0, 0.5);
}

.leaderboard-entry.rank-2 {
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.2), rgba(192, 192, 192, 0.05));
    border-color: rgba(192, 192, 192, 0.5);
}

.leaderboard-entry.rank-3 {
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.2), rgba(205, 127, 50, 0.05));
    border-color: rgba(205, 127, 50, 0.5);
}

.rank-number {
    font-size: 1.5rem;
    font-weight: 700;
    min-width: 40px;
    text-align: center;
}

.rank-1 .rank-number {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
}

.rank-2 .rank-number {
    color: #c0c0c0;
    text-shadow: 0 0 10px rgba(192, 192, 192, 0.8);
}

.rank-3 .rank-number {
    color: #cd7f32;
    text-shadow: 0 0 10px rgba(205, 127, 50, 0.8);
}

.player-info {
    flex: 1;
    margin: 0 15px;
}

.player-name {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 2px;
}

.player-score {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary-color);
}

#close-leaderboard-btn,
#submit-score-btn {
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: bold;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s, box-shadow 0.1s;
    margin-top: 10px;
}

#close-leaderboard-btn:active,
#submit-score-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Name Input */
#high-score-entry {
    margin: 20px 0;
}

.congrats-text {
    font-size: 1.2rem;
    color: var(--accent-color);
    margin-bottom: 15px;
    animation: rainbow 2s linear infinite;
}

@keyframes rainbow {

    0%,
    100% {
        color: #ff0080;
    }

    25% {
        color: #00ffff;
    }

    50% {
        color: #ffe600;
    }

    75% {
        color: #00ff00;
    }
}

#player-name-input {
    width: 100%;
    padding: 12px 20px;
    font-size: 1.1rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-family: var(--font-main);
    text-align: center;
    margin-bottom: 15px;
    transition: all 0.3s ease;
}

#player-name-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
}

#player-name-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Particles */
#particles-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: white;
    box-shadow: 0 0 6px currentColor;
    animation: explode 0.8s ease-out forwards;
}

@keyframes explode {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

/* Screen Shake */
.shake {
    animation: shake 0.3s cubic-bezier(.36, .07, .19, .97) both;
}

@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);
    }
}

/* Compact Start Screen Styles */
.start-content {
    min-width: 300px;
    max-width: 90%;
    /* Removed max-height and overflow since we want it to fit naturally */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 20px;
}

.start-content .neon-text {
    font-size: 2.5rem;
    /* Smaller title */
    margin-bottom: 5px;
}

.start-content .sub-title {
    font-size: 1rem;
    margin-bottom: 10px;
}

.start-content .pulse-btn {
    padding: 10px 40px;
    /* Smaller button */
    font-size: 1.2rem;
    margin-top: 10px;
}

/* Compact specific Leaderboard styles for Start Screen */
#start-leaderboard-list {
    margin-bottom: 10px;
    width: 100%;
    max-width: 400px;
}

#start-leaderboard-list .leaderboard-entry {
    padding: 6px 15px;
    /* Much smaller padding */
    margin: 4px 0;
    /* Tighter margins */
    font-size: 0.9rem;
}

#start-leaderboard-list .player-rank {
    width: 25px;
    height: 25px;
    line-height: 25px;
    font-size: 0.9rem;
}

/* Ensure pagination fits compactly */
#start-pagination-controls {
    margin-bottom: 10px;
    margin-top: 5px;
}

#start-pagination-controls .pagination-btn {
    padding: 5px 15px;
}

/* Tablet & Large Screen Adjustments */
@media (min-width: 600px) and (min-height: 800px) {
    :root {
        --cell-size: 55px;
        --gap-size: 6px;
    }

    #game-container {
        max-width: 650px;
        padding: 40px;
    }

    .score-value {
        font-size: 2.2rem;
    }

    .icon-btn {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
    }
}

@media (min-width: 768px) {

    /* iPad Portrait / Standard Tablet */
    #game-container {
        max-width: 700px;
    }
}

.hidden {
    display: none !important;
}

.draggable-clone {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.9;
    /* Ensure clones are on top of everything including modals if needed, though usually modals block interact */
}

.draggable-clone .block-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
}

/* Prevent text selection and handling for touch devices */
.hand-slot,
.block-shape {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}