/* Cos i html: estils globals per a tota la pàgina (tots els modes) */
body, html {
    font-family: Arial, sans-serif;
    background-color: #333;
    color: white;
    overflow: auto !important; /* Activa el desplaçament */
    overflow-x: hidden !important;
    height: 100vh;
    -webkit-overflow-scrolling: touch; /* Millora l'experiència en dispositius mòbils */
}

/* Tots els elements: reset de marges, padding i box-sizing (tots els modes) */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Contenidor principal: layout horitzontal (tots els modes, excepte mobile) */
.container {
    display: flex;
    flex-direction: row;
    height: 100%;
}

/* Botons de control: estil general (escriptori) */
.control-btn {
    width: 200px;
    border: none;
    padding: 8px 16px;
    margin-bottom: 10px;
    border-radius: 5px;
    color: white;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(76, 175, 80, 0.3);
    background: linear-gradient(45deg, #4CAF50, #45a049);
    font-size: 1.0em;
}

/* Botons de control: efectes hover (escriptori) */
.control-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

/* Botons de control actius i botó de netejar: color de fons especial (escriptori) */
.control-btn.active,
.clear-btn {
    background: linear-gradient(45deg, #ff6b6b, #ee5a52);
    box-shadow: 0 2px 10px rgba(255, 107, 107, 0.3);
}

/* Botó pas a pas: color de fons especial (escriptori) */
.step-btn {
    background: linear-gradient(45deg, #9f6bff, #4213ec);
    box-shadow: 0 2px 10px rgba(255, 107, 107, 0.3);
}

/* Barra lateral: layout i estil (escriptori) */
.sidebar {
    width: 400px;
    display: flex;
    flex-direction: column;
    padding-left: 10px;
    padding-right: 10px;
    box-sizing: border-box;
    justify-content: space-around;
    text-align: center;
    overflow-y: auto;
    max-height: 100vh;
}

/* Contenidor del canvas: centra el canvas (tots els modes) */
.canvas-container {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #222;
    overflow: hidden;
}

/* Canvas: ocupa tot l'espai disponible (tots els modes) */
canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #0f0f23, #000);
    cursor: crosshair;
}

/* Títol principal (tots els modes) */
#titol {
    text-align: center;
    color: white;
}

/* Bloc d'instruccions: estil general (escriptori) */
.instruccions {
    display: block;
    background-color: #333;
    padding-left: 10px;
    padding-right: 10px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    width: 100%;
    box-sizing: border-box;
    text-align: center;
}

/* Títol i paràgrafs d'instruccions (tots els modes) */
.instruccions h3,
.instruccions p {
    margin: 10px;
}

/* Comptadors i estadístiques (tots els modes) */
#fpsCounter, #statusTime, #statusBodies, #statusMouse {
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
}

/* Contenidor de controls: layout i estil (escriptori) */
.controls {
    padding: 10px;
    border-radius: 8px;
    display: flex;
    flex-flow: column nowrap;
    align-items: center;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    background-color: #333;
    gap: 10px;
    text-align: center;
}

/* Controls de paràmetres: layout i marges (tots els modes) */
.controls > div[title] {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    margin-bottom: 2px;
}

.controls > div[title] label,
.controls > div[title] output {
    margin: 0;
}

/* Copyright: estil de text (tots els modes) */
.sidebar > a,
.copyright-line {
    font-size: 0.9em;
    color: #ccc;
}

/* --- Mode mòbil --- */
@media (max-width: 900px) and (pointer: coarse) {
    /* Contenidor principal: layout vertical (mobile) */
    .container {
        flex-direction: column !important;
        height: 100vh;
    }
    /* Barra lateral: ocupa tota l'amplada a dalt (mobile) */
    .sidebar {
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: unset !important;
        height: auto !important;
        max-height: none !important;
        order: 0 !important;
        box-shadow: none;
        padding: 0.5rem 0.2rem 0 0.2rem !important;
        margin: 0 !important;
        overflow-y: visible !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        position: relative;
        flex-shrink: 0 !important;
        padding-top: 0 !important;
    }
    /* Amaga copyright (mobile) */
    .sidebar > a {
        display: none !important;
    }
    /* Canvas ocupa la resta de la pantalla (mobile) */
    .canvas-container {
        order: 1 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        flex: 1 1 0 !important;
        min-height: 0 !important;
        height: auto !important;
        display: flex !important;
    }
    /* Controls: layout horitzontal i compacte (mobile) */
    .controls {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 5px !important;
        padding: 4px !important;
        margin-top: 0 !important;
    }
    /* Botons de control: rodons i petits (mobile) */
    .control-btn {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.3em !important;
        padding: 0 !important;
        border-radius: 50% !important;
        min-width: unset !important;
        min-height: unset !important;
        text-align: center !important;
        text-indent: -9999px;
        overflow: hidden;
        position: relative;
        margin: 0 !important;
    }
    /* Icones per als botons (mobile) */
    #playBtn::after { content: '▶'; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); text-indent: 0; }
    #stepBtn::after { content: '⏯'; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); text-indent: 0; }
    #clearBtn::after { content: '🗑'; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); text-indent: 0; }
    #helpBtn::after { content: '?'; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); text-indent: 0; }
    #playBtn[data-icon]::after {
        content: attr(data-icon);
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        text-indent: 0;
    }
    /* Amaga instruccions (mobile) */
    .instruccions {
        display: none !important;
    }
    /* Mostra el botó d'ajuda (mobile) */
    #helpBtn {
        display: block !important;
    }
    /* Colors de fons segons estat del play (mobile) */
    #playBtn.play-green {
        background: linear-gradient(45deg, #4CAF50, #45a049) !important;
    }
    #playBtn.pause-red {
        background: linear-gradient(45deg, #ff6b6b, #ee5a52) !important;
    }
    /* Fila de botons: layout compacte (tots els modes, s'anomena .btn-row) */
    .btn-row {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-evenly !important;
        align-items: center !important;
        margin-top: 10px !important;
        margin-bottom: 6px !important;
        width: 100%;
    }
    /* Amaga info de ratolí (mobile) */
    #statusMouse {
        display: none !important;
    }
    /* Fila d'estat: layout compacte (mobile) */
    .status-row {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        min-height: 38px;
        margin-bottom: 6px !important;
    }
    /* Comptadors d'estat: estil més gran (mobile) */
    #statusTime, #fpsCounter, #statusBodies {
        display: inline-flex;
        align-items: center;
        height: 100%;
        font-size: 14px;
        font-family: inherit;
    }
    /* Amaga copyright (mobile) */
    .copyright-line, .sidebar > a {
        display: none !important;
    }
}

/* Botó d'ajuda: estil general (tots els modes) */
#helpBtn {
    display: none;
    position: relative;
    background: linear-gradient(45deg, #FFD600, #FFB300);
    color: #333;
    border: none;
    box-shadow: 0 2px 10px rgba(255, 214, 0, 0.3);
    cursor: pointer;
    z-index: 10;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5em;
    padding: 0;
    margin: 0;
}

/* Amaga el comptador de FPS per defecte (tots els modes) */
#fpsCounter {
    display: none !important;
}

/* Redueix l'espai sota la fila de botons (escriptori) */
.btn-row {
    margin-bottom: -14px;
}
