/* ═══════════════════════════════════════════════════════
   Math&Notes – Full-Screen-Layout
   Toolbar sitzt direkt unter der Bootstrap-Navbar (80px).
   mn-main füllt den Rest des Viewports.
═══════════════════════════════════════════════════════ */

:root {
    --mn-navbar-h: 80px;
    --mn-toolbar-h: 48px;
    --mn-handle-w: 8px;
    --calc-bg:  #141b2d;
    --calc-disp: #0d1321;
    --calc-text: #b8d4f0;
    --calc-acc:  #3498db;
    --calc-acc2: #85c1e9;
}

html, body { overflow: hidden; }
footer { display: none !important; }

/* ── Hilfklasse ── */
.mn-hidden { display: none !important; }

/* ══════════════════════════════════════════════════════
   Werkzeug-Toolbar
══════════════════════════════════════════════════════ */
#mn-toolbar {
    position: fixed;
    top: var(--mn-navbar-h);
    left: 0; right: 0;
    height: var(--mn-toolbar-h);
    background: linear-gradient(135deg, #1e3c72 0%, #2980b9 100%);
    border-bottom: 1px solid #154360;
    display: flex; align-items: center;
    padding: 0 12px; gap: 6px;
    z-index: 200;
    user-select: none;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    overflow-x: auto;
}
#mn-toolbar::-webkit-scrollbar { display: none; }

/* ── Haupt-Split-Bereich ── */
#mn-main {
    position: fixed;
    top: calc(var(--mn-navbar-h) + var(--mn-toolbar-h));
    left: 0; right: 0; bottom: 0;
    display: flex;
}

/* ══════════════════════════════════════════════════════
   Toolbar-Elemente (identisch zu geo-notes)
══════════════════════════════════════════════════════ */
.mn-logo {
    font-size: 15px; font-weight: 700;
    color: #fff; letter-spacing: -.3px; flex-shrink: 0;
}
.mn-logo em { color: #85c1e9; font-style: normal; }

.mn-vr {
    width: 1px; height: 20px;
    background: rgba(255,255,255,.25);
    flex-shrink: 0; margin: 0 2px;
}

.mn-mode-pill {
    display: flex;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 5px; overflow: hidden; flex-shrink: 0;
}
.mn-mode-pill button {
    padding: 0 8px; height: 28px;
    background: transparent; border: none;
    color: rgba(255,255,255,.7);
    font-family: 'Poppins', sans-serif; font-size: 9.5px;
    cursor: pointer;
    transition: background .12s, color .12s;
    white-space: nowrap;
}
.mn-mode-pill button.on {
    background: rgba(255,255,255,.2);
    color: #fff;
}
.mn-mode-pill button + button {
    border-left: 1px solid rgba(255,255,255,.2);
}

.mn-tb {
    display: flex; align-items: center; gap: 4px;
    height: 28px; padding: 0 9px;
    background: transparent;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 5px;
    color: rgba(255,255,255,.75);
    font-family: 'Poppins', sans-serif; font-size: 10px;
    cursor: pointer; flex-shrink: 0; white-space: nowrap;
    transition: color .12s, border-color .12s, background .12s;
}
.mn-tb:hover { color: #fff; border-color: rgba(255,255,255,.6); }
.mn-tb.on {
    background: rgba(255,255,255,.2);
    border-color: #85c1e9;
    color: #fff;
}

.mn-swatch {
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer; flex-shrink: 0;
    transition: transform .12s, border-color .12s;
}
.mn-swatch.on { border-color: #fff; transform: scale(1.25); }

.mn-slider {
    -webkit-appearance: none;
    width: 60px; height: 3px;
    background: rgba(255,255,255,.25);
    border-radius: 2px; outline: none; flex-shrink: 0;
}
.mn-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #85c1e9;
    cursor: pointer;
}

.mn-lbl {
    font-size: 9px;
    color: rgba(255,255,255,.65);
    flex-shrink: 0;
    font-family: 'Poppins', sans-serif;
}

.mn-select {
    height: 26px; padding: 0 4px;
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 4px;
    color: #fff;
    font-family: 'Poppins', sans-serif; font-size: 10px;
    cursor: pointer; flex-shrink: 0;
    outline: none;
}
.mn-select option { background: #1e3c72; color: #fff; }

.mn-spacer { flex: 1; min-width: 4px; }

/* PDF-Export-Button */
.mn-export-btn {
    display: flex; align-items: center; gap: 5px;
    height: 28px; padding: 0 12px;
    background: rgba(255, 255, 255, .15);
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 5px; color: #fff;
    font-family: 'Poppins', sans-serif; font-size: 10px; font-weight: 600;
    cursor: pointer; flex-shrink: 0;
    transition: background .12s;
}
.mn-export-btn:hover { background: rgba(255, 255, 255, .25); }
.mn-export-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ══════════════════════════════════════════════════════
   Trennbalken
══════════════════════════════════════════════════════ */
#mn-handle {
    flex: 0 0 var(--mn-handle-w);
    width: var(--mn-handle-w);
    background: #f0f2f5;
    cursor: col-resize;
    position: relative;
    display: flex; align-items: center; justify-content: center;
    z-index: 10;
    user-select: none;
    border-left: 1px solid #dde2ea;
    border-right: 1px solid #dde2ea;
    transition: background .15s;
}
#mn-handle::after {
    content: '';
    width: 3px; height: 40px;
    border-radius: 2px;
    background: #b0b8c8;
    transition: background .15s, height .15s;
}
#mn-handle:hover { background: #e8ecf2; }
#mn-handle:hover::after { background: #3498db; height: 52px; }
#mn-handle.dragging::after { background: #1e3c72; height: 60px; }

/* ══════════════════════════════════════════════════════
   Notiz-Panel (identisch zu geo-notes)
══════════════════════════════════════════════════════ */
#notes-wrap {
    flex: 1 1 0;
    min-width: 120px;
    position: relative; overflow: hidden;
    background-color: #fafcff;
    background-image:
        linear-gradient(to right,  rgba(52,152,219,.18) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(52,152,219,.18) 1px, transparent 1px),
        linear-gradient(to right,  rgba(52,152,219,.06) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(52,152,219,.06) 1px, transparent 1px);
    background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
}

