/* ============================================
   TI-84 Calculator Emulator Styles
   Faithful recreation of TI-84 Plus CE look
   ============================================ */

/* ---- Calculator Container ---- */
.calc-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-6);
    background: var(--bg-body);
}

.calc-wrapper {
    display: flex;
    gap: var(--space-8);
    max-width: 1200px;
    width: 100%;
    align-items: flex-start;
}

.calc-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.calc-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
}

/* ---- Calculator Shell ---- */
.calculator {
    width: 360px;
    background: linear-gradient(145deg, #2D3142, #1F2233);
    border-radius: 24px;
    padding: 20px 16px 24px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    position: relative;
    user-select: none;
}

/* Brand label */
.calculator::before {
    content: 'TI-84 Plus CE';
    display: block;
    text-align: center;
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.35);
    margin-bottom: 12px;
}

/* ---- Display Screen ---- */
.calc-display {
    background: #1A1D2E;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    border: 2px solid rgba(255, 255, 255, 0.06);
    position: relative;
    overflow: hidden;
}

/* Subtle screen reflection */
.calc-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent);
    pointer-events: none;
    border-radius: 10px 10px 0 0;
}

.calc-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 10px;
    color: rgba(255, 255, 255, 0.35);
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 8px;
}

.calc-status-bar .mode-indicator {
    padding: 1px 6px;
    background: rgba(var(--accent-rgb), 0.15);
    border-radius: 3px;
    color: var(--accent);
    font-weight: 600;
}

.calc-status-bar .mode-indicator.active-2nd {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.calc-history {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 70px;
    scrollbar-width: none;
}

.calc-history::-webkit-scrollbar {
    display: none;
}

.calc-history-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.calc-history-input {
    font-family: var(--font-mono);
    font-size: 13px;
    color: rgba(255, 255, 255, 0.4);
    word-break: break-all;
}

.calc-history-result {
    font-family: var(--font-mono);
    font-size: 14px;
    color: rgba(var(--accent-rgb), 0.6);
    word-break: break-all;
}

.calc-input-line {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
    text-align: right;
    min-height: 24px;
    word-break: break-all;
    letter-spacing: 0.02em;
}

.calc-input-line .cursor {
    display: inline-block;
    width: 2px;
    height: 18px;
    background: var(--accent);
    vertical-align: text-bottom;
    animation: blink 1s step-end infinite;
    margin-left: 1px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0; }
}

.calc-result-line {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
    color: var(--accent);
    text-align: right;
    min-height: 28px;
    letter-spacing: 0.01em;
    text-shadow: 0 0 12px rgba(var(--accent-rgb), 0.3);
}

.calc-error {
    color: var(--danger) !important;
    text-shadow: 0 0 12px rgba(239, 68, 68, 0.3) !important;
}

/* ---- Graph Display ---- */
.calc-graph-viewport {
    display: none;
    width: 100%;
    height: 200px;
    background: #0D1117;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    position: relative;
    overflow: hidden;
    cursor: crosshair;
}

.calc-graph-viewport.active {
    display: block;
}

.calc-graph-viewport canvas {
    width: 100%;
    height: 100%;
}

.graph-coords {
    position: absolute;
    bottom: 6px;
    left: 8px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--accent);
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ---- Navigation Pad (D-Pad) ---- */
.calc-dpad {
    display: grid;
    grid-template-areas:
        ".  up  ."
        "lt ok rt"
        ".  dn  .";
    grid-template-columns: 32px 32px 32px;
    grid-template-rows: 32px 32px 32px;
    gap: 2px;
    justify-content: center;
    margin: 8px auto 12px;
}

.calc-dpad button {
    border-radius: 50%;
    background: #3A3F55;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: all 0.1s ease;
}

.calc-dpad button:active {
    transform: scale(0.9);
    background: #4A4F65;
}

.dpad-up    { grid-area: up; }
.dpad-down  { grid-area: dn; }
.dpad-left  { grid-area: lt; }
.dpad-right { grid-area: rt; }
.dpad-ok    { grid-area: ok; background: #4A4F65 !important; }

/* ---- Keypad ---- */
.calc-keypad {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calc-key-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
}

/* Base key style */
.calc-key {
    height: 38px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-sans);
    transition: all 0.08s ease;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.04);
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.calc-key:active {
    transform: scale(0.93);
    filter: brightness(0.85);
}

/* 2nd function label (above key) */
.calc-key .key-2nd {
    position: absolute;
    top: -13px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    font-weight: 600;
    color: #F59E0B;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0.7;
}

/* Alpha label (above key, right side) */
.calc-key .key-alpha {
    position: absolute;
    top: -13px;
    right: 2px;
    font-size: 8px;
    font-weight: 700;
    color: #22C55E;
    pointer-events: none;
    opacity: 0.7;
}

/* ---- Key Color Variants ---- */

