:root {
    --chassis-bg: #d0ceca;
    --chassis-border: #a9a7a3;
    --screen-bg: #9eb59e;
    --screen-text: #1a241a;
    --key-num-bg: #e8e6e1;
    --key-num-text: #2b2b2b;
    --key-op-bg: #8d9499;
    --key-op-text: #ffffff;
    --key-danger: #c0392b;
    --key-action: #d35400;
    --key-tab: #b5b3af;
    --hard-shadow: #888681;
    --hard-shadow-dark: #5c5a57;
    --highlight: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Courier New', Courier, monospace, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: #2c3e50;
    color: var(--key-num-text);
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 10px;
}

/* math {
            font-size: 0.85rem;


        } */

.app {
    width: 100%;
    max-width: 480px;
    background: var(--chassis-bg);
    border: 4px solid var(--chassis-border);
    border-radius: 12px;
    box-shadow:
        inset 2px 2px 5px var(--highlight),
        inset -4px -4px 10px rgba(0, 0, 0, 0.1),
        8px 12px 25px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    padding: 14px;
    gap: 12px;
    position: relative;
}

/* ===== DISPLAY ===== */
.display-module {
    background: #111;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid #555;
    box-shadow: 0 4px 0 #888;
    flex-shrink: 0;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 0 4px;
}

