/* Professional Scientific Calculator - Casio Style Layout */
/* Integrated with Layer WebApp Themes */

.calculator-overlay.casio-style {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    
    /* Theme Integration */
    background: var(--card, #1c1c1f); /* Solid background */
    backdrop-filter: none;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    box-shadow: var(--glass-shadow, 0 24px 48px rgba(0, 0, 0, 0.2));
    
    border-radius: 28px;
    width: 300px; /* Initial width */
    min-width: 300px;
    min-height: 480px;
    resize: both; /* Allow resizing */
    overflow: hidden; /* Required for resize handle */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    display: none;
    flex-direction: column;
    animation: calcFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    
    /* Modern aesthetic variables */
    --calc-body-padding: 24px;
    --calc-btn-gap: 10px;
    --calc-btn-radius: 12px;
    --calc-screen-bg: transparent;
}

.calculator-overlay.visible {
    display: flex;
}

@keyframes calcFadeIn {
    from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Header Section */
.calculator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px 8px;
    background: transparent;
    border-bottom: none;
    cursor: grab;
}

.calculator-header:active {
    cursor: grabbing;
}

.brand-section {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.brand-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--foreground);
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.model-name {
    display: none; /* Hide model name for cleaner look */
}

.solar-strip {
    display: none; /* Remove retro solar strip */
}

.calculator-close {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--muted-foreground);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calculator-close:hover {
    background: var(--destructive);
    color: var(--destructive-foreground);
}

/* Screen Section */
.calc-screen-bezel {
    padding: 0 24px 8px;
}

.calc-screen {
    background: var(--calc-screen-bg);
    border-radius: 0;
    padding: 12px 0;
    text-align: right;
    box-shadow: none;
    border: none;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Align to bottom */
}

.calc-indicators {
    display: flex;
    gap: 8px;
    font-size: 9px;
    color: var(--muted-foreground);
    font-weight: 600;
    height: 12px;
}

.calc-indicators .ind {
    opacity: 0.3;
}

.calc-indicators .ind.active {
    opacity: 1;
    color: var(--primary);
}

.calc-expression {
    font-family: 'Source Code Pro', monospace;
    font-size: 13px;
    color: var(--muted-foreground);
    min-height: 18px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-top: 4px;
}

.calc-result {
    font-family: 'Times New Roman', serif;
    font-size: 24px;
    font-weight: 400;
    color: var(--foreground);
    letter-spacing: 0.5px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 8px 0;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* KaTeX Styling for Scientific Calculator Display */
.calc-result .katex {
    font-family: 'Times New Roman', serif !important;
    font-size: 1em !important;
    color: inherit !important;
}

.calc-result .katex .frac-line {
    border-bottom-width: 1.5px !important;
    border-color: currentColor !important;
}

.calc-result .katex .sqrt > .root {
    margin-right: 0.1em !important;
    border-top: 1.5px solid currentColor !important;
}

.calc-result .katex .sqrt > .root::before {
    content: none !important;
}

.calc-result .katex .fontsize-ensurer.reset-size1.size1 {
    font-size: 1em !important;
}

.calc-result .katex .delimsizing.size1 {
    font-family: 'Times New Roman', serif !important;
}

/* Expression display styling */
.calc-expression {
    font-family: 'Times New Roman', serif;
    font-size: 14px;
    color: var(--muted-foreground);
    min-height: 18px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-top: 4px;
    padding: 4px 0;
}

.calc-expression .katex {
    font-family: 'Times New Roman', serif !important;
    font-size: 0.9em !important;
    color: inherit !important;
}

.calc-expression .katex .frac-line {
    border-bottom-width: 1px !important;
    border-color: currentColor !important;
}

.calc-expression .katex .sqrt > .root {
    margin-right: 0.05em !important;
    border-top: 1px solid currentColor !important;
}

/* Mathematical Fractions */
.math-fraction {
    display: inline-flex;
    flex-direction: column;
    vertical-align: middle;
    text-align: center;
    margin: 0 2px;
}

.fraction-numerator {
    display: block;
    font-size: 0.7em;
    line-height: 1.2;
    border-bottom: none;
    padding: 0 2px;
}

.fraction-bar {
    display: block;
    height: 1px;
    background: currentColor;
    margin: 1px 0;
    opacity: 0.8;
}

.fraction-denominator {
    display: block;
    font-size: 0.7em;
    line-height: 1.2;
    padding: 0 2px;
}

/* Mixed Numbers */
.mixed-number {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    margin: 0 2px;
}

.whole-number {
    font-size: 1em;
    margin-right: 2px;
    align-self: flex-end;
    padding-bottom: 0.2em;
}

/* Square Roots */
.math-sqrt {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.sqrt-content {
    border-top: 1px solid currentColor;
    padding: 0 2px;
    margin-left: 1px;
}

/* Nth Roots */
.math-nth-root {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    position: relative;
}

.root-index {
    font-size: 0.6em;
    vertical-align: super;
    margin-right: 1px;
    line-height: 1;
}

.root-symbol {
    font-size: 1.1em;
    margin-right: 1px;
}

.root-content {
    border-top: 1px solid currentColor;
    padding: 0 2px;
}

/* Logarithms with Bases */
.math-log {
    display: inline-flex;
    align-items: baseline;
}

.log-base {
    font-size: 0.7em;
    vertical-align: sub;
    margin-left: 1px;
}

/* Trigonometric Functions with Powers */
.math-trig-power {
    display: inline-flex;
    align-items: baseline;
}

.trig-power {
    font-size: 0.7em;
    vertical-align: super;
    margin-left: 1px;
}

/* Mathematical Constants */
.math-constant {
    font-style: italic;
    font-family: 'Times New Roman', serif;
}

/* Scientific Notation */
.math-scientific {
    display: inline-flex;
    align-items: baseline;
}

.math-scientific .power {
    font-size: 0.7em;
    vertical-align: super;
    margin-left: 1px;
}

/* Body & Keypad */
.calc-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Button Reset */
.calc-body button {
    appearance: none;
    border: none;
    outline: none;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    user-select: none;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    position: relative;
    overflow: hidden;
    /* Removed 3D effect base */
    box-shadow: none;
}

.calc-body button:active {
    transform: scale(0.95);
    opacity: 0.8;
    box-shadow: none;
}

/* Control Row */
.calc-row-control {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.btn-control {
    height: 32px;
    border-radius: 16px; /* Pill shape */
    font-size: 11px;
    font-weight: 600;
    color: var(--foreground);
    background: var(--secondary);
    opacity: 0.8;
}

.btn-control:hover {
    opacity: 1;
}

.btn-shift {
    color: #fbbf24; /* Amber for Shift */
    background: rgba(251, 191, 36, 0.15);
}

.btn-alpha {
    color: #f87171; /* Red for Alpha */
    background: rgba(248, 113, 113, 0.15);
}

.d-pad-placeholder {
    grid-column: span 1;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: var(--muted-foreground);
    background: transparent;
    border-radius: 16px;
    border: 1px dashed var(--border);
    opacity: 0.5;
}

/* Scientific Grid */
.calc-grid-sci {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    flex: 3;
    grid-auto-rows: 1fr;
    min-height: 0; /* Allow shrinking */
}

.btn-sci {
    height: 100%;
    min-height: 32px;
    border-radius: var(--calc-btn-radius);
    background: rgba(255, 255, 255, 0.03); /* Subtle glass for keys */
    color: var(--muted-foreground);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid transparent;
}

.btn-sci:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--foreground);
}

/* Main Keypad */
.calc-grid-main {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 12px;
    flex: 4;
    grid-auto-rows: 1fr;
    min-height: 0;
}

.btn-num {
    height: 100%;
    min-height: 40px;
    border-radius: var(--calc-btn-radius);
    background: var(--card); /* Standard keys */
    color: var(--foreground);
    font-size: 18px;
    font-weight: 500;
    border: 1px solid var(--border);
}

.btn-num:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-op {
    height: 100%;
    min-height: 40px;
    border-radius: var(--calc-btn-radius);
    background: var(--secondary);
    color: var(--foreground);
    font-size: 18px;
    font-weight: 500;
    border: 1px solid transparent;
}

.btn-op.del, .btn-op.ac {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    font-size: 13px;
    font-weight: 600;
}

.btn-op.del:hover, .btn-op.ac:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-op.exe {
    background: var(--primary);
    color: var(--primary-foreground);
    grid-column: span 1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); /* Slight shadow for call to action */
}

.btn-op.exe:hover {
    filter: brightness(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.btn-op.ans {
    font-size: 13px;
    background: transparent;
    color: var(--muted-foreground);
    border: 1px solid var(--border);
}

/* Theme-specific overrides if needed */
[data-theme="light"] .btn-sci {
    background: #e5e5e5;
    color: #333;
}

[data-theme="light"] .btn-num {
    background: #fff;
    color: #000;
}
