/* Google Font */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Poppins", sans-serif;
}

body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg);
    transition: 0.3s ease-in-out;
}

/* ---------- THEME COLORS ---------- */
:root {
    --bg: linear-gradient(135deg, #edf0f5, #dcdfe6);
    --glass: rgba(255, 255, 255, 0.6);
    --border: rgba(255, 255, 255, 0.4);
    --text: #111;
    --btn-bg: rgba(255, 255, 255, 0.7);
    --btn-hover: rgba(255, 255, 255, 0.95);
    --special: rgba(0, 0, 0, 0.7);
}

.darkmode {
    --bg: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    --glass: rgba(255, 255, 255, 0.1);
    --border: rgba(255, 255, 255, 0.2);
    --text: #fff;
    --btn-bg: rgba(255, 255, 255, 0.1);
    --btn-hover: rgba(255, 255, 255, 0.25);
    --special: rgba(0, 255, 150, 0.4);
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.switch {
    position: relative;
    width: 50px;
    height: 25px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0;
    right: 0; bottom: 0;
    background: #ccc;
    transition: 0.3s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 2.5px;
    background: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background: #4bd865;
}

input:checked + .slider:before {
    transform: translateX(24px);
}

/* ---------- CALCULATOR ---------- */
.calculator {
    width: 340px;
    padding: 20px;
    border-radius: 22px;
    background: var(--glass);
    border: 1px solid var(--border);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(14px);
    transition: 0.25s;
}

/* DISPLAY (updated to prevent overflow & allow scaling) */
.display {
    background: rgba(0,0,0,0.12);
    padding: 20px 14px;
    border-radius: 15px;
    margin-bottom: 20px;
    color: var(--text);
    min-height: 70px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    overflow: hidden;               /* penting: sembunyikan overflow */
}

#result {
    font-size: 40px;                /* default size */
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;            /* mencegah wrap */
    overflow: hidden;               /* sembunyikan overflow */
    text-overflow: ellipsis;        /* potong dengan ... jika sangat panjang */
    transition: font-size 0.12s ease, transform 0.12s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    max-width: 100%;
}


/* ---------- BUTTONS ---------- */
.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.btn {
    padding: 15px;
    border-radius: 16px;
    border: none;
    background: var(--btn-bg);
    cursor: pointer;
    font-size: 18px;
    color: var(--text);
    font-weight: 500;
    transition: 0.2s ease;
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn:hover {
    background: var(--btn-hover);
    transform: scale(1.08);
}

.btn:active {
    transform: scale(0.95);
}

/* Special buttons */
.operator {
    background: rgba(0, 200, 255, 0.3);
    color: #fff;
}

.function {
    background: rgba(255, 80, 80, 0.4);
    color: #fff;
}

.equals {
    background: var(--special);
    color: #fff;
}

.zero {
    grid-column: span 2;
}

/* Scientific Buttons */
.sci {
    background: rgba(255, 255, 0, 0.3);
}

/* ---------- Animation ---------- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */
@media (max-width: 450px) {
    .calculator {
        width: 100%;
        max-width: 340px;
    }

    .theme-toggle {
        top: 10px;
        right: 10px;
        scale: 0.9;
    }
}
