:root {
    color-scheme: dark;
    --accent1: #00ffcc;
    --accent2: #38bdf8;
    --accent3: #c084fc;
    --bg: #070b12;
    --bg-soft: #0b111c;
    --surface: rgba(255, 255, 255, .055);
    --surface-strong: rgba(255, 255, 255, .09);
    --text: #f3f7fb;
    --muted: #a7b3c4;
    --muted-strong: #c7d2e4;
    --border: rgba(255, 255, 255, .11);
    --border-strong: rgba(56, 189, 248, .32);
    --shadow-soft: 0 18px 50px rgba(0, 0, 0, .28);
    --shadow-glow: 0 0 28px rgba(0, 255, 204, .18);
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: #070b12; /* Base color */
    font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 15% 0%, rgba(0, 255, 204, .09), transparent 30rem),
        radial-gradient(circle at 85% 8%, rgba(192, 132, 252, .11), transparent 28rem),
        linear-gradient(180deg, #070b12 0%, #0b0f14 42%, #070b12 100%);
    animation: glow-breathe 10s ease-in-out infinite alternate;
}

@keyframes glow-breathe {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.1); opacity: 1; }
}

@keyframes reveal-text {
    from {
        opacity: 0;
        transform: translateY(30px);
        filter: blur(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

button {
    font: inherit;
}

svg {
    display: block;
}

.chat-studio-page {
    padding: 60px 20px 80px; /* Further reduced top gap */
}

.studio-hero {
    padding: 20px 20px 30px; /* Tighter hero section */
    text-align: center;
}

.studio-kicker {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 7px 12px;
    border: 1px solid rgba(0, 255, 204, 0.26);
    border-radius: 999px;
    background: rgba(0, 255, 204, 0.07);
    color: #79ffe4;
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 20px;
    animation: reveal-text 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.studio-hero h1 {
    font-size: clamp(2.8rem, 7vw, 5.2rem);
    margin-bottom: 20px;
    line-height: 1.05;
    background: linear-gradient(90deg, var(--accent1), var(--accent2), var(--accent3));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 30px rgba(0, 255, 204, 0.15);
    animation: reveal-text 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.studio-hero p {
    max-width: 760px;
    margin: 0 auto 36px;
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    line-height: 1.7;
    color: var(--muted-strong);
    opacity: 0.9;
    animation: reveal-text 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 0.15s both;
}

.studio-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
    animation: reveal-text 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 0.3s both;
}

.studio-actions .btn {
    min-width: 160px;
}

.chat-studio {
    display: grid;
    grid-template-columns: minmax(420px, 1fr) minmax(360px, 470px);
    grid-template-rows: auto 1fr;
    gap: 18px clamp(18px, 3vw, 34px);
    width: min(1440px, calc(100% - 32px));
    margin: 0 auto;
    padding: 20px 0 60px;
}

.preview-header {
    grid-row: 1;
    grid-column: 1;
    display: flex;
    align-items: baseline; /* Connect baselines automatically */
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 4px;
}

.design-header {
    grid-row: 1;
    grid-column: 2;
    display: flex;
    align-items: baseline; /* Connect baselines automatically */
    justify-content: space-between;
    gap: 16px;
    padding: 24px 20px 12px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: rgba(9, 18, 34, .78);
    backdrop-filter: blur(16px);
}

.preview-stage {
    grid-row: 2;
    grid-column: 1;
}

.design-panel {
    grid-row: 2;
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: 580px;
}

.preview-stage,
.design-panel,
.css-panel {
    min-width: 0;
}

.preview-header,
.section-heading,
.css-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.preview-header {
    margin-bottom: 0;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(2rem, 4vw, 4.6rem);
    line-height: 1.02;
    letter-spacing: 0;
    text-shadow: 0 0 36px rgba(56, 189, 248, .16);
}

h2 {
    color: #f8fafc;
    font-size: 18px;
    line-height: 1.2;
}

#selected-theme-name {
    margin-top: 8px;
    color: var(--muted-strong);
    font-size: 15px;
    font-weight: 700;
}

.live-dot {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid rgba(0, 255, 204, .24);
    border-radius: 999px;
    background: rgba(0, 255, 204, .08);
    color: var(--accent1);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.live-dot::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent1);
    box-shadow: 0 0 0 6px rgba(0, 255, 204, .12);
}

.preview-stage {
    position: relative;
    isolation: isolate;
    height: 580px; /* Fixed height for consistency */
    overflow: hidden;
    border: 1px solid rgba(0, 255, 204, .18);
    border-radius: var(--radius-lg);
    background:
        linear-gradient(145deg, rgba(255, 255, 255, .12), transparent 20%),
        linear-gradient(180deg, rgba(9, 18, 34, .96), rgba(3, 8, 16, .98));
    box-shadow: var(--shadow-soft), var(--shadow-glow);
}

.stream-backdrop {
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        linear-gradient(90deg, rgba(5, 10, 20, .92), rgba(5, 10, 20, .55)),
        radial-gradient(circle at 76% 24%, rgba(0, 255, 204, .18), transparent 20rem),
        radial-gradient(circle at 22% 76%, rgba(192, 132, 252, .16), transparent 24rem),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 84px),
        repeating-linear-gradient(0deg, rgba(255, 255, 255, .025) 0 1px, transparent 1px 84px),
        #050a14;
}

.stream-backdrop::after {
    content: "";
    position: absolute;
    inset: 18px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--radius-md);
    pointer-events: none;
}