#draw-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    touch-action: none;
    cursor: crosshair;
}

#text-layer {
    position: absolute; inset: 0;
    z-index: 20;
    pointer-events: none;
}
#text-layer.active {
    pointer-events: auto;
    cursor: text;
}

.mn-textbox {
    position: absolute;
    min-width: 60px;
    padding: 2px 5px;
    border: 1px dashed transparent;
    border-radius: 2px;
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Poppins', sans-serif;
    line-height: 1.4;
    cursor: text;
    box-sizing: border-box;
    transition: border-color .15s;
}
#text-layer.active .mn-textbox { border-color: rgba(52,152,219,.2); }
.mn-textbox:focus {
    border-color: rgba(52,152,219,.75);
    background: rgba(255,255,255,.35);
}

/* ══════════════════════════════════════════════════════
   Rechner-Panel
══════════════════════════════════════════════════════ */
#calc-wrap {
    flex: 0 0 auto;
    width: 50%;
    min-width: 280px;
    background: var(--calc-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* ── Display ── */
#calc-display {
    flex: 0 0 auto;
    background: var(--calc-disp);
    padding: 10px 14px 8px;
    border-bottom: 2px solid #1e3c72;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#display-indicators {
    display: flex;
    gap: 6px;
    align-items: center;
    min-height: 16px;
}

#display-indicators span {
    font-family: 'Poppins', sans-serif;
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(52,152,219,.15);
    color: var(--calc-acc2);
    letter-spacing: .5px;
}

#ind-shift { background: rgba(255,200,0,.15) !important; color: #ffd700 !important; }
#ind-mem   { background: rgba(52,200,100,.15) !important; color: #5de08a !important; }
#ind-error { background: rgba(231,79,81,.2) !important; color: #e74c3c !important; }

#display-input-row {
    min-height: 22px;
    display: flex;
    align-items: center;
}

#display-input {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: rgba(184,212,240,.7);
    white-space: pre;
    overflow-x: auto;
    letter-spacing: .5px;
    flex: 1;
}
#display-input::-webkit-scrollbar { display: none; }

#display-preview {
    min-height: 36px;
    display: flex;
    align-items: center;
    color: var(--calc-text);
    font-size: 15px;
    overflow-x: auto;
    padding: 2px 0;
}
#display-preview::-webkit-scrollbar { display: none; }
#display-preview .MathJax { max-width: none !important; }

#display-result-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    border-top: 1px solid rgba(52,152,219,.2);
    padding-top: 6px;
}

#display-result {
    flex: 1;
    font-size: 20px;
    font-weight: 600;
    color: var(--calc-acc2);
    overflow-x: auto;
    white-space: nowrap;
}
#display-result::-webkit-scrollbar { display: none; }
#display-result .MathJax { max-width: none !important; }

#sd-btn {
    flex-shrink: 0;
    padding: 2px 7px;
    background: rgba(52,152,219,.15);
    border: 1px solid rgba(52,152,219,.4);
    border-radius: 4px;
    color: var(--calc-acc2);
    font-family: 'Poppins', sans-serif;
    font-size: 9px;
    cursor: pointer;
    transition: background .12s;
}
#sd-btn:hover { background: rgba(52,152,219,.3); }

