:root {
    --bg-app: #0d1117;
    --bg-header: #161b22;
    --bg-pane: #0d1117;
    --bg-editor: #1c2128;
    --bg-preview: #ffffff;

    --border-color: #30363d;
    --text-primary: #c9d1d9;
    --text-muted: #8b949e;

    /* Flexbox Theme (Blue) */
    --flex-primary: #3b82f6;
    --flex-bg: rgba(59, 130, 246, 0.05);

    /* Grid Theme (Purple) */
    --grid-primary: #a855f7;
    --grid-bg: rgba(168, 85, 247, 0.05);

    --font-ui: 'Inter', system-ui, sans-serif;
    --font-mono: 'Fira Code', 'JetBrains Mono', monospace;
}

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

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.app-header {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 70px;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    background: linear-gradient(90deg, var(--flex-primary), var(--grid-primary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.controls {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

select {
    background: var(--bg-editor);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

select:focus {
    border-color: var(--flex-primary);
}

.slider-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

input[type="range"] {
    appearance: none;
    -webkit-appearance: none;
    width: 150px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    cursor: grab;
}

input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
}

#viewport-val {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-primary);
    width: 50px;
}

/* Main Split Layout */
.split-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.pane {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.pane-flexbox {
    width: 50%;
    /* Initial width, JS updates this */
    background: var(--flex-bg);
}

.pane-grid {
    flex: 1;
    /* Takes remaining space */
    background: var(--grid-bg);
}

.resizer {
    width: 8px;
    background: var(--bg-header);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.2s;
}

.resizer:hover,
.resizer.dragging {
    background: var(--border-color);
}

.grip {
    width: 2px;
    height: 30px;
    background: var(--text-muted);
    border-radius: 2px;
}

/* Pane Headers */
.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    height: 60px;
    flex-shrink: 0;
}

.pane-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pane-title h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.flex-dot {
    background: var(--flex-primary);
}

.grid-dot {
    background: var(--grid-primary);
}

.ribbon {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    letter-spacing: 0.05em;
    opacity: 0;
    /* Hidden by default */
}

.ribbon.winner {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.4);
    opacity: 1;
}

.ribbon.winner::before {
    content: '🏆 Winner';
}

.ribbon.loser {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    opacity: 1;
}

.ribbon.loser::before {
    content: '⚠️ Overkill / Hacky';
}

.ribbon.tie {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.2);
    opacity: 1;
}

.ribbon.tie::before {
    content: '🤝 Tie (Both Good)';
}

/* Editors */
.editor-container {
    flex: 0 0 40%;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.editor-label,
.preview-label {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--border-color);
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-bottom-left-radius: 4px;
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    z-index: 5;
}

textarea {
    width: 100%;
    height: 100%;
    background: var(--bg-editor);
    color: #e2e8f0;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.5;
    padding: 1.5rem;
    border: none;
    resize: none;
    outline: none;
}

.pane-flexbox textarea:focus {
    box-shadow: inset 2px 0 0 var(--flex-primary);
}

.pane-grid textarea:focus {
    box-shadow: inset 2px 0 0 var(--grid-primary);
}

/* Previews */
.preview-container {
    flex: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
}

.preview-frame-wrapper {
    background: var(--bg-preview);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    overflow: hidden;
    transition: width 0.1s;
    /* width is explicitly set via JS for sync resizing */
    width: 100%;
    min-height: 100%;
}

.preview-frame {
    width: 100%;
    height: 100%;
    color: #333;
    /* Default text color for preview */
    font-family: system-ui, sans-serif;
}

.preview-content {
    width: 100%;
    height: 100%;
}

/* Default generic styles injected into preview to make it look nice */
.base-preview-styles {
    /* This class doesn't do anything directly, it's just a marker for where defaults live if needed in JS */
}