
html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #f6f7fb;
    color: #111827;
}

* { box-sizing: border-box; }

.app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    height: 52px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    background: #ffffff;
    color: #0f172a;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 2px 14px rgba(15, 23, 42, 0.06);
    z-index: 60;
    position: relative;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.header-left { flex: 1; }
.header-right {
    flex: 0 0 auto;
    justify-content: flex-end;
}

.brand-name {
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.2px;
}

.badge {
    padding: 8px 12px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #dbe3ef;
    font-size: 13px;
    font-weight: 700;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.badge span:first-child {
    font-size: 14px;
}

.badge #views {
    font-size: 14px;
    font-weight: 700;
}

.top-action {
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #0f172a;
    padding: 8px 13px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    white-space: nowrap;
}

.top-action:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.top-action:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.12);
}

.top-action .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.top-action .btn-icon svg {
    display: block;
}

#save {
    color: #fff;
    background: linear-gradient(180deg, #7c3aed 0%, #7043ec 100%);
    border-color: #7043ec;
}

#save:hover {
    background: linear-gradient(180deg, #8b5cf6 0%, #7043ec 100%);
    border-color: #6d28d9;
    filter: brightness(1.02);
}

#download {
    background: #ffffff;
}

.content {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: 360px;
    flex: 0 0 auto;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    overflow: hidden;
    position: relative;
    transition: width 0.25s ease, transform 0.25s ease;
    box-shadow: 10px 12px 32px rgba(15, 23, 42, 0.12);
    z-index: 50;
}

.sidebar-inner {
    width: 360px;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    box-shadow: 10px 0 30px rgba(15, 23, 42, 0.16);
    transform: translateX(0);
    opacity: 1;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.sidebar.collapsed {
    width: 0;
}

.sidebar.collapsed .sidebar-inner {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.sidebar-body {
    padding: 12px;
    overflow: auto;
    min-height: 0;
    flex: 1 1 auto;
}

.sidebar-tip {
    margin-top: 10px;
    padding: 10px 12px;
    font-size: 13px;
    color: #64748b;
    line-height: 1.4;
    user-select: none;
}

.side-btn {
    border: 1px solid #cbd5e1;
    background: linear-gradient(180deg, #ffffff 0%, #eef2f7 100%);
    color: #0f172a;
    padding: 9px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.side-btn:hover {
    transform: translateY(-1px);
}

.side-btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.12);
}

#add {
    background: linear-gradient(180deg, #7c3aed 0%, #7043ec 100%);
    border-color: #7043ec;
    color: #fff;
}

#add:hover {
    background: linear-gradient(180deg, #8b5cf6 0%, #7043ec 100%);
    border-color: #6d28d9;
    filter: brightness(1.02);
}

.section {
    margin-bottom: 14px;
}

.section h4 {
    margin: 0 0 8px;
    font-size: 14px;
    color: #334155;
}

.controls {
    margin-bottom: 12px;
}

.plot-area {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
    background: #eef4fb;
    transition: flex-basis 0.25s ease, width 0.25s ease, margin 0.25s ease;
}

.plot-shell {
    width: 100%;
    height: 100%;
    padding: 0;
}

.plot-card {
    width: 100%;
    height: 100%;
    background: #f8fafc;
    border: 1px solid #dbe6f3;
    overflow: hidden;
    position: relative;
    box-shadow: 0 8px 24px rgba(15,23,42,0.05);
}

#plot {
    width: 100%;
    height: 100%;
}

#probeStage {
    position: absolute;
    left: -99999px;
    top: 0;
    width: 900px;
    height: 450px;
    visibility: hidden;
    overflow: hidden;
    pointer-events: none;
}

.expand-bar {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 70;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid #d1d5db;
    background: rgba(255,255,255,0.96);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 18px rgba(0,0,0,0.08);
    transition: transform 0.15s ease, background 0.15s ease;
    font-size: 18px;
    color: #173a63;
}

.expand-bar:hover {
    background: #fff;
    transform: scale(1.03);
}

