/* Base Styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #0a0a16 0%, #1a1030 50%, #0a0a16 100%);
    color: #e0e0ff;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* Adding hardware acceleration hint for the animation container */
    will-change: transform; 
    transform: translateZ(0);
}

/* Calculator Shell */
#calculator {
    position: relative;
    width: 440px;
    max-width: 95vw;
    background: rgba(16, 18, 37, 0.95);
    border-radius: 20px;
    backdrop-filter: blur(15px);
    box-shadow: 0 0 60px rgba(0, 191, 255, 0.5),
                0 0 120px rgba(147, 51, 234, 0.3),
                inset 0 0 30px rgba(0, 150, 255, 0.15);
    z-index: 10;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border: 2px solid rgba(0, 191, 255, 0.5);
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 60px rgba(0, 191, 255, 0.5), 0 0 120px rgba(147, 51, 234, 0.3), inset 0 0 30px rgba(0, 150, 255, 0.15); }
    50% { box-shadow: 0 0 80px rgba(0, 212, 255, 0.7), 0 0 150px rgba(160, 60, 250, 0.5), inset 0 0 40px rgba(0, 170, 255, 0.2); }
}

.title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid rgba(0, 191, 255, 0.4);
}

.title {
    font-size: clamp(20px, 4vw, 26px);
    font-weight: 900;
    background: linear-gradient(90deg, #00d4ff, #0099ff, #9933ff, #ff0099);
    background-size: 300% 300%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradient-shift 4s ease infinite;
    letter-spacing: 2px;
}

@keyframes gradient-shift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.subtitle {
    font-size: clamp(10px, 1.6vw, 12px);
    color: #6a89cc;
    letter-spacing: 1.6px;
    text-transform: uppercase;
}

/* Developer link/button in title bar */
.dev-btn {
    display: inline-block;
    padding: 8px 12px;
    background: linear-gradient(90deg, rgba(0,212,255,0.12), rgba(147,51,234,0.12));
    color: #9fe6ff;
    border: 1px solid rgba(0,212,255,0.18);
    border-radius: 10px;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 6px 18px rgba(0,212,255,0.06);
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s;
    font-size: 11px;
}

.dev-btn:hover {
    transform: translateY(-2px) scale(1.02);
    filter: brightness(1.12);
}

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    background: rgba(10, 12, 28, 0.6);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid rgba(0, 191, 255, 0.2);
}

.mode-btn {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(0, 191, 255, 0.3);
    border-radius: 8px;
    color: #6a89cc;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.mode-btn.active {
    background: linear-gradient(135deg, #2979ff, #00b0ff);
    border-color: #00b0ff;
    color: white;
    box-shadow: 0 0 20px rgba(0, 176, 255, 0.6);
}

/* Display Area */
#display {
    height: 100px;
    background: rgba(10, 12, 28, 0.95);
    border-radius: 12px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    padding: 12px 18px;
    overflow: hidden;
    box-shadow: inset 0 0 25px rgba(0, 0, 0, 0.8), inset 0 0 12px rgba(0, 191, 255, 0.15);
    border: 2px solid rgba(0, 191, 255, 0.25);
    position: relative;
}

#display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 191, 255, 0.5), transparent);
}

/* Input/Expression Display */
#expression {
    font-size: 13px;
    color: #9aa7ff;
    height: 24px;
    width: 100%;
    text-align: right;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    margin-bottom: 8px;
    font-weight: 600;
    opacity: 0.9;
}

/* Result Display */
#result {
    font-size: 42px;
    font-weight: 800;
    color: #00d4ff;
    min-height: 50px;
    height: auto;
    width: 100%;
    text-align: right;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.8), 0 0 40px rgba(0, 150, 255, 0.5);
    letter-spacing: 1px;
    line-height: 1;
    padding: 8px 4px;
    display: inline-block;
}

/* Make sure the result container can be scaled horizontally without clipping */
#display .result-wrapper {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    overflow: hidden;
}

/* Custom Scrollbars */
#expression::-webkit-scrollbar,
#result::-webkit-scrollbar,
#calculator::-webkit-scrollbar {
    height: 4px;
    width: 4px;
}

#expression::-webkit-scrollbar-track,
#result::-webkit-scrollbar-track,
#calculator::-webkit-scrollbar-track {
    background: rgba(0, 191, 255, 0.05);
}

#expression::-webkit-scrollbar-thumb,
#result::-webkit-scrollbar-thumb,
#calculator::-webkit-scrollbar-thumb {
    background: rgba(0, 191, 255, 0.6);
    border-radius: 5px;
}

/* Programmer Conversion Display */
#programmer-conversions {
    display: none;
    flex-direction: column;
    gap: 5px;
    padding: 15px;
    background: rgba(10, 12, 28, 0.95);
    border-radius: 15px;
    margin-bottom: 12px;
    border: 1px solid rgba(0, 191, 255, 0.3);
    box-shadow: inset 0 0 10px rgba(0, 191, 255, 0.1);
}

#programmer-conversions.show {
    display: flex;
}

.conversion-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.conversion-label {
    color: #ff0099;
    font-weight: 700;
    width: 40px;
}

