:root {
    --bg-color: #050505;
    --accent-primary: #00f2ff;
    --accent-dim: rgba(0, 242, 255, 0.3);
    --text-main: #e0e6ed;
    --text-secondary: #8899a6;
    --glass-bg: rgba(10, 14, 20, 0.9);
    --font-ui: 'JetBrains Mono', monospace;
    --font-heading: 'Cinzel', serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-ui);
}

body,
html {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    position: relative;
}

/* Background Grid Effect from previous step */
body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(rgba(0, 242, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 242, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    z-index: -1;
    pointer-events: none;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: opacity 0.5s ease;
}

.hidden {
    display: none !important;
    opacity: 0;
}

/* Boot Screen */
#boot-screen {
    background: #000;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 3rem;
    letter-spacing: 0.5rem;
    color: var(--accent-primary);
    text-shadow: 0 0 15px var(--accent-primary);
    margin-bottom: 2rem;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(0, 242, 255, 0.1);
    border-top: 2px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.status-text {
    color: var(--text-secondary);
    font-size: 0.8rem;
    letter-spacing: 2px;
}

/* Main UI */
.system-header {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    border-bottom: 1px solid var(--accent-dim);
    background: rgba(5, 5, 5, 0.8);
    backdrop-filter: blur(5px);
}

.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    transition: color 0.3s;
}

.back-link:hover {
    color: var(--accent-primary);
}

.system-clock {
    font-size: 1.2rem;
    color: var(--accent-primary);
    text-shadow: 0 0 5px var(--accent-dim);
}

.stat {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-left: 1rem;
}

/* Interaction Area */
.interaction-area {
    flex: 1;
    display: flex;
    padding: 1.5rem 2rem;
    gap: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    min-height: 0; /* 关键：允许 flex 容器收缩，触发内部滚动 */
    height: calc(100vh - 60px); /* 撑满视口去除顶栏后的空间 */
    overflow: hidden;
}

/* Avatar Section */
.avatar-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.avatar-container {
    width: 300px;
    height: 300px;
    /* Reduced specific size, can use aspect ratio */
    position: relative;
    border: 1px solid var(--accent-dim);
    background: var(--glass-bg);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.1);
    margin-bottom: 1rem;
}

#avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 1;
    filter: none;
    mix-blend-mode: normal;
}

.scanline {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: rgba(0, 242, 255, 0.5);
    box-shadow: 0 0 10px var(--accent-primary);
    animation: scan 3s linear infinite;
    opacity: 0.5;
}

.ui-overlay .frame {
    position: absolute;
    width: 10px;
    height: 10px;
    border: 2px solid var(--accent-primary);
    transition: all 0.3s;
}

.corner-tl {
    top: -1px;
    left: -1px;
    border-right: 0;
    border-bottom: 0;
}

.corner-tr {
    top: -1px;
    right: -1px;
    border-left: 0;
    border-bottom: 0;
}

.corner-bl {
    bottom: -1px;
    left: -1px;
    border-right: 0;
    border-top: 0;
}

.corner-br {
    bottom: -1px;
    right: -1px;
    border-left: 0;
    border-top: 0;
}

/* Audio Visualizer (Fake) */
.audio-visualizer {
    display: flex;
    gap: 4px;
    height: 30px;
    align-items: center;
}

.bar {
    width: 6px;
    height: 10px;
    background: var(--accent-primary);
    animation: visualize 1s ease-in-out infinite alternate;
}

.bar:nth-child(2n) {
    animation-duration: 0.8s;
}

.bar:nth-child(3n) {
    animation-duration: 1.2s;
}

.audio-visualizer.speaking .bar {
    animation-duration: 0.35s !important;
    background: #ffffff;
    box-shadow: 0 0 8px var(--accent-primary);
}

