/* ============================================
   General Styles and Layout
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 30px;
    max-width: 1200px;
    width: 100%;
}

/* ============================================
   Header Section
   ============================================ */

.header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid #27ae60;
    padding-bottom: 15px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.header h1 {
    color: #333;
    font-size: 32px;
    flex: 1;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.user-section {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.user-name {
    color: #27ae60;
    font-weight: 600;
    padding: 6px 12px;
    background: #f0f0f0;
    border-radius: 20px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-small:hover {
    background: #229954;
    transform: translateY(-1px);
}

.score-board {
    display: flex;
    justify-content: space-around;
    gap: 20px;
}

.score,
.level {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.label {
    color: #666;
    font-size: 14px;
    font-weight: 500;
}

.value {
    color: #27ae60;
    font-size: 24px;
    font-weight: bold;
    min-width: 40px;
}

/* ============================================
   Game Board (Canvas)
   ============================================ */

.game-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 25px;
}

canvas {
    border: 3px solid #333;
    background-color: #1a1a1a;
    display: block;
    cursor: none;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 100%;
    height: auto;
}

/* ============================================
   Controls Section
   ============================================ */

.controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 24px;
    font-size: 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: #27ae60;
    color: white;
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(39, 174, 96, 0.6);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background-color: #f0f0f0;
    color: #333;
    border: 2px solid #27ae60;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #27ae60;
    color: white;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Game Over Modal
   ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
    max-width: 350px;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #333;
    font-size: 28px;
    margin-bottom: 20px;
}

.modal-content p {
    color: #666;
    font-size: 18px;
    margin-bottom: 15px;
    font-weight: 500;
}

.modal-content span {
    color: #27ae60;
    font-weight: bold;
}

.modal-content .btn {
    margin-top: 25px;
    width: 100%;
}

/* Username Modal Specific */

.username-modal {
    max-width: 320px;
}

.username-modal h2 {
    margin-bottom: 10px;
}

.modal-description {
    font-size: 14px !important;
    color: #999 !important;
    margin-bottom: 20px !important;
}

.username-input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 6px;
    margin-bottom: 15px;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

.username-input:focus {
    outline: none;
    border-color: #27ae60;
    box-shadow: 0 0 0 3px rgba(39, 174, 96, 0.1);
}

.username-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.username-actions .btn {
    flex: 1;
    margin-top: 0;
}

.modal-hint {
    font-size: 12px !important;
    color: #aaa !important;
    margin-top: 15px !important;
}

.ranking-message {
    color: #27ae60;
    font-weight: 600;
    margin: 15px 0;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 6px;
    font-size: 14px;
}

/* ============================================
   Instructions Section
   ============================================ */

.instructions {
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid #ddd;
    font-size: 13px;
    color: #666;
    line-height: 1.6;
}

.instructions p {
    margin-bottom: 8px;
}

.instructions strong {
    color: #333;
    font-weight: 600;
}

/* ============================================
   Leaderboard Section
   ============================================ */

.leaderboard-section {
    margin-top: 30px;
    padding-top: 25px;
    border-top: 2px solid #e0e0e0;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.leaderboard-header h3 {
    color: #333;
    font-size: 20px;
    margin: 0;
}

.leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e0e0e0;
    transition: background-color 0.2s ease;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-item:hover {
    background-color: #f0f0f0;
}

.leaderboard-rank {
    font-weight: 700;
    font-size: 18px;
    color: #27ae60;
    min-width: 30px;
    text-align: center;
}

.leaderboard-rank.rank-1 {
    color: #ffd700;
    font-size: 20px;
}

.leaderboard-rank.rank-2 {
    color: #c0c0c0;
    font-size: 20px;
}

.leaderboard-rank.rank-3 {
    color: #cd7f32;
    font-size: 20px;
}

.leaderboard-info {
    flex: 1;
    margin-left: 15px;
}

.leaderboard-name {
    font-weight: 600;
    color: #333;
    font-size: 14px;
    margin-bottom: 4px;
}

.leaderboard-date {
    font-size: 12px;
    color: #999;
}

.leaderboard-score {
    font-weight: 700;
    color: #27ae60;
    font-size: 16px;
    min-width: 50px;
    text-align: right;
}

.loading-spinner {
    padding: 20px;
    text-align: center;
    color: #999;
    font-style: italic;
}

.leaderboard-empty {
    padding: 20px;
    text-align: center;
    color: #999;
}

/* ============================================
   Desktop Layout (Two-Column)
   ============================================ */

.desktop-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-top: 30px;
}

.leaderboard-section {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    order: 1;
}

.instructions {
    text-align: left;
    padding-top: 0;
    border-top: none;
    order: 2;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.instructions p {
    margin-bottom: 15px;
    font-size: 14px;
}

/* ============================================
   Responsive Design
   ============================================ */

/* Mobile: Stack vertically */
@media (max-width: 768px) {
    .container {
        padding: 20px;
        max-width: 100%;
    }

    .desktop-layout {
        display: flex;
        flex-direction: column;
        gap: 20px;
        margin-top: 20px;
        margin-bottom: 20px;
    }

    .leaderboard-section {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
        order: 1;
    }

    .instructions {
        text-align: left;
        padding-top: 0;
        border-top: none;
        order: 2;
    }

    .instructions p {
        margin-bottom: 8px;
        font-size: 12px;
        line-height: 1.4;
    }

    .instructions strong {
        font-size: 12px;
    }

    .leaderboard-header h3 {
        font-size: 16px;
    }

    .leaderboard-list {
        max-height: 250px;
        font-size: 12px;
    }

    .leaderboard-item {
        padding: 8px 10px;
    }

    .leaderboard-rank {
        min-width: 20px;
        font-size: 14px;
    }

    .leaderboard-rank.rank-1,
    .leaderboard-rank.rank-2,
    .leaderboard-rank.rank-3 {
        font-size: 16px;
    }

    .leaderboard-name {
        font-size: 12px;
    }

    .leaderboard-date {
        font-size: 10px;
    }

    .leaderboard-score {
        font-size: 13px;
        min-width: 35px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
    }

    .header-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .header h1 {
        font-size: 22px;
    }

    .user-section {
        width: 100%;
        justify-content: space-between;
    }

    .score-board {
        flex-direction: column;
        gap: 10px;
    }

    canvas {
        max-width: 90vw;
        height: auto;
    }

    .controls {
        gap: 8px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    .modal-content {
        max-width: 90vw;
        padding: 25px 15px;
    }

    .username-input {
        font-size: 16px;
    }
}