/* Scientific Calculator Specific Styles */
:root {
    --fx-body: #22252b;
    --fx-screen: #dbe8e8;
    --fx-text: #111;
    --btn-func-bg: linear-gradient(to bottom, #4a4f5a, #3a3f4b);
    --btn-num-bg: linear-gradient(to bottom, #fdfdfd, #e0e0e0);
    --btn-accent: linear-gradient(to bottom, #ffac63, #ff9100);
    --btn-shift-bg: linear-gradient(#f7d794, #e1b12c);
    --btn-alpha-bg: linear-gradient(#e056fd, #be2edd);
}

.calc-wrapper {
    max-width: 1000px;
    margin: 40px auto;
    text-align: center;
}

.calculator-card {
    background: white;
    border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    padding: 40px;
    margin-bottom: 40px;
    display: flex;
    flex-direction: column;
    /* Mobile First: Stacked */
    align-items: center;
    gap: 40px;
}

/* Desktop Layout: Side-by-Side */
@media (min-width: 1024px) {
    .calc-wrapper {
        max-width: 1200px;
        /* Widen wrapper for side-by-side */
    }

    .calculator-card {
        display: grid;
        grid-template-columns: 420px 1fr;
        grid-template-areas: "calc content";
        align-items: start;
        text-align: left;
        padding: 50px;
    }

    .fx-calculator {
        grid-area: calc;
        position: sticky;
        /* Sticky Calculator */
        top: 20px;
        margin: 0;
        /* Override auto margin */
    }

    .explainer-section {
        grid-area: content;
        min-width: 0;
        /* Critical for text wrap */
        padding-left: 20px;
    }
}

/* Calculator Unit */
.fx-calculator {
    grid-area: calc;
    /* Default for mobile/desktop shared */
    width: 100%;
    max-width: 420px;
    background-color: var(--fx-body);
    background-image: linear-gradient(180deg, #2b2e36 0%, #1f2228 100%);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.4);
    margin: 0 auto;
    position: relative;
    transition: all 0.3s ease;
}

/* Screen */
.fx-screen {
    background-color: var(--fx-screen);
    border-radius: 6px;
    height: 140px;
    padding: 12px;
    margin-bottom: 18px;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15);
    border: 1px solid #99a;
    text-align: left;
    cursor: text;
}

.fx-status-bar {
    font-size: 11px;
    font-weight: 700;
    display: flex;
    gap: 8px;
    color: #222;
    height: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.status-badge {
    background: #111;
    color: #fff;
    padding: 2px 5px;
    border-radius: 2px;
    font-size: 10px;
    display: none;
}

.status-badge.active {
    display: inline-block;
}

#fx-input {
    flex-grow: 1;
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    font-family: 'Fira Code', monospace;
    font-size: 1.6rem;
    color: var(--fx-text);
    margin-top: 5px;
    white-space: pre-wrap;
    word-break: break-all;
    resize: none;
    line-height: 1.3;
}

#fx-result {
    text-align: right;
    font-family: 'Fira Code', monospace;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--fx-text);
    min-height: 35px;
    margin-top: auto;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Keypad Grid */
.fx-keypad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 2px;
}

.key-wrapper {
    position: relative;
    height: 56px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* Shift/Alpha Labels */
.label-shift,
.label-alpha {
    position: absolute;
    top: 0;
    font-size: 9px;
    font-weight: 700;
    white-space: nowrap;
    pointer-events: none;
}

.label-shift {
    left: 2px;
    color: #ffd32a;
    /* Brigther Yellow */
}

.label-alpha {
    right: 2px;
    color: #ff5e57;
    /* Brighter Red/Pink */
}

/* Buttons */
.fx-btn {
    width: 100%;
    height: 40px;
    background: var(--btn-func-bg);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
    transition: transform 0.05s, box-shadow 0.05s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.fx-btn:active,
.fx-btn.active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    filter: brightness(1.2);
}

.btn-num {
    background: var(--btn-num-bg);
    color: #111;
    font-size: 18px;
    font-weight: 600;
}

.btn-ac {
    background: var(--btn-accent);
    color: #111;
    font-weight: 800;
    font-size: 14px;
}

.btn-shift {
    background: var(--btn-shift-bg);
    color: #222;
    font-weight: 700;
}

.btn-alpha {
    background: var(--btn-alpha-bg);
    color: #fff;
    font-weight: 700;
}

/* Small Buttons (Top Row) */
.top-row .fx-btn {
    height: 30px;
    font-size: 11px;
}

.top-row .key-wrapper {
    height: 42px;
}

/* Fullscreen Mode */
.fx-calculator.fullscreen-mode {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background-color: #1a1d21;
    margin: 0;
}

.fx-calculator.fullscreen-mode .fx-screen {
    flex-grow: 0;
    width: 100%;
    max-width: 600px;
    margin-bottom: 20px;
    height: 180px;
}

.fx-calculator.fullscreen-mode .fx-keypad {
    flex-grow: 1;
    width: 100%;
    max-width: 600px;
    gap: 12px;
    max-height: 70vh;
}

.fx-calculator.fullscreen-mode .fx-btn {
    height: 100%;
    font-size: 1.2rem;
}

.fx-calculator.fullscreen-mode .key-wrapper {
    height: auto;
}



.status-badge.active {
    display: inline-block;
}

#fx-input {
    flex-grow: 1;
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    font-family: 'Fira Code', monospace;
    font-size: 1.6rem;
    color: var(--fx-text);
    margin-top: 5px;
    white-space: pre-wrap;
    word-break: break-all;
    resize: none;
    line-height: 1.3;
}

#fx-result {
    text-align: right;
    font-family: 'Fira Code', monospace;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--fx-text);
    min-height: 35px;
    margin-top: auto;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Keypad Grid */
.fx-keypad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 2px;
}

.key-wrapper {
    position: relative;
    height: 56px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* Shift/Alpha Labels */
.label-shift,
.label-alpha {
    position: absolute;
    top: 0;
    font-size: 9px;
    font-weight: 700;
    white-space: nowrap;
    pointer-events: none;
}

.label-shift {
    left: 2px;
    color: #ffd32a;
    /* Brigther Yellow */
}

.label-alpha {
    right: 2px;
    color: #ff5e57;
    /* Brighter Red/Pink */
}

/* Buttons */
.fx-btn {
    width: 100%;
    height: 40px;
    background: var(--btn-func-bg);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
    transition: transform 0.05s, box-shadow 0.05s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.fx-btn:active,
.fx-btn.active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    filter: brightness(1.2);
}

.btn-num {
    background: var(--btn-num-bg);
    color: #111;
    font-size: 18px;
    font-weight: 600;
}

.btn-ac {
    background: var(--btn-accent);
    color: #111;
    font-weight: 800;
    font-size: 14px;
}

.btn-shift {
    background: var(--btn-shift-bg);
    color: #222;
    font-weight: 700;
}

.btn-alpha {
    background: var(--btn-alpha-bg);
    color: #fff;
    font-weight: 700;
}

/* Small Buttons (Top Row) */
.top-row .fx-btn {
    height: 30px;
    font-size: 11px;
}

.top-row .key-wrapper {
    height: 42px;
}

/* Fullscreen Mode */
.fx-calculator.fullscreen-mode {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background-color: #1a1d21;
    margin: 0;
}

.fx-calculator.fullscreen-mode .fx-screen {
    flex-grow: 0;
    width: 100%;
    max-width: 600px;
    margin-bottom: 20px;
    height: 180px;
}

.fx-calculator.fullscreen-mode .fx-keypad {
    flex-grow: 1;
    width: 100%;
    max-width: 600px;
    gap: 12px;
    max-height: 70vh;
}

.fx-calculator.fullscreen-mode .fx-btn {
    height: 100%;
    font-size: 1.2rem;
}

.fx-calculator.fullscreen-mode .key-wrapper {
    height: auto;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .fx-keypad {
        gap: 6px;
    }

    .fx-btn {
        height: 42px;
        font-size: 14px;
    }

    .key-wrapper {
        height: 58px;
    }

    .top-row .fx-btn {
        height: 32px;
    }

    .fx-screen {
        height: 120px;
    }
}

/* History Overlay in Screen */
.fx-history {
    flex-grow: 1;
    overflow-y: auto;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: #889;
    text-align: right;
    padding-right: 4px;
    margin-bottom: 4px;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: #889 transparent;
}

.fx-history::-webkit-scrollbar {
    width: 4px;
}

.fx-history::-webkit-scrollbar-thumb {
    background-color: #889;
    border-radius: 4px;
}

.hist-item:hover {
    color: #222;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 2px;
}

/* Updates for Input Layout */
#fx-input {
    flex-grow: 0;
    height: 1.6em;
    overflow: hidden;
    margin-top: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding-top: 2px;
}