* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-base: #06060a;
    --bg-surface: #0c0c14;
    --bg-elevated: #12121e;
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(167, 139, 250, 0.3);
    --text-primary: #f0f0f5;
    --text-secondary: rgba(255, 255, 255, 0.55);
    --text-muted: rgba(255, 255, 255, 0.35);
    --accent-purple: #a78bfa;
    --accent-violet: #5227FF;
    --accent-pink: #FF9FFC;
    --accent-gradient: linear-gradient(135deg, #5227FF 0%, #a78bfa 50%, #FF9FFC 100%);
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-bg-hover: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-hover: rgba(167, 139, 250, 0.25);
    --glow-purple: 0 0 40px rgba(82, 39, 255, 0.15);
    --glow-pink: 0 0 60px rgba(255, 159, 252, 0.1);
    --input-bg: rgba(255, 255, 255, 0.03);
    --input-bg-focus: rgba(167, 139, 250, 0.05);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

[data-theme="light"] {
    --bg-base: #f5f5fa;
    --bg-surface: #ffffff;
    --bg-elevated: #f0f0f5;
    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(82, 39, 255, 0.3);
    --text-primary: #1a1a2e;
    --text-secondary: rgba(0, 0, 0, 0.55);
    --text-muted: rgba(0, 0, 0, 0.38);
    --accent-purple: #7c3aed;
    --accent-violet: #5227FF;
    --accent-pink: #d946ef;
    --accent-gradient: linear-gradient(135deg, #5227FF 0%, #7c3aed 50%, #d946ef 100%);
    --glass-bg: rgba(0, 0, 0, 0.03);
    --glass-bg-hover: rgba(0, 0, 0, 0.06);
    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-border-hover: rgba(124, 58, 237, 0.25);
    --glow-purple: 0 0 40px rgba(124, 58, 237, 0.08);
    --glow-pink: 0 0 60px rgba(217, 70, 239, 0.06);
    --input-bg: rgba(0, 0, 0, 0.03);
    --input-bg-focus: rgba(124, 58, 237, 0.05);
}

body {
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-base);
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Dot grid pattern overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
    z-index: 0;
}

/* ==================== Light Theme Overrides ==================== */
[data-theme="light"] body::before {
    background-image: radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px);
}

[data-theme="light"] .login-box {
    background: rgba(255, 255, 255, 0.85);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.04),
        0 20px 60px rgba(0, 0, 0, 0.1),
        var(--glow-purple),
        var(--glow-pink);
}

[data-theme="light"] .login-box::before {
    background: linear-gradient(90deg, transparent, rgba(124, 58, 237, 0.2), rgba(217, 70, 239, 0.15), transparent);
}

