/* CSS Variables */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: #475569;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang HK', 'Microsoft JhengHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* Header */
.header {
    text-align: center;
    padding: 30px 0;
}

.header h1 {
    font-size: 1.8rem;
    margin-bottom: 10px;
    color: var(--primary);
}

.header h1 i {
    margin-right: 10px;
}

.header p {
    color: var(--text-secondary);
}

/* Header Stats Panel */
.header-stats-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 15px;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-radius: 25px;
    display: inline-flex;
}

.header-stats-panel .header-stat {
    font-weight: 500;
    color: var(--warning);
}

.header-stats-panel .leaderboard-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    padding: 6px 12px;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 15px;
    transition: all 0.2s ease;
}

.header-stats-panel .leaderboard-link:hover {
    background: rgba(37, 99, 235, 0.2);
}

.header-stats-panel .leaderboard-link i {
    margin-right: 5px;
    color: var(--warning);
}

/* Upload Section */
.upload-section {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 25px;
    margin-bottom: 20px;
}

/* Input Mode Toggle */
.input-mode-toggle {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-btn {
    flex: 1;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

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

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Text Input Area */
.text-input-area textarea {
    min-height: 150px;
    font-family: inherit;
    line-height: 1.6;
}

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
}

.upload-area.dragover {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.upload-placeholder i {
    font-size: 3rem;
    color: var(--secondary);
    margin-bottom: 15px;
}

.upload-placeholder p {
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.upload-placeholder span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Image Preview */
.image-preview {
    position: relative;
    display: inline-block;
}

.image-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
}

.btn-remove {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Input Groups */
.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-group textarea,
.input-group input,
.input-group select {
    width: 100%;
    padding: 12px 15px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    resize: vertical;
}

.input-group textarea {
    min-height: 80px;
}

.input-group textarea:focus,
.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Options Row */
.options-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.option-group {
    flex: 1;
}

.option-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.option-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

/* Collapsible */
.collapsible .collapse-toggle {
    width: 100%;
    padding: 12px 15px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
}

.collapsible .collapse-toggle:hover {
    background: var(--border);
}

.collapsible .collapse-toggle i {
    transition: transform 0.3s ease;
}

.collapsible.open .collapse-toggle i {
    transform: rotate(180deg);
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 15px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

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

.btn-secondary {
    width: 100%;
    padding: 12px;
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
}

/* Loading */
.loading {
    text-align: center;
    padding: 50px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

/* Results Section */
.results-section {
    margin-bottom: 20px;
}

.result-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 15px;
}

.result-card h2 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-content {
    color: var(--text-primary);
    line-height: 1.8;
}

.result-content p {
    margin-bottom: 10px;
}

/* Steps List */
.steps-list .step {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary);
}

.steps-list .step-number {
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 5px;
}

/* Socratic Mode Styles */
.socratic-step {
    border-left-color: var(--warning) !important;
}

.socratic-step .step-number {
    color: var(--warning);
}

.socratic-question {
    font-size: 1.1em;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.socratic-hints {
    margin: 12px 0;
}

.hint-wrapper {
    margin-bottom: 8px;
}

.hint-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
}

.hint-toggle:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.hint-toggle.revealed {
    background: var(--warning);
    color: #000;
    border-color: var(--warning);
}

.hint-content {
    background: rgba(245, 158, 11, 0.1);
    border-left: 3px solid var(--warning);
    padding: 12px 15px;
    margin-top: 8px;
    border-radius: 0 6px 6px 0;
    color: var(--text-primary);
}

.hint-content.hidden {
    display: none;
}

.socratic-input-wrapper {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.socratic-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1em;
}

.socratic-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.socratic-check {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s ease;
}

.socratic-check:hover {
    background: var(--primary-dark);
}

.socratic-feedback {
    margin-top: 12px;
    padding: 12px 15px;
    background: rgba(34, 197, 94, 0.1);
    border-left: 3px solid var(--success);
    border-radius: 0 6px 6px 0;
}

.socratic-feedback .your-answer {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 6px;
}

.socratic-feedback .feedback-text {
    color: var(--success);
    font-weight: 500;
}

/* Practice Section Styles */
.practice-card {
    border: 2px solid var(--warning);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), transparent);
}

.practice-card h2 {
    color: var(--warning);
}

.practice-content {
    padding: 10px 0;
}

.practice-question {
    margin-bottom: 20px;
}

.practice-question .question-text {
    font-size: 1.1em;
    line-height: 1.6;
}

.practice-loading {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
}

.practice-error {
    color: var(--danger);
    text-align: center;
}

.practice-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.practice-option {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.practice-option:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
}

.practice-option.selected {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.2);
}

