html, body {
    margin: 0;
    padding: 0;
    background-color: #ffe4e1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50vh;
    min-height: 50dvh;
    font-family: 'Fredoka', sans-serif;
    touch-action: manipulation;
    overscroll-behavior-y: none;
}

.calculator {
    width: 100%;
    max-width: 400px;
    background-color: #fce4ec;
    height: 100vh; /*  fallback для очень старых браузеров */
    height: 100dvh; 
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(233, 30, 99, 0.3);
    padding: 20px;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

/* @media (min-width: 401px) {
    .calculator {
        height: auto;
        border-radius: 40px;
        margin: 20px 0;
    }
} */

/* Специально для мобильных экранов (захватываем ВСЕ iPhone) */
@media (max-width: 500px) {
    .calculator {
        max-width: 100%; 
        width: 100vw; /* Принудительно растягиваем на всю ширину окна */
        padding: 10px 5px; /* Уменьшили боковые отступы до 5px (чтобы было почти вплотную, как на Android) */
        border-radius: 0; 
    }

    .buttons {
        gap: 8px; /* Расстояние между кнопками */
    }
}

.header-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: auto;
}

.logo {
    font-size: 1.5rem;
    color: #d81b60;
    font-weight: 1000;
    letter-spacing: 0.5px;
    padding-left: 5px;
}

.btn-history-icon {
    background: none;
    border: none;
    color: #d81b60;
    cursor: pointer;
    padding: 5px;
    margin-top: 8px;
    margin-left: 0px;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: 'Fredoka', sans-serif;
    font-size: 3rem;
    font-weight: 500;
}

.btn-history-icon:active {
    transform: scale(0.9);
}

.modal-overlay {
    position: absolute;
    /* Стартуем с середины экрана, а не с самого верха */
    top: 50%; 
    left: 0;
    width: 100%;
    /* Высота ровно на половину контейнера */
    height: 65%; 
    background-color: rgba(252, 228, 236, 0.95);
    z-index: 10;
    display: flex;
    flex-direction: column;
    /* Убираем окно вниз за пределы экрана */
    transform: translateY(100%); 
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    padding: 20px;
    padding-top: 30px; /* Оставляем место под полосочку-ручку */
    box-sizing: border-box;
    /* Закругляем только верхние углы */
    border-radius: 30px 30px 0 0; 
    box-shadow: 0 -5px 25px rgba(233, 30, 99, 0.15);
}

/* Состояние открытого окна */
.modal-overlay.active {
    transform: translateY(0); 
}

/* Делаем визуальную "ручку" для свайпа как на iOS */
.modal-overlay::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 5px;
    background-color: #f8bbd0;
    border-radius: 5px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #d81b60;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f8bbd0;
}

.modal-close {
    background: none;
    border: none;
    color: #d81b60;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    text-align: right;
    color: #c2185b;
    font-size: 1.3rem;
    padding-right: 10px;
    scrollbar-width: thin;
    scrollbar-color: #f48fb1 transparent;
}

.modal-body .history-item {
    margin-bottom: 15px;
    border-bottom: 1px dashed #f8bbd0;
    padding-bottom: 5px;
}

.screen {
    flex: none;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    margin-bottom: 20px;
    margin-top: 10px;
    height: 120px;
}

.history {
    flex: 1;
    overflow-y: auto;
    text-align: right;
    color: #f06292;
    font-size: 1rem;
    padding-bottom: 0px;
    scrollbar-width: none;
}
.history::-webkit-scrollbar {
    display: none;
}
.history-item {
    margin-bottom: 5px;
}

.display {
    color: #c2185b;
    text-align: right;
    font-size: 2.5rem;
    font-weight: 500;
    word-wrap: break-word;
    word-break: break-all;
    line-height: 1;
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
}

button {
    border: none;
    border-radius: 70%;
    aspect-ratio: 1;
    font-size: 2.5rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: filter 0.1s;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

button:active {
    filter: brightness(0.8);
}

.btn-number {
    background-color: #f8bbd0;
    color: #880e4f;
}

.btn-action {
    background-color: #f48fb1;
    color: #880e4f;
}

.btn-operator {
    background-color: #ec407a;
    color: white;
    font-size: 2.5rem;
    padding-bottom: 6px;
    box-sizing: border-box;
    line-height: 1;
}

.btn-paren {
    background-color: #f8bbd0;
    color: #880e4f;
    padding-bottom: 4px;
}

.btn-equal {
    grid-column: span 2;
    border-radius: 50px;
    aspect-ratio: auto;
    padding: 15px 0;
    padding-bottom: 21px;
}