/* =================================================================== */
/* SEKSJON 1: GENERELL STYLING OG LAYOUT                               */
/* =================================================================== */

body {
    font-family: 'Inter', sans-serif;
    background-color: #111827;
    color: #d1d5db;
    display: flex;
    justify-content: center;
    align-items: center; /* Endret for bedre mobilvisning */
    min-height: 100vh;
    margin: 0;
    /* Fjernet overflow: hidden for å tillate scrolling på små mobiler hvis nødvendig */
    touch-action: manipulation; /* Forbedrer touch-respons */
}

#app-wrapper {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 24px;
    padding: 20px;
    flex-wrap: wrap; /* VIKTIG: Lar elementer dette ned på ny linje på mobil */
}

/* =================================================================== */
/* SEKSJON 2: HOVEDSPILL-CONTAINER                                     */
/* =================================================================== */

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background-color: #1f2937;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    border: 1px solid #374151;
    order: 1; /* Sørger for at spillet kommer først på mobil */
}

h1 {
    font-size: 2rem;
    color: #f9fafb;
    margin-top: 0;
    margin-bottom: 12px;
}

#score-display {
    font-size: 1.25rem;
    font-weight: 700;
    color: #9ca3af;
    margin-bottom: 12px;
    background-color: #374151;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid #4b5563;
    width: 100%;
    max-width: 300px;
    text-align: center;
    box-sizing: border-box;
}

#score {
    color: #60a5fa;
}

/* =================================================================== */
/* SEKSJON 3: SPILLBRETT OG OVERLEGG                                   */
/* =================================================================== */

#canvas-wrapper {
    position: relative;
}

canvas#tetris-board {
    background-color: #111827;
    border: 2px solid #4b5563;
    border-radius: 4px;
    display: block;
    /* Gjør canvas responsivt, men beholder aspect ratio */
    max-width: 100%; 
    height: auto;
}

#game-over, #pause-message {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    text-align: center;
    z-index: 10;
    font-weight: 700;
}

#game-over {
    color: #f87171;
    font-size: 2rem;
    background-color: rgba(31, 41, 55, 0.95);
    padding: 16px 24px;
    border: 2px solid #f87171;
}

#pause-message {
    color: #60a5fa;
    font-size: 2.5rem;
    background-color: rgba(31, 41, 55, 0.95);
    padding: 16px 24px;
    border: 2px solid #60a5fa;
}

p.instructions {
    font-size: 0.9rem;
    color: #9ca3af;
    margin-top: 16px;
    text-align: center;
    max-width: 300px;
}

/* =================================================================== */
/* SEKSJON 4: MOBIL KONTROLLER (NY)                                    */
/* =================================================================== */

#mobile-controls {
    display: none; /* Skjult som standard (desktop) */
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    width: 100%;
    max-width: 300px;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.control-btn {
    background-color: #374151;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 15px;
    font-size: 1.5rem;
    font-weight: bold;
    touch-action: manipulation; /* Hindrer zooming ved dobbelttrykk */
    cursor: pointer;
    flex: 1;
    box-shadow: 0 4px 0 #1f2937;
    active: translateY(4px); /* Trykke-effekt */
}

.control-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0;
}

.round-btn {
    border-radius: 50%;
    width: 60px;
    height: 60px;
    flex: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #4b5563;
}

.wide-btn {
    background-color: #dc2626; /* Rød for drop */
    font-size: 1rem;
    text-transform: uppercase;
    padding: 12px;
}

/* =================================================================== */
/* SEKSJON 5: SIDEPANELER                                              */
/* =================================================================== */

#side-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 120px;
    order: 2; /* Kommer etter spillet på mobil */
}

#highscore-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 180px;
    order: 3; 
}

/* Gjenbruk av eksisterende stiler... */
.side-panel {
    background-color: #1f2937;
    border-radius: 12px;
    border: 1px solid #374151;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* ... (Resten av CSSen for knapper og canvas beholdes) ... */

canvas.side-canvas {
    background-color: #111827;
    border-radius: 4px;
    border: 1px solid #4b5563;
}

#level-display { font-size: 1.75rem; font-weight: 700; color: #f9fafb; }
#lines-display { font-size: 0.8rem; color: #9ca3af; margin-top: 4px; }

.side-button {
    background-color: #374151;
    color: #f9fafb;
    border: 1px solid #4b5563;
    border-radius: 8px;
    padding: 12px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 4px;
}
.side-button:hover { background-color: #4b5563; }

/* Highscore liste stiler (samme som før) */
#highscore-list { list-style: none; padding: 0; margin: 0; width: 100%; font-size: 0.9rem; }
#highscore-list li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid #374151; color: #d1d5db; }
#highscore-list li:last-child { border-bottom: none; }
#highscore-list li span { font-weight: 400; color: #9ca3af; margin-right: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#highscore-list li strong { font-weight: 700; color: #f9fafb; }

/* Modal Stiler (samme som før) */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.85); display: flex; justify-content: center; align-items: center; z-index: 100; opacity: 1; transition: opacity 0.3s ease; }
.modal.hidden { display: none; opacity: 0; pointer-events: none; }
.modal-content { background-color: #1f2937; border: 2px solid #60a5fa; border-radius: 12px; padding: 32px; text-align: center; box-shadow: 0 0 50px rgba(96, 165, 250, 0.3); width: 300px; }
.modal-content h2 { color: #60a5fa; margin-top: 0; }

#player-name-input {
    background-color: #111827;
    border: 1px solid #4b5563;
    border-radius: 8px;
    color: #f9fafb;
    font-family: 'Inter', sans-serif;
    font-size: 1.5rem;
    text-align: center;
    padding: 12px;
    margin: 16px 0;
    width: 100%;
    box-sizing: border-box;
    text-transform: uppercase;
    letter-spacing: 2px;
}
#player-name-input:focus { outline: none; border-color: #60a5fa; }
.highlight-btn { background-color: #2563eb; width: 100%; margin-top: 8px; }
.highlight-btn:hover { background-color: #3b82f6; }

/* =================================================================== */
/* RESPONSIV STYLING (MEDIA QUERIES)                                   */
/* =================================================================== */

@media (max-width: 768px) {
    #app-wrapper {
        flex-direction: column;
        align-items: center;
        gap: 16px;
        padding: 10px;
    }

    #game-container {
        width: 100%;
        padding: 16px;
        box-sizing: border-box;
    }

    /* Vis mobil-kontroller, skjul instruksjoner */
    #mobile-controls { display: flex; }
    .desktop-only { display: none; }

    /* Gjør side-panelet om til en horisontal bar under spillet */
    #side-container {
        width: 100%;
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }

    .side-panel {
        width: auto;
        min-width: 80px;
        padding: 10px;
    }

    .side-button {
        padding: 10px;
        font-size: 0.9rem;
    }
}