[data-theme="light"] .login-box h1 {
    background: linear-gradient(135deg, #1a1a2e 0%, #7c3aed 40%, #d946ef 70%, #1a1a2e 100%);
    -webkit-background-clip: text;
    background-clip: text;
}

[data-theme="light"] .form input {
    background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .form input:focus {
    background: rgba(124, 58, 237, 0.05);
}

[data-theme="light"] .tab.active {
    background: rgba(124, 58, 237, 0.08);
}

[data-theme="light"] .chat-header {
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-primary);
    box-shadow: 0 1px 0 var(--border-subtle), 0 8px 32px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .chat-header::after {
    background: linear-gradient(90deg, transparent, rgba(124, 58, 237, 0.15), transparent);
}

[data-theme="light"] .chat-input-area {
    background: rgba(255, 255, 255, 0.95);
}

[data-theme="light"] .chat-input-area::before {
    background: linear-gradient(90deg, transparent, rgba(124, 58, 237, 0.1), transparent);
}

[data-theme="light"] .chat-input-area input {
    background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .chat-input-area input:focus {
    background: rgba(124, 58, 237, 0.05);
}

[data-theme="light"] .voice-overlay {
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .scene-panel {
    background: rgba(255, 255, 255, 0.97);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .scene-panel-header {
    background: rgba(245, 245, 250, 0.9);
    color: var(--text-primary);
}

[data-theme="light"] .scene-actions-bar {
    background: rgba(255, 255, 255, 0.92);
}

[data-theme="light"] .message.assistant .message-bubble {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .character-portrait {
    background: linear-gradient(135deg, #e8e8f0 0%, #d8d8e8 100%);
}

[data-theme="light"] .message.system {
    color: var(--text-muted);
}

[data-theme="light"] .login-box .message.error {
    background: rgba(220, 38, 38, 0.08);
    color: #b91c1c;
    border-color: rgba(220, 38, 38, 0.15);
}

[data-theme="light"] .login-box .message.success {
    background: rgba(22, 163, 74, 0.08);
    color: #15803d;
    border-color: rgba(22, 163, 74, 0.15);
}

/* ==================== Theme Toggle ==================== */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s ease;
    color: var(--text-secondary);
}

.theme-toggle:hover {
    background: var(--glass-bg-hover);
    border-color: var(--glass-border-hover);
    transform: rotate(30deg);
    box-shadow: var(--glow-purple);
}

.login-page .theme-toggle {
    position: absolute;
}

.chat-header .theme-toggle {
    position: static;
    width: 40px;
    height: 40px;
    font-size: 18px;
    flex-shrink: 0;
}

/* ==================== Login Page ==================== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-base);
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

#moltenCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.login-container {
    width: 100%;
    max-width: 440px;
    animation: slideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    z-index: 1;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-box {
    background: rgba(12, 12, 20, 0.7);
    backdrop-filter: blur(40px) saturate(1.5);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: 52px 44px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.03),
        0 20px 60px rgba(0, 0, 0, 0.6),
        var(--glow-purple),
        var(--glow-pink);
    position: relative;
    overflow: hidden;
}

.login-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(167, 139, 250, 0.3), rgba(255, 159, 252, 0.2), transparent);
}

.login-box h1 {
    text-align: center;
    margin-bottom: 40px;
    font-size: 36px;
    font-weight: 800;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #fff 0%, #a78bfa 40%, #f0abfc 70%, #fff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
}

.login-box h1::after {
    content: '';
    display: block;
    width: 40px;
    height: 3px;
    background: var(--accent-gradient);
    border-radius: 2px;
    margin: 16px auto 0;
}

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 32px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 4px;
}

.tab {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.5px;
}

.tab:hover {
    color: var(--text-secondary);
}

.tab.active {
    background: rgba(167, 139, 250, 0.1);
    color: var(--accent-purple);
    box-shadow: 0 0 20px rgba(82, 39, 255, 0.1);
    border: 1px solid rgba(167, 139, 250, 0.15);
}

.form {
    display: none;
}

.form.active {
    display: block;
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.form input {
    width: 100%;
    padding: 15px 20px;
    margin-bottom: 16px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    transition: all 0.3s ease;
    background: var(--input-bg);
    color: var(--text-primary);
}

.form input:focus {
    outline: none;
    border-color: var(--accent-purple);
    background: var(--input-bg-focus);
    box-shadow: 0 0 0 4px rgba(82, 39, 255, 0.1), 0 0 20px rgba(82, 39, 255, 0.05);
}

.form input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(82, 39, 255, 0.3);
    margin-top: 8px;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    transition: left 0.5s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(82, 39, 255, 0.4), 0 0 60px rgba(82, 39, 255, 0.15);
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:active {
    transform: translateY(0);
}

.login-box .message {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 13px;
    display: none;
    animation: shake 0.4s ease;
    font-weight: 500;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.login-box .message.error {
    display: block;
    background: rgba(255, 80, 80, 0.1);
    color: #ff8a8a;
    border: 1px solid rgba(255, 80, 80, 0.2);
}

.login-box .message.success {
    display: block;
    background: rgba(80, 255, 120, 0.08);
    color: #8affb0;
    border: 1px solid rgba(80, 255, 120, 0.15);
}

/* ==================== Characters Page ==================== */
.characters-page {
    padding: 60px 24px;
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-base);
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

.characters-page #moltenCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.characters-page h1,
.characters-page .characters-grid {
    position: relative;
    z-index: 1;
}

.characters-page h1 {
    font-size: 42px;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #fff 0%, #a78bfa 50%, #f0abfc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.characters-header {
    text-align: center;
    margin-bottom: 56px;
    position: relative;
    z-index: 1;
}

.characters-header h1 {
    margin-bottom: 12px;
}

.characters-subtitle {
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.5px;
}

.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 28px;
}

.character-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(1.4);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.character-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: opacity 0.4s;
    z-index: 2;
}

.character-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-xl);
    opacity: 0;
    transition: opacity 0.5s;
    background: radial-gradient(600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%), rgba(167, 139, 250, 0.06), transparent 40%);
    z-index: 1;
    pointer-events: none;
}

.character-card:hover {
    transform: translateY(-8px) perspective(800px) rotateY(calc((var(--mouse-x, 50%) - 50%) * 0.05deg)) rotateX(calc((50% - var(--mouse-y, 50%)) * 0.05deg));
    border-color: var(--glass-border-hover);
    background: var(--glass-bg-hover);
    box-shadow:
        0 20px 40px rgba(0, 0, 0, 0.4),
        0 0 40px rgba(82, 39, 255, 0.1),
        0 0 80px rgba(255, 159, 252, 0.05);
}

.character-card:hover::after {
    opacity: 1;
}

.character-portrait {
    width: 100%;
    height: 340px;
    object-fit: cover;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.character-card:hover .character-portrait {
    transform: scale(1.03);
}

.character-info {
    padding: 28px;
    position: relative;
    z-index: 2;
}

.character-info h2 {
    margin-bottom: 10px;
    color: var(--text-primary);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.character-info p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.7;
}

/* ==================== Chat Page ==================== */
.chat-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-base);
    position: relative;
}

