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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #ffffff; /* Pure white background to match iframe */
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height - fixes iPhone URL bar issue */
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height - fixes iPhone URL bar issue */
    max-width: 800px;
    margin: 0 auto;
    background: #ffffff; /* Pure white background to match iframe */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    border-radius: 12px; /* Rounded corners for desktop */
    overflow: hidden; /* Ensures content stays within rounded corners */
    border: 1px solid #ffffff; /* White border to fill any gaps */
}

/* Top Bar */
.top-bar {
    background: linear-gradient(135deg, #FF6A00 0%, #F36 100%);
    color: white;
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.logo-container {
    flex-shrink: 0;
}

#logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

.top-bar h1 {
    font-size: 1.5rem;
    font-weight: 600;
    flex: 1;
    min-width: 0;
}

.level-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.level-selector label {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

.level-dropdown {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    outline: none;
}

.level-dropdown:hover {
    background: rgba(255, 255, 255, 0.3);
}

.level-dropdown:focus {
    border-color: white;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.level-dropdown option {
    background: #FF6A00;
    color: white;
}

.reset-chat-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.reset-chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: white;
    transform: scale(1.1);
}

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

/* Begin Chat Button */
.begin-chat-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    background: #f8f9fa;
    flex: 1;
}

.begin-chat-btn {
    background: linear-gradient(135deg, #FF6A00 0%, #F36 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 106, 0, 0.4);
}

.begin-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 106, 0, 0.6);
}

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

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8f9fa;
}

.message {
    margin-bottom: 1rem;
    display: flex;
    animation: fadeIn 0.3s ease-in;
}

.message.student {
    justify-content: flex-end;
}

.message.tutor {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
}

.message.student .message-content {
    background: #FF6A00;
    color: white;
    border-bottom-right-radius: 4px;
    position: relative;
    padding-right: 3rem; /* Make room for feedback icon */
}

.message.tutor .message-content {
    background: white;
    color: #333;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding-right: 2.5rem;
}

.replay-btn {
    position: absolute;
    right: 0.3rem;
    top: calc(50% - 0.3rem);
    transform: translateY(-50%);
    background: #ff6b35;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.replay-btn:hover {
    background: #e55a2b;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
    transform: translateY(-50%) scale(1.05);
}

/* Feedback Icons */
.feedback-icon {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.feedback-icon.correct {
    background: #4caf50;
    color: white;
}

.feedback-icon.warning {
    background: #ffa726;
    color: white;
}

.feedback-icon:hover {
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.feedback-icon.correct:hover {
    background: #45a049;
}

.feedback-icon.warning:hover {
    background: #ff9800;
}

/* Loading Dots */
.loading-dots {
    animation: fadeIn 0.3s ease-in;
}

/* Situational Practice Styles */
.situational-selection {
    text-align: center;
    padding: 2rem;
    max-width: 600px;
    margin: 0 auto;
}

.situational-selection h2 {
    color: #333;
    margin-bottom: 2rem;
    font-size: 1.5rem;
}

.level-buttons, .topic-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}

.level-btn, .topic-btn {
    background: #ff6b35;
    color: white;
    border: none;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-height: 80px;
    justify-content: center;
}

.topic-icon {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.topic-text {
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
}

.level-btn:hover, .topic-btn:hover {
    background: #e55a2b;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
}

.level-btn:active, .topic-btn:active {
    transform: translateY(0);
}

.loading-content {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.75rem 1rem;
}

.loading-content .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #666;
    animation: loadingDot 1.4s infinite ease-in-out;
}

.loading-content .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-content .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.loading-content .dot:nth-child(3) {
    animation-delay: 0s;
}

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

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

/* Bottom Bar */
.bottom-bar {
    background: white;
    border-top: 1px solid #e1e5e9;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)); /* iOS safe area bottom padding */
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}

.input-area {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.mic-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.mic-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF6A00 0%, #F36 100%);
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    box-shadow: 0 6px 20px rgba(255, 106, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-icon svg {
    width: 24px;
    height: 24px;
    display: block;
}

.mic-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(255, 106, 0, 0.6);
}

.mic-btn:active {
    transform: translateY(-1px) scale(0.98);
    box-shadow: 0 4px 15px rgba(255, 106, 0, 0.4);
}

.mic-btn.recording {
    background: #e74c3c;
    animation: pulse 1.5s infinite;
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.6);
}

@keyframes pulse {
    0% { transform: scale(1.1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1.1); }
}

.mic-label {
    font-size: 0.85rem;
    color: #666;
    font-weight: 500;
    text-align: center;
    margin-top: 0.3rem;
}

.timer {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
}

.text-input-container {
    flex: 1;
    display: flex;
    gap: 0.5rem;
}

#textInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #e1e5e9;
    border-radius: 25px;
    font-size: 16px; /* Minimum font size to prevent zoom on mobile */
    outline: none;
    transition: border-color 0.3s ease;
    touch-action: manipulation; /* Prevent touch zoom */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Prevent auto-scroll when input is focused */
#textInput:focus {
    scroll-behavior: auto;
}

