:root {
    /* Light Theme */
    --bg-color: #e8ecf1;
    --bg-gradient: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
    --text-color: #1c1c1e;
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.6);
    --glass-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
    
    --btn-bg: rgba(255, 255, 255, 0.5);
    --btn-hover: rgba(255, 255, 255, 0.9);
    --btn-active: rgba(255, 255, 255, 0.3);
    --btn-operator-text: #ff9500;
    --btn-action-text: #6e6e73;
    
    --gold: #d4af37;
    --gold-hover: #b5952f;
    --gold-text: #ffffff;
}

[data-theme="dark"] {
    /* Dark Theme */
    --bg-color: #000000;
    --bg-gradient: linear-gradient(135deg, #141418 0%, #24243e 100%);
    --text-color: #ffffff;
    --glass-bg: rgba(30, 30, 35, 0.5);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 15px 45px rgba(0, 0, 0, 0.6);
    
    --btn-bg: rgba(45, 45, 55, 0.4);
    --btn-hover: rgba(75, 75, 85, 0.6);
    --btn-active: rgba(25, 25, 30, 0.5);
    --btn-operator-text: #ff9f0a;
    --btn-action-text: #a1a1a6;
    
    --gold: #d4af37;
    --gold-hover: #f1c40f;
    --gold-text: #000000;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    background-image: var(--bg-gradient);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.5s ease, color 0.5s ease;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
}

/* Glassmorphism Panel Base */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: none;
    border-radius: 0;
    box-shadow: none;
    transition: all 0.4s ease;
}

/* Header */
.header {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    display: flex;
    justify-content: space-between;
    z-index: 10;
}

.icon-btn {
    background: var(--btn-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-color);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.icon-btn:hover {
    background-color: var(--btn-hover);
    transform: none;
    box-shadow: none;
}

.icon-btn:active {
    background-color: var(--btn-active);
    transform: scale(0.9);
}

/* Calculator Main */
.calculator {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    position: relative;
}

/* Display Area */
.display {
    flex: 0.35;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 30px 25px;
    min-height: 150px;
}

.equation {
    font-size: 1.3rem;
    color: var(--btn-action-text);
    min-height: 1.6rem;
    word-break: break-all;
    text-align: right;
    margin-bottom: 5px;
    font-weight: 400;
    letter-spacing: 0.5px;
}

.current {
    font-size: 4.5rem;
    font-weight: 200;
    line-height: 1.1;
    white-space: nowrap; /* Prevent wrapping */
    overflow-x: auto; /* Enable horizontal scroll when too big */
    overflow-y: hidden;
    text-align: right; /* Note: overflow behavior with right-align handles seamlessly in modern browsers with JS scroll tracking */
    letter-spacing: -2px;
    width: 100%;
    padding-bottom: 10px;
    margin-bottom: -10px;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: font-size 0.15s ease-out;
    scrollbar-width: none; /* Firefox */
}

.current::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Edge */
}

/* Inline Scheme Chips */
.inline-scheme-bar {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
    animation: slideDownFade 0.3s ease;
}

.inline-scheme-bar.hidden {
    display: none;
}

@keyframes slideDownFade {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.scheme-chip {
    background: rgba(128,128,128,0.1);
    border: 1px solid var(--glass-border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.scheme-chip.active {
    border-color: var(--gold);
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

.scheme-chip span {
    font-weight: 600;
}

.scheme-chip-btn {
    background: var(--gold);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.4);
}

.scheme-chip-btn:active {
    transform: scale(0.95);
}

/* Keypad Grid */
.keypad {
    flex: 0.65;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 14px;
    padding: 0 20px 30px 20px;
}

.btn {
    border: 1px solid var(--glass-border);
    border-radius: 24px; /* Premium squircle */
    font-size: 1.8rem;
    font-weight: 400;
    cursor: pointer;
    background: var(--btn-bg);
    color: var(--text-color);
    box-shadow: 0 6px 16px rgba(0,0,0,0.06), inset 0 2px 4px rgba(255, 255, 255, 0.05);
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1); /* Bouncy press effect */
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

.btn:active {
    transform: scale(0.9);
    background: var(--btn-active);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05), inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    background: var(--btn-hover);
}

.btn-operator {
    color: var(--btn-operator-text);
    font-size: 2rem;
    font-weight: 500;
}

.btn-action {
    color: var(--btn-action-text);
    font-weight: 500;
}

/* Special Gold Button */
@keyframes pulseGold {
    0% { box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3); }
    50% { box-shadow: 0 4px 25px rgba(212, 175, 55, 0.6); }
    100% { box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3); }
}

