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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a2e;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
}

/* Main app container - LOCKED */
#app {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    contain: strict;
    z-index: 1;
}

/* Background image container - FIXED CENTERED */
#avatar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    z-index: 2;
}

/* Live2D canvas - FIXED CENTERED */
#live2d-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2;
    display: none;
    background: #FFFFFF;
}

/* Subtitle - FIXED CENTERED */
#subtitle {
    position: fixed;
    bottom: 15%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 18px;
    max-width: 80%;
    text-align: center;
    opacity: 0;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(10px);
    z-index: 10;
    will-change: opacity, transform;
}

#subtitle.visible {
    opacity: 1;
}

/* Loading indicator - FIXED CENTERED */
#loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 20px 40px;
    border-radius: 10px;
    font-size: 18px;
    z-index: 100;
    display: none;
    will-change: transform;
}

/* Mic guide - FIXED CENTERED */
#mic-guide {
    position: fixed;
    bottom: 115px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    text-align: center;
    z-index: 10;
    pointer-events: none;
    will-change: transform;
}

/* Input area - FIXED CENTERED */
#input-area {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: #ff8c00;
    padding: 10px 15px;
    border-radius: 30px;
    backdrop-filter: blur(10px);
    z-index: 20;
    will-change: transform;
}

/* Mic button */
.mic-button {
    width: 55px;
    height: 55px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.mic-button:hover {
    transform: scale(1.1);
}

.mic-button:active {
    transform: scale(0.95);
}

.mic-button.recording {
    animation: pulse 1s infinite;
    background: linear-gradient(135deg, #ff4757 0%, #ff6b81 100%);
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 10px rgba(233, 69, 96, 0.5); }
    50% { box-shadow: 0 0 25px rgba(233, 69, 96, 0.9); }
}

/* Text input */
#userText {
    flex: 1;
    padding: 12px 15px;
    font-size: 16px;
    border: none;
    border-radius: 20px;
    background: white;
    color: black;
    outline: none;
    min-width: 150px;
    max-width: 250px;
}

#userText::placeholder {
    color: rgba(0, 0, 0, 0.5);
}

#userText:focus {
    background: white;
}

/* Send button */
.send-button {
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 50%;
    background: #1a46a5;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.send-button:hover {
    background: #2456b8;
    transform: scale(1.1);
}

/* Model type selector - FIXED TOP RIGHT */
#model-selector {
    position: fixed;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 5px;
    z-index: 30;
    background: rgba(0, 0, 0, 0.6);
    padding: 5px;
    border-radius: 25px;
    backdrop-filter: blur(10px);
    will-change: transform;
}

.model-btn {
    padding: 8px 18px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.model-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.model-btn.active {
    background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
    color: white;
}

/* History button - FIXED TOP LEFT */
.history-button {
    position: fixed;
    top: 15px;
    left: 15px;
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 22px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 1001;
    backdrop-filter: blur(10px);
    will-change: transform;
}

.history-button:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.history-button:active {
    transform: scale(0.95);
}

/* History count badge */
.history-count {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e94560;
    color: white;
    font-size: 10px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    font-weight: bold;
}

/* History modal overlay - FIXED */
.history-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: none;
    justify-content: flex-start;
    align-items: flex-start;
    padding-top: 80px;
    padding-left: 80px;
    backdrop-filter: blur(5px);
}

.history-modal.show {
    display: flex;
}

/* History modal content */
.history-content {
    background: #1a1a2e;
    border-radius: 15px;
    width: 400px;
    max-width: 90vw;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    transform: none !important;
    margin: 0 !important;
}

/* History header */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px 15px 0 0;
}

.history-header h3 {
    color: white;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

/* History search */
.history-search-container {
    padding: 10px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.history-search {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: white;
    outline: none;
}

.history-search::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.history-search:focus {
    border-color: #e94560;
    background: rgba(255, 255, 255, 0.1);
}

/* Close button */
.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #e94560;
}

/* History list */
.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* History item */
.history-item {
    padding: 12px 45px 12px 15px;
    margin-bottom: 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-left: 4px solid transparent;
    transition: background 0.2s;
    position: relative;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Delete entry button */
.delete-entry-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 18px;
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
    padding: 0;
}

.delete-entry-btn:hover {
    color: #e94560;
    background: rgba(233, 69, 96, 0.1);
    transform: scale(1.1);
}

.delete-entry-btn:active {
    transform: scale(0.9);
}

.history-item.user {
    border-left-color: #e94560;
}

.history-item.ai {
    border-left-color: #4CAF50;
}

.history-message {
    color: white;
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    word-wrap: break-word;
}

.history-time {
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    margin-top: 5px;
}

/* Empty history */
.history-empty {
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    padding: 40px 20px;
    font-style: italic;
}

/* History footer */
.history-footer {
    padding: 10px 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 15px 15px;
}

/* Clear history button */
.clear-history-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 20px;
    background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.clear-history-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.clear-history-btn:active {
    transform: scale(0.98);
}

/* Export history button */
.export-history-btn {
    padding: 8px 20px;
    border: 1px solid #4CAF50;
    border-radius: 20px;
    background: transparent;
    color: #4CAF50;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    margin-left: 10px;
}

.export-history-btn:hover {
    background: #4CAF50;
    color: white;
    transform: scale(1.05);
}

.export-history-btn:active {
    transform: scale(0.98);
}

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

.history-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

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

.history-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Mobile adjustments */
@media (max-width: 600px) {
    body, html {
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
    
    #app {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 1;
    }
    
    #app::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(26, 26, 46, 0.7);
        z-index: 1;
    }
    
    #avatar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 2;
    }

    #live2d-canvas {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 2;
    }
    
    #input-area {
        width: 90%;
        bottom: 60px;
        padding: 8px 12px;
        z-index: 20;
    }
    
    #mic-guide {
        bottom: 80px;
    }
    
    .mic-button {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
    
    #userText {
        padding: 10px 12px;
        font-size: 14px;
        min-width: 120px;
    }
    
    .send-button {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    #subtitle {
        bottom: 15%;
        font-size: 14px;
        padding: 10px 20px;
        z-index: 20;
    }

    #model-selector {
        top: 10px;
        right: 10px;
        padding: 3px;
    }

    .model-btn {
        padding: 6px 14px;
        font-size: 12px;
    }
    
    .history-button {
        top: 10px;
        left: 10px;
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .history-count {
        top: -3px;
        right: -3px;
        min-width: 16px;
        height: 16px;
        font-size: 9px;
    }
    
    .history-content {
        width: 95%;
        max-height: 85vh;
        margin-top: 60px;
        margin-left: 10px;
    }
    
    .history-header h3 {
        font-size: 16px;
    }
    
    .history-message {
        font-size: 13px;
    }
    
    .close-btn {
        font-size: 24px;
    }
    
    .clear-history-btn {
        padding: 6px 15px;
        font-size: 12px;
    }
}

/* Hide old elements */
#controls, #help, #chat-container {
    display: none !important;
}