:root {
    --bg-0: #090203;
    --bg-1: #120406;
    --bg-2: #1c070b;
    --panel: rgba(23, 8, 11, 0.72);
    --panel-strong: rgba(35, 10, 14, 0.9);
    --panel-soft: rgba(255, 255, 255, 0.04);
    --line: rgba(255, 130, 120, 0.14);
    --line-strong: rgba(255, 130, 120, 0.3);
    --text: #fff6f3;
    --muted: #f5b8b0;
    --accent: #ff4d38;
    --accent-2: #ff9170;
    --danger: #ff7e7e;
    --shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
    --radius-xl: 32px;
    --radius-lg: 24px;
    --radius-md: 18px;
    --topbar-h: 82px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    color: var(--text);
    background:
        radial-gradient(circle at 15% 20%, rgba(255, 80, 50, 0.18), transparent 22%),
        radial-gradient(circle at 85% 12%, rgba(156, 0, 0, 0.18), transparent 18%),
        linear-gradient(160deg, var(--bg-0), var(--bg-1) 48%, var(--bg-2));
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

body {
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

.fx-canvas,
.noise-layer,
.background-grid,
.background-orb {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

.fx-canvas {
    z-index: 0;
    opacity: 0.8;
}

.noise-layer {
    z-index: 0;
    opacity: 0.04;
    background-image:
        linear-gradient(0deg, rgba(255, 255, 255, 0.6) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.4) 1px, transparent 1px);
    background-size: 3px 3px, 4px 4px;
    mix-blend-mode: soft-light;
}

.background-grid {
    z-index: 0;
    background-image:
        linear-gradient(rgba(255, 90, 90, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 90, 90, 0.05) 1px, transparent 1px);
    background-size: 64px 64px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent 88%);
}

.background-orb {
    z-index: 0;
    border-radius: 999px;
    filter: blur(80px);
    opacity: 0.26;
}

.orb-a {
    inset: 8% auto auto -8%;
    width: 34rem;
    height: 34rem;
    background: rgba(255, 75, 56, 0.28);
    animation: orbFloatA 15s ease-in-out infinite alternate;
}

.orb-b {
    inset: auto -8% 6% auto;
    width: 30rem;
    height: 30rem;
    background: rgba(182, 10, 30, 0.26);
    animation: orbFloatB 20s ease-in-out infinite alternate;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--topbar-h);
    padding: 18px 28px;
    background: rgba(10, 3, 4, 0.56);
    backdrop-filter: blur(20px) saturate(130%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 1rem;
}

.brand-flag {
    width: 18px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
    background:
        linear-gradient(
            to bottom,
            #ffffff 0 33.333%,
            #1f5cff 33.333% 66.666%,
            #d52b1e 66.666% 100%
        );
}

.brand::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -6px;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), transparent);
}

.nav-links {
    display: flex;
    gap: 20px;
    color: var(--muted);
}

.nav-links a {
    transition: color 0.2s ease, transform 0.2s ease;
}

.nav-links a:hover {
    color: var(--text);
    transform: translateY(-1px);
}

.page {
    position: relative;
    z-index: 1;
    padding: 36px 28px 64px;
}

.chat-page {
    height: calc(100dvh - var(--topbar-h));
    padding-bottom: 24px;
    overflow: hidden;
}

.hero-card,
.card,
.chat-shell {
    width: min(1320px, 100%);
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015)),
        rgba(13, 4, 6, 0.6);
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
}

.hero-card {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 24px;
    padding: 28px;
    min-height: calc(100vh - 170px);
}

.hero-copy,
.hero-panel,
.pane,
.sidebar,
.chat-panel {
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-lg);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 35%),
        var(--panel);
}

.hero-copy,
.hero-panel,
.pane {
    padding: 26px;
}

.hero-copy {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.eyebrow,
.status-pill,
.pow-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid rgba(255, 120, 120, 0.14);
    border-radius: 999px;
    background: rgba(255, 80, 60, 0.08);
    color: #ffd8d2;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.7rem;
}

.hero-copy h1,
.pane h1,
.sidebar-top h1 {
    margin: 14px 0 18px;
    font-size: clamp(2.4rem, 5vw, 5.5rem);
    line-height: 0.92;
    max-width: 12ch;
}

.hero-page .hero-copy h1 {
    max-width: 11ch;
}

.hero-copy p,
.pane p,
.feature-grid p,
.sidebar-note,
.inline-status {
    color: var(--muted);
    line-height: 1.65;
    font-size: 1rem;
}

.hero-actions,
.sidebar-top {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.metric-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 24px;
}

.metric-strip div,
.feature-grid article,
.hero-terminal {
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.03);
}

.metric-strip div {
    padding: 16px;
}

.metric-strip strong,
.feature-grid h3 {
    display: block;
    margin-bottom: 8px;
}

.metric-strip span {
    color: var(--muted);
    font-size: 0.92rem;
}

.feature-grid {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.feature-grid article {
    padding: 18px;
}

.hero-terminal {
    margin-top: 18px;
    padding: 18px;
    font-family: Consolas, monospace;
    color: #ffd7cf;
}

.terminal-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px rgba(255, 77, 56, 0.7);
}

