@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Fira+Code:wght@400;500;600&display=swap');

:root {
    --red: #dc1414;
    --red-dark: #b01010;
    --blue: #1e64a0;
    --blue-dark: #154a78;
    --yellow: #fac832;
    --dark: #0f172a;
    --dark-light: #1e293b;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-600: #475569;
    --gray-800: #1e293b;
    --white: #ffffff;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--dark);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--gray-200);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--dark);
}

.nav-logo { height: 40px; width: auto; }

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.02em; }
.brand-version { font-size: 0.75rem; color: var(--gray-400); font-weight: 600; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-links a {
    text-decoration: none;
    color: var(--gray-600);
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.nav-links a:hover, .nav-links a.active { color: var(--red); }

.github-link {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--dark);
}

@media (max-width: 768px) {
    .mobile-toggle { display: block; }
    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--white);
        flex-direction: column;
        padding: 1rem;
        border-bottom: 1px solid var(--gray-200);
        gap: 1rem;
    }
    .nav-links.active { display: flex; }
}

/* Editor main */
.editor-main {
    flex: 1;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 7rem 1.5rem 3rem;
}

.editor-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.section-tag {
    display: inline-block;
    background: rgba(220, 20, 20, 0.1);
    color: var(--red);
    padding: 0.35rem 0.9rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.editor-header h1 {
    font-size: 2.25rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.editor-header p {
    color: var(--gray-600);
    max-width: 600px;
    margin: 0 auto;
}

.editor-header code {
    background: var(--gray-200);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    color: var(--red);
}

/* Layout */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 520px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 1200px) {
    .editor-layout { grid-template-columns: 1fr; }
}

/* Workspace */
.editor-workspace {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-200);
    gap: 1rem;
    flex-wrap: wrap;
}

.editor-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.red { background: #ff5f56; }
.dot.yellow { background: #ffbd2e; }
.dot.green { background: #27c93f; }

.filename {
    margin-left: 0.5rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--gray-600);
    font-weight: 500;
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-sm { padding: 0.45rem 0.85rem; font-size: 0.8rem; }
.btn-primary { background: var(--red); color: white; }
.btn-primary:hover { background: var(--red-dark); }
.btn-secondary { background: var(--blue); color: white; }
.btn-secondary:hover { background: var(--blue-dark); }
.btn-run { background: var(--red); color: white; font-weight: 800; }
.btn-run:hover { background: var(--red-dark); }
.btn-run.running { opacity: 0.7; cursor: wait; }
.btn-ghost { background: transparent; color: var(--gray-600); border: 1px solid var(--gray-200); }
.btn-ghost:hover { background: var(--gray-100); color: var(--dark); }

/* Panes */
.editor-panes {
    position: relative;
    height: 600px;
    min-height: 50vh;
    background: #2d2d2d;
}

.editor-pane {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 1.25rem;
    font-family: 'Fira Code', 'SF Mono', Consolas, monospace;
    font-size: 1rem;
    line-height: 1.7;
    border: none;
    outline: none;
    white-space: pre;
    overflow: auto;
    tab-size: 4;
    -moz-tab-size: 4;
}

#code-editor {
    z-index: 2;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    resize: none;
    caret-color: #fff;
}

#code-editor::placeholder { color: rgba(255, 255, 255, 0.35); }

#code-preview {
    z-index: 1;
    background: #2d2d2d;
    pointer-events: none;
    border-radius: 0;
}

#code-preview.hidden { display: none; }

#code-preview code,
#code-preview pre {
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    text-shadow: none;
}

/* Status */
.editor-status {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    padding: 0.65rem 1rem;
    background: var(--gray-100);
    border-top: 1px solid var(--gray-200);
    font-size: 0.85rem;
    color: var(--gray-600);
}

.editor-status strong { color: var(--dark); }

/* Output box */
.output-box {
    background: #1e1e1e;
    color: #e2e8f0;
    border-top: 1px solid #334155;
    display: flex;
    flex-direction: column;
    max-height: 260px;
    min-height: 140px;
}

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1rem;
    background: #252525;
    border-bottom: 1px solid #334155;
    font-weight: 600;
    font-size: 0.85rem;
}

.output-header button {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
}

.output-tip {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: #94a3b8;
    background: #252525;
    border-bottom: 1px solid #334155;
}

.output-tip code {
    background: #334155;
    color: #fff;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
}

#output-content {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    margin: 0;
}

#output-content.error { color: #ff8585; }
#output-content.empty { color: #64748b; font-style: italic; }

/* Template bar */
.template-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    font-size: 0.9rem;
}

.chip {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 9999px;
    padding: 0.3rem 0.8rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-700);
}

.chip:hover {
    background: rgba(220, 20, 20, 0.08);
    border-color: var(--red);
    color: var(--red);
}

/* Reference panel */
.reference-panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 1.25rem;
    max-height: calc(100vh - 8rem);
    overflow-y: auto;
    position: sticky;
    top: 5rem;
}

.reference-panel h2 {
    font-size: 1.3rem;
    margin-bottom: 0.4rem;
}

.reference-intro {
    font-size: 0.9rem;
    color: var(--gray-600);
    margin-bottom: 1.25rem;
}

.reference-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ref-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 1rem;
    background: var(--gray-50);
}

.ref-card h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--dark);
}

.ref-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.ref-block {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.ref-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-400);
}

.ref-block pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: 'Fira Code', monospace;
    font-size: 0.78rem;
    line-height: 1.55;
    margin: 0;
}

.ref-block pre code {
    background: transparent;
    padding: 0;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
}

.ref-mith { border-left: 4px solid var(--blue); }

/* Footer */
.footer {
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 1.5rem;
    margin-top: auto;
}

.footer-bottom {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
    color: var(--gray-600);
    font-size: 0.9rem;
}

.footer-bottom a {
    color: var(--red);
    text-decoration: none;
}

@media (max-width: 768px) {
    .editor-panes { height: 400px; }
    .ref-row { grid-template-columns: 1fr; }
    .editor-actions { width: 100%; justify-content: flex-end; }
}