.chat-page #moltenCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.chat-page > *:not(#moltenCanvas):not(.theme-toggle):not(#scenePanel) {
    position: relative;
    z-index: 1;
}

#chatStage {
    position: relative;
    flex: 1;
    overflow: hidden;
    background: rgba(6, 6, 10, 0.75);
}

#chatStage[data-scene="daily"] { background: linear-gradient(180deg, rgba(30,30,50,0.9) 0%, rgba(20,20,35,0.95) 100%); }
#chatStage[data-scene="cafe"] { background: linear-gradient(135deg, rgba(80,60,50,0.85) 0%, rgba(60,40,50,0.9) 100%); }
#chatStage[data-scene="park"] { background: linear-gradient(135deg, rgba(50,40,70,0.85) 0%, rgba(70,50,40,0.9) 100%); }
#chatStage[data-scene="movie"] { background: linear-gradient(135deg, rgba(30,30,60,0.9) 0%, rgba(50,25,70,0.9) 100%); }
#chatStage[data-scene="beach"] { background: linear-gradient(135deg, rgba(20,50,70,0.85) 0%, rgba(30,40,80,0.9) 100%); }

[data-theme="light"] #chatStage {
    background: rgba(245, 245, 250, 0.8);
}

[data-theme="light"] #chatStage[data-scene="daily"] { background: linear-gradient(180deg, rgba(248,249,252,0.92) 0%, rgba(238,240,246,0.95) 100%); }
[data-theme="light"] #chatStage[data-scene="cafe"] { background: linear-gradient(135deg, rgba(250,240,232,0.92) 0%, rgba(246,232,236,0.94) 100%); }
[data-theme="light"] #chatStage[data-scene="park"] { background: linear-gradient(135deg, rgba(240,236,248,0.92) 0%, rgba(248,240,232,0.94) 100%); }
[data-theme="light"] #chatStage[data-scene="movie"] { background: linear-gradient(135deg, rgba(232,232,244,0.92) 0%, rgba(240,230,246,0.94) 100%); }
[data-theme="light"] #chatStage[data-scene="beach"] { background: linear-gradient(135deg, rgba(228,242,248,0.92) 0%, rgba(232,236,250,0.94) 100%); }

