* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: #0f0f1a;
    color: #e0e0f0;
    font-family: 'Courier New', monospace;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 24px 16px;
}

#wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1 {
    font-size: 2.4rem;
    letter-spacing: 0.3em;
    color: #c084fc;
    text-shadow: 0 0 20px #a855f7;
}

#game-area {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

#center-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#canvas-container {
    position: relative;
    flex-shrink: 0;
}

#board {
    display: block;
    border: 2px solid #3b3b5c;
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.2);
}

#overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 26, 0.85);
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

#login-btn {
    padding: 10px 20px;
    background: #24292e;
    color: #ffffff;
    border: 1px solid #3b3b5c;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
}

#login-btn:hover {
    background: #2c3137;
    border-color: #c084fc;
}

#overlay-msg {
    color: #e0e0f0;
    font-size: 1rem;
    text-align: center;
    padding: 16px 24px;
    border: 1px solid #3b3b5c;
    background: #16213e;
    line-height: 1.6;
    max-width: 200px;
    white-space: pre-line;
}

@keyframes ellipsis {
    0%   { content: '.'; }
    33%  { content: '..'; }
    66%  { content: '...'; }
    100% { content: '.'; }
}

.loading::after {
    content: '...';
    animation: ellipsis 1.2s steps(1) infinite;
}

.leaderboard-pb {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px dashed #3b3b5c;
}

.leaderboard-empty {
    font-size: 0.7rem;
    color: #7070a0;
    text-align: center;
    padding: 10px 0;
}

#leaderboard-container {
    width: 100%;
    max-width: 240px;
    margin-top: 15px;
    display: none;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid #3b3b5c;
    padding-top: 15px;
}

.leaderboard-title {
    font-size: 0.75rem;
    color: #c084fc;
    letter-spacing: 0.2em;
    margin-bottom: 8px;
    text-align: center;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #e0e0f0;
}

.leaderboard-entry.is-user {
    color: #c084fc;
    background: rgba(168, 85, 247, 0.15);
    border-radius: 4px;
    padding: 0 4px;
}

.leaderboard-rank {
    color: #7070a0;
    width: 25px;
}

.leaderboard-name {
    flex-grow: 1;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 10px;
}

.leaderboard-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    object-fit: cover; /* Ensures image covers the area without distortion */
    border: 1px solid #3b3b5c;
}

#left-panel,
#panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 140px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #16213e;
    border: 1px solid #2a2a4a;
    padding: 10px 12px;
}

.label {
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    color: #7070a0;
}

[data-tooltip] {
    cursor: help;
}

#tooltip {
    position: fixed;
    display: none;
    background: #1a1a3e;
    border: 1px solid #3b3b5c;
    color: #c0c0e0;
    font-size: 0.6rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.05em;
    padding: 5px 9px;
    border-radius: 3px;
    max-width: 200px;
    line-height: 1.5;
    pointer-events: none;
    z-index: 1000;
}

.stat span:last-child {
    font-size: 1.4rem;
    color: #c084fc;
}

#hold-container,
#next-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #16213e;
    border: 1px solid #2a2a4a;
    padding: 10px 8px;
}

#hold {
    display: block;
    width: 90px;
    height: 90px;
    align-self: center;
}

#next {
    display: block;
    align-self: center;
}

#controls {
    font-size: 0.65rem;
    color: #404068;
    line-height: 1.8;
    pointer-events: none;
    align-self: flex-end;
    padding-bottom: 4px;
    white-space: nowrap;
}

#settings {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #16213e;
    border: 1px solid #2a2a4a;
    padding: 8px 12px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

input[type="range"] {
    width: 100%;
    accent-color: #c084fc;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: #505080;
    cursor: pointer;
    user-select: none;
}

.setting-item:hover {
    border-color: #c084fc;
    color: #c084fc;
}

/* ─── Responsive: stack on mobile / touch screens ──────────────────────── */
@media (max-width: 560px), (pointer: coarse) {
    body { padding: 8px 4px; }

    h1 {
        font-size: 1.5rem;
        letter-spacing: 0.15em;
    }

    #center-column {
        order: -1;
        gap: 6px;
    }

    #game-area {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    #left-panel,
    #panel {
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        max-width: 320px;
        gap: 4px;
        justify-content: center;
    }

    .stat {
        flex: 1;
        min-width: 80px;
        padding: 4px 6px;
        gap: 0;
    }

    .stat span:last-child {
        font-size: 1.1rem;
    }

    #hold-container, #next-container {
        flex: 0 0 auto;
        padding: 4px 8px;
        align-items: center;
    }

    #hold { width: 50px; height: 50px; }
    #next { width: 50px; height: 150px; }

    #settings {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        font-size: 0.55rem;
        padding: 6px;
        gap: 6px;
    }

    .setting-group { gap: 2px; }

    #controls { display: none; }
}
