* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft JhengHei', 'PingFang TC', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

.selector-panel {
    background: #f8f9fa;
    padding: 25px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: center;
    border-bottom: 2px solid #e9ecef;
}

.selector-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.selector-group label {
    font-weight: bold;
    color: #495057;
}

select {
    padding: 10px 15px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 1em;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
}

select:hover {
    border-color: #667eea;
}

select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn-primary, .btn-secondary {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.content-area {
    padding: 30px;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    border-bottom: 2px solid #e9ecef;
}

.tab-btn {
    padding: 12px 25px;
    border: none;
    background: transparent;
    font-size: 1em;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    color: #6c757d;
}

.tab-btn:hover {
    color: #667eea;
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: bold;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.schedule-card {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.schedule-card h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.8em;
}

.week-schedule {
    background: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 15px;
    border-left: 4px solid #667eea;
}

.week-schedule h3 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.subject-item {
    background: #f8f9fa;
    padding: 15px;
    margin: 10px 0;
    border-radius: 8px;
    border-left: 3px solid #667eea;
}

.subject-item h4 {
    color: #667eea;
    margin-bottom: 8px;
    font-size: 1.2em;
}

.subject-item p {
    color: #6c757d;
    line-height: 1.6;
}

.subject-item ul {
    margin-left: 20px;
    color: #6c757d;
}

.subject-item li {
    margin: 5px 0;
}

.game-area {
    text-align: center;
}

.game-area h2 {
    color: #667eea;
    margin-bottom: 25px;
    font-size: 1.8em;
}

.game-card {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 12px;
    margin: 20px 0;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.game-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(102, 126, 234, 0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.5s;
}

.game-card.success-animation::before {
    opacity: 1;
    animation: celebrate 0.6s ease-out;
}

@keyframes celebrate {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

.game-question {
    font-size: 1.5em;
    margin-bottom: 30px;
    color: #495057;
    font-weight: bold;
}

.game-options {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
}

.game-option {
    padding: 15px 30px;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1em;
    transition: all 0.3s;
    min-width: 150px;
    position: relative;
}

.game-option:hover {
    border-color: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.2);
}

.game-option.correct {
    background: #d4edda;
    border-color: #28a745;
    color: #155724;
    animation: correctPulse 0.5s ease-out;
}

@keyframes correctPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.game-option.incorrect {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.game-option.disabled {
    pointer-events: none;
    opacity: 0.6;
}

.score-display {
    font-size: 1.2em;
    font-weight: bold;
    color: #667eea;
    margin-top: 20px;
}

.game-feedback {
    margin-top: 20px;
    padding: 15px;
    border-radius: 10px;
    font-size: 1.1em;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-feedback.success {
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
    color: #155724;
    border: 2px solid #28a745;
}

.game-feedback.encourage {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    color: #856404;
    border: 2px solid #ffc107;
}

.game-feedback.show {
    display: flex;
}

.star-animation {
    display: inline-block;
    font-size: 2em;
    animation: starSpin 0.6s ease-out;
}

@keyframes starSpin {
    0% {
        transform: rotate(0deg) scale(0);
    }
    50% {
        transform: rotate(180deg) scale(1.5);
    }
    100% {
        transform: rotate(360deg) scale(1);
    }
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background: #ffd700;
    position: absolute;
    animation: confettiFall 3s linear;
    pointer-events: none;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.next-question-btn {
    margin-top: 20px;
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    cursor: pointer;
    display: none;
    transition: all 0.3s;
    pointer-events: auto;
    z-index: 10;
    position: relative;
}

.next-question-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.next-question-btn.show {
    display: inline-block !important;
    pointer-events: auto !important;
}

.reset-game-btn {
    padding: 10px 20px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
}

.reset-game-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.subject-selector {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.subject-selector label {
    font-weight: bold;
    color: #495057;
}

.subject-selector select {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 1em;
    background: white;
    cursor: pointer;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
    position: relative;
    z-index: 10;
}

.question-header strong {
    flex: 1;
    min-width: 200px;
}

.question-text {
    font-size: 1.3em;
    color: #495057;
    margin-top: 10px;
}

.play-question-btn {
    padding: 8px 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 5px;
    pointer-events: auto !important;
    z-index: 100;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
}

.play-question-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.play-question-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 5px rgba(102, 126, 234, 0.3);
}

.play-question-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.game-option-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    position: relative;
}

.game-option-wrapper .play-option-btn {
    flex-shrink: 0;
}

.game-option {
    flex: 1;
}

.play-option-btn {
    padding: 8px 12px;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s;
    min-width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto !important;
    z-index: 100;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
}

.play-option-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.play-option-btn:active {
    transform: scale(0.95);
}

.play-option-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* 教學材料區域樣式 */
.materials-section {
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
    border-left: 4px solid #667eea;
}

.materials-section h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.material-item {
    background: white;
    padding: 15px;
    margin: 10px 0;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
    cursor: pointer;
}

.material-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #667eea;
}

.material-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.material-item h4 {
    color: #495057;
    margin: 0;
    font-size: 1.1em;
    flex: 1;
}

.material-play-btn {
    padding: 6px 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s;
    margin-left: 10px;
}

.material-play-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.material-preview {
    color: #6c757d;
    line-height: 1.6;
    margin: 5px 0;
}

.material-detail {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px dashed #dee2e6;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.teacher-character-mini {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: linear-gradient(135deg, #fff5f5 0%, #ffe5e5 100%);
    border-radius: 10px;
    margin-top: 10px;
}

.teacher-avatar-mini {
    font-size: 2em;
    animation: bounce 2s infinite;
}

.teacher-speech-mini {
    flex: 1;
    padding: 12px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.teacher-speech-mini .teacher-name {
    font-weight: bold;
    color: #667eea;
    margin-bottom: 5px;
    font-size: 1em;
}

.teacher-speech-mini p {
    margin: 8px 0;
    color: #495057;
    font-size: 0.95em;
    line-height: 1.6;
}

.teacher-speech-mini ul {
    margin: 8px 0 8px 20px;
    color: #495057;
    font-size: 0.9em;
    line-height: 1.8;
}

.teacher-speech-mini li {
    margin: 5px 0;
}

/* 小女生活潑教學角色 */
.teacher-character {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: linear-gradient(135deg, #fff5f5 0%, #ffe5e5 100%);
    border-radius: 12px;
    margin: 15px 0;
    border: 2px solid #ffcccc;
}

.teacher-avatar {
    font-size: 3em;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.teacher-speech {
    flex: 1;
    padding: 15px;
    background: white;
    border-radius: 10px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.teacher-header-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.teacher-info {
    flex: 1;
}

.teacher-info .teacher-name {
    font-weight: bold;
    color: #667eea;
    margin-bottom: 5px;
}

.teacher-info p {
    margin: 0;
    color: #495057;
    font-size: 1em;
    line-height: 1.6;
}

.voice-selector-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    flex-wrap: wrap;
}

.voice-select-label {
    font-size: 0.9em;
    color: #495057;
    font-weight: bold;
    white-space: nowrap;
}

.voice-select-dropdown {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.9em;
    background: white;
    cursor: pointer;
    min-width: 200px;
    transition: all 0.3s;
}

.voice-select-dropdown:hover {
    border-color: #667eea;
}

.voice-select-dropdown:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.test-voice-btn {
    padding: 8px 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.test-voice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.test-voice-btn:active {
    transform: translateY(0);
}

.voice-change-message {
    margin-top: 10px;
    padding: 8px 12px;
    background: #d4edda;
    color: #155724;
    border-radius: 6px;
    font-size: 0.9em;
    animation: slideDown 0.3s ease-out;
}

@media (max-width: 768px) {
    .voice-selector-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    .voice-select-label {
        width: 100%;
    }
    
    .voice-select-dropdown {
        width: 100%;
        min-width: auto;
    }
    
    .test-voice-btn {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .question-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .play-question-btn {
        width: 100%;
        justify-content: center;
    }
    
    .game-option-wrapper {
        flex-direction: column;
    }
    
    .play-option-btn {
        width: 100%;
    }
    
    .teacher-character {
        flex-direction: column;
        text-align: center;
    }
    
    .teacher-speech::before {
        display: none;
    }
}

.pronunciation-area, .listening-area {
    text-align: center;
}

.pronunciation-area h2, .listening-area h2 {
    color: #667eea;
    margin-bottom: 25px;
    font-size: 1.8em;
}

.word-display {
    font-size: 3em;
    color: #667eea;
    margin: 30px 0;
    font-weight: bold;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pronunciation-controls, .listening-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin: 30px 0;
    flex-wrap: wrap;
}

.pronunciation-result, .listening-result {
    margin-top: 20px;
    padding: 20px;
    border-radius: 10px;
    background: #f8f9fa;
    min-height: 100px;
}

.input-area {
    margin: 20px 0;
}

.input-area input {
    padding: 15px 20px;
    font-size: 1.2em;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    width: 300px;
    max-width: 100%;
    text-align: center;
}

.input-area input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.feedback {
    margin-top: 15px;
    padding: 15px;
    border-radius: 8px;
    font-size: 1.1em;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
}

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
}

.word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    margin: 20px 0;
}

.word-item {
    padding: 15px 25px;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s;
    min-width: 120px;
}

.word-item:hover {
    border-color: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.2);
}

.word-item.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* iOS 安全區域適配 */
@supports (padding: max(0px)) {
    body {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* 觸控優化 */
button, select, .game-option, .word-item {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
    touch-action: manipulation;
}

/* 移動設備優化 */
@media (max-width: 768px) {
    body {
        padding: 10px;
        padding-bottom: env(safe-area-inset-bottom, 10px);
    }

    .container {
        border-radius: 15px;
        max-width: 100%;
    }

    header {
        padding: 20px 15px;
        padding-top: max(20px, env(safe-area-inset-top));
    }

    header h1 {
        font-size: 1.8em;
        line-height: 1.2;
    }

    .subtitle {
        font-size: 0.95em;
    }

    .selector-panel {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
        gap: 12px;
    }

    .selector-group {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .selector-group label {
        margin-bottom: 5px;
        font-size: 0.95em;
    }

    select {
        width: 100%;
        padding: 12px;
        font-size: 1em;
    }

    .btn-primary, .btn-secondary {
        width: 100%;
        padding: 14px;
        font-size: 1em;
    }

    .content-area {
        padding: 15px;
    }

    .tabs {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 20px;
    }

    .tab-btn {
        padding: 10px 15px;
        font-size: 0.9em;
        flex: 1;
        min-width: calc(50% - 4px);
    }

    .schedule-card {
        padding: 15px;
    }

    .schedule-card h2 {
        font-size: 1.4em;
    }

    .game-card {
        padding: 20px 15px;
        min-height: 250px;
    }

    .game-question {
        font-size: 1.2em;
        margin-bottom: 20px;
    }

    .game-options {
        flex-direction: column;
        gap: 12px;
    }

    .game-option {
        width: 100%;
        padding: 14px;
        font-size: 1em;
    }

    .word-display {
        font-size: 2.5em;
        margin: 20px 0;
        min-height: 80px;
    }

    .word-list {
        flex-direction: column;
        gap: 10px;
    }

    .word-item {
        width: 100%;
        padding: 12px;
        font-size: 1em;
    }

    .pronunciation-controls, .listening-controls {
        flex-direction: column;
        gap: 10px;
    }

    .btn-primary, .btn-secondary {
        width: 100%;
    }

    .input-area input {
        width: 100%;
        padding: 12px;
        font-size: 1em;
    }
}

/* iPad 橫向適配 */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 95%;
    }

    .selector-panel {
        padding: 20px;
    }

    .tab-btn {
        padding: 12px 20px;
    }
}

/* 橫向模式適配 */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 15px;
    }

    header h1 {
        font-size: 1.5em;
        margin-bottom: 5px;
    }

    .subtitle {
        font-size: 0.85em;
    }

    .selector-panel {
        padding: 12px;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .selector-group {
        flex: 1;
        min-width: 120px;
    }
}

/* 防止 iOS Safari 自動縮放 */
@media screen and (max-width: 480px) {
    select, input, textarea {
        font-size: 16px !important;
    }
}