.split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    padding: 18px;
}

.pane {
    min-height: 420px;
}

.stack-form {
    display: grid;
    gap: 16px;
    margin-top: 22px;
}

.stack-form label,
.message-form {
    display: grid;
    gap: 10px;
}

input[type="text"],
input[type="file"],
textarea {
    width: 100%;
    padding: 15px 16px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    outline: none;
    transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus {
    background: rgba(255, 255, 255, 0.065);
    border-color: var(--line-strong);
    transform: translateY(-1px);
    box-shadow: 0 0 0 4px rgba(255, 77, 56, 0.08);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 50px;
    padding: 0 18px;
    border-radius: 16px;
    border: 0;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, background 0.2s ease;
}

.button:hover {
    transform: translateY(-2px);
}

.button.primary {
    color: #fff;
    background:
        linear-gradient(135deg, rgba(255, 145, 112, 0.2), transparent 45%),
        linear-gradient(135deg, #ff4d38, #b5101f);
    box-shadow: 0 18px 35px rgba(255, 77, 56, 0.25);
}

.button.ghost {
    color: var(--text);
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.button.danger {
    color: #ffd0d0;
    border-color: rgba(255, 120, 120, 0.2);
}

.button.small {
    min-height: 40px;
    padding: 0 14px;
}

.button.full {
    width: 100%;
}

.chat-shell {
    display: grid;
    grid-template-columns: minmax(320px, 360px) minmax(0, 1fr) minmax(320px, 360px);
    gap: 18px;
    padding: 18px;
    height: 100%;
    min-height: 0;
}

.sidebar,
.chat-panel {
    padding: 18px;
    min-height: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}

.profile-sidebar,
.history-sidebar {
    min-height: 0;
}

.account-card-primary {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    min-height: 0;
}

.history-card,
.account-card {
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.history-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 280px;
    padding: 16px;
    overflow: hidden;
}

.history-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.history-head h2,
.account-head h2 {
    margin: 10px 0 0;
}

.history-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(255, 77, 56, 0.14);
    border: 1px solid rgba(255, 120, 120, 0.16);
    color: #ffd8d2;
    font-weight: 700;
}

.sidebar-top {
    align-items: start;
}

.sidebar-note {
    max-width: 36ch;
    margin: 8px 0 0;
}

.account-card {
    padding: 18px;
    flex-shrink: 0;
}

.api-key-section {
    display: grid;
    gap: 10px;
    margin: 16px 0;
    padding: 14px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.025));
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.api-key-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.api-key-copy {
    flex-shrink: 0;
}

.api-key-display {
    display: block;
    padding: 12px 14px;
    border-radius: 14px;
    color: #f3c8c0;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    font-family: Consolas, monospace;
    font-size: 0.79rem;
    line-height: 1.5;
    word-break: break-all;
}

.account-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 14px 0;
}

.account-stats div {
    padding: 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.account-stats strong,
.account-stats span {
    display: block;
}

.account-stats strong {
    font-size: 1.15rem;
}

.account-stats span {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.88rem;
}

.account-actions {
    display: grid;
    gap: 10px;
}

.chat-list {
    display: grid;
    gap: 12px;
    overflow: auto;
    min-height: 0;
    flex: 1;
    align-content: start;
    padding-right: 8px;
}

.chat-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 12px;
    width: 100%;
    padding: 18px;
    color: inherit;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid transparent;
    border-radius: 20px;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.chat-item:hover,
.chat-item.active {
    transform: translateX(4px);
    border-color: rgba(255, 120, 120, 0.28);
    background:
        linear-gradient(135deg, rgba(255, 77, 56, 0.16), transparent 65%),
        rgba(255, 255, 255, 0.05);
}

.chat-item strong,
.chat-item span {
    display: block;
}

.chat-item span {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.92rem;
}

.chat-open,
.chat-delete {
    border: 0;
    color: inherit;
    background: transparent;
    cursor: pointer;
}

.chat-open {
    padding: 0;
    text-align: left;
    min-width: 0;
}

.chat-open strong {
    font-size: 1rem;
    line-height: 1.35;
    word-break: break-word;
}

.chat-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    color: #ffb6b6;
    background: rgba(255, 255, 255, 0.04);
    transition: background 0.2s ease, transform 0.2s ease;
}

.chat-delete:hover {
    background: rgba(255, 77, 56, 0.18);
    transform: translateY(-1px);
}

