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

/* :root {} */

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
    /* background: conic-gradient(at right top, rgb(187, 247, 208), rgb(74, 222, 128), rgb(126, 34, 206)); */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;

    .author {
        margin-top: 10px;
        font-weight: 500px;
        font-size: 18px;
        color: #ecf0f195;
    }
}

.calculator-container {
    /* background: rgba(255, 255, 255, 0.1); */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
    border: 1px solid rgba(255, 255, 255, 0.18);
    max-width: 500px;
    width: 100%;

    .calc-selector {
        display: flex;
        justify-content: center;
        gap: 15px;
        margin-bottom: 25px;
        flex-wrap: wrap;
    }

    input[type="radio"] {
        display: none;
    }

    :checked+label {
        /* background: rgba(255, 255, 255, 0.3); */
        background: #667eea;
        color: white;
        transform: translateY(-2px);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }

    label {
        padding: 10px 20px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 25px;
        cursor: pointer;
        transition: all 0.3s ease;
        /* color: white; */
        color: #2c3e50;
        font-weight: 500;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    .unit-converter {
        color: white;

        .unit-selector {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
            margin-bottom: 25px;
            flex-wrap: nowrap;

            input[type="radio"] {
                display: none;
            }

            :checked+label {
                /* background: rgba(255, 255, 255, 0.3); */
                background: #667eea;
                color: white;
                transform: translateY(-2px);
                /* box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); */
                box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
            }

            label {
                padding: 7px 14px;
                background: rgba(255, 255, 255, 0.1);
                /* border-radius: 25px; */
                border-radius: 10px;
                cursor: pointer;
                transition: all 0.3s ease;
                /* color: white; */
                color: #2c3e50;
                font-weight: 300;
                /* border: 1px solid rgba(255, 255, 255, 0.2); */
                border: 1px solid rgba(102, 126, 234, 0.4);
            }
        }

        .reset-btn {
            padding: 11px;
            font-size: 15px;
            border-radius: 10px;
            color: rgba(177, 38, 38, 0.836);
            background: rgba(255, 99, 132, 0.3);
            border: 1px solid rgba(177, 38, 38, 0.603);
            transition: all 0.2s ease;
        }

        .reset-btn:hover {
            background: rgba(255, 99, 132, 0.2);
            transform: translateY(-2px);
        }

        .reset-btn:active {
            transform: translateY(0);
        }

        .converter-section {
            margin-bottom: 25px;
            background: rgba(255, 255, 255, 0.05);
            padding: 20px;
            border-radius: 15px;

            h3 {
                margin-bottom: 15px;
                text-align: center;
                color: #2c3e50;
            }

            .converter-row {
                display: flex;
                align-items: center;
                gap: 10px;
                margin-bottom: 10px;
                flex-wrap: wrap;
                justify-content: center;
                color: #2c3e50;
            }

            select,
            input {
                padding: 10px;
                border-radius: 8px;
                /* border: 1px solid rgba(255, 255, 255, 0.3); */
                /* background: rgba(255, 255, 255, 0.1); */
                /* color: white; */
                border: 1px solid rgba(44, 62, 80, 0.3);
                background: rgba(44, 62, 80, 0.1);
                color: #2c3e50;
                font-size: 14px;
            }

            input::placeholder {
                /* color: rgba(255, 255, 255, 0.7); */
                color: rgba(44, 62, 80, 0.7);
            }

            option {
                background-color: #2c3e50;
            }

            .reverse-btn {
                /* background: linear-gradient(135deg, #ff6b6b, #ee5a52); */
                /* background: rgba(255, 255, 255, 0.1); */
                /* color: white; */
                /* border: none; */
                /* border: 1px solid rgba(255, 255, 255, 0.4); */
                background: rgba(44, 62, 80, 0.1);
                color: #2c3e50;
                border: 1px solid rgba(44, 62, 80, 0.4);
                border-radius: 50%;
                width: 40px;
                height: 40px;
                cursor: pointer;
                transition: all 0.3s ease;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 18px;
                box-shadow: 0 6px 20px rgb(44, 62 80 / 10%);
                /* box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3); */
                /* box-shadow: 0 6px 20px rgb(255 255 255 / 10%) */
            }

            .reverse-btn:hover {
                transform: rotate(180deg) scale(1.1);
                /* box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4); */
                box-shadow: 0 6px 20px rgb(255 255 255 / 20%)
            }

            /* .convert-btn {
                padding: 11px;
                font-size: 15px;
                border-radius: 10px;
                background: rgba(75, 192, 192, 0.3);
                color: rgb(59, 134, 59);
                border: 1px solid rgb(59, 134, 59);
            }

            .convert-btn:hover {
                background: rgba(75, 192, 192, 0.2);
                transform: translateY(-2px);
            }

            .convert-btn:active {
                transform: translateY(0);
            } */

        }
    }
}

.display {
    background: #2c3e50;
    color: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    font-family: 'Courier New', monospace;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    position: relative;

    .display-top {
        width: 100%;
        font-size: 14px;
        color: #bdc3c7;
        min-height: 30px;
        overflow-wrap: anywhere;
        border-bottom: 1px solid #34495e;
        padding-bottom: 10px;
        margin-bottom: 10px;
        overflow: hidden;
        text-align: right;
    }

    .display-bottom {
        font-size: 24px;
        font-weight: bold;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        text-align: right;
        overflow-wrap: anywhere;
        overflow: hidden;
        position: relative;

        #current-input {
            direction: rtl;
            text-align: right;
            width: 100%;
            overflow: hidden;
        }

        .cursor {
            position: absolute;
            width: 2px;
            height: 1em;
            background: white;
            animation: blink 1s infinite;
            right: 0;
        }

    }
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

.buttons {
    display: grid;
    gap: 10px;

    .btn {
        padding: 15px;
        border-radius: 10px;
        font-size: 18px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        /* background: rgba(255, 255, 255, 0.1); */
        /* color: white; */
        background: #ecf0f1;
        color: #2c3e50;
        ;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    .btn:hover {
        /* background: rgba(255, 255, 255, 0.2); */
        background: rgba(44, 62, 80, 0.2);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        transform: translateY(-2px);
    }

    .btn:active {
        transform: translateY(0);
    }

    .btn.disabled {
        opacity: 0.3;
        cursor: not-allowed;
        background: rgba(255, 255, 255, 0.05);
    }

    .btn.disabled:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.05);
    }

    .btn.clear {
        /* background: rgba(255, 99, 132, 0.3); */
        background: #e67f22;
        color: white;
    }

    .btn.operator {
        /* background: rgba(54, 162, 235, 0.3); */
        background: #3598db;
        color: white;
    }

    .btn.equals {
        /* background: rgba(75, 192, 192, 0.3); */
        background: #e84c3d;
        color: white;
    }

    .btn.function {
        /* background: rgba(153, 102, 255, 0.3); */
        background: #9a59b5;
        color: white;
    }

}

