:root {
    /* Palette */
    --bg-color: #0a0a0c;
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.1);
    --accent-primary: #ff3e00;
    /* Contrast color for conversion - vibrant orange-red */
    --accent-secondary: #00f2ff;
    --text-main: #ffffff;
    --text-secondary: #a0a0a0;

    /* Bento Specs */
    --bento-gap: 16px;
    --bento-radius: 8px;

    /* Typo */
    --font-base: 'Outfit', 'Inter', system-ui, sans-serif;
    --btn-font-size: 0.9rem;
    /* Reduced from 1.2rem */

    /* Motion */
    --transition-main: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-base);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 24px;
}

/* --- BACKGROUND ORGANIC SHAPES --- */
.bg-blob-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    filter: blur(80px);
    opacity: 0.4;
}

.blob {
    position: absolute;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    animation: blob-float 15s infinite alternate ease-in-out;
}

.blob-1 {
    width: 500px;
    height: 500px;
    top: -100px;
    right: -100px;
}

.blob-2 {
    width: 400px;
    height: 400px;
    bottom: -50px;
    left: -50px;
    background: linear-gradient(135deg, #7000ff, var(--accent-secondary));
    animation-duration: 20s;
}

@keyframes blob-float {
    0% {
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
        transform: translate(0, 0) rotate(0deg);
    }

    50% {
        border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
        transform: translate(50px, 100px) rotate(90deg);
    }

    100% {
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
        transform: translate(-30px, 50px) rotate(180deg);
    }
}

/* --- LAYOUT --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    z-index: 10;
}

h1 {
    font-size: 2.5rem;
    font-weight: 600;
    background: linear-gradient(to right, #fff, var(--text-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* --- STANDARD BUTTON --- */
.btn-run {
    background-color: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--card-border);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: var(--btn-font-size);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-main);
    box-shadow: none;
    animation: none;
    text-transform: none;
    letter-spacing: normal;
}

@keyframes pulse-btn {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 62, 0, 0.7);
        transform: scale(1);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(255, 62, 0, 0);
        transform: scale(1.05);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 62, 0, 0);
        transform: scale(1);
    }
}

.btn-run:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

/* --- BENTO GRID --- */
.bento-container {
    display: grid;
    gap: var(--bento-gap);
    flex-grow: 1;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    --html-size: 1fr;
    --css-size: 1fr;
    --js-size: 1fr;
    --main-split-size: 350px;
    transition: grid-template-columns 0.3s ease, grid-template-rows 0.3s ease;
}

.bento-container.no-transition {
    transition: none !important;
}

.bento-tile {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--card-border);
    border-radius: var(--bento-radius);
    padding: 20px;
    display: grid;
    /* Changed from flex to grid for better height control */
    grid-template-rows: auto minmax(0, 1fr);
    transition: var(--transition-main);
    overflow: hidden;
    position: relative;
    gap: 0;
    /* Header has its own margin */
}

.bento-tile:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.07);
    transform: translateY(-4px);
}

/* --- LAYOUTS --- */

/* Default: layout-top (3 editors top, resizer, 1 preview bottom) */
/* Default: layout-top (3 editors top, resizer, 1 preview bottom) */
.bento-container.layout-top {
    grid-template-columns: minmax(0, var(--html-size)) minmax(0, var(--css-size)) minmax(0, var(--js-size));
    grid-template-rows: var(--main-split-size) 8px minmax(0, 1fr);
}

.bento-container.layout-top .tile-html,
.bento-container.layout-top .tile-css,
.bento-container.layout-top .tile-js {
    grid-column: span 1;
    grid-row: 1;
}

.bento-container.layout-top .resizer {
    grid-column: span 3;
    grid-row: 2;
    cursor: row-resize;
    height: 8px;
    margin: -4px 0;
    z-index: 100;
}

.bento-container.layout-top .tile-preview {
    grid-column: span 3;
    grid-row: 3;
}

/* layout-bottom: 1 preview top, resizer, 3 editors bottom */
/* layout-bottom: 1 preview top, resizer, 3 editors bottom */
.bento-container.layout-bottom {
    grid-template-columns: minmax(0, var(--html-size)) minmax(0, var(--css-size)) minmax(0, var(--js-size));
    grid-template-rows: minmax(0, 1fr) 8px var(--main-split-size);
}

