:root {
    /* Purple Haze Palette */
    --primary: #6C5CE7;
    --primary-hover: #5A4BDE;
    --secondary: #A29BFE;
    --accent: #FFEAA7;

    --bg-dark: #1A0E2E;
    --bg-panel: #241744;
    --bg-input: #31215C;

    --text-main: #FFFFFF;
    --text-muted: #B3ABC6;
    --border: #443274;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Base Components */
.layout {
    display: flex;
    height: 100vh;
    width: 100VW;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    outline: none;
}

.primary-btn {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 14px rgba(108, 92, 231, 0.4);
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.5);
}

.secondary-btn {
    background: rgba(162, 155, 254, 0.15);
    color: var(--secondary);
    border: 1px solid rgba(162, 155, 254, 0.3);
}

.secondary-btn:hover {
    background: rgba(162, 155, 254, 0.25);
    color: white;
}

/* Sidebar Editor */
.editor-sidebar {
    width: 380px;
    min-width: 380px;
    background: rgba(36, 23, 68, 0.8);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Form Styles */
.builder-form {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.builder-form::-webkit-scrollbar {
    width: 6px;
}

.builder-form::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.form-section {
    margin-bottom: 2rem;
}

.form-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--secondary);
    letter-spacing: 1px;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(162, 155, 254, 0.2);
    padding-bottom: 0.5rem;
}

.input-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.input-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.input-group .hint {
    font-size: 0.75rem;
    color: rgba(179, 171, 198, 0.6);
}

input[type="text"],
textarea,
select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: white;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    transition: var(--transition);
}

textarea {
    resize: vertical;
    min-height: 60px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 2px rgba(162, 155, 254, 0.2);
}

/* Checkboxes */
.checkbox-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Toggle Switches */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    cursor: pointer;
    user-select: none;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    border-radius: 50%;
    transition: var(--transition);
}

input:checked+.toggle-slider {
    background-color: var(--primary);
    border-color: var(--primary);
}

input:checked+.toggle-slider::before {
    transform: translateX(20px);
    background-color: white;
}

.toggle-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

input:checked~.toggle-label {
    color: white;
}

/* Main Workspace */
.workspace {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at top right, rgba(162, 155, 254, 0.05), transparent 40%);
}

.workspace-header {
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(26, 14, 46, 0.6);
    backdrop-filter: blur(10px);
}

.tabs {
    display: flex;
    gap: 0.5rem;
    background: var(--bg-input);
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    color: var(--text-muted);
    font-weight: 500;
    border-radius: calc(var(--radius-sm) - 2px);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
}

.tab-btn:hover {
    color: white;
}

.tab-btn.active {
    background: var(--bg-panel);
    color: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.actions {
    display: flex;
    gap: 1rem;
}

.workspace-content {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
}

.view-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    padding: 2rem;
}

.view-panel.active {
    opacity: 1;
    pointer-events: all;
}

/* Raw Markdown Editor */
#raw-markdown {
    width: 100%;
    height: 100%;
    background: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    resize: none;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

#raw-markdown:focus {
    outline: none;
    border-color: var(--primary);
}

/* Markdown Render Container (GitHub Style Base) */
.markdown-body {
    background: white;
    color: #24292f;
    border-radius: var(--radius-md);
    padding: 3rem;
    max-width: 880px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    line-height: 1.5;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.markdown-body h1,
.markdown-body h2 {
    border-bottom: 1px solid #d0d7de;
    padding-bottom: .3em;
    margin-bottom: 16px;
    margin-top: 24px;
}

.markdown-body h1 {
    font-size: 2em;
}

.markdown-body h2 {
    font-size: 1.5em;
}

.markdown-body h3 {
    font-size: 1.25em;
    margin-top: 24px;
    margin-bottom: 16px;
}

.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre,
.markdown-body details {
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body pre {
    background-color: #f6f8fa;
    border-radius: 6px;
    padding: 16px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
    font-size: 85%;
}

.markdown-body code {
    background-color: rgba(175, 184, 193, 0.2);
    border-radius: 6px;
    padding: .2em .4em;
    margin: 0;
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
    font-size: 85%;
}

.markdown-body pre code {
    background-color: transparent;
    padding: 0;
}

.markdown-body a {
    color: #0969da;
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 30px;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(108, 92, 231, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.toast.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}