.portrait-stage {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    transform-origin: 50% 100%;
}

.portrait-glow {
    position: absolute;
    right: -5%;
    bottom: -10%;
    width: 65%;
    height: 95%;
    background: radial-gradient(ellipse at 60% 65%, rgba(167, 139, 250, 0.28), transparent 70%);
    filter: blur(6px);
}

[data-theme="light"] .portrait-glow {
    background: radial-gradient(ellipse at 60% 65%, rgba(167, 139, 250, 0.18), transparent 70%);
}

.sprite {
    position: absolute;
    bottom: 0;
    right: 3%;
    height: 88%;
    max-width: 62%;
    width: auto;
    object-fit: contain;
    object-position: bottom center;
    opacity: 0;
    transition: opacity 0.4s ease;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
}

.sprite.visible {
    opacity: 1;
}

.blush-overlay {
    position: absolute;
    right: 12%;
    bottom: 58%;
    width: 34%;
    height: 16%;
    background: radial-gradient(ellipse at center, rgba(255, 90, 120, 0.5), transparent 70%);
    filter: blur(10px);
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.blush-overlay.on {
    opacity: 1;
}

#portraitStage[data-expr="normal"] .sprite.visible { animation: sprite-breathe 4s ease-in-out infinite; }
#portraitStage[data-expr="happy"] .sprite.visible { animation: sprite-bounce 1.1s ease-in-out infinite; }
#portraitStage[data-expr="shy"] .sprite.visible { animation: sprite-sway 2.6s ease-in-out infinite; }
#portraitStage[data-expr="angry"] .sprite.visible { animation: sprite-shake 0.55s ease-in-out 4; }
#portraitStage[data-expr="sad"] .sprite.visible {
    animation: sprite-droop 3.2s ease-in-out infinite;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35)) saturate(0.85) brightness(0.95);
}

#portraitStage.expr-pop {
    animation: expr-pop 0.45s ease;
}

@keyframes sprite-breathe {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-6px) scale(1.01); }
}

@keyframes sprite-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    30% { transform: translateY(-14px) rotate(-1.5deg); }
    60% { transform: translateY(-4px) rotate(1deg); }
}

@keyframes sprite-sway {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-5px) rotate(-1deg); }
    75% { transform: translateX(5px) rotate(1deg); }
}

@keyframes sprite-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(4px); }
}

@keyframes sprite-droop {
    0%, 100% { transform: translateY(2px) scale(1); }
    50% { transform: translateY(8px) scale(0.995); }
}

@keyframes expr-pop {
    0% { transform: scale(0.97); }
    55% { transform: scale(1.025); }
    100% { transform: scale(1); }
}

.chat-header {
    background: rgba(10, 10, 18, 0.9);
    backdrop-filter: blur(20px) saturate(1.5);
    color: white;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 0 var(--border-subtle), 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 10;
    position: relative;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(167, 139, 250, 0.2), transparent);
}

.chat-header img {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(167, 139, 250, 0.3);
    box-shadow: 0 0 20px rgba(82, 39, 255, 0.15);
}

