:root {
    --bg: #f4efe7;
    --panel: #fffaf3;
    --text: #22201c;
    --muted: #6f665b;
    --accent: #8b5e34;
    --border: rgba(34, 32, 28, 0.12);
    --shadow: 0 18px 50px rgba(52, 39, 21, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    color: var(--text);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(139, 94, 52, 0.08), transparent 30%),
        linear-gradient(180deg, #fbf8f2 0%, var(--bg) 100%);
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 250, 243, 0.72);
    backdrop-filter: blur(10px);
}

.eyebrow {
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.2rem;
}

h1 {
    font-size: clamp(1.4rem, 2.5vw, 2.1rem);
    line-height: 1.1;
}

.help-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--accent);
    text-decoration: none;
    background: rgba(255, 255, 255, 0.7);
    font-weight: 600;
}

.topbar-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.container {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 1rem;
    padding: 1rem;
    min-height: 0;
}

.panel-left {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.panel-right {
    display: flex;
    min-height: 0;
}

.graph-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    min-height: 0;
}

.card,
.guide-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.card {
    padding: 1rem;
}

.guide-card {
    padding: 1.25rem;
}

h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--accent);
}

math-field {
    display: block;
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    font-size: 1.35rem;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

.input-section p,
.analysis-section p,
.hint,
#conic-properties {
    color: var(--muted);
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.analysis-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#conic-type {
    font-size: 1.05rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}

#conic-properties ul {
    list-style: none;
}

#conic-properties li {
    margin-bottom: 0.45rem;
}

.jxgbox {
    width: 100%;
    min-height: 520px;
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    background: linear-gradient(180deg, #ffffff 0%, #fcf8f1 100%);
}

.graph-controls {
    padding: 1rem;
}

.graph-controls h2 {
    margin-bottom: 0.85rem;
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.control-btn {
    appearance: none;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #fff, #f7efe4);
    color: var(--text);
    border-radius: 14px;
    padding: 0.85rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.control-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(139, 94, 52, 0.35);
    box-shadow: 0 10px 24px rgba(52, 39, 21, 0.08);
}

.control-btn-primary {
    grid-column: 1 / -1;
    background: linear-gradient(180deg, #8b5e34, #6f4928);
    color: #fff;
    border-color: rgba(0, 0, 0, 0.06);
}

.control-btn-primary:hover {
    border-color: rgba(0, 0, 0, 0.06);
    box-shadow: 0 12px 28px rgba(139, 94, 52, 0.24);
}

.graph-controls-small {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    justify-content: center;
}

.control-btn-small {
    appearance: none;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #fff, #f7efe4);
    color: var(--text);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn-small:hover {
    transform: translateY(-1px);
    border-color: rgba(139, 94, 52, 0.35);
    box-shadow: 0 8px 20px rgba(52, 39, 21, 0.08);
}

.control-btn-pdf {
    background: linear-gradient(180deg, #8b5e34, #6f4928);
    color: #fff;
    border-color: rgba(0, 0, 0, 0.06);
    width: auto;
    padding: 0 1rem;
    font-size: 0.9rem;
}

.control-btn-pdf:hover {
    border-color: rgba(0, 0, 0, 0.06);
    box-shadow: 0 10px 24px rgba(139, 94, 52, 0.24);
}

.guide {
    width: 100%;
    margin: 0;
    padding: 0;
}

.guide-grid {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    overflow-x: auto;
    padding: 1rem;
}

.guide-wide {
    grid-column: 1 / -1;
}

.guide-card h2 {
    margin-bottom: 0.85rem;
}

.guide-card p,
.guide-card li {
    color: var(--text);
    line-height: 1.6;
}

.guide-card ul {
    padding-left: 1.2rem;
    display: grid;
    gap: 0.5rem;
}

.equation-list {
    display: grid;
    gap: 0.5rem;
    color: var(--text);
}

.equation-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.65);
}

.equation-text {
    font-family: "Consolas", "Courier New", monospace;
    overflow-wrap: anywhere;
}

.equation-latex {
    font-size: 0.85rem;
    color: var(--muted);
    font-style: italic;
}

.copy-btn {
    align-self: flex-start;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #fff, #f7efe4);
    color: var(--accent);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.copy-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(139, 94, 52, 0.35);
    box-shadow: 0 8px 20px rgba(52, 39, 21, 0.08);
}

.guide-page .guide-card {
    background: linear-gradient(180deg, #fffaf3 0%, #f8f1e6 100%);
}

.custom-dropdown {
    position: relative;
    width: 100%;
    margin-top: 0.85rem;
    font-family: inherit;
}

.dropdown-header {
    padding: 0.85rem 1rem;
    background: linear-gradient(180deg, #fff, #f7efe4);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--text);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.dropdown-header:hover {
    transform: translateY(-1px);
    border-color: rgba(139, 94, 52, 0.35);
    box-shadow: 0 8px 20px rgba(52, 39, 21, 0.08);
}

.dropdown-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    backdrop-filter: blur(2px);
}

.sheet-handle {
    display: none;
}

.dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    margin-top: 0.5rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(52, 39, 21, 0.15);
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    flex-direction: column;
}

.custom-dropdown.open .dropdown-list {
    display: flex;
}

.dropdown-group-label {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
    background: rgba(139, 94, 52, 0.05);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    border-top: 1px solid var(--border);
}
.dropdown-list .dropdown-group-label:first-child {
    border-top: none;
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
}

.dropdown-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text);
    transition: background 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.dropdown-item:hover {
    background: rgba(139, 94, 52, 0.08);
}

.dropdown-item span.eq {
    font-family: monospace;
    color: var(--muted);
    font-size: 0.85em;
}


@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr;
    }

    .panel-left {
        order: 2;
    }

    .panel-right {
        order: 1;
    }

    .jxgbox {
        min-height: 420px;
    }

    .guide-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .container {
        padding: 0.75rem;
    }

    .card,
    .guide-card,
    .jxgbox {
        border-radius: 18px;
    }

    .jxgbox {
        min-height: 360px;
    }

    math-field {
        font-size: 1.2rem;
    }

    .control-grid {
        grid-template-columns: 1fr;
    }
    
    .custom-dropdown.open .dropdown-backdrop {
        display: block;
    }
    
    .dropdown-list {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        margin: 0;
        top: auto;
        border-radius: 20px 20px 0 0;
        max-height: 80vh;
        z-index: 100;
        
        display: flex !important;
        visibility: hidden;
        transform: translateY(100%);
        transition: transform 0.3s ease-out, visibility 0.3s;
    }
    
    .custom-dropdown.open .dropdown-list {
        visibility: visible;
        transform: translateY(0);
    }
    
    .dropdown-list .dropdown-group-label:first-child {
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
    }
    
    .sheet-handle {
        width: 40px;
        height: 5px;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 5px;
        margin: 12px auto;
        display: block;
    }
}

@media print {
    body {
        background: #fff;
    }

    .topbar,
    .panel-left,
    .graph-controls {
        display: none;
    }

    .container {
        display: block;
        padding: 0;
    }

    .panel-right {
        display: block;
    }

    .graph-stack {
        gap: 0;
    }

    .jxgbox {
        min-height: 0;
        box-shadow: none;
        border-color: #ddd;
        height: 90vh;
    }

    .card {
        box-shadow: none;
        border-color: #ddd;
    }
}