/* ── Verlauf-Panel ── */
#calc-history {
    position: absolute;
    top: 0; left: 0; right: 0;
    background: rgba(12,18,35,.97);
    border-bottom: 2px solid var(--calc-acc);
    z-index: 50;
    max-height: 70%;
    overflow-y: auto;
}

#calc-history-inner {
    padding: 10px 14px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-family: 'Poppins', sans-serif;
    font-size: 10px;
    color: var(--calc-acc2);
    letter-spacing: .5px;
}

#history-clear-btn {
    background: rgba(231,79,81,.15);
    border: 1px solid rgba(231,79,81,.3);
    color: #e74c3c;
    font-family: 'Poppins', sans-serif;
    font-size: 9px;
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
}

.history-item {
    padding: 6px 8px;
    border-radius: 5px;
    cursor: pointer;
    transition: background .12s;
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.history-item:hover { background: rgba(52,152,219,.12); }
.history-item:last-child { border-bottom: none; }

.history-expr {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: rgba(184,212,240,.55);
}
.history-result {
    font-size: 14px;
    color: var(--calc-acc2);
    margin-top: 2px;
}
.history-result .MathJax { font-size: inherit !important; }

/* ── Tastatur ── */
#calc-keypad {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    padding: 10px;
    overflow-y: auto;
    align-content: start;
}