.gold-highlight {
    background: linear-gradient(135deg, var(--gold), #f1c40f);
    color: var(--gold-text);
    border: none;
    animation: pulseGold 3s infinite ease-in-out;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.gold-highlight:hover {
    background: linear-gradient(135deg, var(--gold-hover), #f39c12);
}

/* History Panel Overlay */
.history-panel {
    position: absolute;
    top: 80px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    padding: 25px;
    transform: translateY(0) scale(1);
    opacity: 1;
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s;
    border-radius: 32px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.history-panel.hidden {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.history-header h2 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.text-btn {
    background: none;
    border: none;
    color: var(--btn-operator-text);
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s;
}

.text-btn:hover {
    opacity: 0.8;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 5px;
}

.history-list::-webkit-scrollbar {
    width: 5px;
}
.history-list::-webkit-scrollbar-thumb {
    background: var(--btn-action-text);
    border-radius: 10px;
    opacity: 0.3;
}

.history-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    background: rgba(128, 128, 128, 0.05);
    padding: 16px 20px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.history-item:hover {
    background: rgba(128, 128, 128, 0.1);
    border-color: var(--glass-border);
    transform: translateX(-2px);
}

.history-equation {
    font-size: 1rem;
    color: var(--btn-action-text);
    margin-bottom: 6px;
}

.history-result {
    font-size: 1.8rem;
    font-weight: 300;
    color: var(--gold);
}

.history-datetime {
    font-size: 0.75rem;
    color: var(--btn-action-text);
    opacity: 0.5;
    margin-top: 8px;
    align-self: flex-start;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Settings Panel */
.settings-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 10px;
}

.slider-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0 25px 15px 25px;
    gap: 12px;
}

.slider-container label {
    font-size: 1rem;
    color: var(--text-color);
    font-weight: 500;
    text-align: left;
}

/* Premium Slider */
#basic-discount-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    background: rgba(128, 128, 128, 0.2);
    border-radius: 10px;
    outline: none;
    border: 1px solid var(--glass-border);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

#basic-discount-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--gold);
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(212, 175, 55, 0.5), inset 0 2px 2px rgba(255, 255, 255, 0.4);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#basic-discount-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

#basic-discount-slider::-webkit-slider-thumb:active {
    transform: scale(0.95);
}

.setting-item {
    display: flex;
    flex-direction: column;
}

.setting-item label {
    font-size: 0.95rem;
    color: var(--btn-action-text);
    margin-bottom: 8px;
    font-weight: 500;
}

.setting-item input {
    background: rgba(128, 128, 128, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 14px 16px;
    border-radius: 16px;
    font-size: 1.1rem;
    outline: none;
    transition: all 0.3s;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.02);
}

.setting-item input:focus {
    border-color: var(--gold);
    background: rgba(128, 128, 128, 0.1);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05), 0 0 0 3px rgba(212, 175, 55, 0.1);
}

/* Responsive adjustments */
@media (min-width: 450px) {
    .app-container {
        padding: 40px 20px;
        height: 100vh;
        max-height: 850px;
        max-width: 450px;
    }
    
    .glass-panel {
        border-radius: 44px;
        border: 1px solid var(--glass-border);
        box-shadow: var(--glass-shadow);
    }
    
    .display {
        padding: 40px 30px;
    }
}
