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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    flex-direction: column;
    background: white;
    position: relative;
}

/* Header */
.device-header {
    background: #1E2152;
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.device-header .logo {
    height: 32px;
    filter: brightness(0) invert(1);
    flex-shrink: 0;
}

.device-header h1 {
    font-size: 0.95rem;
    font-weight: 500;
    margin: 0;
    opacity: 0.9;
    flex: 1;
}

.device-header p {
    display: none;
}

/* Burger Menu Button */
.burger-menu {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.burger-menu:hover {
    opacity: 0.8;
}

/* Mode Dropdown */
.mode-dropdown {
    position: absolute;
    top: 56px;
    right: 8px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 160px;
    overflow: hidden;
}

.mode-dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border: none;
    background: white;
    cursor: pointer;
    font-size: 0.95rem;
    color: #374151;
    transition: background 0.2s;
    text-align: left;
}

.mode-dropdown-item:hover {
    background: #f9fafb;
}

.mode-dropdown-item.active {
    background: #f0f4ff;
    color: #1E2152;
    font-weight: 500;
}

.mode-dropdown-item i {
    font-size: 1.2rem;
    width: 20px;
    text-align: center;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    padding-bottom: 90px; /* Space for fixed input area */
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    height: calc(100vh - 64px - 72px); /* Full height minus header and input */
    max-height: calc(100vh - 64px - 72px);
}

/* Messages */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-in;
}

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

.message p {
    margin: 0;
}

/* Markdown styling inside messages */
.message strong {
    font-weight: 600;
    color: inherit;
}

.message ul {
    margin: 8px 0 0 0;
    padding-left: 0;
    list-style-position: inside;
}

.message li {
    margin: 4px 0;
    line-height: 1.5;
}

.message br {
    display: block;
    content: "";
    margin: 4px 0;
}

.message.user {
    align-self: flex-end;
    background: #1E2152;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #e5e7eb;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.message.loading p {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.4;
    }
    50% {
        opacity: 1;
    }
}

/* Input Area */
.input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: white;
    flex-shrink: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    /* Fixed at bottom */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.input-area input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    font-size: 16px;
    outline: none;
    font-family: inherit;
    background: #f9fafb;
    transition: all 0.2s;
}

.input-area input:focus {
    border-color: #1E2152;
    background: white;
}

.input-area input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.voice-btn, .send-btn, .auto-listen-btn, .camera-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.voice-btn {
    background: #f3f4f6;
    color: #374151;
    display: none; /* Hidden by default (Realtime mode uses auto-listen-btn) */
}

.voice-btn:hover {
    background: #e5e7eb;
}

.voice-btn:active {
    transform: scale(0.95);
}

.voice-btn.recording {
    background: #ef4444;
    animation: pulse-recording 1s infinite;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.3);
}

.voice-btn.recording::after {
    content: '●';
    color: white;
    font-size: 24px;
}

@keyframes pulse-recording {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.3);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.2);
    }
}

.voice-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn {
    background: #1E2152;
    color: white;
}

.send-btn:hover:not(:disabled) {
    background: #151841;
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Auto-Listen Button */
.auto-listen-btn {
    background: #f3f4f6;
    color: #374151;
}

.auto-listen-btn:hover {
    background: #e5e7eb;
}

.auto-listen-btn.active {
    background: #10b981;
    color: white;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.3);
    animation: pulse-active 2s infinite;
}

.auto-listen-btn.active:hover {
    background: #059669;
}

@keyframes pulse-active {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.3);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0.2);
    }
}

/* Camera Button */
.camera-btn {
    background: #f3f4f6;
    color: #374151;
}

.camera-btn:hover {
    background: #e5e7eb;
}

.camera-btn:active {
    transform: scale(0.95);
}

/* Image message styling */
.image-message {
    align-self: flex-end;
    max-width: 85%;
}

.image-message img {
    max-width: 200px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: block;
}

/* Safe area for iPhone notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}

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

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

.chat-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Error message */
.message.error {
    background: #fee2e2;
    color: #991b1b;
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.typing-indicator {
    padding: 12px 16px;
    display: flex;
    align-items: center;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Loading indicator for recording */
.recording-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #fef3c7;
    border-radius: 12px;
    font-size: 0.875rem;
    color: #92400e;
    align-self: flex-start;
}

.recording-indicator .dot {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

/* Mobile optimizations */
@media (max-width: 600px) {
    .container {
        max-width: 100%;
    }

    .message {
        max-width: 90%;
    }
}

/* Landscape mode */
@media (max-height: 500px) {
    .device-header {
        padding: 12px 20px;
    }

    .device-header h1 {
        font-size: 1rem;
    }

    .device-header p {
        display: none;
    }
}


/* Training Progress Bar */
.training-progress {
    padding: 12px 16px;
    background: #fef3c7;
    border-bottom: 1px solid #fde047;
    flex-shrink: 0;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.875rem;
    color: #78350f;
    font-weight: 500;
}

.progress-bar {
    height: 8px;
    background: #fef9c3;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #fbbf24, #f59e0b);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Quiz Score Display */
.quiz-score {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background: #f0fdf4;
    border-bottom: 1px solid #bbf7d0;
    flex-shrink: 0;
}

.score-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.score-label {
    font-size: 0.75rem;
    color: #166534;
    font-weight: 500;
}

.score-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #15803d;
}