.practice-option.correct-answer {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.2);
}

.practice-option.wrong-answer {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.2);
}

.practice-option input[type="radio"] {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.practice-option .option-text {
    flex: 1;
}

.practice-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.practice-result {
    padding: 15px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 15px;
}

.practice-result.correct {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid var(--success);
}

.practice-result.incorrect {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--danger);
}

.practice-result.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
}

.practice-result .result-icon {
    font-size: 1.5em;
}

.practice-result .result-text {
    font-weight: 500;
}

.practice-stats {
    display: flex;
    gap: 20px;
    padding: 12px 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    font-size: 0.95em;
}

.practice-stats .stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.practice-stats .stat-item span:last-child {
    font-weight: 600;
    color: var(--warning);
}

/* Mistakes & Tips */
.result-content ul {
    list-style: none;
    padding: 0;
}

.result-content li {
    padding: 10px 15px;
    background: var(--bg-card);
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.result-content li::before {
    content: "•";
    color: var(--warning);
    font-weight: bold;
}

/* Final Answer */
.final-answer {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success);
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

/* Glossary */
.glossary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.glossary .term {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 10px 15px;
}

.glossary .term-en {
    font-weight: 600;
    color: var(--primary);
}

.glossary .term-zh {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Chat Section */
.chat-section {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.chat-section h2 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-messages {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 15px;
    padding: 10px;
    background: var(--bg-card);
    border-radius: 8px;
    min-height: 100px;
}

.chat-message {
    margin-bottom: 15px;
    padding: 12px 15px;
    border-radius: 12px;
    max-width: 85%;
}

.chat-message.user {
    background: var(--primary);
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    background: var(--bg-secondary);
    border-bottom-left-radius: 4px;
}

.chat-options {
    margin-bottom: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.chat-input-row {
    display: flex;
    gap: 10px;
}

.chat-input-row textarea {
    flex: 1;
    padding: 12px 15px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    min-height: 50px;
    max-height: 120px;
}

.btn-send {
    width: 50px;
    height: 50px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

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

/* Auth Section */
.auth-section {
    margin-top: 15px;
}

.btn-auth {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
}

.btn-auth:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-auth.btn-logout {
    border-color: var(--danger);
    color: var(--danger);
}

.btn-auth.btn-logout:hover {
    background: var(--danger);
    color: white;
}

.auth-logged-in {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.user-email {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Login Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal[hidden] {
    display: none !important;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 30px;
    max-width: 400px;
    width: 100%;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

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

.modal-content h2 {
    margin-bottom: 10px;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.login-status {
    margin-top: 15px;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.login-status.success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
}

.login-status.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* Google Login Button */
.btn-google {
    width: 100%;
    padding: 12px 20px;
    background: white;
    border: 1px solid #dadce0;
    border-radius: 8px;
    color: #3c4043;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.3s ease;
}

.btn-google:hover {
    background: #f8f9fa;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.btn-google:active {
    background: #f1f3f4;
}

.google-icon {
    flex-shrink: 0;
}

/* History Section */
.history-section {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.history-header h2 {
    font-size: 1.1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
}

.history-item {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 12px 15px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-item:hover {
    background: var(--border);
}

.history-item-icon {
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    flex-shrink: 0;
}

.history-item-content {
    flex: 1;
    min-width: 0;
}

.history-item-summary {
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 30px 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 15px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .upload-area {
        padding: 25px;
    }

    .options-row {
        flex-direction: column;
    }

    .glossary {
        grid-template-columns: 1fr;
    }
}

/* Error Message */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Success Message */
.success-message {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

/* Debug Section */
.debug-section {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 15px;
    margin-top: 20px;
    border: 1px solid var(--warning);
}

.debug-section .collapse-toggle {
    background: transparent;
    border: none;
    color: var(--warning);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px;
}

.debug-content {
    margin-top: 15px;
}

.debug-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.btn-small {
    padding: 5px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
}

.btn-small:hover {
    background: var(--border);
}

#debugLog {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.75rem;
    color: #58a6ff;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

#debugLog .log-time {
    color: #8b949e;
}

#debugLog .log-info {
    color: #58a6ff;
}

#debugLog .log-success {
    color: #3fb950;
}

#debugLog .log-error {
    color: #f85149;
}

#debugLog .log-data {
    color: #d2a8ff;
}