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

html {
    font-size: 16px;
}

body {
    background-image: url('bg.jpg');
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto auto auto auto auto auto auto auto;
    grid-template-areas:
        "header dom-help dom-help"
        "output output output"
        "keypad eraser otherop"
        "keypad opbase otherop"
        "keypad opbase degrad"
        "keypad opbase trigo"
        "special accurate trigo"
        "special random trigo";
    gap: 1rem;
    padding: 1rem;
    justify-content: center;
    max-width: 1300px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* From Uiverse.io by alexruix */
.input-group {
    display: flex;
    align-items: center;
}

.header {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
}

.random {
    grid-area: random;
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
}

.accurate {
    grid-area: accurate;
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
}

.input {
    min-height: 50px;
    width: 100%;
    max-width: 20em;
    padding: 0 1rem;
    color: #fff;
    font-size: clamp(14px, 4vw, 22px);
    border: 1px solid #5e4dcd;
    border-radius: 6px 0 0 6px;
    background-color: transparent;
    box-sizing: border-box;
}

.button--submit {
    min-height: 50px;
    padding: .4em 1em;
    border: none;
    border-radius: 0 6px 6px 0;
    background-color: #5e4dcd;
    color: #fff;
    font-size: clamp(14px, 4vw, 22px);
    cursor: pointer;
    transition: background-color .3s ease-in-out;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.button--submit:hover {
    background-color: #5e5dcd;
}

.res {
    color: #ffffff;
    font-size: 30px;
    font-weight: 700;
    margin: 0;
    font-family: inherit;
    grid-area: output;
}

.res p {
    margin: 0;
    padding: 10px;
    background-color: #100361CC;
    border-radius: 6px;
    border: 1px solid #f0cfff;
    max-width: 30em;
    overflow: auto;
}

.alert {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1200;
    margin: 0;
}
.alert p {
    margin: 0;
    padding: 14px 18px;
    background-color: #FF0048CC;
    border-radius: 10px;
    font-family: inherit;
    font-size: 20px;
    font-weight: 700;
    color: #fdcbcb;
    border-color: #fdcbcb;
    max-width: min(90%, 720px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.input:focus, .input:focus-visible {
    border-color: #0a2374;
    outline: none;
}


/* From Uiverse.io by adamgiebl */
button {
    background: #b59be3;
    font-family: inherit;
    padding: 0.6em 1.3em;
    font-weight: 600;
    font-size: 21px;
    border: 3px solid #130232;
    border-radius: 0.4em;
    box-shadow: 0.1em 0.1em;
    cursor: pointer;
    height: 100%;
}

button:hover {
    transform: translate(-0.05em, -0.05em);
    box-shadow: 0.15em 0.15em;
}

button:active {
    transform: translate(0.05em, 0.05em);
    box-shadow: 0.05em 0.05em;
}

button:disabled {
    cursor: not-allowed;
}

.eraser {
    /* place two buttons in a small grid so each matches .opbase column width */
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    justify-content: center;
    align-items: center;
    grid-area: eraser;
}

.eraser button {
    width: 100%;
    background: #ef75cc;
}

.opbase button {
    background: #8a82fd;
}

.special button {
    background: #ea79e5;
}

.otherop button {
    background: #d171ff;
}

.trigo button {
    background: #9f79ea;
}

.degrad button {
    background: #400960;
    color: #d49eef;
    border-color: #d49eef;
}

.number {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    justify-content: center;
    grid-area: keypad;
}

.opbase {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    justify-content: center;
    grid-area: opbase;
}

.special {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    justify-content: center;
    grid-area: special;
}

.otherop {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    justify-content: center;
    grid-area: otherop;
}

.trigo {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    justify-content: center;
    grid-area: trigo;
}

.degrad {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 10px;
    justify-content: center;
    grid-area: degrad;
}

.dom {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    grid-area: dom-help;
}

.dom button {
    transition: 0.5s;
    flex: 1 1 72px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0.4em 0.6em;
    box-sizing: border-box;
}

/* bouton actif */
.dom button.active {
    background-color: #0b0045;
    border-color: #f0cfff;
    color: #f0cfff;
}



/* Help button fixed top-right */
.help-button {
    position: static;
    grid-area: help;
    justify-self: end;
    align-self: start;
    z-index: 2;
    padding: 0.4em 0.9em;
    font-size: 21px;
    margin-left: 2rem;
}

/* Overlay and modal for help */
.help-div {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1090;
    padding-left: 1.5rem;
    font-size: 25px;
}

.help-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(6px);
}

.help-modal {
    position: relative;
    z-index: 1101;
    width: min(90%, 700px);
    max-height: 80vh;
    overflow: auto;
    background: rgba(10,6,40,0.95);
    color: #E9CBF4FF;
    border-radius: 12px;
    border: 3px solid #999dff;
    padding: 1.2rem 1.4rem 1.6rem 1.4rem;
    box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}

.help-close {
    position: absolute;
    top: 0.5rem;
    right: 0.6rem;
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.help-content p {
    margin: 0;
    white-space: pre-line;
}

/* Media queries for responsiveness */
@media (max-width: 1024px) {
    #app {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
        padding: 1rem;
    }
    
    #app {
        grid-template-areas:
            "header dom-help"
            "output output"
            "keypad eraser"
            "keypad opbase"
            "keypad otherop"
            "keypad degrad"
            "special trigo"
            "accurate random";
    }
}

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
    
    #app {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 0.75rem;
        grid-template-areas:
            "header"
            "dom-help"
            "output"
            "keypad"
            "eraser"
            "opbase"
            "otherop"
            "degrad"
            "trigo"
            "special"
            "accurate"
            "random";
    }
    
    .number,
    .opbase,
    .otherop,
    .trigo {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    
    .special {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .degrad {
        grid-template-columns: repeat(1, 1fr) !important;
    }
    
    .input {
        min-height: 45px;
        max-width: 100%;
    }
    
    .button--submit {
        min-height: 47px;
        padding: 0.4em 0.8em;
        font-size: 16px;
    }
    
    button {
        padding: 0.5em 0.8em;
        font-size: 16px;
        border: 2px solid #130232;
        box-shadow: 0.05em 0.05em;
    }
    
    .res {
        font-size: 24px;
    }
    
    .res p {
        max-width: 100%;
        padding: 8px;
    }
    
    .help-modal {
        width: min(95%, 90vh);
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 12px;
    }
    
    #app {
        gap: 0.5rem;
        padding: 0.5rem;
        max-width: 100%;
    }
    
    .input {
        width: 100%;
        min-height: 40px;
        padding: 0 0.75rem;
        font-size: 14px;
    }
    
    .button--submit {
        min-height: 40px;
        padding: 0.3em 0.6em;
        font-size: 14px;
    }
    
    button {
        padding: 0.4em 0.6em;
        font-size: 14px;
        border: 1px solid #130232;
        box-shadow: 0.03em 0.03em;
    }
    
    button:hover {
        box-shadow: 0.05em 0.05em;
    }
    
    .res {
        font-size: 18px;
    }
    
    .res p {
        padding: 6px;
        font-size: 16px;
    }
    
    .dom button {
        padding: 0.3em 0.4em;
        font-size: 12px;
    }
    
    .help-modal {
        padding: 1rem;
        font-size: 14px;
    }
    
    .alert p {
        font-size: 14px;
        padding: 10px 12px;
    }
}