/* 全局樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Microsoft JhengHei", "微軟正黑體", "PingFang TC", "Apple LiGothic", sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.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;
    animation: fadeIn 0.5s ease-in;
}

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

/* 頭部 */
.header {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 20px;
    text-align: center;
}

.header h1 {
    font-size: 2em;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1em;
    opacity: 0.95;
}

.sync-status {
    margin-top: 10px;
    font-size: 0.85em;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.sync-status.success {
    color: #d4edda;
}

.sync-status.error {
    color: #f8d7da;
}

/* 標籤導航 */
.tab-nav {
    display: flex;
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
}

.tab-btn:hover {
    background: #e9ecef;
}

.tab-btn.active {
    background: white;
    color: #f5576c;
    border-bottom: 3px solid #f5576c;
}

/* 內容區域 */
.content-section {
    display: none;
    padding: 15px 20px;
    animation: slideIn 0.3s ease-out;
}

.content-section.active {
    display: block;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 空狀態 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #6c757d;
}

.empty-icon {
    font-size: 5em;
    margin-bottom: 20px;
    animation: bounce 2s infinite;
}

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

/* 選擇框 */
.lesson-selector {
    margin-bottom: 15px;
}

.lesson-selector h2 {
    margin-bottom: 10px;
    color: #333;
    font-size: 1.5em;
}

.select-box {
    width: 100%;
    padding: 10px;
    font-size: 1em;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
}

.select-box:focus {
    outline: none;
    border-color: #f5576c;
    box-shadow: 0 0 0 3px rgba(245, 87, 108, 0.1);
}

/* 學習區域 */
.word-display {
    text-align: center;
    padding: 15px 20px;
}

.word-display.hidden {
    display: none;
}

.word-card {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.big-word {
    font-size: 6em;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    animation: scaleIn 0.5s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.speak-btn {
    padding: 10px 20px;
    font-size: 1em;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.speak-btn:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.5);
}

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

.speak-btn-small {
    padding: 6px 12px;
    font-size: 0.9em;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    margin-left: 8px;
}

.word-info {
    margin: 8px 0;
    font-size: 1.1em;
    color: #666;
}

/* 學習模式左右佈局 */
.learn-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 15px;
}

.learn-left {
    flex: 1;
    min-width: 300px;
}

.learn-right {
    flex: 1;
    min-width: 300px;
}

/* 臨摹練習區域 */
.trace-practice-section {
    padding: 15px;
    background: linear-gradient(135deg, #e0f7fa 0%, #e1bee7 100%);
    border-radius: 15px;
    height: 100%;
}

.trace-practice-section h3 {
    text-align: center;
    font-size: 1.2em;
    color: #333;
    margin-bottom: 5px;
}

.trace-hint {
    text-align: center;
    color: #666;
    font-size: 0.9em;
    margin-bottom: 10px;
}

.control-btns {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 15px;
}

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

.ctrl-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

/* 手寫練習 */
.practice-area {
    max-width: 800px;
    margin: 0 auto;
}

.practice-header {
    text-align: center;
    margin-bottom: 30px;
}

.practice-word-display {
    margin-top: 20px;
    font-size: 1.5em;
}

.practice-target {
    font-size: 3em;
    font-weight: bold;
    color: #f5576c;
    margin: 0 15px;
}

.canvas-container {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px;
    margin: 10px 0;
}

canvas {
    display: block;
    margin: 0 auto;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    cursor: crosshair;
    touch-action: none;
}

.canvas-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}

.canvas-btn {
    padding: 8px 16px;
    font-size: 0.95em;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
}

.canvas-btn:first-child {
    background: #dc3545;
    color: white;
}

.canvas-btn:first-child:hover {
    background: #c82333;
}

.canvas-btn:last-child {
    background: #28a745;
    color: white;
}

.canvas-btn:last-child:hover {
    background: #218838;
}

.practice-result {
    text-align: center;
    font-size: 1.5em;
    padding: 20px;
    margin: 20px 0;
    border-radius: 10px;
    font-weight: bold;
}

.practice-result.correct {
    background: #d4edda;
    color: #155724;
    border: 2px solid #c3e6cb;
}

.practice-result.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #f5c6cb;
}

/* 字格子 */
.word-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 15px;
    margin-top: 30px;
}

.word-item {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    font-size: 2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    border: 3px solid transparent;
}

.word-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    border-color: #f5576c;
}

.word-item.selected {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border-color: #333;
}

/* 測驗區域 */
.test-area {
    max-width: 800px;
    margin: 0 auto;
}

.test-header {
    margin-bottom: 30px;
}

.test-controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.test-controls .select-box {
    flex: 1;
}

