/* ===== SciCalc Pro — Style Sheet ===== */
/* Inspired by Casio FX-991 CW */

/* ---------- Reset & Base ---------- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* Colors */
    --bg-body: #0b0e14;
    --bg-calc: linear-gradient(145deg, #1a1f2e 0%, #0f1320 50%, #151b2a 100%);
    --bg-display: linear-gradient(135deg, rgba(194,232,206,.08) 0%, rgba(120,200,160,.04) 100%);
    --display-border: rgba(100,210,160,.18);
    --text-expression: #8fa8b8;
    --text-result: #e8f5e9;
    --text-brand: #5ef0a8;
    --text-dim: #4a5568;

    /* Buttons */
    --btn-num-bg: #1e2433;
    --btn-num-hover: #262d40;
    --btn-num-text: #e2e8f0;
    --btn-func-bg: #19202e;
    --btn-func-hover: #212a3d;
    --btn-func-text: #93c5fd;
    --btn-op-bg: #1c2536;
    --btn-op-hover: #243048;
    --btn-op-text: #fbbf24;
    --btn-eq-bg: linear-gradient(135deg, #059669, #10b981);
    --btn-eq-hover: linear-gradient(135deg, #10b981, #34d399);
    --btn-eq-text: #fff;
    --btn-ac-bg: #7f1d1d;
    --btn-ac-hover: #991b1b;
    --btn-ac-text: #fca5a5;
    --btn-shift-bg: #92400e;
    --btn-shift-hover: #a3520f;
    --btn-shift-text: #fde68a;
    --btn-alpha-bg: #1e3a5f;
    --btn-alpha-hover: #264a73;
    --btn-alpha-text: #7dd3fc;

    /* Layout */
    --calc-width: 460px;
    --border-radius: 14px;
    --btn-radius: 10px;
    --gap: 6px;

    /* Shadows */
    --shadow-calc: 0 25px 80px rgba(0,0,0,.55), 0 0 120px rgba(16,185,129,.06);
    --shadow-display: inset 0 2px 12px rgba(0,0,0,.45);
    --shadow-btn: 0 2px 6px rgba(0,0,0,.25);
    --shadow-btn-active: inset 0 2px 6px rgba(0,0,0,.35);
}

html { font-size: 16px; }

body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(16,185,129,.07) 0%, transparent 70%),
        radial-gradient(ellipse 60% 40% at 80% 110%, rgba(59,130,246,.05) 0%, transparent 70%);
    color: var(--btn-num-text);
    overflow-y: auto;
    padding: 20px 0;
}

/* ---------- Calculator Body ---------- */
.calculator {
    width: var(--calc-width);
    max-width: 96vw;
    background: var(--bg-calc);
    border-radius: 24px;
    padding: 18px 14px 16px;
    box-shadow: var(--shadow-calc);
    border: 1px solid rgba(255,255,255,.05);
    position: relative;
    backdrop-filter: blur(12px);
}

/* ---------- Brand Bar ---------- */
.brand-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px 10px;
}
.brand-name {
    font-size: .75rem;
    font-weight: 700;
    color: #cbd5e1;
    letter-spacing: 2px;
    text-transform: uppercase;
}
.brand-accent { color: var(--text-brand); }
.brand-model {
    font-size: .65rem;
    color: var(--text-dim);
    letter-spacing: 1px;
}

/* ---------- Display ---------- */
.display-container {
    background: var(--bg-display);
    border: 1px solid var(--display-border);
    border-radius: var(--border-radius);
    padding: 10px 14px 14px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-display);
    min-height: 110px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}
.display-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,.012) 0%, transparent 40%);
    pointer-events: none;
}