/* ── Tasten allgemein ── */
.key {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: none;
    border-radius: 7px;
    background: #1e2d4a;
    color: var(--calc-text);
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    transition: background .1s, transform .08s;
    padding: 4px 2px 2px;
    line-height: 1.2;
    box-shadow: 0 2px 4px rgba(0,0,0,.25);
}
.key:hover  { background: #263654; }
.key:active { transform: scale(.93); background: #2d3f60; }

/* Shift-Sekundärbeschriftung */
.key-shift-lbl {
    font-size: 7.5px;
    color: #f4d03f;
    font-weight: 600;
    letter-spacing: .3px;
    position: absolute;
    top: 3px; left: 4px;
    line-height: 1;
    pointer-events: none;
}

/* Zahlen-Tasten etwas heller */
.key-num { background: #243453; color: #d4e6f8; }
.key-num:hover { background: #2c3f63; }

/* Operator-Tasten */
.key-op { background: #1a3050; color: var(--calc-acc2); font-size: 14px; }
.key-op:hover { background: #204068; }

/* Funktion-Tasten */
.key-func { background: #1d2b44; color: #a8c8e8; font-size: 11px; }
.key-func:hover { background: #24344f; }

/* Speicher-Tasten */
.key-mem { background: #162538; color: #7fc3a8; font-size: 11px; }
.key-mem:hover { background: #1c3048; }

/* SHIFT-Taste */
.key-shift { background: #1e3a5a; color: #f4d03f; font-weight: 700; font-size: 11px; }
.key-shift:hover { background: #264870; }
.key-shift.active { background: #f4d03f; color: #1a1a2e; box-shadow: 0 0 8px rgba(244,208,63,.4); }

/* STAT-Taste */
.key-stat { background: #1e3a5a; color: #85c1e9; font-size: 11px; }
.key-stat:hover { background: #264870; }
.key-stat.active { background: rgba(52,152,219,.3); border: 1px solid var(--calc-acc); }

/* DEL / AC */
.key-del { background: #2c2820; color: #e0a070; font-size: 14px; }
.key-del:hover { background: #3a3020; }
.key-ac  { background: #3a1f20; color: #e74c3c; font-weight: 700; font-size: 11px; }
.key-ac:hover { background: #4a2828; }

/* S↔D */
.key-sd { background: #1e3a5a; color: #85c1e9; font-size: 10px; }
.key-sd:hover { background: #264870; }

/* Dezimalpunkt */
.key-dot { background: #243453; color: #d4e6f8; font-size: 16px; font-weight: 700; }

/* = Taste */
.key-equals {
    grid-column: span 2;
    background: linear-gradient(135deg, #1e6fb5, #2980b9);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    box-shadow: 0 3px 8px rgba(41,128,185,.35);
}
.key-equals:hover { background: linear-gradient(135deg, #2176bb, #3498db); }
.key-equals:active { transform: scale(.93); }

/* 0 Taste (doppelt breit) */
.key-zero { grid-column: span 2; font-size: 14px; }

/* ══════════════════════════════════════════════════════
   Overlay-Panels (Speicher / Statistik)
══════════════════════════════════════════════════════ */
#mem-panel,
#stat-panel {
    position: absolute;
    inset: 0;
    background: rgba(12,18,35,.98);
    z-index: 60;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(52,152,219,.2);
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: var(--calc-acc2);
    letter-spacing: .5px;
    flex-shrink: 0;
}

.panel-close {
    background: rgba(231,79,81,.12);
    border: 1px solid rgba(231,79,81,.3);
    color: #e74c3c;
    font-size: 12px;
    width: 24px; height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* ── Speicher-Register ── */
#mem-registers {
    padding: 12px 16px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.mem-reg {
    background: rgba(30,60,90,.4);
    border: 1px solid rgba(52,152,219,.2);
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background .12s;
}
.mem-reg:hover { background: rgba(52,152,219,.15); }
.mem-reg.target-highlight { border-color: #f4d03f; background: rgba(244,208,63,.1); }

.mem-reg-name {
    font-family: 'Poppins', sans-serif;
    font-size: 10px;
    font-weight: 700;
    color: var(--calc-acc2);
    margin-bottom: 3px;
}
.mem-reg-val {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--calc-text);
    word-break: break-all;
}

/* ── Statistik ── */
#stat-inner {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stat-section-title {
    font-family: 'Poppins', sans-serif;
    font-size: 10px;
    font-weight: 600;
    color: var(--calc-acc2);
    margin-bottom: 6px;
    letter-spacing: .4px;
}

.stat-section textarea {
    width: 100%;
    background: rgba(30,60,90,.4);
    border: 1px solid rgba(52,152,219,.25);
    border-radius: 6px;
    color: var(--calc-text);
    font-family: 'Courier New', monospace;
    font-size: 12px;
    padding: 8px;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
}
.stat-section textarea:focus { border-color: var(--calc-acc); }

.stat-section button {
    margin-top: 6px;
    padding: 5px 14px;
    background: rgba(52,152,219,.2);
    border: 1px solid var(--calc-acc);
    border-radius: 5px;
    color: var(--calc-acc2);
    font-family: 'Poppins', sans-serif;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: background .12s;
}
.stat-section button:hover { background: rgba(52,152,219,.35); }

.stat-result-table {
    margin-top: 8px;
    font-family: 'Poppins', sans-serif;
    font-size: 11px;
    width: 100%;
    border-collapse: collapse;
}
.stat-result-table td {
    padding: 3px 6px;
    border-bottom: 1px solid rgba(255,255,255,.05);
}
.stat-result-table td:first-child { color: rgba(184,212,240,.6); }
.stat-result-table td:last-child  { color: var(--calc-acc2); font-weight: 600; text-align: right; }

.stat-error {
    margin-top: 6px;
    font-family: 'Poppins', sans-serif;
    font-size: 11px;
    color: #e74c3c;
}

/* ── Cursor-Blinken ── */
@keyframes calcBlink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}
.calc-cursor {
    color: var(--calc-acc2);
    animation: calcBlink 1s step-end infinite;
    font-weight: 400;
}

/* ── MathJax-Farben im dunklen Display ── */
#calc-display mjx-container,
#calc-display mjx-container * { color: inherit !important; }
#display-preview  { color: var(--calc-text); }
#display-result   { color: var(--calc-acc2); }
#display-preview mjx-container  { color: var(--calc-text) !important; }
#display-result  mjx-container  { color: var(--calc-acc2) !important; }

/* Verlauf-Ergebnis MathJax */
.history-result mjx-container { color: var(--calc-acc2) !important; font-size: 14px !important; }

/* ══════════════════════════════════════════════════════
   Toast
══════════════════════════════════════════════════════ */
#mn-toast {
    position: fixed;
    bottom: 18px; left: 50%; transform: translateX(-50%);
    background: #1e3c72;
    border: 1px solid #2980b9;
    color: #fff;
    font-size: 12px; font-family: 'Poppins', sans-serif;
    padding: 8px 16px; border-radius: 6px;
    opacity: 0; transition: opacity .25s;
    pointer-events: none; z-index: 400; white-space: nowrap;
}
#mn-toast.show { opacity: 1; }

/* ══════════════════════════════════════════════════════
   Responsive – Mobil: vertikal stapeln
══════════════════════════════════════════════════════ */
@media (max-width: 680px) {
    :root {
        --mn-navbar-h: 70px;
        --mn-toolbar-h: 44px;
    }

    #mn-main { flex-direction: column; }

    #calc-wrap {
        flex: 0 0 calc(50% - var(--mn-handle-w) / 2);
        width: 100% !important;
        min-width: 0;
    }

    #mn-handle {
        flex: 0 0 var(--mn-handle-w);
        width: 100%;
        cursor: row-resize;
    }
    #mn-handle::after { width: 40px; height: 3px; }

    .mn-mode-pill { display: none; }
    .mn-lbl { display: none; }
    .mn-slider { width: 44px; }

    #calc-display { min-height: 120px; }
    .key { min-height: 36px; font-size: 11px; }
    #calc-keypad { gap: 4px; padding: 7px; }
}
