/* ==========================================================================
   1. Core Page Layout
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background-color: #01022b;
}

body {
    color: #ffeb3b;
    font-family: 'Vibur', cursive;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; 
    min-height: 100dvh; /* Fluid viewport adaptation */
    padding: 20px 12px;
    transform: scale(0.85); /* Initial scaling for mobile */
}

h1 {
    font-size: clamp(2rem, 5vh, 3.2rem); 
    margin-top: 0;
    margin-bottom: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* ==========================================================================
   2. Calculator Wrapper (Main Fluid Box Container)
   ========================================================================== */
.calculator {
    background: #111111;
    padding: clamp(16px, 3vw, 36px); 
    border-radius: 20px;
    border: 1px solid #ffeb3b;
    box-shadow: 0 0 35px rgba(255, 235, 59, 0.22);
    width: 100%;
    max-width: 820px; /* Dominant profile on desktop viewports */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* ==========================================================================
   3. Display Screen
   ========================================================================== */
.displaytext {
    background-color: #0d0d0d;
    padding: clamp(15px, 2vw, 25px);
    border: 1px solid #333333;
    border-radius: 12px;
    margin-bottom: clamp(15px, 2.5vh, 28px); 
    user-select: none;
    display: flex;
    justify-content: flex-end; 
    align-items: center;
    min-height: clamp(75px, 10vh, 110px); 
    overflow-x: auto; 
    scrollbar-width: none; 
    flex-shrink: 0;
    font-family: 'Vibur', cursive;
}

.displaytext::-webkit-scrollbar {
    display: none; /* Hides horizontal bars on Chrome, Safari, and Opera */
}

.displaytext span {
    font-size: clamp(2.4rem, 6vh, 4rem); /* Large font scaling readout */
    color: white;
    margin: 0;
    padding: 0;
    white-space: nowrap; 
}

/* ==========================================================================
   4. Grid Layout Structure
   ========================================================================== */
.buttons {
    display: grid;
    gap: clamp(8px, 1.8vw, 20px); /* Tighter spacing configuration on mobile */
    width: 100%;
    justify-content: center; 
    align-content: center;   
}

/* 4 Column Mapping */
.buttons[data-layout="4-col"] {
    grid-template-columns: repeat(4, 1fr);
}
.buttons[data-layout="4-col"] .equals {
    grid-column: span 4;
}

/* 8 Column Mapping */
.buttons[data-layout="8-col"] {
    grid-template-columns: repeat(8, 1fr);
}
.buttons[data-layout="8-col"] .equals {
    grid-column: span 8;
}

/* ==========================================================================
   5. Button Elements Styling
   ========================================================================== */
.addition, .subtraction, .multiplication, .division, .number, .equals, .open-parenthesis, .power-of {
    background: #1a1a1a;
    color: white;
    border: 1px solid #ffeb3b;
    padding: clamp(12px, 2vh, 22px); 
    min-height: clamp(55px, 7.5vh, 85px); /* Ensures buttons maintain structure on mobile */
    width: 100%; 
    font-family: 'Vibur', cursive;
    font-size: clamp(1.3rem, 2.5vh, 2rem); /* Dynamic button text scaling */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center; 
    text-align: center;
    transition: transform 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.addition:hover, .subtraction:hover, .multiplication:hover, .division:hover, .number:hover, .equals:hover, .open-parenthesis:hover, .power-of:hover {
    color: #0d0d0d;
    background-color: #ffeb3b;
    transform: scale(1.04);
}

.equals {
    border-color: #ff3b3b;
}

.equals:hover {
    background-color: #ff3b3b;
    color: white;
}

/* ==========================================================================
   6. Landscape & Mobile Height Adjustments (Prevents Layout Squishing)
   ========================================================================== */
@media (max-height: 580px) and (orientation: landscape) {
    body { padding: 8px; }
    h1 { margin-bottom: 8px; font-size: 1.8rem; }
    .displaytext { min-height: 55px; margin-bottom: 12px; padding: 10px 20px; }
    .calculator { padding: 14px; }
    .addition, .subtraction, .multiplication, .division, .number, .equals, .open-parenthesis, .power-of {
        min-height: 44px;
        padding: 6px;
        font-size: 1.2rem;
    }
}