/* Function row keys (Y=, WINDOW, etc.) */
.key-func {
    background: linear-gradient(180deg, #3A3F55, #2D3142);
    color: rgba(255, 255, 255, 0.85);
    font-size: 10px;
    letter-spacing: 0.02em;
}

/* Blue modifier keys (2nd) */
.key-2nd-btn {
    background: linear-gradient(180deg, #3B82F6, #2563EB);
    color: white;
    font-weight: 700;
}

.key-2nd-btn.active {
    background: linear-gradient(180deg, #F59E0B, #D97706);
    animation: glow 1.5s ease-in-out infinite;
}

/* Green alpha key */
.key-alpha-btn {
    background: linear-gradient(180deg, #22C55E, #16A34A);
    color: white;
    font-weight: 700;
}

/* Dark operation keys (math, trig, etc.) */
.key-op {
    background: linear-gradient(180deg, #3A3F55, #2D3142);
    color: rgba(255, 255, 255, 0.85);
}

/* Number keys (lighter) */
.key-num {
    background: linear-gradient(180deg, #4A5069, #3D4258);
    color: white;
    font-size: 16px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.key-num:hover {
    background: linear-gradient(180deg, #565B75, #4A5069);
}

/* Arithmetic operator keys */
.key-arith {
    background: linear-gradient(180deg, #4A5069, #3D4258);
    color: rgba(255, 255, 255, 0.9);
    font-size: 16px;
    font-family: var(--font-mono);
}

/* Clear key */
.key-clear {
    background: linear-gradient(180deg, #3A3F55, #2D3142);
    color: rgba(255, 255, 255, 0.85);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
}

/* Enter key */
.key-enter {
    background: linear-gradient(180deg, #1E6B4F, #155E44);
    color: white;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.05em;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.key-enter:hover {
    background: linear-gradient(180deg, #22805C, #1A7050);
}

/* DEL key */
.key-del {
    background: linear-gradient(180deg, #3A3F55, #2D3142);
    color: rgba(255, 255, 255, 0.85);
    font-size: 10px;
    font-weight: 700;
}

/* ON key */
.key-on {
    background: linear-gradient(180deg, #3A3F55, #2D3142);
    color: rgba(255, 255, 255, 0.6);
    font-size: 10px;
    font-weight: 700;
}

/* Negate key */
.key-neg {
    background: linear-gradient(180deg, #4A5069, #3D4258);
    color: rgba(255, 255, 255, 0.8);
    font-size: 11px;
}

/* Wide keys (span 2 columns) */
.key-wide {
    grid-column: span 2;
}

/* ---- Mode Toggle Tabs ---- */
.calc-mode-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 12px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 3px;
    border: 1px solid var(--border);
}

.calc-mode-tab {
    flex: 1;
    padding: 8px 12px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: all var(--duration-fast) var(--ease-out);
    text-align: center;
}

.calc-mode-tab:hover {
    color: var(--text-primary);
}

.calc-mode-tab.active {
    background: var(--accent);
    color: var(--text-inverse);
    box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.3);
}

/* ---- Graph Y= Editor ---- */
.graph-editor {
    display: none;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: var(--space-4);
    margin-top: var(--space-4);
    width: 360px;
}

.graph-editor.active {
    display: block;
}

.graph-editor h4 {
    font-size: var(--text-sm);
    margin-bottom: var(--space-3);
    color: var(--text-secondary);
}

.graph-func-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.graph-func-label {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--accent);
    min-width: 28px;
}

.graph-func-row .color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.graph-func-input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text-primary);
    transition: border-color var(--duration-fast);
}

.graph-func-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.graph-controls {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}

.graph-controls .btn {
    flex: 1;
    padding: 8px;
    font-size: var(--text-xs);
}

/* ---- Window Settings ---- */
.window-settings {
    display: none;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: var(--space-4);
    margin-top: var(--space-3);
    width: 360px;
}

.window-settings.active {
    display: block;
}

.window-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.window-row label {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    min-width: 50px;
}

.window-row input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-primary);
}

.window-row input:focus {
    border-color: var(--accent);
}

/* ---- Calculator Tool Info Panel ---- */
.calc-info-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    margin-top: var(--space-6);
    width: 360px;
}

.calc-info-panel h3 {
    font-size: var(--text-base);
    margin-bottom: var(--space-3);
}

.calc-shortcuts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
}

.calc-shortcuts kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-primary);
    white-space: nowrap;
}

.calc-shortcuts span {
    color: var(--text-secondary);
}

/* ---- Responsive Calculator ---- */
@media (max-width: 1024px) {
    .calc-wrapper {
        flex-direction: column;
        align-items: center;
    }

    .calc-sidebar {
        width: 100%;
        max-width: 360px;
    }
}

@media (max-width: 480px) {
    .calc-page {
        padding: var(--space-3);
    }

    .calculator {
        width: 100%;
        max-width: 360px;
        border-radius: 18px;
        padding: 14px 10px 18px;
    }

    .calc-key {
        height: 34px;
        font-size: 11px;
        border-radius: 5px;
    }

    .key-num {
        font-size: 14px;
    }

    .calc-display {
        min-height: 120px;
        padding: 10px 12px;
    }

    .calc-input-line {
        font-size: 16px;
    }

    .calc-result-line {
        font-size: 18px;
    }

    .graph-editor,
    .calc-info-panel,
    .window-settings {
        width: 100%;
    }
}

/* ---- Touch optimization ---- */
@media (hover: none) {
    .calc-key:active {
        transform: scale(0.92);
        filter: brightness(0.8);
    }

    .calc-key .key-2nd,
    .calc-key .key-alpha {
        display: none;
    }
}