.classic-buttons {
    grid-template-columns: repeat(4, 1fr);
}

.scientific-buttons {
    grid-template-columns: repeat(5, 1fr);
}

.hidden {
    display: none;
}

.keyboard-hint {
    display: block;
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.46);
    color: #ecf0f1;
    padding: 10px;
    border-radius: 5px;
    font-size: 12px;
    max-width: 200px;
    z-index: 1000;
}

/* @media (max-width: 600px) {
    .calculator-container {
        padding: 20px;
    }

    .calc-selector {
        gap: 10px;
    }

    .calc-selector label {
        padding: 8px 15px;
        font-size: 14px;
    }

    .btn {
        padding: 12px;
        font-size: 16px;
    }
} */

@media screen and (max-width: 480px) {
    body {
        padding: 10px;
    }

    .calculator-container {
        padding: 20px;
        max-width: 100%;
        margin: 0 auto;
    }

    .calc-selector {
        gap: 8px;
        margin-bottom: 20px;
        flex-wrap: nowrap !important;
    }

    .calc-selector label {
        padding: 8px 12px;
        font-size: 14px;
        white-space: nowrap;
    }

    .unit-converter .unit-selector {
        gap: 5px;
        flex-wrap: wrap !important;
        justify-content: center;
    }

    .unit-converter .unit-selector label {
        padding: 6px 10px;
        font-size: 12px;
        min-width: auto;
    }

    .unit-converter .converter-section {
        /* padding: 15px; */
        margin-bottom: 0 !important;
    }

    .unit-converter .converter-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .unit-converter .converter-row select,
    .unit-converter .converter-row input {
        width: 100%;
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    .unit-converter .reverse-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
        align-self: center;
    }

    .display {
        padding: 15px;
        min-height: 80px;
    }

    .display .display-bottom {
        font-size: 20px;
    }

    .display .display-top {
        font-size: 12px;
    }

    /* .buttons {
        padding: 12px;
        font-size: 16px;
    } */

    .classic-buttons {
        gap: 8px;

        .btn {
            padding: 12px;
            font-size: 16px;
        }
    }

    .scientific-buttons {
        gap: 5px;
        /* grid-template-columns: repeat(4, 1fr); */
        grid-template-columns: repeat(5, 1fr);
        /* Reduce to 4 columns on mobile */

        .btn {
            padding: 10px;
            font-size: 14px;
        }
    }

    .unit-converter .reset-btn {
        width: 100%;
        margin-top: 10px;
    }

    .author {
        font-size: 16px;
        text-align: center;
    }

    .keyboard-hint {
        display: none;
    }
}