.chat-header-info h2 {
    font-size: 18px;
    margin-bottom: 4px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.chat-header-info p {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
}

.chat-messages {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow-y: auto;
    padding: 24px;
    background: transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.message {
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    animation: messageSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: linear-gradient(135deg, #5227FF 0%, #a78bfa 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 2px 12px rgba(82, 39, 255, 0.2);
}

.message-bubble {
    max-width: 70%;
    padding: 14px 18px;
    border-radius: 18px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    position: relative;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #5227FF 0%, #7c3aed 100%);
    color: white;
    border-bottom-right-radius: 4px;
    border-color: rgba(167, 139, 250, 0.2);
    box-shadow: 0 4px 16px rgba(82, 39, 255, 0.2);
}

.message.assistant .message-bubble {
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    padding: 18px 24px;
    background: rgba(10, 10, 18, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: 12px;
    align-items: center;
    position: relative;
}

.chat-input-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(167, 139, 250, 0.15), transparent);
}

.chat-input-area input {
    flex: 1;
    min-width: 0;
    padding: 14px 20px;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    font-size: 15px;
    font-family: inherit;
    transition: all 0.3s ease;
    background: var(--input-bg);
    color: var(--text-primary);
}

.chat-input-area button {
    flex-shrink: 0;
}

.chat-input-area input:focus {
    outline: none;
    border-color: var(--accent-purple);
    background: var(--input-bg-focus);
    box-shadow: 0 0 0 4px rgba(82, 39, 255, 0.08);
}

.chat-input-area input::placeholder {
    color: var(--text-muted);
}

.chat-input-area button {
    padding: 14px 28px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 16px rgba(82, 39, 255, 0.25);
    letter-spacing: 0.5px;
}

.chat-input-area button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(82, 39, 255, 0.35);
}

#ttsToggle {
    padding: 14px 18px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    opacity: 0.5;
    font-size: 20px;
    box-shadow: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ttsToggle:hover {
    border-color: var(--accent-purple);
    opacity: 0.8;
    background: rgba(167, 139, 250, 0.1);
}

/* ==================== Voice Input ==================== */
.hidden {
    display: none !important;
}

#inputModeBtn {
    padding: 0;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    font-size: 20px;
    box-shadow: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#inputModeBtn:hover:not(:disabled) {
    border-color: var(--accent-purple);
    background: rgba(167, 139, 250, 0.1);
}

#inputModeBtn:disabled {
    cursor: not-allowed;
}

#holdTalkBtn {
    flex: 1;
    padding: 14px 20px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 3px;
    border-radius: 24px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: background 0.2s ease, border-color 0.2s ease;
}

#holdTalkBtn.recording {
    border-color: var(--accent-purple);
    background: rgba(167, 139, 250, 0.18);
}

#holdTalkBtn.cancelling {
    border-color: #ff5470;
    background: rgba(255, 84, 112, 0.18);
    color: #ff8fa3;
}

.voice-overlay {
    position: fixed;
    left: 50%;
    bottom: 110px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 26px;
    border-radius: 20px;
    background: rgba(12, 12, 22, 0.92);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    color: var(--text-primary);
    z-index: 300;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    max-width: calc(100vw - 32px);
}

.voice-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff5470;
    flex-shrink: 0;
    animation: voicePulse 1s ease-in-out infinite;
}

.voice-overlay.recognising .voice-dot {
    animation: none;
    background: var(--accent-purple);
}

.voice-text {
    font-size: 15px;
    line-height: 1.4;
    max-width: 62vw;
    max-height: 3.9em;
    overflow-y: auto;
    margin-bottom: 4px;
    word-break: break-all;
}

.voice-hint {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.voice-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
}

.voice-overlay.cancelling {
    border-color: rgba(255, 84, 112, 0.6);
}

.voice-overlay.cancelling .voice-hint {
    color: #ff8fa3;
}

.voice-overlay.cancelling .voice-dot {
    animation: none;
}

@keyframes voicePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.55; }
}

/* ==================== Scene Toggle Button ==================== */
.scene-toggle-btn {
    margin-left: auto;
    padding: 10px 14px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.scene-toggle-btn:hover {
    background: var(--glass-bg-hover);
    border-color: var(--glass-border-hover);
    color: var(--accent-purple);
    box-shadow: 0 0 20px rgba(82, 39, 255, 0.1);
}

/* ==================== Scene Panel ==================== */
.scene-panel {
    position: fixed;
    top: 0;
    right: -380px;
    width: 360px;
    height: 100vh;
    background: rgba(10, 10, 18, 0.97);
    backdrop-filter: blur(24px) saturate(1.5);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
    z-index: 100;
    transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--glass-border);
}