.preview-stage .sl__chat__layout {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 10px;
    padding: 28px;
}

.chat-item,
.sl__chat__layout > div {
    display: flex;
    width: 100%;
    animation: message-in 420ms cubic-bezier(.2, .8, .2, 1) both;
}

.bubble,
.sl__chat__layout > div:not(.chat-item) {
    min-width: 0;
    max-width: 92%;
}

.badges {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badges img,
.badge {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex-shrink: 0;
}

.username,
.name {
    min-width: 0;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text,
.message {
    margin-top: 5px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.emote {
    width: 28px;
    height: 28px;
    vertical-align: middle;
}

.design-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: 580px;
}

.theme-section,
.css-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: rgba(9, 18, 34, .78);
    box-shadow: 0 18px 42px rgba(0, 0, 0, .24);
    backdrop-filter: blur(16px);
    min-height: 0;
}

.theme-section {
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    flex: 0 0 auto;
    padding: 0 16px 16px;
}

.section-heading {
    margin-bottom: 12px;
}

.section-heading span,
#selected-theme-path {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.theme-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-height: 160px; /* Constrain height */
    overflow-y: auto;
    padding-right: 4px;
}

.theme-button {
    min-width: 0;
    min-height: 38px;
    padding: 0 12px;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .045);
    color: #dfe8f4;
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: border-color .2s ease, background .2s ease, color .2s ease, transform .2s ease;
}

.theme-button:hover {
    border-color: rgba(56, 189, 248, .26);
    background: rgba(56, 189, 248, .08);
    transform: translateY(-1px);
}

.theme-button.is-active {
    border-color: rgba(0, 255, 204, .34);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, .24), transparent 38%),
        linear-gradient(90deg, var(--accent1), var(--accent2));
    color: #041018;
    box-shadow: 0 0 22px rgba(0, 255, 204, .18);
}

.css-panel {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    padding: 16px;
}

.css-toolbar {
    flex: 0 0 auto;
    margin-bottom: 12px;
}

.css-toolbar h2 {
    margin-bottom: 4px;
}

.copy-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(0, 255, 204, .22);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .045);
    color: var(--accent1);
    cursor: pointer;
    transition: border-color .2s ease, background .2s ease, color .2s ease, transform .2s ease;
}

.copy-button:hover {
    border-color: rgba(0, 255, 204, .48);
    background: rgba(0, 255, 204, .1);
    transform: translateY(-1px);
}

.copy-button svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.css-code {
    flex: 1;
    margin: 0;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--radius-sm);
    background: rgba(2, 6, 12, .74);
    color: #d8f8ff;
    font: 12px/1.55 Consolas, "SFMono-Regular", Menlo, monospace;
}

.css-code code {
    display: block;
    min-width: 100%;
    padding: 14px;
    white-space: pre;
}

.copy-status {
    min-height: 18px;
    margin-top: 10px;
    color: var(--accent1);
    font-size: 12px;
    font-weight: 800;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateX(-24px) translateY(10px) scale(.98);
    }

    to {
        opacity: 1;
        transform: translateX(0) translateY(0) scale(1);
    }
}

@keyframes message-out {
    to {
        opacity: 0;
        transform: translateX(-20px);
    }
}

.chat-item.removing,
.sl__chat__layout > div.removing {
    animation: message-out 260ms ease forwards;
}

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

    .chat-studio {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto; /* Sequential stacking */
        height: auto;
        min-height: 100vh;
        gap: 20px;
        padding: 20px 0;
    }

    .preview-header, .design-header, .preview-stage, .design-panel {
        grid-column: 1;
    }

    .preview-header { grid-row: 1; }
    .preview-stage { grid-row: 2; }
    .design-header {
        grid-row: 3;
        border-bottom: 1px solid var(--border);
        border-radius: var(--radius-lg);
    }
    .design-panel { grid-row: 4; }

    .preview-stage {
        min-height: 480px;
    }

    .theme-switcher {
        max-height: 320px;
    }

    .css-panel {
        min-height: 400px;
    }
}

@media (max-width: 620px) {
    .chat-studio {
        width: min(100% - 20px, 1440px);
        padding: 16px 0;
    }

    .preview-header,
    .css-toolbar {
        align-items: flex-start;
    }

    h1 {
        font-size: 1.8rem;
        line-height: 1.1;
    }

    .preview-stage {
        min-height: 360px;
    }

    .preview-stage .sl__chat__layout {
        padding: 16px;
    }

    .theme-switcher {
        grid-template-columns: repeat(2, 1fr);
        max-height: 280px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}