.expr {
    display: grid;
    grid-template-columns: 30px 1fr 30px;
    align-items: center;
    padding: 3px;
    padding-left: 6px;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    margin-bottom: 8px;
    background: #fff;
    gap: 6px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.expr:hover {
    border-color: #c7d7f0;
    box-shadow: 0 2px 10px rgba(15,23,42,0.04);
}

.expr.disabled {
    opacity: 0.55;
}

.expr.error {
    border-color: #ef4444;
}

.expr:focus-within {
    border-color: #6ea8ff;
    box-shadow: 0 0 0 3px rgba(110,168,255,0.18);
}

.dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1.5px rgba(0,0,0,.12);
    flex: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
}

.dot:hover {
    transform: scale(1.06);
}

.del {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    color: #6b7280;
    border-radius: 8px;
    width: 26px;
    height: 26px;
}

.del:hover {
    background: rgba(107,114,128,0.08);
    color: #374151;
}

math-field {
    min-height: 48px;
    font-size: 20px;
    display: block;
    padding: 6px 8px;
    background: white;
    border: none;
    outline: none;
    width: 100%;
}

math-field:focus {
    outline: none;
}

.mf::part(menu-toggle) {
    display: none !important;
}

.plot-controls {
    position: absolute;
    right: 21px;
    bottom: 21px;
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.plot-controls button {
    width: 34px;
    height: 34px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.10);
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, filter 0.15s ease;
    color: #0f172a;
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
}

.plot-controls button:hover {
    transform: translateY(-1px);
    background: linear-gradient(180deg, #ffffff 0%, #dbe4ef 100%);
}

.plot-controls button:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: inset 0 2px 6px rgba(15, 23, 42, 0.18);
    filter: brightness(0.98);
}

.plot-controls button:focus-visible {
    outline: 3px solid rgba(22, 119, 255, 0.28);
    outline-offset: 2px;
}

#zin, #zout, #zreset {
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
}

#zin:hover, #zout:hover, #zreset:hover {
    background: linear-gradient(180deg, #ffffff 0%, #dbe4ef 100%);
}

.function-plot .axis .tick text { font-size: 12px !important; font-weight: 600; fill: #334155 !important; }
.function-plot .axis path.domain { stroke: #0f172a !important; stroke-width: 2px !important; }
.function-plot .origin { stroke: #02060f !important; stroke-width: 2px !important; }

.sidebar-backdrop {
    display: none;
}

@media (max-width: 900px) {
    .sidebar {
    width: 300px;
    }
    .sidebar-inner {
    width: 300px;
    }
}

.side-close {
    display: none;
    }

@media (max-width: 700px) {

    .sidebar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    }

    #add {
    flex: 1 1 auto;
    }

    .side-close {
    display: inline-flex;
    height: 35px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: #0f172a;
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    align-items: center;
    }

    .side-close:active {
    transform: scale(0.96);
    }

        
    .header {
    height: 56px;
    min-height: 56px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 8px;
    }

    .header-left {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    white-space: nowrap;
    }

    .header-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    white-space: nowrap;
    }

    .brand-logo {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    }

    .brand-logo img {
    width: 26px;
    height: 26px;
    display: block;
    }

    .brand-name {
    font-size: 15px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    }  
    
    .badge {
    padding: 6px 8px;
    font-size: 12px;
    gap: 4px;
    }

    .badge #views {
    font-size: 12px;
    }
    

    .top-action {
    padding: 6px 8px;
    font-size: 12px;
    min-height: 34px;
    }

    .content {
    position: relative;
    }

    .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    width: min(88vw, 320px);
    z-index: 80;
    box-shadow: 6px 0 24px rgba(0,0,0,0.14);
    transform: translateX(0);
    }

    .sidebar-inner {
    width: 100%;
    height: 100%;
    }

    .sidebar.collapsed {
    width: min(88vw, 320px);
    transform: translateX(-102%);
    pointer-events: none;
    }

    .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 70;
    }

    .sidebar:not(.collapsed) + .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
    }

    .plot-area {
    width: 100%;
    }
    .expand-bar {
    top: 12px;
    left: 12px;
    }

    math-field {
    min-height: 54px;
    font-size: 18px;
    padding: 8px 10px;
    }

    .expr {
    grid-template-columns: 34px 1fr 34px;
    }

    .sidebar-body {
    padding-bottom: 18px;
    }

    #download span,
    #save span:last-child {
    display: none;
    }

    #download i,
    #save .btn-icon svg {
    width: 16px;
    height: 16px;
    }

    
    .mf::part(virtual-keyboard-toggle) {
    display: none !important;
    }

}

