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

:root {
    --bg: #f0f2f5;
    --header-bg: #1e293b;
    --header-text: #f1f5f9;
    --editor-bg: #1e1e2e;
    --editor-text: #cdd6f4;
    --preview-bg: #ffffff;
    --border: #e2e8f0;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --pane-header-bg: #f8fafc;
    --pane-header-text: #64748b;
    --error: #ef4444;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: #1e293b;
}

body {
    display: flex;
    flex-direction: column;
}

/* Header */

header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1.25rem;
    height: 56px;
    background: var(--header-bg);
    color: var(--header-text);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
}

header h1 {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.subtitle {
    font-size: 0.8rem;
    opacity: 0.5;
    white-space: nowrap;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.toolbar select,
.toolbar button {
    padding: 0.35rem 0.75rem;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.08);
    color: var(--header-text);
    font-size: 0.8rem;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.15s;
}

.toolbar select:hover,
.toolbar button:hover {
    background: rgba(255,255,255,0.18);
}

.toolbar select option {
    background: var(--header-bg);
    color: var(--header-text);
}

/* Main layout */

main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.editor-pane {
    display: flex;
    flex-direction: column;
    width: 40%;
    min-width: 300px;
    border-right: 1px solid var(--border);
    background: var(--editor-bg);
}

.divider {
    width: 4px;
    background: var(--border);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.15s;
}

.divider:hover,
.divider.dragging {
    background: var(--primary);
}

.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--preview-bg);
    min-width: 300px;
    position: relative;
}

/* Pane headers */

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.editor-pane .pane-header {
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.4);
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
}

.toggle-label input[type="checkbox"] {
    accent-color: var(--primary);
}

/* Floating toolbar (shared) */

.floating-toolbar {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    z-index: 10;
}

.ft-top {
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
}

.ft-bottom {
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
}

.floating-toolbar button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #475569;
    cursor: pointer;
    padding: 0;
    transition: all 0.1s;
}

.floating-toolbar button:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.floating-toolbar button.active {
    background: #eff6ff;
    color: var(--primary);
}

.tb-label {
    font-size: 0.7rem;
    color: #64748b;
    min-width: 2.5rem;
    text-align: center;
    user-select: none;
}

.tb-sep {
    width: 1px;
    height: 20px;
    background: #e2e8f0;
    margin: 0 2px;
    flex-shrink: 0;
}

/* Toolbar dropdowns */

.tb-dropdown {
    position: relative;
}

.tb-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 2px;
}

.tb-dropdown-trigger .chevron {
    opacity: 0.4;
}

.tb-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    min-width: 160px;
    padding: 4px;
    z-index: 20;
}

.tb-dropdown-menu.open {
    display: block;
}

.tb-menu-title {
    padding: 6px 10px 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
}

.tb-dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 10px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: #334155;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: left;
    height: auto;
    justify-content: flex-start;
}

.tb-dropdown-menu button:hover {
    background: #f1f5f9;
}

.tb-dropdown-menu button.active {
    background: #eff6ff;
    color: var(--primary);
    font-weight: 500;
}

/* Editor textarea */

#editor {
    flex: 1;
    padding: 1rem;
    background: var(--editor-bg);
    color: var(--editor-text);
    border: none;
    outline: none;
    resize: none;
    font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
    font-size: 0.9rem;
    line-height: 1.65;
    tab-size: 4;
}

#editor::placeholder {
    color: rgba(255,255,255,0.2);
}

/* Processed code panel */

#processed-wrapper {
    border-top: 1px solid rgba(255,255,255,0.08);
    max-height: 35%;
    display: flex;
    flex-direction: column;
}

#processed-wrapper.hidden {
    display: none;
}

#processed-code {
    flex: 1;
    padding: 0.75rem 1rem;
    margin: 0;
    background: rgba(0,0,0,0.2);
    color: rgba(255,255,255,0.55);
    font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Preview area */

#preview {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

#preview.panning {
    cursor: grabbing;
    user-select: none;
}

#preview svg {
    position: absolute;
    top: 0;
    left: 0;
}

#preview .placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #94a3b8;
    font-size: 0.95rem;
    text-align: center;
}

#preview .error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--error);
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    font-size: 0.85rem;
    line-height: 1.5;
    max-width: 500px;
    white-space: pre-wrap;
    font-family: "Cascadia Code", "Fira Code", "Consolas", monospace;
}

/* Footer */

footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    background: var(--header-bg);
    color: rgba(255,255,255,0.35);
    font-size: 0.7rem;
    flex-shrink: 0;
}

footer a {
    color: rgba(255,255,255,0.5);
    text-decoration: none;
}

footer a:hover {
    color: rgba(255,255,255,0.8);
    text-decoration: underline;
}

/* Responsive */

@media (max-width: 768px) {
    header {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .toolbar {
        width: 100%;
        margin-left: 0;
    }

    main {
        flex-direction: column;
    }

    .editor-pane {
        width: 100%;
        min-width: 0;
        height: 50%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .divider {
        display: none;
    }

    .preview-pane {
        min-width: 0;
    }
}