.conversion-value {
    flex-grow: 1;
    text-align: right;
    color: #00d4ff;
    font-weight: 500;
    padding: 2px 5px;
    background: rgba(0, 191, 255, 0.05);
    border-radius: 5px;
    overflow-x: auto;
    white-space: nowrap;
}

/* Sections */
.scientific-section, .programmer-keypad {
    margin-bottom: 15px;
    display: none;
}

.scientific-section.show, .programmer-keypad.show {
    display: block;
}

.section-title {
    font-size: 11px;
    color: #6a89cc;
    letter-spacing: 1px;
    margin-bottom: 10px;
    text-transform: uppercase;
    font-weight: 600;
}

/* Keypad Styling */
#keypad-basic, .sci-grid, .prog-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(64px, 1fr));
    grid-gap: 12px;
}

.key {
    background: rgba(20, 25, 50, 0.88);
    border: none;
    border-radius: 10px;
    color: #e8f0ff;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55), 0 0 18px rgba(0, 191, 255, 0.22);
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(0, 191, 255, 0.38);
    min-height: 58px;
    padding: 6px 8px;
}

.key::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: 0.5s;
}

.key:hover::before {
    left: 100%;
}

.key:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 12px 36px rgba(0, 191, 255, 0.72), 0 0 22px rgba(0, 191, 255, 0.52);
    background: rgba(34, 44, 80, 0.98);
}

.key:active {
    transform: translateY(2px) scale(0.98);
    box-shadow: 0 3px 15px rgba(0, 191, 255, 0.3);
}

/* Key Variants */
.operator {
    background: linear-gradient(135deg, rgba(40, 50, 100, 0.9), rgba(50, 60, 120, 0.9));
    color: #00d4ff;
    border: 1px solid rgba(0, 212, 255, 0.5);
}

.equals {
    background: linear-gradient(135deg, #2979ff, #00b0ff);
    color: white;
    grid-column: span 2;
    font-size: 20px;
    border: 1px solid rgba(0, 212, 255, 0.6);
}

.clear {
    background: linear-gradient(135deg, rgba(200, 50, 80, 0.9), rgba(220, 40, 60, 0.9));
    color: white;
    border: 1px solid rgba(255, 100, 100, 0.5);
}

.special {
    background: linear-gradient(135deg, #9c27b0, #e91e63);
    color: white;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.5px;
    grid-column: span 1;
    border: 1px solid rgba(233, 30, 99, 0.6);
}

.scientific, .programmer {
    background: linear-gradient(135deg, rgba(80, 60, 150, 0.8), rgba(100, 70, 180, 0.8));
    color: #a8c5ff;
    border: 1px solid rgba(168, 197, 255, 0.4);
    font-size: 13px;
}

.programmer-hex {
    background: rgba(255, 100, 0, 0.8);
    color: #fff;
    font-size: 16px;
    border: 1px solid rgba(255, 150, 50, 0.6);
}

/* Programmer UI Elements */
.prog-base-selector {
    display: flex;
    justify-content: space-around;
    margin-bottom: 15px;
    background: rgba(10, 12, 28, 0.6);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid rgba(0, 191, 255, 0.2);
}

.base-btn {
    padding: 5px 10px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #6a89cc;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.base-btn.active {
    color: #00d4ff;
    background: rgba(0, 176, 255, 0.2);
    box-shadow: 0 0 10px rgba(0, 176, 255, 0.4);
}

.particle-counter {
    font-size: 10px;
    color: #6a89cc;
    background: rgba(0, 191, 255, 0.1);
    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid rgba(0, 191, 255, 0.3);
}

.glow {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    border-radius: 25px;
    box-shadow: 0 0 80px rgba(0, 191, 255, 0.8);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: -1;
}

.active-glow {
    opacity: 1;
}

.sci-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    grid-gap: 12px;
    margin-bottom: 12px;
}

.sci-grid .key {
    min-height: 54px;
    font-size: 14px;
}

/* Mobile layout - matches screenshot */
@media (max-width: 600px) {
    body {
        overflow: auto;
    }

    #container {
        padding: 15px;
        align-items: flex-start;
    }

    #calculator {
        width: 100%;
        max-width: 440px;
        padding: 18px;
        border-radius: 18px;
        margin: 0 auto;
    }

    .title-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 15px;
    }

    .title-bar > div:last-child {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
    }

    #display {
        height: 90px;
        padding: 10px 15px;
    }

    #result {
        font-size: 36px;
    }

    #expression {
        font-size: 13px;
    }

    .key {
        min-height: 52px;
        font-size: 16px;
        border-radius: 10px;
    }

    #keypad-basic, .sci-grid, .prog-grid {
        grid-gap: 10px;
    }

    .sci-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .sci-grid .key {
        min-height: 50px;
        font-size: 14px;
    }

    .mode-btn {
        padding: 10px;
        font-size: 11px;
    }
}

/* Desktop layout */
@media (min-width: 601px) {
    #calculator {
        width: 440px;
        padding: 22px;
    }

    #keypad-basic, .sci-grid, .prog-grid {
        grid-gap: 12px;
    }

    .key {
        min-height: 58px;
        font-size: 17px;
    }
}