/* Theme Toggle Styling */
.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.theme-btn {
    background: var(--calc-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 30px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-btn:hover {
    transform: translateY(-2px);
    background: var(--btn-hover);
}

:root {
    --bg-gradient: radial-gradient(circle at 50% 50%, #0f172a 0%, #020617 100%);
    --calc-bg: rgba(15, 23, 42, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #00f2ff;
    --accent-glow: rgba(0, 242, 255, 0.4);
    --display-bg: rgba(0, 0, 0, 0.4);
    --btn-bg: rgba(255, 255, 255, 0.03);
    --btn-hover: rgba(0, 242, 255, 0.1);
    --btn-shadow: 0 0 15px rgba(0, 242, 255, 0.1);
    --btn-border: 1px solid rgba(255, 255, 255, 0.05);
    --font-main: 'Outfit', sans-serif;
    --font-display: 'Outfit', sans-serif;
    --border-radius: 28px;
    --btn-radius: 14px;
    --neon-purple: #7000ff;
    --neon-blue: #00f2ff;
}

body.retro-theme {
    --bg-gradient: #475569;
    /* Slightly darker for better contrast with the beige calc */
    --calc-bg: #d1d5db;
    /* Classic gray/beige */
    --glass-border: #94a3b8;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    /* Darker secondary text for retro */
    --accent-color: #2563eb;
    --accent-glow: rgba(37, 99, 235, 0.2);
    --display-bg: #a7f3d0;
    /* Brighter Green LCD */
    --btn-bg: #e5e7eb;
    --btn-hover: #f3f4f6;
    --btn-shadow: 2px 2px 0px #64748b, -1px -1px 0px #ffffff;
    --btn-border: 1px solid #94a3b8;
    --font-main: 'Share Tech Mono', monospace;
    --font-display: 'Share Tech Mono', monospace;
    --border-radius: 4px;
    --btn-radius: 2px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
}

body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-gradient);
    overflow: hidden;
    color: var(--text-primary);
    transition: background 0.5s ease;
}

/* Hide blobs in retro theme */
body.retro-theme .background-blobs {
    display: none;
}

/* Animated Background Blobs */
.background-blobs {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    background: var(--bg-gradient);
}

.grid-overlay {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 242, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 242, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image: radial-gradient(circle at 50% 50%, black, transparent 80%);
    z-index: 0;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
    animation: move 20s infinite alternate;
}

.blob-1 {
    width: 500px;
    height: 500px;
    background: var(--neon-blue);
    top: -10%;
    left: -10%;
    animation: move 25s infinite alternate ease-in-out;
}

.blob-2 {
    width: 450px;
    height: 450px;
    background: var(--neon-purple);
    bottom: -10%;
    right: -10%;
    animation: move 30s infinite alternate-reverse ease-in-out;
    animation-delay: -5s;
}

.blob-3 {
    width: 350px;
    height: 350px;
    background: #3b82f6;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: float 20s infinite ease-in-out;
    animation-delay: -10s;
}

.blob-4 {
    width: 300px;
    height: 300px;
    background: #06b6d4;
    top: 20%;
    right: 20%;
    animation: move 22s infinite alternate ease-in-out;
    animation-delay: -7s;
}

.blob-5 {
    width: 400px;
    height: 400px;
    background: #8b5cf6;
    bottom: 20%;
    left: 10%;
    animation: move 28s infinite alternate-reverse ease-in-out;
}

@keyframes float {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-45%, -55%) scale(1.1);
    }
}

@keyframes move {
    from {
        transform: translate(0, 0) scale(1);
    }

    to {
        transform: translate(100px, 50px) scale(1.1);
    }
}

/* Calculator Container */
.calculator-container {
    perspective: 1000px;
}

.calculator {
    background: var(--calc-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 24px;
    width: 320px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.calculator:hover {
    transform: translateY(-5px);
}

/* Display Area */
.display {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 24px;
    text-align: right;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    word-wrap: break-word;
    word-break: break-all;
    position: relative;
    /* For copy button */
}

/* Copy Button Styling */
.copy-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0.3;
    /* Subtle by default */
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    opacity: 1;
    transform: scale(1.05);
}

.conv-group .copy-btn {
    position: static;
    margin-left: 4px;
    height: 38px;
    width: 38px;
    opacity: 0.4;
}

/* Tooltip Feedback */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 80px;
    background-color: var(--accent-color);
    color: #0f172a;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
    position: absolute;
    z-index: 11;
    bottom: 125%;
    left: 50%;
    margin-left: -40px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.75rem;
    font-weight: 600;
}

.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--accent-color) transparent transparent transparent;
}

.tooltip.show-tooltip .tooltiptext {
    visibility: visible;
    opacity: 1;
}

.previous-operand {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    height: 1.2rem;
}

.current-operand {
    font-size: 2rem;
    font-weight: 600;
}

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

.btn {
    border: var(--btn-border);
    outline: none;
    background: var(--btn-bg);
    color: var(--text-primary);
    box-shadow: var(--btn-shadow);
    font-size: 1.25rem;
    padding: 16px;
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all 0.1s ease;
}

.btn:hover {
    background: var(--btn-hover);
    transform: scale(1.05);
}

.retro-theme .btn:active,
.retro-theme .btn.pressed {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.btn:active,
.btn.pressed {
    transform: scale(0.95);
}

.btn-operator {
    color: var(--accent-color);
    font-weight: 600;
}

.btn-equals {
    grid-column: span 2;
    background: var(--accent-color);
    color: #0f172a;
    font-weight: 600;
}

.btn-equals:hover {
    background: #7dd3fc;
    box-shadow: 0 0 15px var(--accent-glow);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px;
    border-radius: 12px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Panels */
.panel {
    display: none;
}

.panel.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Converter Styling */
.conv-header select,
.conv-group select {
    width: 100%;
    background: var(--btn-bg);
    /* Use theme variable */
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 12px;
    border-radius: var(--btn-radius);
    outline: none;
    cursor: pointer;
    font-size: 1rem;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

/* Modern theme specific override for arrow color */
body:not(.retro-theme) .conv-header select,
body:not(.retro-theme) .conv-group select {
    background-color: #1e293b;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.conv-header select {
    margin-bottom: 24px;
}

.conv-group select {
    width: 40%;
}

.conv-group input {
    width: 60%;
    background: var(--btn-bg);
    /* Use theme variable */
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--btn-radius);
    font-size: 1.1rem;
    font-weight: 500;
    outline: none;
    transition: all 0.3s ease;
}

body:not(.retro-theme) .conv-group input {
    background: rgba(0, 0, 0, 0.2);
}

select option {
    background: var(--btn-bg);
    color: var(--text-primary);
}

.conv-group input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-glow);
    background: rgba(0, 0, 0, 0.3);
}

/* Remove Arrows from Number Input */
.conv-group input::-webkit-outer-spin-button,
.conv-group input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.conv-group input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.conv-separator {
    text-align: center;
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin: 8px 0;
    font-weight: 300;
    opacity: 0.5;
}

/* Responsive adjustments */
@media (max-width: 400px) {
    .calculator {
        width: 280px;
        padding: 16px;
    }

    .current-operand {
        font-size: 1.5rem;
    }
}