.chat-panel {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 16px;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.messages {
    display: grid;
    align-content: start;
    gap: 14px;
    overflow: auto;
    min-height: 0;
    padding-right: 4px;
}

.message {
    position: relative;
    max-width: min(84%, 780px);
    padding: 16px 18px;
    border-radius: 24px;
    line-height: 1.65;
    white-space: pre-wrap;
    animation: rise 0.24s ease;
}

.message p,
.message ul,
.message pre,
.message h1,
.message h2,
.message h3,
.message h4,
.message h5,
.message h6 {
    margin: 0;
}

.message p + p,
.message p + ul,
.message ul + p,
.message pre + p,
.message p + pre,
.message h1 + p,
.message h2 + p,
.message h3 + p,
.message h4 + p,
.message h5 + p,
.message h6 + p,
.message p + h1,
.message p + h2,
.message p + h3,
.message p + h4,
.message p + h5,
.message p + h6,
.message ul + pre,
.message pre + ul {
    margin-top: 12px;
}

.message ul {
    padding-left: 20px;
}

.message li + li {
    margin-top: 6px;
}

.message code {
    padding: 2px 7px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.22);
    font-family: Consolas, monospace;
    font-size: 0.95em;
}

.message pre {
    overflow: auto;
    padding: 14px;
    border-radius: 16px;
    background: rgba(5, 5, 8, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.message pre code {
    display: block;
    padding: 0;
    background: transparent;
    line-height: 1.55;
}

.message a {
    color: #ffd7cf;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.message h1,
.message h2,
.message h3,
.message h4,
.message h5,
.message h6 {
    line-height: 1.2;
}

.message.user {
    justify-self: end;
    background:
        linear-gradient(135deg, rgba(255, 145, 112, 0.2), transparent 40%),
        linear-gradient(135deg, rgba(255, 77, 56, 0.98), rgba(169, 14, 30, 0.96));
    box-shadow: 0 16px 34px rgba(255, 77, 56, 0.2);
}

.message.assistant {
    justify-self: start;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 70%),
        rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.message-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.message-regenerate {
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.message-regenerate:hover {
    color: var(--text);
    background: rgba(255, 77, 56, 0.12);
    transform: translateY(-1px);
}

.message-form {
    grid-template-columns: 1fr auto;
    align-items: end;
    padding: 14px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.message-form textarea {
    min-height: 58px;
    max-height: 200px;
    resize: vertical;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.inline-status {
    min-height: 24px;
}

.inline-status.error {
    color: var(--danger);
}

.inline-status.success {
    color: #ffd6a1;
}

.reveal {
    animation: reveal 0.5s ease;
}

@keyframes reveal {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes orbFloatA {
    from {
        transform: translate3d(0, 0, 0) scale(1);
    }
    to {
        transform: translate3d(90px, 30px, 0) scale(1.15);
    }
}

@keyframes orbFloatB {
    from {
        transform: translate3d(0, 0, 0) scale(1);
    }
    to {
        transform: translate3d(-80px, -20px, 0) scale(1.12);
    }
}

@media (max-width: 1024px) {
    .hero-card,
    .split,
    .chat-shell {
        grid-template-columns: 1fr;
    }

    .hero-card {
        min-height: auto;
    }

    .chat-shell {
        height: auto;
        min-height: auto;
    }

    .chat-page {
        height: auto;
        overflow: visible;
    }

    .sidebar {
        overflow: visible;
    }

    .chat-list {
        max-height: 360px;
    }

    .history-card {
        min-height: 240px;
    }

    .account-card-primary {
        display: grid;
        justify-content: stretch;
    }

    .messages {
        min-height: 360px;
        max-height: 58vh;
    }

    .account-card {
        margin-top: 0;
    }
}

@media (max-width: 680px) {
    .topbar,
    .page {
        padding-left: 16px;
        padding-right: 16px;
    }

    .topbar {
        flex-direction: column;
        align-items: start;
        gap: 10px;
    }

    .nav-links {
        flex-wrap: wrap;
        gap: 12px;
    }

    .hero-card,
    .split,
    .chat-shell {
        padding: 14px;
    }

    .hero-page {
        padding-top: 18px;
    }

    .hero-card {
        gap: 14px;
    }

    .hero-copy,
    .hero-panel,
    .pane,
    .sidebar,
    .chat-panel {
        padding: 18px;
    }

    .hero-copy h1,
    .pane h1,
    .sidebar-top h1 {
        max-width: none;
        font-size: clamp(2rem, 10vw, 3rem);
        line-height: 1;
    }

    .metric-strip {
        grid-template-columns: 1fr;
    }

    .chat-header,
    .hero-actions,
    .sidebar-top,
    .message-form {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .chat-page {
        height: auto;
        min-height: auto;
        overflow: visible;
        padding-bottom: 18px;
    }

    .chat-shell {
        gap: 14px;
        height: auto;
        min-height: auto;
    }

    .sidebar {
        gap: 12px;
    }

    .chat-list {
        max-height: 260px;
        padding-right: 0;
    }

    .history-head {
        align-items: stretch;
        flex-direction: column;
    }

    .api-key-header {
        align-items: stretch;
        flex-direction: column;
    }

    .chat-panel {
        gap: 12px;
        overflow: visible;
    }

    .chat-header {
        padding-bottom: 8px;
    }

    .messages {
        min-height: 42vh;
        max-height: 50vh;
        padding-right: 0;
    }

    .message-form {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: rgba(18, 6, 8, 0.92);
        backdrop-filter: blur(14px);
    }

    .account-stats {
        grid-template-columns: 1fr;
    }

    .message {
        max-width: 100%;
    }
}
