* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: var(--font-family, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif);
    background: var(--body-background, #f0f0f0);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
}

.calculator-container {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: var(--calculator-background, #ffffff);
    display: flex;
    flex-direction: column;
    padding: var(--spacing-small, 10px);
    gap: var(--spacing-small, 8px);
    overflow: hidden;
    position: relative;
}

.calculator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--spacing-small, 6px);
    border-bottom: 2px solid var(--border-color, #e0e0e0);
    flex-shrink: 0;
}

.calculator-header h1 {
    font-size: var(--header-font-size, 20px);
    color: var(--text-color, #333333);
    font-weight: 600;
}

.controls {
    display: flex;
    gap: var(--spacing-small, 6px);
    flex-wrap: wrap;
    align-items: center;
}

.control-button {
    padding: 6px 10px;
    border: 1px solid var(--border-color, #cccccc);
    border-radius: var(--border-radius, 6px);
    background: var(--control-background, #f8f8f8);
    color: var(--text-color, #333333);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.control-button:hover {
    background: var(--control-hover-background, #e8e8e8);
}

.control-button-close {
    color: #d32f2f;
    font-weight: bold;
    font-size: 18px;
}

.control-button-close:hover {
    background: #ffebee;
    color: #b71c1c;
}

.control-select {
    padding: 6px 10px;
    border: 1px solid var(--border-color, #cccccc);
    border-radius: var(--border-radius, 6px);
    background: var(--control-background, #f8f8f8);
    color: var(--text-color, #333333);
    font-size: var(--control-font-size, 12px);
    font-family: var(--font-family, inherit);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.control-select:hover {
    background: var(--control-hover-background, #e8e8e8);
}

.control-select:focus {
    outline: 2px solid var(--accent-color, #4CAF50);
    outline-offset: 2px;
}

.display-container {
    background: var(--display-background, #f5f5f5);
    border-radius: var(--border-radius, 8px);
    padding: var(--spacing-medium, 12px);
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 4px;
    border: 2px solid var(--display-border-color, #e0e0e0);
    flex-shrink: 0;
}

.display-memory {
    font-size: 12px;
    color: var(--memory-text-color, #2196F3);
    font-weight: 600;
    text-align: right;
    font-family: var(--font-family-mono, 'Courier New', monospace);
}

.display-history {
    font-size: 14px;
    color: var(--history-text-color, #666666);
    min-height: 16px;
    text-align: right;
    font-family: var(--font-family-mono, 'Courier New', monospace);
}

.display-main {
    background: transparent;
    border: none;
    font-size: var(--display-font-size, 32px);
    font-weight: var(--display-font-weight, 300);
    color: var(--display-text-color, #000000);
    text-align: right;
    font-family: var(--font-family-mono, 'Courier New', monospace);
    width: 100%;
    padding: 0;
    margin: 0;
}

.display-main:focus {
    outline: none;
}

.button-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--button-gap, 8px);
    padding: var(--spacing-small, 6px) 0;
    overflow: auto;
    min-height: 0;
}

.scientific-grid {
    grid-template-columns: repeat(7, 1fr);
}

.btn {
    border: none;
    border-radius: var(--button-border-radius, 8px);
    font-size: var(--button-font-size, 18px);
    font-family: var(--font-family, inherit);
    font-weight: var(--button-font-weight, 500);
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--button-background, #ffffff);
    color: var(--button-text-color, #333333);
    border: 1px solid var(--button-border-color, #e0e0e0);
    min-height: 45px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--button-shadow, rgba(0, 0, 0, 0.1));
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px var(--button-shadow, rgba(0, 0, 0, 0.1));
}

.btn-number {
    background: var(--number-button-background, #ffffff);
    color: var(--number-button-text-color, #333333);
}

.btn-number:hover {
    background: var(--number-button-hover-background, #f5f5f5);
}

.btn-operator {
    background: var(--operator-button-background, #ff9800);
    color: var(--operator-button-text-color, #ffffff);
    font-weight: 600;
}

.btn-operator:hover {
    background: var(--operator-button-hover-background, #fb8c00);
}

.btn-function {
    background: var(--function-button-background, #e0e0e0);
    color: var(--function-button-text-color, #333333);
}

.btn-function:hover {
    background: var(--function-button-hover-background, #d5d5d5);
}

.btn-scientific {
    background: var(--scientific-button-background, #2196F3);
    color: var(--scientific-button-text-color, #ffffff);
    font-size: 14px;
}

.btn-scientific:hover {
    background: var(--scientific-button-hover-background, #1976D2);
}

.btn-memory {
    background: var(--memory-button-background, #9C27B0);
    color: var(--memory-button-text-color, #ffffff);
    font-size: 14px;
    font-weight: 600;
}

.btn-memory:hover {
    background: var(--memory-button-hover-background, #7B1FA2);
}

/* Accent color class for specific buttons */
.btn-accent {
    background: var(--accent-color, #0078d4) !important;
    color: #ffffff !important;
}

.btn-accent:hover {
    background: var(--accent-hover-color, #005a9e) !important;
}

.btn-equals {
    background: var(--equals-button-background, #4CAF50);
    color: var(--equals-button-text-color, #ffffff);
    font-weight: 700;
    font-size: 1.3em;
    grid-column: span 2;
}

.btn-equals:hover {
    background: var(--equals-button-hover-background, #45a049);
}

/* Unit Converter Styles */
.converter-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-medium, 12px);
    padding: var(--spacing-small, 6px) 0;
    overflow: auto;
    min-height: 0;
}

.converter-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.converter-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color, #333333);
}

.converter-select {
    width: 100%;
    padding: 10px;
    font-size: 14px;
}

.converter-input-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-medium, 12px);
    align-items: center;
}

.converter-input-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.converter-input {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color, #cccccc);
    border-radius: var(--border-radius, 8px);
    font-size: 20px;
    font-family: var(--font-family-mono, 'Courier New', monospace);
    background: var(--input-background, #ffffff);
    color: var(--text-color, #333333);
    text-align: right;
}

.converter-input:focus {
    outline: 2px solid var(--accent-color, #4CAF50);
    outline-offset: 2px;
}

.converter-unit-select {
    width: 100%;
    padding: 10px;
    font-size: 14px;
}

.btn-swap {
    background: var(--accent-color, #4CAF50);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-swap:hover {
    background: var(--accent-hover-color, #45a049);
    transform: rotate(180deg);
}

.converter-info {
    padding: var(--spacing-medium, 15px);
    background: var(--info-background, #e3f2fd);
    border-radius: var(--border-radius, 8px);
    border-left: 4px solid var(--accent-color, #2196F3);
    color: var(--text-color, #333333);
    font-size: var(--info-font-size, 14px);
    line-height: 1.5;
    flex-shrink: 0;
}

/* History Panel - Popover Style */
.history-panel {
    position: absolute;
    top: 60px;
    right: 10px;
    width: 280px;
    max-height: 400px;
    background: var(--calculator-background, #ffffff);
    border: 2px solid var(--border-color, #e0e0e0);
    border-radius: var(--border-radius, 8px);
    box-shadow: 0 4px 12px var(--container-shadow, rgba(0, 0, 0, 0.15));
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 2px solid var(--border-color, #e0e0e0);
}

.history-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-color, #333333);
}

.btn-clear-history {
    padding: 4px 10px;
    background: var(--function-button-background, #e0e0e0);
    color: var(--function-button-text-color, #333333);
    border: none;
    border-radius: var(--border-radius, 6px);
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s ease;
}

.btn-clear-history:hover {
    background: var(--function-button-hover-background, #d5d5d5);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 8px;
    margin-bottom: 6px;
    background: var(--display-background, #f5f5f5);
    border-radius: var(--border-radius, 6px);
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: var(--control-hover-background, #e8e8e8);
    transform: translateX(-4px);
}

.history-expression {
    font-size: 12px;
    color: var(--history-text-color, #666666);
    font-family: var(--font-family-mono, 'Courier New', monospace);
}

.history-result {
    font-size: 14px;
    color: var(--text-color, #333333);
    font-weight: 600;
    font-family: var(--font-family-mono, 'Courier New', monospace);
    margin-top: 2px;
}

.history-empty {
    text-align: center;
    padding: var(--spacing-medium, 15px);
    color: var(--history-text-color, #666666);
    font-style: italic;
    font-size: 12px;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .calculator-container {
        padding: 8px;
    }
    
    .calculator-header h1 {
        font-size: 16px;
    }
    
    .display-main {
        font-size: 28px;
    }
    
    .btn {
        font-size: 16px;
        min-height: 40px;
    }

    .btn-scientific {
        font-size: 12px;
    }

    .btn-memory {
        font-size: 12px;
    }

    .scientific-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 6px;
    }

    .controls {
        flex-wrap: wrap;
    }

    .control-select {
        font-size: 11px;
        padding: 4px 8px;
    }

    .control-button {
        padding: 4px 8px;
        font-size: 14px;
    }

    .history-panel {
        width: calc(100vw - 20px);
        right: 10px;
        left: 10px;
        max-height: 300px;
    }
}

@media (min-width: 1200px) {
    .calculator-container {
        max-width: 700px;
        max-height: 850px;
        border-radius: var(--border-radius-large, 16px);
        box-shadow: 0 10px 40px var(--container-shadow, rgba(0, 0, 0, 0.1));
        padding: 20px;
    }

    .calculator-header h1 {
        font-size: 24px;
    }

    .display-main {
        font-size: 40px;
    }

    .btn {
        font-size: 20px;
        min-height: 50px;
    }

    .btn-scientific {
        font-size: 15px;
    }

    .btn-memory {
        font-size: 15px;
    }
}

@media (max-height: 600px) {
    .display-container {
        min-height: 60px;
        padding: 8px;
    }

    .display-main {
        font-size: 24px;
    }

    .btn {
        min-height: 35px;
        font-size: 14px;
    }

    .btn-scientific, .btn-memory {
        font-size: 11px;
    }

    .button-grid {
        gap: 5px;
    }
}
/* ── Settings Panel ─────────────────────────────────────────────────────── */
.settings-panel {
    position: absolute;
    top: 60px;
    right: 10px;
    width: 290px;
    background: var(--calculator-background, #ffffff);
    border: 2px solid var(--border-color, #e0e0e0);
    border-radius: var(--border-radius, 8px);
    box-shadow: 0 4px 16px var(--container-shadow, rgba(0, 0, 0, 0.18));
    z-index: 1100;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.settings-panel--open {
    display: flex;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border-color, #e0e0e0);
    background: var(--display-background, #f5f5f5);
}

.settings-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-color, #333333);
}

.btn-settings-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    color: var(--text-color, #666666);
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.btn-settings-close:hover {
    background: var(--control-hover-background, #e0e0e0);
}

.settings-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.settings-label {
    font-size: 13px;
    color: var(--text-color, #333333);
    flex-shrink: 0;
    min-width: 90px;
    font-weight: 500;
}

.settings-select {
    flex: 1;
    min-width: 0;
    font-size: 12px;
}

/* Accent colour row */
.settings-row--accent {
    align-items: center;
}

.settings-accent-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: flex-end;
}

.settings-color-input {
    width: 42px;
    height: 32px;
    border: 1px solid var(--border-color, #cccccc);
    border-radius: var(--border-radius, 6px);
    cursor: pointer;
    padding: 2px;
    background: none;
}

.settings-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.settings-color-input::-webkit-color-swatch         { border-radius: 4px; border: none; }

.btn-reset-accent {
    padding: 5px 10px;
    font-size: 11px;
    background: var(--function-button-background, #e0e0e0);
    color: var(--function-button-text-color, #333333);
    border: none;
    border-radius: var(--border-radius, 6px);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.btn-reset-accent:hover {
    background: var(--function-button-hover-background, #d5d5d5);
}

/* URL hint footer */
.settings-url-hint {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color, #e0e0e0);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-url-hint__label {
    font-size: 11px;
    font-weight: 600;
    color: var(--history-text-color, #888888);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-url-hint__code {
    font-size: 10px;
    color: var(--history-text-color, #888888);
    background: var(--display-background, #f5f5f5);
    padding: 4px 6px;
    border-radius: 4px;
    word-break: break-all;
    font-family: var(--font-family-mono, 'Courier New', monospace);
    line-height: 1.4;
}

/* Responsive */
@media (max-width: 600px) {
    .settings-panel {
        width: calc(100vw - 20px);
        right: 10px;
        left: 10px;
    }
}