/* Large Mobile / Small Tablet (481px - 768px) */
@media screen and (min-width: 481px) and (max-width: 768px) {
    .calculator-container {
        max-width: 450px;
        padding: 25px;
    }

    .calc-selector {
        gap: 10px;
    }

    .unit-converter .converter-row {
        flex-wrap: nowrap;
        justify-content: space-between;
    }

    .unit-converter .converter-row select,
    .unit-converter .converter-row input {
        flex: 1;
        min-width: 120px;
    }

    .display {
        min-height: 90px;
    }

    .display .display-bottom {
        font-size: 22px;
    }

    .buttons .btn {
        padding: 14px;
        font-size: 17px;
    }

    .scientific-buttons {
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
    }
}

/* Tablet (769px - 1024px) */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    body {
        padding: 30px;
    }

    .calculator-container {
        max-width: 500px;
    }

    .unit-converter .converter-section {
        padding: 25px;
    }

    .display {
        min-height: 100px;
    }

    .buttons .btn {
        padding: 16px;
        font-size: 18px;
    }
}

/* Desktop and larger screens (1025px+) */
/* @media screen and (min-width: 1025px) {
    body {
        padding: 40px;
    }

    .calculator-container {
        max-width: 550px;
    }

    .calc-selector {
        gap: 20px;
    }

    .unit-converter .converter-section {
        padding: 30px;
    }

    .display {
        min-height: 110px;
        padding: 25px;
    }

    .display .display-bottom {
        font-size: 26px;
    }

    .buttons .btn {
        padding: 18px;
        font-size: 19px;
    }

    .buttons {
        gap: 12px;
    }
} */

/* Ultra-wide screens (1440px+) */
/* @media screen and (min-width: 1440px) {
    .calculator-container {
        max-width: 600px;
    }

    .display {
        min-height: 120px;
        padding: 30px;
    }

    .display .display-bottom {
        font-size: 28px;
    }

    .buttons .btn {
        padding: 20px;
        font-size: 20px;
    }
} */

/* Landscape orientation adjustments for mobile */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .calculator-container {
        padding: 15px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .display {
        min-height: 60px;
        padding: 10px;
    }

    .display .display-bottom {
        font-size: 18px;
    }

    .buttons .btn {
        padding: 8px;
        font-size: 14px;
    }

    .calc-selector {
        margin-bottom: 15px;
    }

    .unit-converter .converter-section {
        padding: 10px;
        margin-bottom: 15px;
    }
}

/* High DPI displays */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
    .calculator-container {
        border-width: 0.5px;
    }

    .buttons .btn {
        border-width: 0.5px;
    }
}

/* Print styles */
@media print {
    body {
        background: white !important;
        color: black !important;
    }

    .calculator-container {
        background: white !important;
        box-shadow: none !important;
        border: 1px solid black !important;
    }

    .display {
        background: #f5f5f5 !important;
        color: black !important;
    }

    .buttons .btn {
        background: #f0f0f0 !important;
        color: black !important;
        border: 1px solid #ccc !important;
    }
}