/* Chat Interface */
.chat-interface {
    flex: 2;
    display: flex;
    flex-direction: column;
    background: rgba(10, 14, 20, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    backdrop-filter: blur(10px);
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

.chat-history {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

.message {
    max-width: 85%;
    padding: 1rem 1.2rem;
    border-left: 2px solid transparent;
    animation: fadeIn 0.3s ease;
}

.message.system {
    align-self: flex-start;
    border-left-color: var(--accent-primary);
    background: linear-gradient(90deg, rgba(0, 242, 255, 0.06), transparent);
}

.message.user {
    align-self: flex-end;
    border-right: 2px solid var(--text-secondary);
    background: linear-gradient(-90deg, rgba(255, 255, 255, 0.06), transparent);
    text-align: left;
}

.sender {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 0.4rem;
    font-weight: bold;
    letter-spacing: 0.08em;
}

.message.system .sender {
    color: var(--accent-primary);
}

.content {
    line-height: 1.65;
    font-size: 0.95rem;
    white-space: normal;
    word-break: break-word;
}

.content p {
    margin: 0 0 0.6em 0;
}

.content p:last-child {
    margin-bottom: 0;
}

.content strong {
    color: #fff;
}

.content code {
    background: rgba(0, 242, 255, 0.1);
    color: var(--accent-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.88em;
}

.content pre {
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(0, 242, 255, 0.2);
    border-radius: 4px;
    padding: 0.85rem 1rem;
    overflow-x: auto;
    margin: 0.6em 0;
}

.content pre code {
    background: transparent;
    color: var(--text-main);
    padding: 0;
}

.content ul, .content ol {
    margin: 0.35em 0 0.65em 1.35em;
    padding: 0;
}

.content ul ul, .content ol ul, .content ul ol, .content ol ol {
    margin: 0.25em 0 0.25em 1.25em;
}

.content li {
    margin-bottom: 0.28em;
}

.content .md-h2 {
    font-size: 1.05rem;
    color: var(--accent-primary);
    border-bottom: 1px solid rgba(0, 242, 255, 0.22);
    padding-bottom: 4px;
    margin: 0.9em 0 0.45em 0;
    letter-spacing: 0.04em;
}

.content .md-h3 {
    font-size: 0.98rem;
    color: #ffffff;
    margin: 0.75em 0 0.35em 0;
}

.content .md-h4 {
    font-size: 0.92rem;
    color: var(--accent-primary);
    margin: 0.6em 0 0.25em 0;
}

.content .md-h2:first-child,
.content .md-h3:first-child {
    margin-top: 0;
}

.content .md-quote {
    border-left: 2px solid var(--accent-primary);
    background: rgba(0, 242, 255, 0.05);
    padding: 0.45rem 0.85rem;
    margin: 0.55em 0;
    color: #cdd6e0;
}

.content .md-hr {
    border: 0;
    border-top: 1px solid rgba(0, 242, 255, 0.16);
    margin: 0.8em 0;
}

.content mjx-container[jax="CHTML"][display="true"] {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    margin: 0.6em 0 !important;
}

.content a.archive-link {
    color: var(--accent-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.ref-bar {
    margin-top: 0.8rem;
    padding-top: 0.6rem;
    border-top: 1px solid rgba(0, 242, 255, 0.15);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-size: 0.78rem;
}

.ref-label {
    color: var(--text-secondary);
    letter-spacing: 0.06em;
}

.ref-chip {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid rgba(0, 242, 255, 0.35);
    border-radius: 3px;
    color: var(--accent-primary);
    text-decoration: none;
    background: rgba(0, 242, 255, 0.06);
    transition: all 0.2s;
}

.ref-chip:hover {
    background: var(--accent-primary);
    color: #000;
}

/* Input Area */
.input-area {
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.3);
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.prompt-char {
    color: var(--accent-primary);
    font-weight: bold;
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: var(--font-ui);
    font-size: 1rem;
    padding: 0.5rem;
}

#user-input:focus {
    outline: none;
}

#send-btn {
    background: transparent;
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    padding: 5px 15px;
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    transition: all 0.2s;
}

#send-btn:hover {
    background: var(--accent-primary);
    color: #000;
}

/* Scrollbar */
.chat-history::-webkit-scrollbar {
    width: 6px;
}

.chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Animations */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes scan {
    0% {
        top: -5%;
    }

    100% {
        top: 105%;
    }
}

@keyframes visualize {
    0% {
        height: 5px;
        opacity: 0.5;
    }

    100% {
        height: 20px;
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* Mobile Reponsive */
@media (max-width: 768px) {
    .interaction-area {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }

    .avatar-container {
        width: 150px;
        height: 150px;
    }

    .chat-interface {
        height: 400px;
    }
}

/* Auth Gate Overlay */
.auth-gate-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 7, 10, 0.92);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-gate-overlay.hidden {
    display: none;
}

.auth-gate-card {
    width: 100%;
    max-width: 420px;
    background: rgba(10, 15, 22, 0.96);
    border: 1px solid var(--accent-primary);
    box-shadow: 0 0 32px rgba(0, 242, 255, 0.16);
    padding: 2rem;
}

.auth-gate-header .auth-badge {
    display: inline-block;
    font-size: 0.72rem;
    color: #ff4d4f;
    border: 1px solid rgba(255, 77, 79, 0.4);
    padding: 2px 8px;
    margin-bottom: 0.75rem;
    letter-spacing: 0.08em;
}

.auth-gate-header h2 {
    font-size: 1.05rem;
    color: var(--accent-primary);
    margin: 0 0 0.4rem 0;
    letter-spacing: 0.05em;
}

.auth-gate-header p {
    font-size: 0.82rem;
    color: #9aa7b8;
    margin: 0 0 1.25rem 0;
    line-height: 1.5;
}

.auth-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.2rem;
    border-bottom: 1px solid rgba(0, 242, 255, 0.2);
}

.auth-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: #8896a6;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.55rem 0;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.auth-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.auth-form.hidden {
    display: none;
}

.auth-field {
    margin-bottom: 1rem;
}

.auth-field label {
    display: block;
    font-size: 0.75rem;
    color: #9aa7b8;
    margin-bottom: 0.35rem;
    letter-spacing: 0.06em;
}

.auth-field input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(5, 8, 12, 0.8);
    border: 1px solid rgba(0, 242, 255, 0.28);
    color: #e6edf3;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.6rem 0.75rem;
    outline: none;
}

.auth-field input:focus {
    border-color: var(--accent-primary);
}

.auth-error {
    color: #ff6b6b;
    font-size: 0.8rem;
    min-height: 1.2em;
    margin-bottom: 0.75rem;
}

.auth-submit-btn {
    width: 100%;
    background: rgba(0, 242, 255, 0.12);
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 0.7rem;
    cursor: pointer;
    letter-spacing: 0.08em;
    transition: all 0.2s;
}

.auth-submit-btn:hover {
    background: var(--accent-primary);
    color: #05070a;
}

.auth-gate-footer {
    margin-top: 1.25rem;
    text-align: center;
}

.auth-gate-footer a {
    color: #7d8b99;
    font-size: 0.78rem;
    text-decoration: none;
}

.auth-gate-footer a:hover {
    color: var(--accent-primary);
}