/* ============================================
   ENDY EDESON Calculator - Stylesheet
   ============================================ */

/* ============================================
   CSS Variables & Root Styles
   ============================================ */
:root {
    --primary-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --secondary-bg: #0f3460;
    --display-bg: #0b50a5;
    --button-bg: #e94560;
    --button-hover: #ff6b7a;
    --operator-bg: #16213e;
    --operator-hover: #1e4d7b;
    --function-bg: #6c757d;
    --function-hover: #81899f;
    --equals-bg: #889e09;
    --equals-hover: #0c648d;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-radius: 12px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 15px 40px rgba(0, 0, 0, 0.4);
    --transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-fast: all 0.15s ease-out;
}

/* ============================================
   Global Reset & Base Styles
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--primary-bg);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* ============================================
   Container & Layout
   ============================================ */
.container {
    width: 100%;
    max-width: 1200px;
    position: relative;
}

.calculator-wrapper {
    background: var(--secondary-bg);
    border-radius: 20px;
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: slideIn 0.6s ease-out;
    display: flex;
    flex-direction: column;
    min-height: 600px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Loading Animation
   ============================================ */
.loader {
    position: fixed;
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--button-bg);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

.loader.hidden {
    opacity: 0;
    pointer-events: none;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ============================================
   Header
   ============================================ */
.header {
    text-align: center;
    padding: 30px 20px 20px;
    background: linear-gradient(135deg, #1a1a2e 0%, #0f3460 100%);
    border-bottom: 2px solid rgba(233, 69, 96, 0.2);
}

.calculator-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 3px;
    background: linear-gradient(135deg, var(--button-bg), var(--button-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 5px;
}

.calculator-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    display: flex;
    flex: 1;
    padding: 20px;
    gap: 20px;
}

.calculator-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ============================================
   Display Screen
   ============================================ */
.display-container {
    background: var(--display-bg);
    border-radius: var(--border-radius);
    padding: 30px 20px;
    box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-align: right;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.previous-operand {
    color: var(--text-secondary);
    font-size: 20px;
    height: 24px;
    min-height: 24px;
    font-weight: 500;
}

.current-operand {
    color: var(--text-primary);
    font-size: 48px;
    font-weight: 700;
    word-wrap: break-word;
    word-break: break-all;
    max-height: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Courier New', monospace;
}

/* ============================================
   Controls (Sound, Copy, History Toggle)
   ============================================ */
.controls {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.control-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn svg {
    width: 22px;
    height: 22px;
}

.control-btn.active {
    background: var(--button-bg);
    color: white;
}

/* ============================================
   Buttons Grid
   ============================================ */
.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 10px 0;
}

.btn {
    padding: 20px;
    font-size: 20px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:active {
    transform: scale(0.98);
}

/* Number Buttons */
.number-btn {
    background: var(--button-bg);
    color: white;
}

.number-btn:hover {
    background: var(--button-hover);
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px);
}

/* Operator Buttons */
.operator-btn {
    background: var(--operator-bg);
    color: var(--button-bg);
    font-size: 22px;
}

.operator-btn:hover {
    background: var(--operator-hover);
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px);
}

/* Function Buttons (C, DEL) */
.function-btn {
    background: var(--function-bg);
    color: white;
    font-size: 18px;
}

.function-btn:hover {
    background: var(--function-hover);
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px);
}

/* Equals Button */
.equals-btn {
    background: var(--equals-bg);
    color: white;
    font-size: 24px;
}

.equals-btn:hover {
    background: var(--equals-hover);
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px);
}

/* Zero Button (Spans 2 columns) */
.zero-btn {
    grid-column: span 2;
}

/* ============================================
   History Sidebar
   ============================================ */
.history-sidebar {
    width: 250px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 20px;
    max-height: 500px;
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.4s ease-out;
    transition: var(--transition);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.history-sidebar.hidden {
    display: none;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.history-header h3 {
    font-size: 16px;
    color: var(--text-primary);
}

.clear-history-btn {
    background: none;
    border: none;
    color: var(--button-bg);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    transition: var(--transition-fast);
}

.clear-history-btn:hover {
    color: var(--button-hover);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    border-left: 3px solid var(--button-bg);
}

.history-item:hover {
    background: rgba(233, 69, 96, 0.2);
    color: var(--text-primary);
    padding-left: 15px;
}

.history-item.result {
    color: var(--button-bg);
    font-weight: 600;
}

.empty-message {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 20px 0;
}

/* Scrollbar Styling */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(233, 69, 96, 0.3);
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--button-bg);
}

/* ============================================
   Footer
   ============================================ */
.footer {
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.5), rgba(15, 52, 96, 0.5));
    border-top: 1px solid rgba(233, 69, 96, 0.1);
}

.footer-text {
    font-size: 12px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.brand-name {
    color: var(--button-bg);
    font-weight: 700;
    transition: var(--transition-fast);
}

.footer-text:hover .brand-name {
    color: var(--button-hover);
}

/* ============================================
   Notification Toast
   ============================================ */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--button-bg);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    font-size: 14px;
    animation: slideUp 0.3s ease-out;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toast.show {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================
   Responsive Design
   ============================================ */

/* Tablet (768px and below) */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
    }

    .history-sidebar {
        width: 100%;
        max-height: 200px;
    }

    .calculator-title {
        font-size: 24px;
    }

    .current-operand {
        font-size: 36px;
    }

    .buttons-grid {
        gap: 10px;
    }

    .btn {
        padding: 18px;
        font-size: 18px;
    }

    .header {
        padding: 20px 15px 15px;
    }
}

/* Mobile (480px and below) */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    .calculator-wrapper {
        min-height: auto;
    }

    .header {
        padding: 15px 10px 10px;
    }

    .calculator-title {
        font-size: 20px;
        letter-spacing: 2px;
    }

    .calculator-subtitle {
        font-size: 10px;
    }

    .main-content {
        padding: 12px;
        gap: 12px;
    }

    .display-container {
        padding: 20px 15px;
        min-height: 80px;
    }

    .previous-operand {
        font-size: 16px;
    }

    .current-operand {
        font-size: 28px;
    }

    .buttons-grid {
        gap: 8px;
    }

    .btn {
        padding: 15px;
        font-size: 16px;
        border-radius: 10px;
    }

    .control-btn {
        width: 40px;
        height: 40px;
    }

    .history-sidebar {
        max-height: 150px;
    }

    .footer {
        padding: 15px;
    }

    .footer-text {
        font-size: 11px;
    }

    .toast {
        bottom: 20px;
        right: 20px;
        font-size: 12px;
        padding: 12px 16px;
    }
}

/* Large Screens (1200px and above) */
@media (min-width: 1200px) {
    .main-content {
        gap: 30px;
    }

    .history-sidebar {
        width: 280px;
    }

    .btn {
        padding: 22px;
        font-size: 22px;
    }
}

/* ============================================
   Accessibility & Focus States
   ============================================ */
.btn:focus,
.control-btn:focus {
    outline: 2px solid var(--button-bg);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: more) {
    .btn {
        border: 2px solid var(--text-primary);
    }

    .display-container {
        border: 2px solid var(--text-primary);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark Mode Preference (already applied by default) */
@media (prefers-color-scheme: dark) {
    body {
        background: var(--primary-bg);
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .controls,
    .history-sidebar,
    .loader {
        display: none !important;
    }

    .calculator-wrapper {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

.app-logo {
    width: 200px;
    height: 120px;
    display: block;
    margin: 0 auto;
}