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

html, body {
    width: 100%;
    height: 100%;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Google Brand Colors */
:root {
    --google-blue: #4285f4;
    --google-red: #ea4335;
    --google-yellow: #fbbc04;
    --google-green: #34a853;
    --google-light-gray: #f8f9fa;
    --google-gray: #dadce0;
    --google-dark-gray: #5f6368;
    --google-text-dark: #202124;
    --google-text-light: #ffffff;
    
    --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    --shadow-md: 0 1px 3px rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root {
        --google-light-gray: #202124;
        --google-gray: #3c4043;
        --google-dark-gray: #9aa0a6;
        --google-text-dark: #f1f3f4;
        --google-text-light: #202124;
    }
}

body {
    background-color: var(--google-light-gray);
    color: var(--google-text-dark);
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 100vh;
    padding-top: 56px;
    overflow-x: hidden;
}

.app-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background-color: var(--google-light-gray);
    border-bottom: 1px solid var(--google-gray);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.app-header h1 {
    font-size: 20px;
    font-weight: 500;
    color: var(--google-text-dark);
    margin: 0;
}

.history-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--google-blue);
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.history-btn:active {
    background-color: rgba(66, 133, 244, 0.1);
    transform: scale(0.95);
}

/* History Panel */
.history-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0;
    background-color: var(--google-light-gray);
    border-top: 1px solid var(--google-gray);
    overflow-y: auto;
    z-index: 900;
    transition: height 0.3s ease;
    box-shadow: 0 -2px 8px rgba(60, 64, 67, 0.15);
}

.history-panel.active {
    height: 50vh;
    max-height: calc(100vh - 56px - 360px);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--google-gray);
    background-color: var(--google-light-gray);
}

.history-header h2 {
    font-size: 16px;
    font-weight: 500;
    margin: 0;
}

.clear-history-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--google-red);
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.clear-history-btn:active {
    background-color: rgba(234, 67, 53, 0.1);
    transform: scale(0.95);
}

.history-list {
    list-style: none;
    padding: 8px;
}

.history-list li {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 4px 0;
    font-family: 'Roboto Mono', monospace;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: transparent;
}

.history-list li:hover {
    background-color: var(--google-gray);
}

.history-list li:active {
    background-color: rgba(66, 133, 244, 0.1);
    color: var(--google-blue);
}

/* Calculator Container */
.calculator-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
    overflow-y: auto;
}

.calculator {
    width: 100%;
    max-width: 360px;
    background-color: var(--google-light-gray);
    border-radius: 24px;
    padding: 20px 12px;
    box-shadow: var(--shadow-md);
}

/* Display */
.display-section {
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.display {
    width: 100%;
    background-color: var(--google-light-gray);
    border: 2px solid var(--google-gray);
    border-radius: 12px;
    padding: 20px 16px;
    font-size: 36px;
    font-weight: 300;
    text-align: right;
    color: var(--google-text-dark);
    font-family: 'Roboto', sans-serif;
    transition: all 0.2s ease;
    outline: none;
}

.display:focus {
    border-color: var(--google-blue);
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.1);
}

.display::placeholder {
    color: var(--google-dark-gray);
}

/* Buttons Grid */
.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 8px;
}