.scene-panel.open {
    right: 0;
}

.scene-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(15, 15, 25, 0.8);
    color: white;
    position: relative;
}

.scene-panel-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(167, 139, 250, 0.15), transparent);
}

.scene-panel-header h3 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.scene-panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.scene-panel-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.scene-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.scene-list::-webkit-scrollbar {
    width: 4px;
}

.scene-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.scene-item {
    display: flex;
    gap: 14px;
    padding: 16px;
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-subtle);
    background: var(--glass-bg);
}

.scene-item:hover {
    background: rgba(167, 139, 250, 0.06);
    border-color: rgba(167, 139, 250, 0.2);
    transform: translateX(-4px);
}

.scene-item.active {
    background: rgba(167, 139, 250, 0.08);
    border-color: rgba(167, 139, 250, 0.3);
    box-shadow: 0 0 20px rgba(82, 39, 255, 0.08);
}

.scene-item.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.scene-item.locked:hover {
    transform: none;
    border-color: var(--border-subtle);
    background: var(--glass-bg);
}

.scene-preview {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.scene-info {
    flex: 1;
    min-width: 0;
}

.scene-info strong {
    display: block;
    font-size: 15px;
    margin-bottom: 4px;
    color: var(--text-primary);
    font-weight: 600;
}

.scene-info p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.scene-lock {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ==================== Scene Actions Bar ==================== */
.scene-actions-bar {
    display: flex;
    gap: 8px;
    padding: 12px 24px;
    background: rgba(10, 10, 18, 0.9);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto;
    flex-shrink: 0;
}

.scene-actions-bar:empty {
    display: none;
}

.scene-actions-bar::-webkit-scrollbar {
    height: 0;
}

.scene-action-btn {
    padding: 8px 18px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-secondary);
    font-weight: 500;
}

.scene-action-btn:hover {
    border-color: var(--accent-purple);
    color: var(--accent-purple);
    background: rgba(167, 139, 250, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(82, 39, 255, 0.15);
}

/* ==================== System Message ==================== */
.message.system {
    text-align: center;
    justify-content: center;
    gap: 0;
}

.message.system .message-avatar {
    display: none;
}

.message.system {
    font-size: 13px;
    color: var(--text-muted);
    background: none;
    padding: 8px 0;
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .login-box {
        padding: 40px 28px;
    }

    .login-box h1 {
        font-size: 28px;
    }

    .characters-page {
        padding: 40px 16px;
    }

    .characters-page h1 {
        font-size: 30px;
        margin-bottom: 36px;
    }

    .characters-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .message-bubble {
        max-width: 80%;
    }

    .scene-panel {
        width: 100%;
        right: -100%;
    }

    .scene-actions-bar {
        padding: 10px 16px;
    }

    .chat-input-area {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        gap: 8px;
    }

    .chat-input-area input {
        padding: 12px 14px;
        font-size: 14px;
    }

    .chat-input-area #sendBtn {
        padding: 12px 16px;
        font-size: 13px;
    }

    #ttsToggle,
    #inputModeBtn {
        width: 40px;
        height: 40px;
        font-size: 17px;
    }

    #holdTalkBtn {
        padding: 12px 10px;
        letter-spacing: 2px;
    }

    .voice-overlay {
        bottom: 84px;
    }
}

@media (max-width: 768px) {
    .sprite {
        height: 62%;
        right: 0;
        max-width: 70%;
    }

    .sprite.visible {
        opacity: 0.55;
    }

    .blush-overlay {
        bottom: 46%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sprite.visible,
    #portraitStage.expr-pop {
        animation: none !important;
    }
}

.icp-footer {
    position: fixed;
    bottom: 10px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 12px;
    z-index: 10;
    pointer-events: none;
}

.icp-footer a {
    color: rgba(140, 140, 155, 0.8);
    text-decoration: none;
    pointer-events: auto;
}

.icp-footer a:hover {
    text-decoration: underline;
}