.btn-primary {
    padding: 15px 30px;
    font-size: 1.1em;
    background: #f5576c;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

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

.test-content.hidden,
.test-result.hidden {
    display: none;
}

.test-progress {
    background: #e9ecef;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    text-align: center;
}

.test-progress p {
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
    margin: 5px 0;
}

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

.test-word {
    font-size: 6em;
    font-weight: bold;
    color: #f5576c;
    margin: 20px 0;
}

.test-feedback {
    text-align: center;
    font-size: 1.5em;
    padding: 20px;
    margin: 20px 0;
    border-radius: 10px;
    font-weight: bold;
}

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

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

.test-result {
    text-align: center;
    padding: 40px;
}

.test-result h3 {
    font-size: 2.5em;
    margin-bottom: 30px;
    color: #f5576c;
}

.result-stats {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
    margin: 30px 0;
}

.result-stats p {
    font-size: 1.5em;
    margin: 15px 0;
    color: #333;
}

.result-score {
    font-size: 2em !important;
    font-weight: bold;
    color: #f5576c !important;
}

/* 課文管理 */
.manage-area {
    max-width: 800px;
    margin: 0 auto;
}

.add-lesson-form {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
    margin-bottom: 40px;
}

.add-lesson-form h3 {
    margin-bottom: 20px;
    color: #333;
}

.input-text {
    width: 100%;
    padding: 15px;
    font-size: 1.1em;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    margin-bottom: 15px;
}

.input-text:focus {
    outline: none;
    border-color: #f5576c;
}

.textarea {
    width: 100%;
    padding: 15px;
    font-size: 1.1em;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    margin-bottom: 15px;
    resize: vertical;
    font-family: inherit;
}

.textarea:focus {
    outline: none;
    border-color: #f5576c;
}

.lesson-list h3 {
    margin-bottom: 20px;
    color: #333;
}

.lesson-item {
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    transition: all 0.3s;
}

.lesson-item:hover {
    border-color: #f5576c;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.lesson-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.lesson-item h4 {
    color: #333;
    font-size: 1.3em;
}

.lesson-item-content {
    color: #666;
    font-size: 1.5em;
    line-height: 1.6;
    margin-bottom: 10px;
}

.lesson-item-meta {
    color: #999;
    font-size: 0.9em;
}

.delete-btn {
    padding: 8px 15px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
}

.delete-btn:hover {
    background: #c82333;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.8em;
    }

    .tab-btn {
        padding: 15px 10px;
        font-size: 0.9em;
    }

    .big-word {
        font-size: 6em;
    }

    .test-word {
        font-size: 4em;
    }

    .word-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
        gap: 10px;
    }

    .word-item {
        font-size: 1.5em;
        padding: 15px;
    }

    canvas {
        max-width: 100%;
    }

    /* 移動端改為上下佈局 */
    .learn-layout {
        flex-direction: column;
        gap: 20px;
    }

    .learn-left,
    .learn-right {
        min-width: 100%;
    }

    .trace-practice-section h3 {
        font-size: 1.3em;
    }
}

/* 載入動畫 */
.loading {
    text-align: center;
    padding: 40px;
    font-size: 1.5em;
    color: #666;
}

.loading::after {
    content: '...';
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { content: '.'; }
    33% { content: '..'; }
    66% { content: '...'; }
}

/* ============ OCR 圖片上傳樣式 ============ */

.ocr-upload-section {
    margin-bottom: 30px;
}

.upload-header h4 {
    color: #333;
    font-size: 1.2em;
    margin-bottom: 10px;
}

.upload-hint {
    color: #666;
    font-size: 0.95em;
    margin-bottom: 15px;
}

/* OCR 使用建議 */
.ocr-tips {
    margin-top: 15px;
    padding: 15px;
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    border-radius: 8px;
}

.ocr-tips summary {
    cursor: pointer;
    font-weight: bold;
    color: #856404;
    font-size: 1em;
    padding: 5px;
    user-select: none;
}

.ocr-tips summary:hover {
    color: #533f03;
}

.tips-list {
    margin: 15px 0 5px 20px;
    padding: 0;
}

.tips-list li {
    margin: 8px 0;
    color: #856404;
    font-size: 0.95em;
    line-height: 1.6;
}

.upload-area {
    position: relative;
    margin: 20px 0;
}

.upload-box {
    border: 3px dashed #dee2e6;
    border-radius: 15px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: #f8f9fa;
}

.upload-box:hover {
    border-color: #f5576c;
    background: #fff;
    transform: translateY(-2px);
}

.upload-box.dragover {
    border-color: #f5576c;
    background: #fff5f7;
    transform: scale(1.02);
}

.upload-icon {
    font-size: 4em;
    margin-bottom: 15px;
    animation: float 3s ease-in-out infinite;
}

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

.upload-text {
    font-size: 1.2em;
    color: #333;
    font-weight: bold;
    margin-bottom: 5px;
}

.upload-subtext {
    color: #999;
    font-size: 0.9em;
}

.preview-container {
    position: relative;
    border-radius: 15px;
    overflow: hidden;
    border: 3px solid #dee2e6;
    max-width: 100%;
}

.preview-container.hidden {
    display: none;
}

.preview-container img {
    width: 100%;
    height: auto;
    display: block;
}

.remove-image-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.remove-image-btn:hover {
    background: #dc3545;
    transform: scale(1.1);
}

.ocr-progress {
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.ocr-progress.hidden {
    display: none;
}

.progress-bar {
    width: 100%;
    height: 30px;
    background: #e9ecef;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 15px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 0.9em;
}

.progress-text {
    text-align: center;
    color: #666;
    font-size: 1.1em;
    font-weight: bold;
}

.btn-ocr {
    width: 100%;
    padding: 15px 30px;
    font-size: 1.1em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
    margin-top: 15px;
}

.btn-ocr:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-ocr:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.form-divider {
    text-align: center;
    margin: 30px 0;
    position: relative;
}

.form-divider::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background: #dee2e6;
}

.form-divider span {
    background: white;
    padding: 0 20px;
    color: #999;
    font-weight: bold;
    position: relative;
    z-index: 1;
}

.manual-input-section h4 {
    color: #333;
    font-size: 1.2em;
    margin-bottom: 15px;
}

/* OCR 成功動畫 */
@keyframes successPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

.ocr-success {
    animation: successPulse 0.6s ease-out;
}

/* 響應式調整 */
@media (max-width: 768px) {
    .upload-box {
        padding: 40px 15px;
    }

    .upload-icon {
        font-size: 3em;
    }

    .upload-text {
        font-size: 1em;
    }
}