/* Keep chat area visible */
.chat-area {
    scroll-behavior: auto;
}

#textInput:focus {
    border-color: #FF6A00;
}

.send-btn {
    background: #FF6A00;
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 50%;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
}

.send-btn:hover {
    background: #F36;
    transform: translateY(-1px);
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Audio Overlay */
.audio-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.audio-overlay-content {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.audio-overlay-content p {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: #333;
}

#unlockAudioBtn {
    background: #FF6A00;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

#unlockAudioBtn:hover {
    background: #F36;
    transform: translateY(-1px);
}

/* Error Toast */
.error-toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: #e74c3c;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    animation: slideIn 0.3s ease;
    max-width: 300px;
}

/* Success Toast */
.success-toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: #27ae60;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    animation: slideIn 0.3s ease;
    max-width: 300px;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive Design */
@media (max-width: 768px) {
    .app {
        height: 100vh; /* Fallback for older browsers */
        height: 100dvh; /* Dynamic viewport height - fixes iPhone URL bar issue */
        max-width: none;
        border-radius: 20px; /* Larger rounded corners for mobile */
        box-shadow: none; /* Remove shadow on mobile to eliminate grey areas */
    }
    
    .top-bar {
        padding: 0.75rem; /* Slightly thicker banner for mobile */
    }
    
    .header-content {
        flex-direction: row; /* Keep horizontal layout */
        gap: 0.5rem;
        align-items: center;
        text-align: left;
    }
    
    .top-bar h1 {
        font-size: 1rem; /* Smaller title */
        flex: 1;
    }
    
    .level-selector {
        flex-direction: column; /* Stack label under selector */
        gap: 0.25rem;
        flex-shrink: 0;
        align-items: center;
    }
    
    .level-selector label {
        display: block; /* Show label under the selector */
        font-size: 0.7rem;
        text-align: center;
        margin-top: 0.25rem;
        opacity: 0.9;
    }
    
    .level-dropdown {
        padding: 0.3rem 0.6rem; /* Smaller dropdown */
        font-size: 0.75rem;
    }
    
    .reset-chat-btn {
        width: 32px; /* Slightly bigger reset button */
        height: 32px;
    }
    
    #logo {
        width: 32px; /* Smaller logo */
        height: 32px;
    }
    
    .input-area {
        justify-content: center;
        width: 100%;
    }
    
    .mic-btn {
        width: 70px; /* Larger microphone button for mobile */
        height: 70px;
        font-size: 1.8rem; /* Larger icon */
    }
    
    .message-content {
        max-width: 85%;
        font-size: 0.9rem;
    }
    
    .message.student .message-content {
        padding-right: 2.5rem; /* Adjust for smaller screens */
    }
    
    .feedback-icon {
        width: 20px;
        height: 20px;
        right: 0.4rem;
    }
    
    .bottom-bar {
        padding: 0.8rem; /* Smaller padding for voice-only */
    }
    
    .mic-label {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .app {
        border-radius: 24px; /* Even larger rounded corners for small mobile */
    }
    
    .top-bar {
        padding: 0.6rem; /* Slightly thicker banner for very small screens */
    }
    
    .header-content {
        gap: 0.25rem; /* Even tighter spacing */
    }
    
    .top-bar h1 {
        font-size: 0.9rem; /* Even smaller title */
    }
    
    .level-dropdown {
        padding: 0.25rem 0.5rem; /* Minimal padding */
        font-size: 0.7rem;
    }
    
    .reset-chat-btn {
        width: 28px; /* Slightly bigger reset button */
        height: 28px;
    }
    
    #logo {
        width: 28px; /* Even smaller logo */
        height: 28px;
    }
    
    .chat-area {
        padding: 0.75rem;
    }
    
    .bottom-bar {
        padding: 0.6rem; /* Smaller padding for voice-only */
    }
    
    .input-area {
        justify-content: center;
        width: 100%;
    }
    
    .mic-btn {
        width: 60px; /* Optimized microphone button for small screens */
        height: 60px;
        font-size: 1.5rem; /* Optimized icon size */
    }
    
    .mic-label {
        font-size: 0.75rem;
    }
    
    .begin-chat-btn {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }
}