.bento-container.layout-bottom .tile-preview {
    grid-column: span 3;
    grid-row: 1;
}

.bento-container.layout-bottom .resizer {
    grid-column: span 3;
    grid-row: 2;
    cursor: row-resize;
    height: 8px;
    margin: -4px 0;
    z-index: 100;
}

.bento-container.layout-bottom .tile-html,
.bento-container.layout-bottom .tile-css,
.bento-container.layout-bottom .tile-js {
    grid-column: span 1;
    grid-row: 3;
}

/* layout-left: column on left, preview right */
/* layout-left: column on left, preview right */
.bento-container.layout-left {
    grid-template-columns: var(--main-split-size) 8px minmax(0, 1fr);
    grid-template-rows: minmax(0, var(--html-size)) minmax(0, var(--css-size)) minmax(0, var(--js-size));
}

.bento-container.layout-left .tile-html,
.bento-container.layout-left .tile-css,
.bento-container.layout-left .tile-js {
    grid-column: 1;
}

.bento-container.layout-left .tile-html {
    grid-row: 1;
}

.bento-container.layout-left .tile-css {
    grid-row: 2;
}

.bento-container.layout-left .tile-js {
    grid-row: 3;
}

.bento-container.layout-left .resizer {
    grid-column: 2;
    grid-row: span 3;
    cursor: col-resize;
    width: 8px;
    margin: 0 -4px;
    z-index: 100;
}

.bento-container.layout-left .tile-preview {
    grid-column: 3;
    grid-row: 1 / span 3;
}

/* layout-right: preview left, resizer, column on right */
/* layout-right: preview left, resizer, column on right */
.bento-container.layout-right {
    grid-template-columns: minmax(0, 1fr) 8px var(--main-split-size);
    grid-template-rows: minmax(0, var(--html-size)) minmax(0, var(--css-size)) minmax(0, var(--js-size));
}

.bento-container.layout-right .tile-preview {
    grid-column: 1;
    grid-row: span 3;
}

.bento-container.layout-right .resizer {
    grid-column: 2;
    grid-row: span 3;
    cursor: col-resize;
    width: 8px;
    margin: 0 -4px;
    z-index: 100;
}

.bento-container.layout-right .tile-html,
.bento-container.layout-right .tile-css,
.bento-container.layout-right .tile-js {
    grid-column: 3;
}

.bento-container.layout-right .tile-html {
    grid-row: 1;
}

.bento-container.layout-right .tile-css {
    grid-row: 2;
}

.bento-container.layout-right .tile-js {
    grid-row: 3;
}

/* Layout Switcher UI */
.layout-switcher {
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px;
    border-radius: 10px;
}

.btn-layout {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    transition: var(--transition-main);
}

.btn-layout.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

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


