@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@500;600;700&family=Sora:wght@300;400;500;600&display=swap');

:root {
    --void: #030303;
    --black: #0a0a0a;
    --ink: #121212;
    --panel: rgba(10, 10, 10, 0.82);
    --line: rgba(180, 30, 40, 0.28);
    --line-strong: rgba(220, 40, 50, 0.55);
    --text: #f2eaea;
    --muted: #9a8585;
    --crimson: #c41228;
    --crimson-bright: #e01e36;
    --blood: #8a0f1e;
    --ember: #ff3b4a;
    --mine: linear-gradient(145deg, #3a0a10 0%, #1a0508 100%);
    --theirs: linear-gradient(145deg, #161616 0%, #0d0d0d 100%);
    --font: 'Sora', sans-serif;
    --display: 'Cinzel', serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    color: var(--text);
    background: var(--void);
}

body {
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -2;
    background:
        radial-gradient(ellipse 80% 55% at 50% -15%, rgba(160, 12, 28, 0.38), transparent 58%),
        radial-gradient(circle at 85% 80%, rgba(90, 0, 12, 0.35), transparent 42%),
        radial-gradient(circle at 10% 70%, rgba(40, 0, 6, 0.55), transparent 40%),
        linear-gradient(180deg, #080000 0%, var(--void) 45%, #050000 100%);
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.09;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    animation: grain 8s steps(8) infinite;
}

.veil {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    box-shadow: inset 0 0 120px 40px rgba(0, 0, 0, 0.75);
}

.ember {
    position: fixed;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    filter: blur(70px);
    pointer-events: none;
    z-index: 0;
    opacity: 0.35;
    animation: drift 14s ease-in-out infinite alternate;
}

.ember-a {
    top: 12%;
    left: -40px;
    background: #7a0614;
}

.ember-b {
    right: -60px;
    bottom: 8%;
    background: #4a020a;
    animation-delay: -5s;
    animation-duration: 18s;
}

.brand {
    margin: 0;
    font-family: var(--display);
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-size: 1.2rem;
    color: var(--text);
    text-shadow: 0 0 24px rgba(196, 18, 40, 0.45);
    animation: brandPulse 4.5s ease-in-out infinite;
}

.stat-line {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 0;
    color: #c9a0a4;
    font-size: 0.78rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.stat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--crimson-bright);
    box-shadow: 0 0 10px rgba(224, 30, 54, 0.8);
    animation: livePulse 1.8s ease-in-out infinite;
}

/* Login */
.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-shell {
    width: min(100%, 420px);
    position: relative;
    z-index: 1;
    animation: fadeRise 0.7s ease-out;
}

.login-form {
    display: grid;
    gap: 14px;
    padding: 34px 30px 30px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 4px;
    backdrop-filter: blur(16px);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.6),
        0 30px 80px rgba(0, 0, 0, 0.65),
        0 0 60px rgba(140, 10, 24, 0.12);
    position: relative;
}

.login-form::before {
    content: '';
    position: absolute;
    top: 0;
    left: 12%;
    right: 12%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--crimson-bright), transparent);
    opacity: 0.85;
}

.login-form .brand {
    text-align: center;
    font-size: 1.55rem;
    letter-spacing: 0.22em;
}

.login-form .stat-line {
    justify-content: center;
    margin-top: 10px;
}

.login-form h1 {
    margin: 10px 0 0;
    font-family: var(--display);
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-align: center;
    text-transform: uppercase;
}

.subtitle {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 300;
    text-align: center;
    line-height: 1.5;
}

.login-form label {
    display: grid;
    gap: 7px;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.login-form input,
.composer input {
    width: 100%;
    border: 1px solid rgba(120, 30, 36, 0.4);
    background: rgba(0, 0, 0, 0.55);
    color: var(--text);
    border-radius: 2px;
    padding: 13px 14px;
    font: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-form input:focus,
.composer input:focus {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 3px rgba(196, 18, 40, 0.15);
}

.login-form button,
.composer button {
    border: 0;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--crimson-bright), var(--blood));
    color: #fff5f5;
    font: inherit;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.2s ease, transform 0.15s ease;
}

.login-form button {
    margin-top: 8px;
    padding: 13px 16px;
    font-size: 0.82rem;
}

.login-form button:hover,
.composer button:hover {
    filter: brightness(1.08);
}

.login-form button:active,
.composer button:active {
    transform: translateY(1px);
}