.header h1 {
    font-size: 1rem;
    color: #d0ceca;
    font-family: Arial, sans-serif;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.mode-badge {
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 8px;
    background: var(--chassis-border);
    color: #000;
    border-radius: 4px;
}

.screen-container {
    background: var(--screen-bg);
    border: 4px inset #6a7c6a;
    border-radius: 4px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: inset 2px 4px 10px rgba(0, 0, 0, 0.2);
}

math-field {
    width: 100%;
    font-size: 1.5rem;
    border: none;
    outline: none;
    background: transparent;
    --math-color: var(--screen-text);
    min-height: 50px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 8px;
}

.result {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--screen-text);
    overflow-x: auto;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.deg-btn {
    background: var(--key-op-bg);
    color: #fff;
    border: 2px solid var(--hard-shadow-dark);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 2px 3px 0 var(--hard-shadow-dark);
    flex-shrink: 0;
    margin-left: 8px;
}

.deg-btn:active {
    transform: translate(2px, 3px);
    box-shadow: 0 0 0 transparent;
}

/* ===== KEYBOARD ===== */
.keyboard {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tabs {
    display: flex;
    gap: 6px;
    padding-top: 10px;
    flex-shrink: 0;
}

.tab {
    flex: 1;
    padding: 9px 4px;
    border: 2px solid var(--hard-shadow);
    border-radius: 6px;
    background: var(--key-tab);
    font-weight: bold;
    font-size: 0.72rem;
    cursor: pointer;
    box-shadow: 2px 4px 0 var(--hard-shadow);
    text-transform: uppercase;
    text-align: center;
    transition: transform 0.05s, box-shadow 0.05s;
}

.tab:active {
    transform: translate(2px, 4px);
    box-shadow: 0 0 0 transparent;
}

.tab.active {
    background: var(--key-op-bg);
    color: white;
    transform: translate(2px, 2px);
    box-shadow: 0 2px 0 var(--hard-shadow-dark);
}

.keys-area {
    flex: 1;
    min-height: 0;
    position: relative;
}

.panel {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.panel.active {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 7px;
    align-content: start;
    padding: 2px 4px 10px 0;
}

/* ===== BUTTONS ===== */
.key {
    height: 48px;
    border: 2px solid var(--chassis-border);
    border-radius: 6px;
    background: var(--key-num-bg);
    font-size: 1.05rem;
    font-weight: bold;
    font-family: Arial, sans-serif;
    color: var(--key-num-text);
    cursor: pointer;
    position: relative;
    box-shadow:
        -1px -1px 0 rgba(255, 255, 255, 0.8) inset,
        2px 3px 0 var(--hard-shadow);
    transition: transform 0.05s, box-shadow 0.05s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
    overflow: hidden;
}

.key:active {
    transform: translate(2px, 3px);
    box-shadow: 0 0 0 transparent;
}

.key.op {
    background: var(--key-op-bg);
    color: var(--key-op-text);
    border-color: var(--hard-shadow-dark);
    box-shadow:
        -1px -1px 0 rgba(255, 255, 255, 0.3) inset,
        2px 3px 0 var(--hard-shadow-dark);
}

.key.eq {
    background: var(--key-action);
    color: white;
    border-color: #a04000;
    box-shadow: 2px 3px 0 #a04000;
    font-size: 1.3rem;
}

.key.del {
    background: var(--key-danger);
    color: white;
    border-color: #922b21;
    box-shadow: 2px 3px 0 #922b21;
}

.key.span2 {
    grid-column: span 2;
}

.key.sym,
.key.func {
    font-family: "Times New Roman", serif;
    font-style: italic;
    background: var(--key-op-bg);
    color: var(--key-op-text);
    border-color: var(--hard-shadow-dark);
    box-shadow:
        -1px -1px 0 rgba(255, 255, 255, 0.3) inset,
        2px 3px 0 var(--hard-shadow-dark);
}

.key.small-text {
    font-size: 1.05rem;
    font-family: Arial, sans-serif;
    font-style: normal;
}

.key math {
    font-size: 1.05rem;
    display: flex;
    word-spacing: 0cap;
    align-items: center;
    justify-content: center;
    font-family: Arial, sans-serif;

}

/* Scrollbar */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: var(--chassis-bg);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--hard-shadow);
    border-radius: 4px;
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: #111;
    color: #0f0;
    font-family: 'Courier New', monospace;
    padding: 10px 24px;
    border: 2px solid #555;
    border-radius: 4px;
    font-weight: bold;
    z-index: 999;
    transition: transform 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Flash animasi hasil */
.result.flash {
    animation: resFlash 0.35s ease;
}

@keyframes resFlash {
    0% {
        opacity: 1;
    }

    30% {
        opacity: 0.3;
    }

    100% {
        opacity: 1;
    }
}

/* ===== MODAL ===== */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    border-radius: 12px;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--chassis-bg);
    border: 3px solid var(--chassis-border);
    padding: 16px;
    border-radius: 8px;
    box-shadow:
        inset 1px 1px 3px var(--highlight),
        4px 6px 0 var(--hard-shadow-dark);
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 85%;
    max-width: 260px;
    transform: translateY(20px);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.show .modal-box {
    transform: translateY(0);
}

.modal-box h3 {
    text-align: center;
    font-family: Arial, sans-serif;
    color: var(--key-num-text);
    text-transform: uppercase;
    border-bottom: 2px solid var(--chassis-border);
    padding-bottom: 8px;
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.modal-inputs {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.modal-inputs label {
    font-weight: bold;
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    flex: 1;
}

.modal-inputs input {
    margin-top: 6px;
    padding: 8px;
    background: var(--key-num-bg);
    border: 2px solid var(--hard-shadow);
    border-top-color: var(--hard-shadow-dark);
    border-left-color: var(--hard-shadow-dark);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1.2rem;
    text-align: center;
    color: var(--key-num-text);
    outline: none;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions button {
    flex: 1;
    height: 42px;
}

/* Matrix result styling */
.result .katex .mord.katex-nohighlight {
    font-size: 0.9em;
}

@media (max-height: 700px) {
    .app {
        height: 100%;
        background: var(--chassis-bg);
        border: 4px solid var(--chassis-border);
        border-radius: 12px;
        box-shadow:
            inset 2px 2px 5px var(--highlight),
            inset -4px -4px 10px rgba(0, 0, 0, 0.1),
            8px 12px 25px rgba(0, 0, 0, 0.5);
        display: flex;
        flex-direction: column;
        padding: 14px;
        gap: 12px;
        position: relative;
    }

    .key {
        height: 46px;
        font-size: 0.8rem;
    }

    .key.small-text {
        font-size: 1rem;
    }

    .key math {
        font-size: 0.8rem;
        display: flex;
        word-spacing: 0cap;
        align-items: center;
        justify-content: center;
        font-family: Arial, sans-serif;

    }

    .key.op .key.sym {
        font-size: 0.8rem;
    }

    .tabs {
        gap: 4px;
    }

    .tab {
        padding: 7px 2px;
        font-size: 0.65rem;
    }

    .panel.active {
        gap: 5px;
    }
}