.tile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tile-header span {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.dot-html {
    background-color: #ff4c1e;
}

.dot-css {
    background-color: #007aff;
}

.dot-js {
    background-color: #ffd600;
}

.dot-preview {
    background-color: #00ff88;
}

/* --- COLLAPSE STATE --- */
.bento-tile.is-collapsed {
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
}

.bento-tile.is-collapsed .CodeMirror,
.bento-tile.is-collapsed textarea,
.bento-tile.is-collapsed iframe {
    display: none;
}

.bento-tile.is-collapsed .tile-header {
    margin-bottom: 0;
}

/* Horizontal Collapse (Narrow Width): editors in top/bottom layout, preview in left/right layout */
.layout-top .bento-tile.is-collapsed:not(.tile-preview),
.layout-bottom .bento-tile.is-collapsed:not(.tile-preview),
.layout-left .tile-preview.is-collapsed,
.layout-right .tile-preview.is-collapsed {
    padding: 15px 10px;
}

.layout-top .bento-tile.is-collapsed:not(.tile-preview) .tile-header,
.layout-bottom .bento-tile.is-collapsed:not(.tile-preview) .tile-header,
.layout-left .tile-preview.is-collapsed .tile-header,
.layout-right .tile-preview.is-collapsed .tile-header {
    flex-direction: column;
    height: 100%;
}

.layout-top .bento-tile.is-collapsed:not(.tile-preview) .tile-header span,
.layout-bottom .bento-tile.is-collapsed:not(.tile-preview) .tile-header span,
.layout-left .tile-preview.is-collapsed .tile-header span,
.layout-right .tile-preview.is-collapsed .tile-header span {
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    margin-top: 15px;
}

/* Vertical Collapse (Short Height): preview in top/bottom layout, editors in left/right layout */
.layout-top .tile-preview.is-collapsed,
.layout-bottom .tile-preview.is-collapsed,
.layout-left .bento-tile.is-collapsed:not(.tile-preview),
.layout-right .bento-tile.is-collapsed:not(.tile-preview) {
    height: 45px !important;
    min-height: 45px !important;
    padding: 0 15px;
    display: flex;
    align-items: center;
}

.layout-top .tile-preview.is-collapsed .tile-header,
.layout-bottom .tile-preview.is-collapsed .tile-header,
.layout-left .bento-tile.is-collapsed:not(.tile-preview) .tile-header,
.layout-right .bento-tile.is-collapsed:not(.tile-preview) .tile-header {
    flex-direction: row;
    width: 100%;
    margin-top: 0 !important;
}

.bento-tile.is-collapsed .tile-header span {
    font-size: 0.8rem;
    opacity: 0.6;
}

.btn-toggle-tile {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition-main);
}

.btn-toggle-tile:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.resizer {
    background: transparent;
    transition: var(--transition-main);
    display: flex;
    align-items: center;
    justify-content: center;
}

.resizer:hover,
.resizer.is-dragging {
    background: rgba(0, 242, 255, 0.2);
}

.resizer::after {
    content: '';
    width: 30px;
    height: 4px;
    background: var(--card-border);
    border-radius: 2px;
}

.layout-left .resizer::after,
.layout-right .resizer::after {
    width: 4px;
    height: 30px;
}

/* --- CODEMIRROR CUSTOMIZATION --- */
.CodeMirror {
    height: 100% !important;
    width: 100%;
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    background: transparent !important;
    /* Let theme handle or transparent */
    border-radius: 0 0 var(--bento-radius) var(--bento-radius);
    line-height: 1.6;
}

.CodeMirror-gutters {
    background: rgba(255, 255, 255, 0.02) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.05) !important;
}

.CodeMirror-scroll {
    overflow-y: auto !important;
    overflow-x: auto !important;
    margin-bottom: 0 !important;
    margin-right: 0 !important;
    padding-bottom: 0 !important;
}

/* --- SPECIFIC TILE SIZES REMOVED (Controlled by layout classes) --- */
.tile-preview {
    padding: 0;
    overflow: hidden;
}

#preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background-color: white;
    /* Default iframe background */
}

/* --- FULLSCREEN MODE --- */
.btn-fullscreen {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-main);
}

.btn-fullscreen:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.tile-preview.is-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    border-radius: 0;
    margin: 0;
}

.tile-preview.is-fullscreen .tile-header {
    position: absolute;
    top: 10px;
    right: 10px;
    left: 10px;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 15px;
    border-radius: 12px;
    backdrop-filter: blur(5px);
    margin: 0 !important;
}


/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    width: 650px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}

.drop-zone {
    border: 2px dashed var(--card-border);
    padding: 40px 20px;
    text-align: center;
    border-radius: 12px;
    margin-bottom: 20px;
    transition: var(--transition-main);
    background: rgba(255, 255, 255, 0.02);
}

.asset-manager-list {
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 5px;
}

.asset-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    margin-bottom: 8px;
    border: 1px solid transparent;
    transition: var(--transition-main);
}

.asset-item:hover {
    border-color: var(--accent-secondary);
    background: rgba(255, 255, 255, 0.08);
}

@media (max-width: 1024px) {
    .bento-container {
        grid-template-rows: auto;
    }

    .tile-html,
    .tile-css,
    .tile-js {
        grid-column: span 12;
        height: 300px;
    }

    .tile-preview {
        grid-column: span 12;
        height: 400px;
    }
}