.error {
    margin: 0;
    padding: 10px 12px;
    border-radius: 2px;
    border: 1px solid rgba(196, 18, 40, 0.4);
    background: rgba(90, 8, 16, 0.45);
    color: #ffb0b8;
    font-size: 0.88rem;
    text-align: center;
}

/* Chat */
.chat-page {
    display: grid;
    place-items: center;
    padding: 16px;
}

.chat-app {
    width: min(100%, 780px);
    height: min(92vh, 840px);
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    z-index: 1;
    backdrop-filter: blur(18px);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.7),
        0 40px 100px rgba(0, 0, 0, 0.7),
        0 0 80px rgba(120, 8, 20, 0.15);
    animation: fadeRise 0.55s ease-out;
}

.chat-app::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--ember), transparent);
    opacity: 0.7;
    z-index: 2;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(30, 0, 6, 0.55), rgba(0, 0, 0, 0.35));
}

.presence {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 300;
    letter-spacing: 0.02em;
}

.presence strong {
    color: #e8d0d0;
    font-weight: 500;
}

.admin-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 2px;
    border: 1px solid rgba(224, 30, 54, 0.45);
    background: rgba(140, 10, 24, 0.35);
    color: #ff8a94;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    vertical-align: middle;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logout,
.danger-btn {
    padding: 8px 12px;
    background: transparent;
    color: var(--muted);
    border: 1px solid rgba(120, 40, 45, 0.35);
    border-radius: 2px;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.logout:hover {
    color: var(--text);
    border-color: rgba(200, 80, 90, 0.5);
}

.danger-btn {
    color: #ff8a94;
    border-color: rgba(196, 18, 40, 0.5);
}

.danger-btn:hover {
    color: #fff;
    background: rgba(140, 10, 24, 0.45);
}

.danger-btn:disabled {
    opacity: 0.55;
    cursor: wait;
}

.messages {
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background:
        radial-gradient(ellipse 70% 40% at 50% 0%, rgba(90, 0, 14, 0.18), transparent 60%),
        rgba(0, 0, 0, 0.25);
}

.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-thumb {
    background: rgba(160, 30, 40, 0.45);
    border-radius: 3px;
}

.msg {
    max-width: min(78%, 480px);
    padding: 11px 13px;
    border-radius: 3px;
    line-height: 1.45;
    animation: rise 0.28s ease-out;
    border: 1px solid transparent;
}

.msg.mine {
    align-self: flex-end;
    background: var(--mine);
    border-color: rgba(196, 18, 40, 0.35);
    border-bottom-right-radius: 0;
    box-shadow: 0 0 24px rgba(140, 10, 24, 0.12);
}

.msg.theirs {
    align-self: flex-start;
    background: var(--theirs);
    border-color: rgba(80, 80, 80, 0.35);
    border-bottom-left-radius: 0;
}

.msg .meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 5px;
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.msg.mine .meta {
    color: #c4868c;
}

.msg .text {
    white-space: pre-wrap;
    word-break: break-word;
    font-weight: 400;
}

.empty {
    margin: auto;
    color: var(--muted);
    text-align: center;
    font-family: var(--display);
    font-size: 0.95rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0.75;
    animation: brandPulse 5s ease-in-out infinite;
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--line);
    background: linear-gradient(0deg, rgba(30, 0, 6, 0.5), rgba(0, 0, 0, 0.4));
}

.composer button {
    padding: 0 20px;
    font-size: 0.75rem;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeRise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes brandPulse {
    0%, 100% {
        text-shadow: 0 0 18px rgba(196, 18, 40, 0.25);
    }
    50% {
        text-shadow: 0 0 28px rgba(224, 30, 54, 0.55);
    }
}

@keyframes livePulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.45;
        transform: scale(0.85);
    }
}

@keyframes drift {
    from {
        transform: translate(0, 0) scale(1);
    }
    to {
        transform: translate(40px, -30px) scale(1.15);
    }
}

@keyframes grain {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-2%, -3%); }
    30% { transform: translate(3%, 1%); }
    50% { transform: translate(-1%, 4%); }
    70% { transform: translate(4%, -2%); }
    90% { transform: translate(-3%, 2%); }
}

@media (max-width: 600px) {
    .chat-page {
        padding: 0;
    }

    .chat-app {
        width: 100%;
        height: 100vh;
        border-radius: 0;
        border: 0;
    }

    .msg {
        max-width: 88%;
    }

    .header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
