:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --text: #eaeaea;
    --text-muted: #a8a8b3;
    --border: #2d2d44;
    --voice-active: #27ae60;
    --truck-green: #2ecc71;
    --truck-yellow: #f39c12;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    width: 100%;
    max-width: 800px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

header {
    text-align: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.truck-emoji {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.voice-toggle {
    margin-top: 1rem;
}

.voice-btn {
    background: var(--bg-card);
    border: 2px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.voice-btn.active {
    border-color: var(--voice-active);
    color: var(--voice-active);
    background: rgba(39, 174, 96, 0.1);
}

.voice-btn:hover {
    border-color: var(--text);
    color: var(--text);
}

.progress-bar {
    height: 4px;
    background: var(--bg-card);
    margin: 0.5rem 0;
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    transition: width 0.3s ease;
}

/* Topic Indicators Styles */
.topic-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.topic-chip {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.topic-chip.discussed {
    border-color: var(--truck-yellow);
    color: var(--truck-yellow);
    background: rgba(243, 156, 18, 0.1);
}

.topic-chip.mastered {
    border-color: var(--truck-green);
    color: var(--truck-green);
    background: rgba(46, 204, 113, 0.1);
}

.topic-chip.mastered::before {
    content: '✅';
    font-size: 0.7rem;
}

.topic-chip.discussed::before {
    content: '🚧';
    font-size: 0.7rem;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 85%;
    padding: 1rem;
    border-radius: 1rem;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.25rem;
}

.message-header {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.message.user .message-header {
    color: rgba(255,255,255,0.8);
}

.speaker-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: 0.5rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.speaker-btn:hover {
    opacity: 1;
}

.input-area {
    padding: 1rem 0;
    border-top: 1px solid var(--border);
}

.typing-indicator {
    display: none;
    gap: 4px;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.typing-indicator.active {
    display: flex;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#messageInput {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.875rem 1rem;
    border-radius: 1.5rem;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: var(--accent);
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.mic-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    border: 2px solid var(--border);
}

.mic-btn:hover {
    border-color: var(--accent);
}

.mic-btn:active,
.mic-btn.recording {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(0.95);
}

.mic-btn.recording {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(233, 69, 96, 0); }
    100% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0); }
}

.send-btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 1.5rem;
    background: var(--accent);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.mic-hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.controls {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    padding-top: 0.75rem;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.secondary-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 1rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

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

.progress-stats {
    margin-top: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.stat-row:last-child {
    border-bottom: none;
}

.topic-list {
    margin-top: 1rem;
}

.topic-list h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
}

.topic-tag {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    margin: 0.25rem;
    border-radius: 1rem;
    font-size: 0.85rem;
}

.topic-tag.weak {
    background: rgba(233, 69, 96, 0.2);
    color: var(--accent);
}

.topic-tag.strong {
    background: rgba(46, 204, 113, 0.2);
    color: var(--truck-green);
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .container {
        padding: 0.5rem;
        padding-bottom: env(safe-area-inset-bottom, 0.5rem);
    }
    
    header {
        padding: 0.75rem 0;
    }
    
    .truck-emoji {
        font-size: 2.5rem;
    }
    
    h1 {
        font-size: 1.15rem;
    }
    
    .subtitle {
        font-size: 0.85rem;
    }
    
    .voice-btn {
        padding: 0.75rem 1.25rem;
        font-size: 1rem;
        min-height: 44px;
        min-width: 44px;
    }
    
    .message {
        max-width: 90%;
        padding: 0.875rem;
        font-size: 1rem;
        line-height: 1.6;
    }
    
    .message-header {
        font-size: 0.8rem;
    }
    
    .message-body {
        font-size: 1rem;
    }
    
    /* Bigger touch targets for mobile */
    .mic-btn {
        width: 64px;
        height: 64px;
        min-width: 64px;
        min-height: 64px;
    }
    
    .mic-icon {
        font-size: 1.5rem;
    }
    
    .send-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0.875rem 1.25rem;
    }
    
    #messageInput {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 1rem 1.25rem;
    }
    
    .input-row {
        gap: 0.75rem;
    }
    
    .controls {
        flex-wrap: nowrap;
        gap: 0.5rem;
        padding-top: 0.5rem;
    }
    
    .secondary-btn {
        flex: 1;
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
    }
    
    .mic-hint {
        font-size: 0.75rem;
        margin-top: 0.75rem;
    }
    
    /* Touch feedback */
    .mic-btn:active,
    .send-btn:active,
    .secondary-btn:active {
        opacity: 0.8;
        transform: scale(0.97);
    }
    
    /* Prevent pull-to-refresh in chat area */
    .chat-container {
        overscroll-behavior: contain;
    }
    
    /* Voice-first mode styling */
    body.voice-dominant .input-row {
        align-items: center;
    }
    
    body.voice-dominant #messageInput {
        border-radius: 2rem;
    }

    .topic-chip {
        font-size: 0.7rem;
        padding: 3px 8px;
    }
}

/* Handle keyboard open on mobile */
@media (max-height: 500px) and (max-width: 600px) {
    .truck-emoji {
        font-size: 1.5rem;
    }
    
    h1, .subtitle {
        display: none;
    }
    
    .chat-container {
        max-height: calc(100vh - 120px);
    }
}

/* Large phone adjustments */
@media (min-width: 601px) and (max-width: 900px) {
    .container {
        max-width: 100%;
        padding: 1rem 2rem;
    }
}
