/*
 * Le Tabelline - Times Tables learning game for children
 * Copyright (C) 2025  Maurizio Meluzzi
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

/* ============================================================
   BASE
   ============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #F4C2DF;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    color: #821f9d;
}

/* ============================================================
   APP LAYOUT — PORTRAIT (default, single column)
   ============================================================ */

#app-layout {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
}

/* ── Left panel: calc-box, res-box, time-counter ─────────── */

#app-left {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1dvh;
    padding: 1.5dvh 2vw;
}

.app-box {
    border-style: none;
    border-radius: clamp(12px, 4vw, 60px);
}

#calc-box {
    width: 96vw;
    min-height: clamp(44px, 13vw, 250px);
    padding: 0 clamp(12px, 5vw, 160px);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #F7D0D5;
    font-size: clamp(2rem, 12vw, 220px);
}

#res-box {
    width: 96vw;
    min-height: clamp(36px, 10vw, 250px);
    padding: 0 clamp(12px, 5vw, 160px);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #FADECB;
    font-size: clamp(1.5rem, 10vw, 220px);
}

/* ── Time counter strip ──────────────────────────────────── */

#time-counter-wrap {
    display: flex;
    flex-direction: row;
    gap: clamp(2px, 0.8vw, 8px);
    width: 96vw;
}

.time-counter {
    flex: 1;
    height: clamp(12px, 2.5vw, 24px);
    border-radius: clamp(4px, 1vw, 10px);
    background-color: #FADECB;
}

/* ── Right panel: digit keypad ───────────────────────────── */

#app-right {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr;
    gap: clamp(4px, 1.5vw, 14px);
    padding: clamp(4px, 1.5vw, 14px);
}

/* .app-font: class shared by calc-box, res-box, and digit buttons.
   Font size is defined per element or context. */
.app-font {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    color: #821f9d;
}

button {
    border-style: none;
    border-radius: clamp(12px, 4vw, 60px);
    width: 100%;
    height: 100%;
    background-color: #FCECC0;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    color: #821f9d;
    font-size: clamp(1.5rem, 15vw, 220px);
    cursor: pointer;
    touch-action: manipulation;
}

/* empty grid cells that flank the "0" button in row 4 */
.keypad-spacer {
    background: transparent;
}

button.digit.pressed {
    transform: translateY(2px);
    box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.25);
    background-color: #ddd;
}

/* ============================================================
   LANDSCAPE LAYOUT (tablet landscape, PC)
   ============================================================ */

@media (orientation: landscape) {
    #app-layout {
        flex-direction: row;
    }

    #app-left {
        flex: 0 0 36vw;
        justify-content: flex-start;
        padding: 3dvh 2vw 2dvh;
        gap: 2dvh;
        background-color: #EDD5E8;
        border-radius: clamp(12px, 2vw, 32px);
    }

    #app-right {
        flex: 1;
        padding: 2dvh 2vw;
        gap: clamp(4px, 1.2dvh, 14px) clamp(4px, 1vw, 14px);
    }

    #calc-box {
        width: 100%;
        min-height: clamp(44px, 22dvh, 250px);
        padding: 0 clamp(10px, 2vw, 60px);
        font-size: clamp(1.5rem, 7vw, 200px);
    }

    #res-box {
        width: 100%;
        min-height: clamp(36px, 17dvh, 250px);
        padding: 0 clamp(10px, 2vw, 60px);
        font-size: clamp(1.5rem, 6vw, 200px);
    }

    #btn-exit {
        height: clamp(44px, 22dvh, 250px);
        font-size: clamp(1rem, 4vw, 56px);
        padding-right: clamp(10px, 2vw, 60px);
    }

    #time-counter-wrap {
        width: 100%;
        gap: clamp(2px, 0.5vw, 8px);
    }

    .time-counter {
        height: clamp(10px, 1.8dvh, 24px);
    }

    button {
        font-size: clamp(1.5rem, min(14dvh, 7vw), 200px);
        border-radius: clamp(10px, 2dvh, 60px);
    }
}

/* ============================================================
   MODALS
   ============================================================ */

#modal-ok, #modal-nok, #modal-time-ended {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

#modal-ok {
    background-color: rgba(0, 255, 0, 0.5);
}

#modal-nok, #modal-time-ended {
    background-color: rgba(255, 0, 0, 0.5);
}

/* modal content card — absolutely centred within the fixed overlay */
.modal-inner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: clamp(13px, 3.3vw, 53px);
    background-color: #FADECB;
    border-radius: clamp(16px, 4vw, 60px);
    padding: clamp(18px, 3.3vw, 53px);
    max-width: 100vw;
    max-height: 97dvh;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.30);
}

.modal-img-wrap img {
    width: clamp(88px, 19.8vw, 308px);
    height: auto;
    display: block;
}

.modal-text-wrap {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 2vw, 24px);
}

#ok-row-01, #nok-row-01, #te-row-01, #wl-row-01 {
    font-size: clamp(1.2rem, 5vw, 60px);
}

#ok-row-02, #nok-row-02, #te-row-02 {
    font-size: clamp(1.5rem, 8vw, 110px);
}

/* ============================================================
   EXIT BUTTON (game.html)
   ============================================================ */

#btn-exit {
    width: 100%;
    height: clamp(44px, 13vw, 250px);
    border-radius: clamp(12px, 4vw, 60px);
    background-color: #F7D0D5;
    color: #821f9d;
    font-weight: bold;
    font-size: clamp(1rem, 5.5vw, 56px);
    cursor: pointer;
    text-align: right;
    padding-right: clamp(12px, 5vw, 160px);
}

#btn-exit:hover,
#btn-exit:active {
    background-color: #f0b8c0;
}

