.hi-latex-page {
    background: var(--color-bg-primary);
    min-height: 100vh;
    padding-top: 88px;
}

.hi-latex-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

.hi-latex-container--wide {
    max-width: 1400px;
}

.hi-latex-hero {
    padding: 28px 0 18px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border-primary);
}

.hi-latex-title {
    font-size: clamp(26px, 3.2vw, 40px);
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin: 0;
    color: var(--color-text-primary);
    font-weight: 800;
}

.hi-latex-subtitle {
    margin-top: 10px;
    margin-bottom: 0;
    max-width: 720px;
    color: var(--color-text-muted);
    font-size: 16px;
    line-height: 1.6;
}

.hi-latex-editor-section {
    padding: 20px 0 40px;
}

.hi-latex-helper {
    margin: 0 0 14px;
    color: var(--color-text-muted);
    font-size: 13px;
}

.hi-latex-shell {
    border: 1px solid var(--color-border-primary);
    border-radius: 16px;
    background: var(--color-surface);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04),
        0 24px 80px rgba(0, 0, 0, 0.25),
        0 8px 32px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    position: relative;
    transition: box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    height: 82vh;
    min-height: 550px;
    display: flex;
    flex-direction: column;
}

.hi-latex-shell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--color-accent-cyan), var(--color-accent-purple), var(--color-accent-cyan));
    background-size: 200% 100%;
    animation: hilatex-gradient-shift 4s ease infinite;
    z-index: 10;
}

@keyframes hilatex-gradient-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.hi-latex-shell:hover {
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06),
        0 28px 90px rgba(0, 0, 0, 0.3),
        0 10px 36px rgba(0, 0, 0, 0.18),
        0 0 40px rgba(0, 210, 255, 0.04);
}

/* === HiLaTeX plugin UI (scoped overrides) — IDE Design === */
.hi-latex-page .hilatex-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    gap: 0;
    margin: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Toolbar ── */
.hi-latex-page .hilatex-actions {
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--color-border-primary);
    background: linear-gradient(180deg, var(--color-surface-elevated, var(--color-surface)) 0%, var(--color-surface) 100%);
    order: -1;
    position: relative;
}

.hi-latex-page .hilatex-actions::after {
    content: 'HiLaTeX Editor';
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    opacity: 0.5;
    pointer-events: none;
}

/* ── Toolbar Buttons ── */
.hi-latex-page .hilatex-actions button {
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.01em;
}

.hi-latex-page .hilatex-compile {
    background: linear-gradient(135deg, #0ea5e9, #06b6d4);
    color: #fff;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}

.hi-latex-page .hilatex-compile:hover {
    background: linear-gradient(135deg, #0284c7, #0891b2);
    box-shadow: 0 4px 16px rgba(14, 165, 233, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.hi-latex-page .hilatex-compile:active {
    transform: translateY(0);
}

.hi-latex-page .hilatex-download {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}

.hi-latex-page .hilatex-download:hover {
    background: linear-gradient(135deg, #059669, #047857);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.hi-latex-page .hilatex-download:active {
    transform: translateY(0);
}

.hi-latex-page .hilatex-clear {
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border-primary);
    box-shadow: none;
}

.hi-latex-page .hilatex-clear:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
    transform: translateY(-1px);
}

/* ── Editor Panel ── */
.hi-latex-page .hilatex-editor {
    height: 100%;
    min-height: 0;
    border: none;
    border-right: 1px solid var(--color-border-primary);
    grid-row: 2;
    grid-column: 1;
    position: relative;
    overflow: hidden;
}

/* ── Preview Panel ── */
.hi-latex-page .hilatex-preview-wrapper {
    background-color: #e8e8e8;
    padding: 16px;
    overflow-y: auto;
    overflow-x: auto;
    grid-row: 2;
    grid-column: 2;
    position: relative;
    min-height: 0;
    height: 100%;
}

.hi-latex-page .hilatex-preview-wrapper::before {
    content: 'PREVIEW';
    position: absolute;
    top: 10px;
    right: 16px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--color-text-muted);
    opacity: 0.35;
    pointer-events: none;
    z-index: 1;
}

/* ── Preview Paper — scale A4 to fit panel ── */
.hi-latex-page #hilatex-preview {
    color: #1a1a1a;
    position: relative;
    min-height: 100px;
    transform-origin: top left;
}

.hi-latex-page #hilatex-preview .ltx-page {
    border-radius: 3px;
    box-shadow:
        0 1px 4px rgba(0,0,0,0.1),
        0 4px 16px rgba(0,0,0,0.12);
    margin: 0 auto 20px;
}

.hi-latex-page #hilatex-preview .hilatex-rendered {
    color: #1a1a1a;
}

/* ── Compile Spinner ── */
.hilatex-compile-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto;
    border: 3px solid rgba(148, 163, 184, 0.2);
    border-top-color: #0ea5e9;
    border-radius: 50%;
    animation: hilatex-spin 0.8s linear infinite;
}

.hilatex-btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: hilatex-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes hilatex-spin {
    to { transform: rotate(360deg); }
}

.hi-latex-page .hilatex-compile:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

.hi-latex-missing {
    padding: 32px;
}

.hi-latex-missing h2 {
    margin: 0 0 8px;
    color: var(--color-text-primary);
    font-size: 18px;
}

.hi-latex-missing p {
    margin: 0;
    color: var(--color-text-muted);
}

@media (max-width: 980px) {
    .hi-latex-shell {
        height: auto;
        min-height: auto;
    }

    .hi-latex-page .hilatex-container {
        grid-template-columns: 1fr;
    }

    .hi-latex-page .hilatex-editor {
        border-right: none;
        border-bottom: 1px solid var(--color-border-secondary);
        min-height: 400px;
        height: 400px;
    }

    .hi-latex-page .hilatex-preview-wrapper {
        min-height: 500px;
        max-height: 80vh;
    }

    .hi-latex-page .hilatex-preview-wrapper::before {
        display: none;
    }

    /* .ltx-page dimensions handled by JS pagination + scalePreviewToFit */

    .hi-latex-page .hilatex-actions::after {
        display: none;
    }
}
