/* CSS Variables for Theming */
:root {
    --primary-color: #2563eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #ffffff;
    --surface-color: #f3f4f6;
    --text-color: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #d1d5db;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

/* App Container */
.app-container {
    max-width: 800px;
    width: 100%;
    background: var(--bg-color);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Header */
.header {
    background: var(--primary-color);
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title {
    font-size: 1.5rem;
    font-weight: 700;
}

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

.level-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
}

.level-label {
    font-size: 0.875rem;
}

.level-number {
    font-size: 1.25rem;
    font-weight: 700;
}

.icon-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Practice Area */
.practice-area {
    padding: 2rem;
}

/* Character Display */
.character-display {
    text-align: center;
    margin-bottom: 2rem;
}

.thai-character {
    font-family: 'Noto Sans Thai', sans-serif;
    font-size: 8rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    user-select: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.thai-character.correct {
    color: var(--success-color);
    animation: bounce 0.5s;
}

.thai-character.incorrect {
    color: var(--error-color);
    animation: violentShake 0.6s cubic-bezier(.36,.07,.19,.97);
}

.character-display.flash-red {
    animation: redFlash 0.6s;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

@keyframes violentShake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-20px) rotate(-5deg); }
    20%, 40%, 60%, 80% { transform: translateX(20px) rotate(5deg); }
}

@keyframes redFlash {
    0%, 100% { background: transparent; }
    50% { background: rgba(239, 68, 68, 0.25); }
}

.character-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-height: 1.25rem;
}

/* Input Area */
.input-area {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.roman-input {
    flex: 1;
    padding: 1rem;
    font-size: 1.25rem;
    border: 3px solid var(--border-color);
    border-radius: 0.5rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.roman-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Real-time validation feedback */
.roman-input.input-correct {
    border-color: var(--success-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.roman-input.input-partial {
    border-color: var(--warning-color);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.roman-input.input-wrong {
    border-color: var(--error-color);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.submit-button {
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.submit-button:hover {
    background: #1d4ed8;
}

.submit-button:active {
    transform: scale(0.98);
}

/* Feedback Area */
.feedback-area {
    margin-bottom: 2rem;
    min-height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback-message {
    padding: 1rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    transition: opacity 0.3s;
}

.feedback-message.correct {
    background: #d1fae5;
    color: #065f46;
}

.feedback-message.incorrect {
    background: #fee2e2;
    color: #991b1b;
}

/* Educational Panel - Side Panel */
.educational-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 450px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.educational-panel.show {
    transform: translateX(0);
}

/* Panel Header */
.edu-panel-header {
    padding: 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex-shrink: 0;
}

.edu-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.edu-answer-display {
    font-size: 2rem;
    font-weight: 700;
    margin: 0.5rem 0;
    font-family: monospace;
}

.edu-char-name {
    font-family: 'Noto Sans Thai', sans-serif;
    font-size: 1.25rem;
    opacity: 0.9;
}

/* Tabs */
.edu-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--surface-color);
}

.edu-tab {
    flex: 1;
    padding: 0.875rem 0.5rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.edu-tab:hover {
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-color);
}

.edu-tab.active {
    background: white;
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Tab Content Areas */
.edu-tab-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: none;
}

.edu-tab-content.active {
    display: block;
}

/* Scrollbar styling for tab content */
.edu-tab-content::-webkit-scrollbar {
    width: 6px;
}

.edu-tab-content::-webkit-scrollbar-track {
    background: var(--surface-color);
}

.edu-tab-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.edu-tab-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Tab Content Styling */
.edu-text {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-color);
    margin-bottom: 1rem;
}

.edu-mnemonic {
    background: #fef3c7;
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 3px solid var(--warning-color);
    font-style: italic;
}

.char-comparison {
    display: flex;
    gap: 2rem;
    justify-content: center;
    align-items: center;
    margin: 1rem 0;
}

.comparison-item {
    text-align: center;
    padding: 1rem;
    background: white;
    border-radius: 0.5rem;
    border: 2px solid var(--border-color);
    min-width: 120px;
}

.comparison-char {
    font-family: 'Noto Sans Thai', sans-serif;
    font-size: 4rem;
    font-weight: 700;
}

.comparison-label {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.visual-features {
    list-style: none;
}

.visual-features li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
}

.visual-features li:before {
    content: "👁️";
    position: absolute;
    left: 0;
}

/* Sticky Re-Type Footer */
.retype-container {
    flex-shrink: 0;
    padding: 1.5rem;
    background: #f9fafb;
    border-top: 2px solid var(--primary-color);
}

.retype-label {
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-color);
}

.retype-input {
    width: 100%;
    padding: 0.75rem;
    font-size: 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: monospace;
    transition: border-color 0.2s;
}

.retype-input.correct {
    border-color: var(--success-color);
    background: #d1fae5;
}

.retype-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.audio-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.audio-button:hover {
    background: #1d4ed8;
}

/* Stats Panel */
.stats-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-item {
    background: var(--surface-color);
    padding: 1rem;
    border-radius: 0.5rem;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 8px;
    background: var(--surface-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.3s ease;
}

/* Modal */
.modal {
    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;
}

.modal-content {
    background: var(--bg-color);
    border-radius: 1rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.5rem;
}

.close-button {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

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

.modal-body {
    padding: 1.5rem;
}

.setting-group {
    margin-bottom: 2rem;
}

.setting-group h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.setting-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
}

.setting-group input[type="number"] {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
}

.secondary-button {
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    background: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    margin-right: 0.5rem;
    transition: background 0.2s;
}

.secondary-button:hover {
    background: #e5e7eb;
}

.danger-button {
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.danger-button:hover {
    background: #dc2626;
}

/* Help Overlay */
.help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.help-content {
    background: var(--bg-color);
    padding: 2rem;
    border-radius: 1rem;
    max-width: 500px;
    width: 90%;
}

.help-content h2 {
    margin-bottom: 1.5rem;
}

.shortcut-list {
    list-style: none;
    margin-bottom: 1.5rem;
}

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

.shortcut-list kbd {
    background: var(--surface-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-family: monospace;
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Educational Panel - Slide up from bottom on mobile */
    .educational-panel {
        width: 100%;
        top: auto;
        bottom: 0;
        height: 75vh;
        max-height: 75vh;
        transform: translateY(100%);
        border-top-left-radius: 1rem;
        border-top-right-radius: 1rem;
    }

    .educational-panel.show {
        transform: translateY(0);
    }

    .char-comparison {
        flex-direction: column;
        gap: 1rem;
    }

    .comparison-item {
        width: 100%;
    }

    .comparison-char {
        font-size: 3rem;
    }
}

@media (max-width: 640px) {
    .thai-character {
        font-size: 5rem;
    }

    .input-area {
        flex-direction: column;
    }

    .stats-panel {
        grid-template-columns: repeat(2, 1fr);
    }

    .title {
        font-size: 1.25rem;
    }

    .edu-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .edu-tab {
        font-size: 0.75rem;
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }
}
