:root {
    --bg: #09090b;
    --panel: #111114;
    --panel-alt: #18181b;
    --border: #27272a;
    --border-strong: #3f3f46;
    --text: #fafafa;
    --text-muted: #a1a1aa;
    --text-dim: #71717a;
    --canvas: #fcfcfd;
    --grid: rgba(255, 255, 255, 0.04);
    --accent: #2563eb;
    --success: #22c55e;
}

[data-theme="light"] {
    --bg: #f6f6f7;
    --panel: #ffffff;
    --panel-alt: #f4f4f5;
    --border: #e4e4e7;
    --border-strong: #d4d4d8;
    --text: #09090b;
    --text-muted: #52525b;
    --text-dim: #71717a;
    --canvas: #ffffff;
    --grid: rgba(0, 0, 0, 0.05);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    width: 100%;
    height: 100%;
}

body {
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 28px 28px;
}

button {
    font: inherit;
}

.floating-toolbar {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    color: var(--text);
    padding: 9px 13px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
    backdrop-filter: blur(12px);
}

.tool-btn:hover {
    background: var(--panel-alt);
}

.html-studio {
    position: relative;
    z-index: 1;
    height: 100vh;
    padding: 14px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.mobile-view-tabs {
    display: none;
    gap: 8px;
    margin-bottom: 12px;
}

.mobile-view-tabs button,
.editor-tabs button {
    border: 1px solid var(--border-strong);
    background: var(--panel);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 12px;
    cursor: pointer;
}

.mobile-view-tabs button.is-active,
.editor-tabs button.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.studio-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(320px, 0.95fr) minmax(320px, 1.05fr);
    gap: 16px;
    padding-top: 42px;
}

.pane {
    min-height: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.pane-kicker {
    margin: 0 0 4px;
    color: var(--text-dim);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.pane-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -0.03em;
}

.editor-tabs {
    display: inline-flex;
    gap: 8px;
}

.editor-stack {
    flex: 1;
    min-height: 0;
    position: relative;
}

.editor-pane-item {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    min-height: 0;
}

.editor-pane-item.is-active {
    display: flex;
}

.editor-shell {
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    background: var(--panel-alt);
}

.editor-host,
.editor-shell .CodeMirror {
    height: 100% !important;
    font-size: 13px;
}

.preview-shell {
    position: relative;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    background: var(--canvas);
}

.preview-page-title {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    max-width: min(70%, 320px);
    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: rgba(15, 23, 42, 0.82);
    color: #f8fafc;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.01em;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
}

.preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

.preview-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.preview-status i {
    font-size: 8px;
}

.preview-status.success {
    color: var(--success);
}

.preview-status.idle {
    color: var(--text-dim);
}

.editor-note {
    margin: 0;
    font-size: 12px;
    color: var(--text-dim);
}

.editor-note--mobile {
    display: none;
}

@media (max-width: 960px) {
    body {
        overflow: auto;
    }

    .editor-note--desktop {
        display: none;
    }

    .editor-note--mobile {
        display: block;
    }

    .html-studio {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .floating-toolbar {
        top: 10px;
        right: 10px;
        max-width: calc(100vw - 20px);
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .tool-btn span {
        display: none;
    }

    .mobile-view-tabs {
        display: flex;
    }

    .studio-layout {
        grid-template-columns: 1fr;
        padding-top: 56px;
        min-height: calc(100vh - 90px);
    }

    .studio-layout[data-mobile-view="preview"] .editor-column {
        display: none;
    }

    .studio-layout[data-mobile-view="code"] .preview-column {
        display: none;
    }

    .studio-layout[data-mobile-view="split"] {
        display: flex;
        flex-direction: column;
    }

    .studio-layout[data-mobile-view="split"] .editor-column {
        flex: 0 0 auto;
        min-height: min(52vh, 520px);
    }

    .studio-layout[data-mobile-view="split"] .preview-column {
        flex: 1 1 auto;
        min-height: min(48vh, 480px);
    }

    .studio-layout[data-mobile-view="code"] .editor-column,
    .studio-layout[data-mobile-view="preview"] .preview-column {
        min-height: min(72vh, 720px);
    }
}

@media (max-width: 640px) {
    .html-studio {
        padding: 10px;
    }

    .pane {
        padding: 12px;
        border-radius: 16px;
    }

    .pane-header h2 {
        font-size: 18px;
    }

    .studio-layout[data-mobile-view="split"] .editor-column {
        min-height: min(46vh, 440px);
    }

    .studio-layout[data-mobile-view="split"] .preview-column {
        min-height: min(42vh, 400px);
    }

    .studio-layout[data-mobile-view="code"] .editor-column,
    .studio-layout[data-mobile-view="preview"] .preview-column {
        min-height: 65vh;
    }
}
