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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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: var(--text-primary);
    line-height: 1.6;
}

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

/* Header */
.header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

.logo h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.tagline {
    font-size: 1.25rem;
    opacity: 0.95;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
    animation: fadeIn 0.3s ease-in;
}

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

.hidden {
    display: none !important;
}

/* Mode Selection */
#mode-selection h2 {
    text-align: center;
    margin-bottom: 32px;
    color: var(--text-primary);
    font-size: 2rem;
}

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 24px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.mode-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.mode-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.mode-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: block;
}

.mode-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: block;
}

/* Practice Interface */
.practice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.score-display {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Tone Display */
.tone-display {
    text-align: center;
    margin-bottom: 32px;
    padding: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    color: white;
}

.current-word .pinyin {
    font-size: 3rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.current-word .hanzi {
    font-size: 4rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.current-word .meaning {
    font-size: 1.25rem;
    opacity: 0.9;
}

.tone-indicator {
    margin-top: 24px;
    font-size: 1.25rem;
}

.tone-number {
    display: inline-block;
    background: rgba(255, 255, 255, 0.3);
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 700;
    margin-left: 12px;
}

/* Audio Controls */
.audio-controls {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 32px;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-record {
    padding: 16px 32px;
    border-radius: 8px;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}

.btn-large {
    padding: 20px 40px;
    font-size: 1.25rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-record {
    background: var(--error-color);
    color: white;
}

.btn-record:hover {
    background: #dc2626;
}

.btn-record.recording {
    background: #dc2626;
    animation: pulse 1.5s infinite;
}

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

/* Visualization */
.visualization {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 32px;
    position: relative;
}

#waveform {
    width: 100%;
    height: 200px;
    display: block;
}

#recording-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(239, 68, 68, 0.9);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.pulse {
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* Feedback Section */
.feedback-section {
    animation: slideUp 0.4s ease-out;
}

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

.feedback-result {
    text-align: center;
    margin-bottom: 32px;
}

.result-icon {
    font-size: 5rem;
    margin-bottom: 16px;
}

.result-icon.success::before {
    content: '✅';
}

.result-icon.error::before {
    content: '❌';
}

.result-icon.close::before {
    content: '🟡';
}

#result-title {
    font-size: 2rem;
    margin-bottom: 8px;
}

#result-message {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

.tone-comparison {
    background: #f8fafc;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.tone-graph {
    margin-bottom: 20px;
}

#pitch-comparison {
    width: 100%;
    height: 150px;
    display: block;
}

.feedback-details p {
    margin-bottom: 12px;
    font-size: 1.125rem;
}

#improvement-tip {
    color: var(--warning-color);
    font-weight: 600;
    margin-top: 16px;
}

/* Stats Section */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-item {
    text-align: center;
    padding: 24px;
    background: #f8fafc;
    border-radius: 12px;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Tone Breakdown */
.tone-breakdown h4 {
    margin-bottom: 20px;
    font-size: 1.25rem;
}

.tone-bars {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tone-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tone-bar-label {
    flex: 0 0 120px;
    font-weight: 500;
}

.tone-bar-fill {
    flex: 1;
    height: 24px;
    background: linear-gradient(90deg, var(--primary-color), var(--success-color));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.tone-bar-value {
    flex: 0 0 50px;
    text-align: right;
    font-weight: 600;
    color: var(--primary-color);
}

/* Footer */
.footer {
    text-align: center;
    color: white;
    padding: 20px;
    opacity: 0.9;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 12px;
    }

    .logo h1 {
        font-size: 2rem;
    }

    .card {
        padding: 20px;
    }

    .mode-buttons {
        grid-template-columns: 1fr;
    }

    .audio-controls {
        flex-direction: column;
    }

    .btn-large {
        padding: 16px 32px;
        font-size: 1.125rem;
    }

    .current-word .hanzi {
        font-size: 3rem;
    }

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