:root {
    /* Calculator specific */
    --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --secondary-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --calculator-bg: var(--bg-card);
    --btn-bg: var(--bg-body);
    --btn-hover: var(--bg-card);
    --btn-active: var(--border-subtle);
    --accent-color: var(--accent);
    --operator-color: #ef4444;
}

[data-theme="dark"] {
    --secondary-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background: radial-gradient(circle at 50% -20%, var(--shadow-accent), transparent 70%), var(--bg-body);
    /* min-height: 100vh; handled by shared.css */
    /* display: flex; handled by shared.css */
    /* justify-content: center; handled by shared.css */
    /* align-items: center; handled by shared.css */
    color: var(--text-primary);
    transition: background 0.4s cubic-bezier(0.4, 0, 0.2, 1), color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.container {
    /* Inherits flex column and 100vh from shared.css */
    align-items: center;
    /* justify-content: center; Removed to keep header at top */
}

.calculator-wrapper {
    background: var(--bg-card);
    border-radius: 30px;
    box-shadow: 0 20px 50px var(--shadow-xl);
    padding: 25px;
    width: 100%;
    max-width: 400px;
    /* Restrict width */
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-subtle);
    margin: auto 0;
    /* Center vertically in remaining space */
}

/* Mode Switch */
.mode-switch {
    display: flex;
    background: var(--bg-body);
    border-radius: 15px;
    padding: 5px;
    margin-bottom: 25px;
    border: 1px solid var(--border-subtle);
}

.mode-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mode-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: 0 4px 6px var(--shadow-sm);
    border: 1px solid var(--border-subtle);
}

/* Calculator Section */
.calculator-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.calculator-section.active {
    display: block;
}

.display {
    text-align: right;
    margin-bottom: 25px;
    padding: 10px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

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

.current-operand {
    color: var(--text-primary);
    font-size: 3rem;
    font-weight: 700;
    word-wrap: break-word;
    word-break: break-all;
    line-height: 1.1;
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.btn {
    border: none;
    background: var(--btn-bg);
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 500;
    border-radius: 20px;
    padding: 20px 0;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px var(--shadow-sm);
    user-select: none;
    border: 1px solid var(--border-subtle);
}

.btn:hover {
    background: var(--btn-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px var(--shadow-md);
    border-color: var(--accent);
}

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

.btn.function {
    color: var(--accent);
    font-weight: 700;
}

.btn.operator {
    color: var(--operator-color);
    font-weight: 700;
    background: var(--bg-body);
}

.btn.operator:hover {
    background: var(--bg-card);
}

.btn.zero {
    grid-column: span 2;
}

.btn.equals {
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 4px 15px var(--shadow-accent);
}

.btn.equals:hover {
    box-shadow: 0 6px 20px var(--shadow-accent);
    background: var(--accent-hover);
}

/* Currency Section */
.currency-section {
    display: none;
    animation: fadeIn 0.3s ease;
    padding: 10px 0;
}

.currency-section.active {
    display: block;
}

.currency-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    position: relative;
}

.currency-header h3 {
    font-size: 1.5rem;
    margin-bottom: 5px;
    background: var(--primary-gradient);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex: 1;
    text-align: left;
}

.last-updated {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    opacity: 0.7;
    position: absolute;
    bottom: -20px;
    left: 0;
}

.converter-box {
    background: var(--bg-body);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 15px;
    border: 1px solid var(--border-subtle);
    transition: all 0.3s ease;
}

.converter-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--shadow-accent);
    background: var(--bg-card);
}

/* Currency Section Enhancements */
.btn-refresh {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-refresh:hover {
    background: var(--bg-body);
    transform: rotate(180deg);
}

.currency-select-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.currency-search {
    background: var(--bg-body);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    width: 100%;
}

.currency-search:focus {
    outline: none;
    border-color: var(--accent);
}

#currency-one,
#currency-two {
    width: 100%;
    background: var(--bg-body);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 0.6rem;
    border-radius: 8px;
    cursor: pointer;
}

.input-group {
    margin-bottom: 10px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}

.input-group input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    outline: none;
    font-family: 'Outfit', sans-serif;
}

.input-group input[type="number"] {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 1.8rem;
    font-weight: 700;
    padding: 0.5rem 0;
}

.input-group input:focus {
    outline: none;
    border-bottom-color: var(--accent);
}

.select-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    background: var(--bg-card);
    font-size: 1rem;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.select-group select:hover {
    border-color: var(--accent);
}

.swap-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0;
    padding: 0 10px;
}

.btn-swap {
    background: var(--accent);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}

.btn-swap:hover {
    transform: rotate(180deg);
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.rate-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    background: var(--bg-body);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-subtle);
}

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

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

/* Responsive */
@media (max-width: 480px) {
    .calculator-wrapper {
        padding: 20px;
    }

    .btn {
        padding: 15px 0;
        font-size: 1.3rem;
    }
}

/* Scientific Calculator Styles */
.calculator-wrapper.scientific-mode {
    max-width: 500px;
}

.scientific-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.scientific-grid .btn {
    padding: 15px 0;
    font-size: 1.1rem;
    border-radius: 15px;
}

.btn.sci-func {
    background: var(--bg-body);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 1rem;
}

.btn.sci-func:hover {
    background: var(--bg-card);
    color: var(--accent);
}

/* Adjust display for scientific mode */
#scientific-calculator .display {
    min-height: 120px;
}

#scientific-calculator .current-operand-sci {
    font-size: 2.5rem;
    color: var(--text-primary);
    font-weight: 700;
    word-wrap: break-word;
    word-break: break-all;
    line-height: 1.1;
}

#scientific-calculator .previous-operand-sci {
    color: var(--text-secondary);
    font-size: 1.2rem;
    min-height: 1.5rem;
    margin-bottom: 5px;
}

/* Loading Animation */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.btn-refresh.loading i {
    animation: spin 1s linear infinite;
}