*,
*::after,
*::before {
    box-sizing: border-box;
}

body {
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: hsl(0, 0%, 80%);
}

#calculate {
    font-family: monospace;
    background-color: hsl(0, 0%, 15%);
    border-radius: 1em;
    max-width: 600px;
    width: 100%;
    overflow: hidden;
    margin: 20px;
}

.memory-textarea {
    height: 75px;
    resize: none;
    width: 100%;
    padding: 5px 20px;
    font-size: 1rem;
    text-align: right;
    color: hsl(0, 0%, 60%);
    background-color: hsl(0, 0%, 20%);
    border: none;
    font-family: monospace;
    white-space: pre;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: hsl(0, 0%, 40%) hsl(0, 0%, 20%);
}

.memory-textarea::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.memory-textarea::-webkit-scrollbar-track {
    background: hsl(0, 0%, 20%);
    border-radius: 4px;
}

.memory-textarea::-webkit-scrollbar-thumb {
    background: hsl(0, 0%, 40%);
    border-radius: 4px;
}

.memory-textarea::-webkit-scrollbar-thumb:hover {
    background: hsl(0, 0%, 50%);
}

#display {
    width: 100%;
    padding: 15px 20px;
    font-size: 4rem;
    text-align: right;
    border: none;
    background-color: hsl(0, 0%, 20%);
    color: white;
    font-family: Arial, Helvetica, sans-serif, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: font-size 0.2s ease;
}

#live-result {
    width: 100%;
    height: 60px;
    resize: none;
    padding: 10px 20px;
    font-size: 1.5rem;
    text-align: right;
    color: hsl(0, 0%, 70%);
    background-color: hsl(0, 0%, 15%);
    border: none;
    border-bottom: 1px solid hsl(0, 0%, 25%);
    font-family: monospace;
}

#simplified {
    display: grid;
    column-gap: 4%;
    row-gap: 10px;
    padding: 25px;
    justify-content: center;
    grid-template-columns: repeat(4, 1fr);
    grid-template-areas:
        'allClear clear backspace divide'
        'seven eight nine multiply'
        'four five six substract'
        'one two three add'
        'invertS zero dot equals';
}

#keys {
    display: none;
    column-gap: 4%;
    row-gap: 10px;
    padding: 25px;
    justify-content: center;
    grid-template-columns: repeat(5, 16%);
    grid-template-areas:
        'repl sin cos tg ctg'
        'power lg ln open-bracket close-bracket'
        'sqrt allClear clear backspace divide'
        'fact seven eight nine multiply'
        'one-divide four five six substract'
        'numPi one two three add'
        'invertK exponent zero dot equals';
}

#revSin {
    grid-area: sin;
}

#revCos {
    grid-area: cos;
}

#revTan {
    grid-area: tan;
}

#revCtg {
    grid-area: ctg;
}

#popPanels {
    padding-top: 10px;
    display: none;
    gap: 10px;
    grid-template-areas: 'trigonometry function';
}

#keys button {
    width: 100%;
    aspect-ratio: 1/1;
    border-radius: 50%;
    border: none;
    background-color: hsl(0, 0%, 30%);
    color: white;
    font-size: clamp(1em, 3vh, 2.5em);
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    justify-self: center;
}

#simplified button {
    width: 100%;
    aspect-ratio: 1/1;
    border-radius: 50%;
    border: none;
    background-color: hsl(0, 0%, 30%);
    color: white;
    font-size: clamp(1em, 3vh, 2.5em);
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    justify-self: center;
}

#keys button:hover,
#simplified button:hover {
    background-color: hsl(0, 0%, 40%);
}

#keys button:active,
#simplified button:active {
    transform: scale(0.95);
    background-color: hsl(0, 0%, 50%);
}

button.data:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    background: hsl(0, 0%, 20%);
    color: white;
    padding: 5px;
    border-radius: 5px;
    font-size: 0.8rem;
    transform: translateY(-100%);
}

.panels {
    background-color: hsl(15, 100%, 50%);
}

.panels:hover {
    background-color: hsl(15, 100%, 60%);
}

#keys .operator-btn,
#simplified .operator-btn {
    background-color: hsl(39, 100%, 35%);
}

#keys .operator-btn:hover,
#simplified .operator-btn:hover {
    background-color: hsl(39, 100%, 45%);
}

#keys #equals,
#simplified #equals {
    background-color: hsl(20, 100%, 50%);
}

#keys #equals:hover #simplified #equals:hover {
    background-color: hsl(20, 100%, 60%);
}

/* Кнопка зміни калькулятора */
.swap-button {
    position: relative;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.5s ease;
    will-change: transform;
}

.swap-button::before,
.swap-button::after {
    content: "";
    position: absolute;
    width: 40%;
    height: 40%;
    background-color: transparent;
    border-radius: 4px;
    border: 2px solid white;
    transition: all 0.4s ease;
    z-index: 2;
}

.swap-button::before {
    bottom: 20%;
    left: 20%;
}
.swap-button::after {
    top: 20%;
    right: 20%;
}

.swap-button.swapped::before {
    top: auto;
    left: auto;
    top: 20%;
    right: 20%;
}
.swap-button.swapped::after {
    bottom: auto;
    right: auto;
    bottom: 20%;
    left: 20%;
}

@media (max-width: 768px) {
    #display {
        font-size: 3.5rem;
    }

    #calculate {
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    button.data:hover::after {
        content: none;
    }
}

@media (max-width: 480px) {
    #display {
        font-size: 2.5rem;
    }
}

@media (max-width: 350px) {
    #display {
        font-size: 2rem;
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.error-shake {
    animation: shake 0.15s linear 3;
}