/* Material Web Component Button Styling */
md-filled-button {
    --md-filled-button-container-height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    font-family: 'Roboto', sans-serif;
    font-size: 18px;
    font-weight: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

md-filled-button:active {
    transform: scale(0.95);
}

md-filled-button svg {
    width: 24px;
    height: 24px;
}

/* Number Buttons - Light Gray */
md-filled-button.btn-number {
    --md-filled-button-container-color: var(--google-light-gray);
    --md-filled-button-label-text-color: var(--google-text-dark);
    border: 2px solid var(--google-gray);
}

md-filled-button.btn-number:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Operator Buttons - Google Blue */
md-filled-button.btn-operator {
    --md-filled-button-container-color: var(--google-blue);
    --md-filled-button-label-text-color: var(--google-text-light);
}

md-filled-button.btn-operator:hover {
    filter: brightness(1.1);
}

md-filled-button.btn-divide {
    --md-filled-button-container-color: var(--google-blue);
}

md-filled-button.btn-multiply {
    --md-filled-button-container-color: var(--google-blue);
}

md-filled-button.btn-minus {
    --md-filled-button-container-color: var(--google-blue);
}

md-filled-button.btn-plus {
    --md-filled-button-container-color: var(--google-blue);
}

/* AC Button - Google Red */
md-filled-button.btn-ac {
    --md-filled-button-container-color: var(--google-red);
    --md-filled-button-label-text-color: var(--google-text-light);
    grid-column: 1;
}

md-filled-button.btn-ac:hover {
    filter: brightness(1.1);
}

/* Delete Button - Light Gray */
md-filled-button.btn-delete {
    --md-filled-button-container-color: var(--google-light-gray);
    --md-filled-button-label-text-color: var(--google-text-dark);
    border: 2px solid var(--google-gray);
    grid-column: 2;
}

md-filled-button.btn-delete:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Percent Button - Google Yellow */
md-filled-button.btn-percent {
    --md-filled-button-container-color: var(--google-yellow);
    --md-filled-button-label-text-color: var(--google-text-dark);
    grid-column: 3;
}

md-filled-button.btn-percent:hover {
    filter: brightness(0.95);
}

/* Equals Button - Google Green */
md-filled-button.btn-equals {
    --md-filled-button-container-color: var(--google-green);
    --md-filled-button-label-text-color: var(--google-text-light);
    --md-filled-button-label-text-font-weight: 600;
    --md-filled-button-label-text-font-size: 24px;
}

md-filled-button.btn-equals:hover {
    filter: brightness(1.1);
}

/* Zero Button Spans 2 Columns */
md-filled-button.btn-zero {
    grid-column: span 2;
}

/* Responsive Design - Tablet */
@media (min-width: 600px) {
    .calculator {
        max-width: 420px;
    }
    
    .display {
        font-size: 42px;
        padding: 24px 20px;
    }
    
    .buttons-grid {
        gap: 10px;
    }
    
    md-filled-button {
        font-size: 20px;
        border-radius: 14px;
    }
}

/* Responsive Design - Desktop */
@media (min-width: 900px) {
    body {
        padding-top: 0;
    }
    
    .app-header {
        position: relative;
        margin-bottom: 24px;
    }
    
    .app-container {
        flex-direction: row;
    }
    
    .calculator-container {
        flex: 1;
        max-width: 500px;
    }
    
    .history-panel {
        position: relative;
        width: 280px;
        height: auto;
        bottom: auto;
        border-top: none;
        border-left: 1px solid var(--google-gray);
        border-radius: 0;
        box-shadow: none;
    }
    
    .history-panel.active {
        height: auto;
    }
    
    .history-btn {
        display: none;
    }
    
    .history-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background-color: var(--google-light-gray);
    }
}

/* Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .app-header {
        height: 48px;
    }
    
    body {
        padding-top: 48px;
    }
    
    .calculator-container {
        padding: 8px;
    }
    
    .calculator {
        padding: 12px 8px;
    }
    
    .display {
        font-size: 24px;
        padding: 12px 12px;
    }
    
    .display-section {
        margin-bottom: 12px;
    }
    
    .buttons-grid {
        gap: 4px;
    }
    
    md-filled-button {
        font-size: 14px;
    }
}

/* Touch Optimization */
@media (hover: none) and (pointer: coarse) {
    md-filled-button {
        min-width: 48px;
        min-height: 48px;
    }
    
    .history-btn,
    .clear-history-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    md-filled-button,
    .display,
    body,
    .history-panel,
    .history-btn,
    .clear-history-btn {
        transition: none;
    }
}

/* Focus visible for keyboard navigation */
md-filled-button:focus-visible,
.history-btn:focus-visible,
.clear-history-btn:focus-visible {
    outline: 2px solid var(--google-blue);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .app-header,
    .history-panel,
    .history-btn,
    .clear-history-btn {
        display: none;
    }
    
    .calculator {
        box-shadow: none;
    }
}
