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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 600px;
    margin: 20px auto;
    padding: 20px;
}

.screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hidden {
    display: none !important;
}

/* Profile Screen Styles */
#profile-screen {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

#profile-screen .container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 40px;
}

h1 {
    color: #4a5568;
    margin-bottom: 10px;
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
}

p {
    color: #718096;
    text-align: center;
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
}

input, select, textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.3s ease;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

small {
    display: block;
    margin-top: 5px;
    color: #718096;
    font-size: 0.9rem;
}

.btn-primary, .btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-secondary:hover {
    background: #667eea;
    color: white;
}

.advanced-section {
    padding-bottom: 20px;
}

/* Chat Screen Styles */
#chat-screen {
    background: white;
    flex-direction: column;
    padding: 0;
    min-height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
}

.btn-cog {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-cog:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-top: 100px;
    padding-bottom: 120px;
    height: 100vh;
}

#messages {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    z-index: 10;
}

.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
    position: relative;
    z-index: 10;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

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

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

.message.correction {
    display: flex;
    flex-direction: column;
    margin-top: -15px;
    margin-bottom: 10px;
}

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

.message-bubble {
    display: inline-block;
    max-width: 70%;
    padding: 15px 20px;
    border-radius: 20px;
    word-wrap: break-word;
    position: relative;
}

.teacher .message-bubble {
    background: #f7fafc;
    border: 2px solid #e2e8f0;
    color: #2d3748;
}

.student .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.correction .message-bubble.corrected {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    color: #718096;
    font-style: italic;
    font-size: 0.9rem;
    max-width: 70%;
}

.clickable-word {
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    display: inline-block;
    margin: 1px;
}

.clickable-word:hover {
    background-color: rgba(102, 126, 234, 0.2);
}

.play-button, .stop-button, .loading-button {
    background: rgba(102, 126, 234, 0.9);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    line-height: 1;
    padding: 0;
    /* Remove margin auto for better icon centering */
    margin-top: 0;
    margin-bottom: 0;
    align-self: center;
}

.play-button:hover, .stop-button:hover {
    background: rgba(102, 126, 234, 1);
    border-color: rgba(102, 126, 234, 0.5);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.play-button:active, .stop-button:active {
    transform: scale(0.95);
}

.stop-button {
    background: rgba(220, 53, 69, 0.9);
    border-color: rgba(220, 53, 69, 0.3);
}

.stop-button:hover {
    background: rgba(220, 53, 69, 1);
    border-color: rgba(220, 53, 69, 0.5);
}

.loading-button {
    background: rgba(108, 117, 125, 0.9);
    border-color: rgba(108, 117, 125, 0.3);
    cursor: not-allowed;
}

.loading-button:hover {
    transform: none;
}

/* Hourglass animation */
.hourglass {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.explanation {
    margin-top: 10px;
    padding: 10px;
    background: #fff5d6;
    border-left: 4px solid #f6ad55;
    border-radius: 5px;
    font-style: italic;
    color: #744210;
}

.chat-input-container {
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 20px;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
}

.suggested-words {
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.suggested-word {
    background: #edf2f7;
    color: #4a5568;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    border: 2px solid transparent;
}

.suggested-word:hover {
    background: #667eea;
    color: white;
    transform: translateY(-1px);
}

.input-group {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
}

#message-input {
    flex: 1;
    min-height: 50px;
    max-height: 120px;
    resize: none;
}

#send-btn {
    width: auto;
    min-width: 80px;
    height: 50px;
}

.btn-mic {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 10px;
    padding: 0;
    width: 50px;
    height: 50px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    display: none; /* Hidden by default, shown when STT is enabled */
    align-items: center;
    justify-content: center;
}

.btn-mic:hover {
    background: #5a67d8;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

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

.btn-mic.recording {
    background: #e53e3e;
    animation: pulse 1.5s infinite;
}

.btn-mic.recording:hover {
    background: #c53030;
}

.btn-mic:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(229, 62, 62, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(229, 62, 62, 0);
    }
}

/* Translation Popup */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.popup-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    text-align: center;
    position: relative;
    max-width: 300px;
    width: 90%;
}

#original-word {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 15px;
}

#translated-word {
    display: block;
    font-size: 1.2rem;
    color: #667eea;
    font-weight: 500;
}

#close-popup {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #a0aec0;
    padding: 5px;
}

#close-popup:hover {
    color: #4a5568;
}

/* System Prompt Modal */
.system-prompt-modal {
    max-width: 800px;
    width: 95%;
    max-height: 80vh;
    text-align: left;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
    margin: 0;
    color: #4a5568;
    font-size: 1.5rem;
}

#close-system-prompt-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #a0aec0;
    padding: 5px;
}

#close-system-prompt-modal:hover {
    color: #4a5568;
}

.modal-body {
    max-height: 60vh;
    overflow-y: auto;
}

#system-prompt-text {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    color: #2d3748;
    background: #f7fafc;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

/* Conversation History Modal */
.conversation-history-modal {
    max-width: 900px;
    width: 95%;
    max-height: 85vh;
    text-align: left;
}

#close-conversation-history-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #a0aec0;
    padding: 5px;
}

#close-conversation-history-modal:hover {
    color: #4a5568;
}

#conversation-history-content {
    max-height: 70vh;
    overflow-y: auto;
    padding-right: 10px;
}

.history-conversation {
    margin-bottom: 30px;
    padding: 20px;
    border-radius: 10px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
}

.history-conversation:last-child {
    margin-bottom: 0;
}

.history-message {
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 15px;
    line-height: 1.5;
}

.history-message.student {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-left: 20%;
    text-align: right;
}

.history-message.teacher {
    background: white;
    border: 2px solid #e2e8f0;
    color: #2d3748;
    margin-right: 20%;
}

.history-message.correction {
    background: #fff5d6;
    border: 1px solid #f6ad55;
    color: #744210;
    font-style: italic;
    margin-left: 20%;
    margin-right: 10%;
    font-size: 0.9rem;
}

.history-message-label {
    font-size: 12px;
    color: #718096;
    font-weight: 600;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.history-explanation {
    background: #fff5d6;
    border-left: 4px solid #f6ad55;
    padding: 10px;
    margin-top: 8px;
    border-radius: 5px;
    font-style: italic;
    color: #744210;
    font-size: 0.9rem;
}

/* Loading Indicator */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    color: #4a5568;
    font-size: 1.1rem;
}

/* Thinking bubble animation */
.thinking-bubble {
    animation: fadeIn 0.3s ease;
}

.thinking-animation {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
}

.thinking-animation span {
    width: 8px;
    height: 8px;
    background-color: #667eea;
    border-radius: 50%;
    display: inline-block;
    animation: thinking 1.4s infinite both;
}

.thinking-animation span:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-animation span:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* Typing preview */
.typing-preview {
    opacity: 0.6;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 0.3; }
    100% { opacity: 0.6; }
}

/* Button spinner */
.button-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

#send-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    #profile-screen .container {
        padding: 20px;
        margin: 10px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    #send-btn {
        width: 100%;
    }
    
    .chat-header {
        padding: 15px;
    }
    
    .chat-header h2 {
        flex: 1;
        text-align: center;
        font-size: 1.4rem;
        margin: 0;
        color: #fff !important;
    }
    
    #chat-container {
        padding-top: 80px;
        padding-bottom: 140px;
    }
    
    .chat-input-container {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    #profile-screen .container {
        padding: 15px;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
    
    input, select, textarea, .btn-primary {
        padding: 10px 14px;
    }
    
    .btn-mic {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }
    
    #send-btn {
        min-width: 70px;
        height: 45px;
    }
}