.display-status-bar {
    display: flex;
    gap: 10px;
    font-size: .6rem;
    font-weight: 600;
    letter-spacing: .8px;
    margin-bottom: 6px;
    color: var(--text-dim);
    text-transform: uppercase;
}
.status-item { cursor: default; user-select: none; }
.angle-indicator { cursor: pointer; color: var(--text-brand); transition: color .2s; }
.angle-indicator:hover { color: #a7f3d0; }
.mode-indicator { color: #93c5fd; }
.memory-indicator { color: #fbbf24; }

.display-expression {
    font-family: 'JetBrains Mono', monospace;
    font-size: .92rem;
    color: var(--text-expression);
    min-height: 1.4em;
    word-break: break-all;
    line-height: 1.5;
    flex: 1;
    display: flex;
    align-items: flex-end;
    padding-right: 4px;
    transition: color .15s;
}

.display-result {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-result);
    text-align: right;
    min-height: 1.3em;
    line-height: 1.3;
    transition: all .2s ease;
    text-shadow: 0 0 20px rgba(94,240,168,.12);
}
.display-result.flash {
    animation: resultFlash .35s ease;
}

@keyframes resultFlash {
    0% { opacity: .4; transform: translateY(4px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Cursor blink */
.cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--text-brand);
    vertical-align: text-bottom;
    animation: blink 1s step-end infinite;
    margin-left: 1px;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ---------- Fraction Template ---------- */
.frac-box {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 2px;
    font-size: .85em;
    line-height: 1.1;
}
.frac-num {
    border-bottom: 1px solid var(--text-expression);
    padding: 0 3px 1px;
    min-width: 14px;
    text-align: center;
    min-height: 1em;
}
.frac-den {
    padding: 1px 3px 0;
    min-width: 14px;
    text-align: center;
    min-height: 1em;
}
.frac-line { display: none; } /* line is on frac-num border */
.frac-placeholder {
    color: rgba(143,168,184,.45);
    font-size: .9em;
}

/* ---------- Log Base Template ---------- */
.log-tmpl {
    display: inline-flex;
    align-items: baseline;
    margin: 0 1px;
}
.log-base {
    font-size: .68em;
    vertical-align: sub;
    min-width: 9px;
    padding: 0 2px;
    border-bottom: 1px solid rgba(143,168,184,.5);
    text-align: center;
    line-height: 1;
}
.log-arg { min-width: 10px; padding: 0 1px; }

/* ---------- Mode Overlay ---------- */
.mode-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(11,14,20,.88);
    backdrop-filter: blur(8px);
    border-radius: 24px;
    align-items: center;
    justify-content: center;
}
.mode-overlay.active {
    display: flex;
    animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- OPTN Overlay ---------- */
.optn-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 55;
    background: rgba(11,14,20,.92);
    backdrop-filter: blur(8px);
    border-radius: 24px;
    align-items: center;
    justify-content: center;
}
.optn-overlay.active {
    display: flex;
    animation: fadeIn .2s ease;
}
.optn-menu { width: 88%; }
.optn-menu-title {
    text-align: center;
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: #93c5fd;
    margin-bottom: 14px;
    text-transform: uppercase;
}
.optn-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.optn-btn {
    background: rgba(147,197,253,.06);
    border: 1px solid rgba(147,197,253,.14);
    border-radius: 10px;
    padding: 12px 6px;
    cursor: pointer;
    font-size: .68rem;
    font-weight: 600;
    color: #93c5fd;
    text-align: center;
    transition: .2s;
    font-family: 'JetBrains Mono', monospace;
}
.optn-btn:hover { background: rgba(147,197,253,.15); border-color: rgba(147,197,253,.35); }
.optn-close { grid-column: 1 / -1; color: #94a3b8; background: rgba(255,255,255,.03); }

.mode-menu { width: 88%; }
.mode-menu-title {
    text-align: center;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--text-brand);
    margin-bottom: 16px;
    text-transform: uppercase;
}
.mode-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.mode-btn {
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: 12px;
    padding: 16px 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: all .2s;
    color: #cbd5e1;
}
.mode-btn:hover { background: rgba(255,255,255,.08); border-color: rgba(94,240,168,.2); }
.mode-btn.active { background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.4); color: #a7f3d0; }
.mode-icon { font-size: 1.4rem; }
.mode-label { font-size: .65rem; font-weight: 600; letter-spacing: .5px; }

/* ---------- Panels (Stats, Matrix, Base, Eqn) ---------- */
.solver-panel, .stat-panel, .matrix-panel, .base-panel {
    background: rgba(255,255,255,.03);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    animation: fadeIn .2s;
}
.solver-title, .stat-title, .matrix-title, .base-title {
    font-size: .72rem;
    font-weight: 600;
    color: #93c5fd;
    letter-spacing: .5px;
    margin-bottom: 10px;
    text-align: center;
}

/* Tabs */
.solver-tabs, .matrix-tabs {
    display: flex; gap: 6px; margin-bottom: 10px;
}
.solver-tab, .matrix-tab {
    flex: 1;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: .65rem;
    font-weight: 600;
    color: #94a3b8;
    cursor: pointer;
    transition: .2s;
    font-family: 'JetBrains Mono', monospace;
}
.solver-tab.active, .matrix-tab.active {
    background: rgba(16,185,129,.12);
    border-color: rgba(16,185,129,.35);
    color: #a7f3d0;
}

/* Input fields */
.solver-inputs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.solver-field { display: flex; align-items: center; gap: 4px; }
.solver-field label {
    font-size: .7rem;
    font-weight: 600;
    color: #93c5fd;
    font-family: 'JetBrains Mono', monospace;
}
.solver-field input, .stat-input-row input, .base-input-row input {
    width: 68px;
    background: rgba(0,0,0,.3);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 6px;
    padding: 5px 8px;
    color: #e2e8f0;
    font-size: .75rem;
    font-family: 'JetBrains Mono', monospace;
    outline: none;
    transition: border-color .2s;
}
.solver-field input:focus, .stat-input-row input:focus, .base-input-row input:focus {
    border-color: var(--text-brand);
}

.stat-input-row, .base-input-row {
    display: flex; gap: 8px; margin-bottom: 10px; align-items: center;
}
.stat-input-row input, .base-input-row input { flex: 1; width: auto; }

.stat-add-btn, .stat-calc-btn, .solver-solve-btn, .base-convert-btn {
    background: rgba(16,185,129,.15);
    border: 1px solid rgba(16,185,129,.3);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: .7rem;
    font-weight: 600;
    color: #a7f3d0;
    cursor: pointer;
    transition: .2s;
}
.stat-add-btn:hover, .stat-calc-btn:hover, .solver-solve-btn:hover, .base-convert-btn:hover {
    background: rgba(16,185,129,.25);
}
.stat-calc-btn, .solver-solve-btn, .base-convert-btn {
    display: block; width: 100%; margin-top: 8px;
}

.stat-data-list {
    max-height: 60px;
    overflow-y: auto;
    font-size: .68rem;
    color: #94a3b8;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 6px;
    padding: 4px;
}

.stat-results, .solver-results, .base-results, .matrix-result {
    margin-top: 10px;
    font-size: .72rem;
    color: var(--text-result);
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.7;
}

/* Base-N select */
.base-input-row select {
    background: rgba(0,0,0,.3);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 6px;
    padding: 5px 8px;
    color: #e2e8f0;
    font-size: .7rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    cursor: pointer;
}

/* Matrix grid */
.matrix-size-selector {
    display: flex; gap: 6px; align-items: center;
    font-size: .7rem; color: #94a3b8; margin-bottom: 10px; justify-content: center;
}
.matrix-size-selector select {
    background: rgba(0,0,0,.3);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 6px; padding: 4px 8px;
    color: #e2e8f0; font-size: .7rem; outline: none; cursor: pointer;
}
.matrix-grid {
    display: grid; gap: 4px; margin-bottom: 10px;
}
.matrix-grid input {
    width: 100%;
    background: rgba(0,0,0,.3);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 5px;
    padding: 5px 4px;
    color: #e2e8f0;
    font-size: .72rem;
    font-family: 'JetBrains Mono', monospace;
    text-align: center;
    outline: none;
}
.matrix-grid input:focus {
    border-color: var(--text-brand);
}
.matrix-ops {
    display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px;
}
.mat-op-btn {
    flex: 1; min-width: 60px;
    background: rgba(147,197,253,.08);
    border: 1px solid rgba(147,197,253,.15);
    border-radius: 7px;
    padding: 5px 6px;
    font-size: .65rem;
    font-weight: 600;
    color: #93c5fd;
    cursor: pointer;
    transition: .2s;
    font-family: 'JetBrains Mono', monospace;
}
.mat-op-btn:hover { background: rgba(147,197,253,.15); }

/* ---------- Buttons ---------- */
.buttons-container {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.btn-row {
    display: grid;
    gap: var(--gap);
}
.btn-row-top { grid-template-columns: repeat(7, 1fr); }
.btn-row-top .btn { padding: 10px 2px; font-size: .55rem; letter-spacing: 0; }
.btn-row:not(.btn-row-top):not(.btn-row-bottom) { grid-template-columns: repeat(6, 1fr); }
.btn-row:nth-child(n+5):not(.btn-row-bottom) { grid-template-columns: repeat(5, 1fr); }
.btn-row-bottom { grid-template-columns: repeat(5, 1fr); }

.btn {
    position: relative;
    border: none;
    border-radius: var(--btn-radius);
    padding: 14px 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .12s ease;
    box-shadow: var(--shadow-btn);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    line-height: 1.2;
}

/* Ripple effect */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%), rgba(255,255,255,.15) 0%, transparent 60%);
    opacity: 0;
    transition: opacity .3s;
    pointer-events: none;
}
.btn:active::after { opacity: 1; transition: opacity 0s; }
.btn:active {
    transform: scale(.95);
    box-shadow: var(--shadow-btn-active);
}

/* Button variants */
.btn-num { background: var(--btn-num-bg); color: var(--btn-num-text); }
.btn-num:hover { background: var(--btn-num-hover); }

.btn-func { background: var(--btn-func-bg); color: var(--btn-func-text); font-size: .7rem; }
.btn-func:hover { background: var(--btn-func-hover); }

.btn-op { background: var(--btn-op-bg); color: var(--btn-op-text); font-size: .9rem; }
.btn-op:hover { background: var(--btn-op-hover); }

.btn-eq {
    background: var(--btn-eq-bg);
    color: var(--btn-eq-text);
    font-size: 1.1rem;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.btn-eq:hover { background: var(--btn-eq-hover); }

.btn-ac { background: var(--btn-ac-bg); color: var(--btn-ac-text); font-size: .75rem; }
.btn-ac:hover { background: var(--btn-ac-hover); }

.btn-shift { background: var(--btn-shift-bg); color: var(--btn-shift-text); font-size: .6rem; letter-spacing: .5px; }
.btn-shift:hover { background: var(--btn-shift-hover); }
.btn-shift.active { box-shadow: 0 0 10px rgba(251,191,36,.3), var(--shadow-btn); }

.btn-alpha { background: var(--btn-alpha-bg); color: var(--btn-alpha-text); font-size: .6rem; letter-spacing: .5px; }
.btn-alpha:hover { background: var(--btn-alpha-hover); }
.btn-alpha.active { box-shadow: 0 0 10px rgba(125,211,252,.3), var(--shadow-btn); }

.btn-mode { background: var(--btn-func-bg); color: #a78bfa; font-size: .6rem; letter-spacing: .5px; }
.btn-mode:hover { background: var(--btn-func-hover); }

.btn-cursor { background: var(--btn-func-bg); color: #94a3b8; font-size: .8rem; }
.btn-cursor:hover { background: var(--btn-func-hover); }

.btn-const { background: var(--btn-func-bg); color: #f0abfc; font-size: .72rem; }
.btn-const:hover { background: var(--btn-func-hover); }

.btn-mplus { background: #1b2235; color: #fbbf24; font-size: .68rem; font-weight: 700; }
.btn-mplus:hover { background: #222b44; }

.btn-std { background: var(--btn-func-bg); color: #34d399; font-size: .62rem; font-weight: 700; }
.btn-std:hover { background: var(--btn-func-hover); }

/* Shift / Alpha sub-labels */
.btn-shift-label, .btn-alpha-label {
    font-size: .48rem;
    font-weight: 500;
    opacity: .55;
    margin-top: 1px;
    transition: opacity .15s;
}
.btn-shift-label { color: var(--btn-shift-text); }
.btn-alpha-label { color: var(--btn-alpha-text); }

/* Highlight shift labels when SHIFT is active */
body.shift-active .btn-shift-label { opacity: 1; }
body.alpha-active .btn-alpha-label { opacity: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 460px) {
    :root { --calc-width: 100vw; --border-radius: 10px; --btn-radius: 8px; }
    .calculator { border-radius: 0; padding: 12px 8px; }
    .btn { padding: 12px 2px; font-size: .7rem; }
    .btn-func { font-size: .6rem; }
    .display-result { font-size: 1.4rem; }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }
