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

body {
    font-family: 'Arial', 'Microsoft JhengHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 800px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.screen {
    display: none;
    padding: 40px;
    animation: fadeIn 0.3s ease-in;
}

.screen.active {
    display: block;
}

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

/* Start Screen */
#startScreen {
    text-align: center;
}

#startScreen h1 {
    font-size: 3rem;
    color: #667eea;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.2rem;
    color: #666;
    margin-bottom: 40px;
}

/* Game Type Selection */
.game-type-selection {
    margin-bottom: 40px;
}

.game-type-selection h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.game-type-options {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.game-type-btn {
    flex: 1;
    max-width: 250px;
    padding: 25px 20px;
    background: white;
    border: 3px solid #ddd;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.game-type-btn:hover {
    border-color: #667eea;
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.2);
}

.game-type-btn.active {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.game-type-btn.active .game-type-icon,
.game-type-btn.active .game-type-title,
.game-type-btn.active .game-type-desc {
    color: white;
}

.game-type-icon {
    font-size: 2.5rem;
}

.game-type-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: #333;
    transition: color 0.3s;
}

.game-type-desc {
    font-size: 0.95rem;
    color: #666;
    transition: color 0.3s;
}

/* Mode Selection */
.mode-selection {
    margin-bottom: 40px;
}

.mode-selection h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.mode-options {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.mode-btn {
    flex: 1;
    max-width: 250px;
    padding: 25px 20px;
    background: white;
    border: 3px solid #ddd;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mode-btn:hover {
    border-color: #667eea;
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.2);
}

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

.mode-btn.active .mode-title,
.mode-btn.active .mode-example {
    color: white;
}

.mode-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
    transition: color 0.3s;
}

.mode-example {
    font-size: 2rem;
    color: #667eea;
    transition: color 0.3s;
}

/* Difficulty Selection */
.difficulty-selection {
    margin-bottom: 40px;
}

.difficulty-selection h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.difficulty-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    max-width: 600px;
    margin: 0 auto;
}

.difficulty-btn {
    padding: 20px 15px;
    background: white;
    border: 3px solid #ddd;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.difficulty-btn:hover {
    border-color: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.2);
}

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

.difficulty-btn.active .difficulty-icon,
.difficulty-btn.active .difficulty-title,
.difficulty-btn.active .difficulty-desc {
    color: white;
}

.difficulty-icon {
    font-size: 2rem;
}

.difficulty-title {
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
    transition: color 0.3s;
}

.difficulty-desc {
    font-size: 0.9rem;
    color: #666;
    transition: color 0.3s;
}

/* Start Button */
.start-button-container {
    margin-bottom: 30px;
    text-align: center;
}

.start-btn {
    padding: 20px 60px;
    font-size: 1.8rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.3);
}

.start-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.5);
}

.stats-preview {
    margin-top: 40px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.stats-preview h3 {
    color: #333;
    margin-bottom: 15px;
}

#statsPreview {
    color: #666;
    margin-bottom: 15px;
}

/* Quiz Screen */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.timer-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.timer-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.score-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.timer-label, .score-label {
    font-size: 1rem;
    color: #666;
}

.timer, .score {
    font-size: 2rem;
    font-weight: bold;
    color: #667eea;
}

.question-timer {
    color: #28a745;
}

.question-timer.warning {
    color: #ff6b6b;
    animation: pulse 0.5s infinite;
}

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

.question-container {
    text-align: center;
    margin-bottom: 30px;
}

.question-type {
    font-size: 1rem;
    color: #764ba2;
    margin-bottom: 20px;
    font-weight: bold;
}

.question-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.question-text {
    font-size: 5rem;
    font-weight: bold;
    color: #333;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.audio-btn {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.audio-btn:hover {
    background: #5568d3;
}

.answer-container {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

/* Handwriting Area */
.handwriting-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.canvas-wrapper {
    position: relative;
    width: 300px;
    height: 300px;
    border: 3px solid #667eea;
    border-radius: 10px;
    background: white;
}

.background-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
}

.drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    background: transparent;
    touch-action: none;
    z-index: 2;
}

/* Legacy canvas styles removed - now using canvas-wrapper border */

/* Canvas Buttons */
.canvas-buttons {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 300px;
}

.hint-btn {
    flex: 1;
    padding: 15px 20px;
    font-size: 1rem;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
    min-height: 48px;
    touch-action: manipulation;
}

.hint-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(245, 87, 108, 0.4);
}

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

/* Text Input Area */
.text-input-area {
    width: 100%;
    display: flex;
    justify-content: center;
}

.text-input {
    width: 300px;
    padding: 20px;
    font-size: 2rem;
    text-align: center;
    border: 3px solid #667eea;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s;
}

.text-input:focus {
    border-color: #764ba2;
}

/* Buttons */
.submit-btn, .primary-btn {
    width: 100%;
    padding: 20px;
    font-size: 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s;
    font-weight: bold;
}

.submit-btn:hover, .primary-btn:hover {
    transform: translateY(-2px);
}

.secondary-btn {
    padding: 15px 30px;
    font-size: 1rem;
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
    min-height: 48px;
    touch-action: manipulation;
}

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

.feedback {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    min-height: 50px;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
}

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
}

/* Results Screen */
#resultsScreen h2 {
    text-align: center;
    color: #667eea;
    font-size: 2.5rem;
    margin-bottom: 30px;
}

.results-summary {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 10px;
    margin-bottom: 30px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #ddd;
}

.result-item:last-child {
    border-bottom: none;
}

.result-label {
    font-size: 1.3rem;
    color: #666;
}

.result-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #667eea;
}

.mistakes-review {
    margin-bottom: 30px;
}

.mistakes-review h3 {
    color: #333;
    margin-bottom: 20px;
    text-align: center;
}

#mistakesList {
    background: #fff3cd;
    padding: 20px;
    border-radius: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.mistake-item {
    padding: 15px;
    background: white;
    margin-bottom: 10px;
    border-radius: 8px;
    border-left: 4px solid #ff6b6b;
}

.mistake-question {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.mistake-answer {
    color: #666;
}

.results-actions {
    display: flex;
    gap: 15px;
}

.results-actions button {
    flex: 1;
}

/* History Screen */
#historyScreen h2 {
    text-align: center;
    color: #667eea;
    font-size: 2.5rem;
    margin-bottom: 30px;
}

.chart-container {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    min-height: 300px;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.history-item {
    background: #f8f9fa;
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.history-date {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 10px;
}

.history-stats {
    display: flex;
    justify-content: space-around;
    text-align: center;
}

.history-stat-item {
    display: flex;
    flex-direction: column;
}

.history-stat-label {
    font-size: 0.9rem;
    color: #666;
}

.history-stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #667eea;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        border-radius: 0;
    }

    .screen {
        padding: 20px;
    }

    #startScreen h1 {
        font-size: 2rem;
    }

    .game-type-options {
        flex-direction: column;
    }

    .game-type-btn {
        max-width: 100%;
    }

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

    .mode-btn {
        max-width: 100%;
    }

    .difficulty-options {
        grid-template-columns: 1fr;
    }

    .start-btn {
        width: 100%;
        padding: 18px 40px;
        font-size: 1.5rem;
    }

    .timer-container {
        width: 100%;
    }

    .canvas-wrapper {
        width: 280px;
        height: 280px;
    }

    .canvas-buttons {
        max-width: 280px;
    }

    .question-text {
        font-size: 3.5rem;
    }

    .text-input {
        width: 100%;
        font-size: 1.5rem;
    }

    .quiz-header {
        flex-direction: column;
        gap: 15px;
    }

    .results-actions {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0;
    }

    #startScreen h1 {
        font-size: 1.8rem;
    }

    .question-text {
        font-size: 2.5rem;
    }

    .canvas-wrapper {
        width: 240px;
        height: 240px;
    }

    .canvas-buttons {
        max-width: 240px;
    }

    .hint-btn, .secondary-btn {
        padding: 12px 16px;
        font-size: 0.95rem;
    }

    .timer, .score {
        font-size: 1.5rem;
    }

    .result-value {
        font-size: 1.3rem;
    }
}
