:root {
    --grad-1: #8ec5fc;
    --grad-2: #e0c3fc;
    --bg-1: #0f0f0f;
    --bg-2: #1b1b1b;
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text: #ffffff;
    --error: #ff8080;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, var(--bg-1), var(--bg-2));
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    overflow-x: hidden;
    min-height: 100vh;
}

a { color: var(--grad-1); }

.logo-image { text-align: center; margin-top: 30px; }
.logo-image img { width: 163px; max-width: 80%; height: auto; display: inline-block; }

.header-logo {
    text-align: center;
    margin-top: 5px;
    font-size: 48px;
    font-weight: 600;
    letter-spacing: -1px;
    background: linear-gradient(90deg, var(--grad-1), var(--grad-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.subtitle { text-align: center; margin-top: 8px; font-size: 18px; opacity: 0.8; }

.glass {
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    background: var(--glass-bg);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    padding: 24px;
    width: 70%;
    margin: 30px auto;
    max-width: 900px;
}

#chatWindow {
    height: 400px;
    overflow-y: auto;
    padding-right: 10px;
    padding-bottom: 22px;
    scroll-behavior: smooth;
}

#chat { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }

#chat li {
    font-size: 17px;
    line-height: 1.45;
    max-width: 78%;
    padding: 12px 14px;
    border-radius: 14px;
    position: relative;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.bubble-user {
    margin-left: auto;
    background: linear-gradient(120deg, var(--grad-1), var(--grad-2));
    color: #000;
    border-top-right-radius: 4px;
}

.bubble-hagen {
    margin-right: auto;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-top-left-radius: 4px;
}

.bubble-system {
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.04);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    color: #ddd;
    max-width: 90%;
    text-align: center;
}

#inputField {
    width: 100%;
    min-height: 52px;
    max-height: 180px;
    padding: 14px;
    font-size: 17px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    outline: none;
    resize: none;
    overflow-x: hidden;
    overflow-y: auto;
    line-height: 1.45;
    white-space: pre-wrap;
    font-family: inherit;
}

#inputField::placeholder { color: #ccc; }

#inputField:focus, #gateInput:focus, #sendButton:focus, #gateButton:focus {
    outline: 2px solid var(--grad-1);
    outline-offset: 2px;
}

.input-meta {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    opacity: 0.7;
    margin-top: 6px;
}

#sendButton {
    margin-top: 12px;
    width: 100%;
    padding: 14px;
    border: none;
    font-size: 18px;
    border-radius: 12px;
    background: linear-gradient(90deg, var(--grad-1), var(--grad-2));
    color: #000;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s, transform 0.2s;
}

#sendButton:hover:not(:disabled) { opacity: 0.9; }
#sendButton:disabled { opacity: 0.5; cursor: not-allowed; }

#gateOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

#gateTitle {
    font-size: 20px;
    font-weight: 600;
}

#gateQuestion {
    display: block;
    margin-top: 10px;
}

#gateBox {
    width: 320px;
    padding: 24px;
    border-radius: 20px;
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    text-align: center;
}

#gateInput {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: none;
    margin-top: 12px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
}

#gateButton {
    width: 100%;
    padding: 12px;
    border: none;
    margin-top: 12px;
    border-radius: 10px;
    background: linear-gradient(90deg, var(--grad-1), var(--grad-2));
    color: #000;
    font-weight: 600;
    cursor: pointer;
    font-size: 16px;
}

#gateButton:disabled { opacity: 0.5; cursor: not-allowed; }
#gateError { color: var(--error); margin-top: 8px; min-height: 1.2em; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

.retry-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    background: rgba(142, 197, 252, 0.2);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    border: 1px solid rgba(142, 197, 252, 0.4);
}
.retry-btn:hover { background: rgba(142, 197, 252, 0.35); }
.retry-btn:focus { outline: 2px solid var(--grad-1); outline-offset: 2px; }

.typing .dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}
.typing .dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    animation: typingBounce 1.2s infinite ease-in-out;
}
.typing .dots span:nth-child(2) { animation-delay: 0.15s; }
.typing .dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

@media (max-width: 640px) {
    .glass { width: 92%; padding: 16px; }
    .header-logo { font-size: 36px; }
}

@media (prefers-reduced-motion: reduce) {
    #chatWindow { scroll-behavior: auto; }
    * { animation: none !important; transition: none !important; }
}
