

body { 
    font-family: "Microsoft JhengHei", sans-serif; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    background: #f0f4f8; 
    padding: 10px; /* 從 20px 改成 10px，讓手機兩邊留白縮小 */
    width: 100%;
    box-sizing: border-box;
    /*-webkit-user-select: none; /* 防止手機長按選取文字 */
    touch-action: manipulation; /* 優化手機點擊反應速度 */
}

/*.toolbar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; justify-content: center; background: white; padding: 15px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }*/
/* 工具列改為自動換行，並加大按鈕 */
.toolbar {
    width: 100%;
    max-width: 500px;
    gap: 8px;
    padding: 10px;
}

.upload-section { display: flex; align-items: center; gap: 10px; }
.filter-section { display: flex; gap: 8px; margin-bottom: 20px; }
.btn-filter { padding: 6px 12px; border: 1px solid #3498db; background: white; color: #3498db; border-radius: 20px; cursor: pointer; font-size: 0.9em; }

/*.btn-filter.active { background: #3498db; color: white; }*/
/* 移除原本的 .btn-filter.active 設定，改為以下： */
.btn-filter[data-level="0"].active { 
    background-color: #27c0e3a4 !important; 
    border-color: #2ea4cca4 !important; 
    color: white; 
}
.btn-filter[data-level="1"].active { 
    background-color: #f30e12c6 !important; 
    border-color: #f30e12c6 !important; 
    color: white; 
}
.btn-filter[data-level="2"].active { 
    background-color: #f2ee0fc2 !important; 
    border-color: #f2ee0fc2 !important; 
    color: white; 
}
.btn-filter[data-level="3"].active { 
    background-color: #38cc2ea4 !important; 
    border-color: #38cc2ea4 !important; 
    color: white; 
}
/* 新增 data-level="4" (未讀) 的顏色 */
.btn-filter[data-level="4"].active { 
    background-color: #95a5a6 !important; 
    border-color: #7f8c8d !important; 
    color: white; 
}



/* 3D 翻轉效果 */
.card-container { width: 420px; height: 350px; perspective: 1000px; cursor: pointer; position: relative; }
.card { width: 100%; height: 100%; position: relative; transition: transform 0.6s; transform-style: preserve-3d; }
.card.is-flipped { transform: rotateY(180deg); }
.card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; border-radius: 20px; box-shadow: 0 10px 20px rgba(0,0,0,0.1); padding: 30px; box-sizing: border-box; display: flex; flex-direction: column; background: white; border: 1px solid #eee; }
.card-front { justify-content: center; align-items: center; font-size: 2.8em; color: #2c3e50; font-weight: bold; }
.card-back { transform: rotateY(180deg); justify-content: flex-start; align-items: flex-start; text-align: left; overflow-y: auto; }

.label { font-size: 0.8em; font-weight: bold; color: #3498db; margin-bottom: 4px; }
.field-word-trans { font-size: 1.5em; color: #e74c3c; font-weight: bold; margin-bottom: 15px; width: 100%; border-bottom: 2px solid #f8f9fa; padding-bottom: 8px; }
.sentence-group { background: #f8f9fa; padding: 12px; border-radius: 10px; width: 100%; box-sizing: border-box; margin-bottom: 15px; border-left: 4px solid #3498db; }
.field-sentence-jp { font-size: 1.1em; color: #34495e; margin-bottom: 6px; line-height: 1.4; }
.field-sentence-zh { font-size: 1em; color: #5d6d7e; font-style: italic; }
.field-grammar { font-size: 0.95em; color: #7f8c8d; line-height: 1.5; }

.btn { padding: 12px 24px; border: none; border-radius: 10px; cursor: pointer; font-weight: bold; box-shadow: 0 4px 6px rgba(0,0,0,0.1); transition: all 0.2s ease;}
.btn-nav { background: #185e97; color: white; }
/*.btn-fam { background: #2ecc71; color: white; }*/
/* 移除原本單一顏色的 .btn-fam 設定，改為以下： */
.btn-fam[data-fam="1"] { background-color: #f30e12c6 !important; color: white; }
.btn-fam[data-fam="2"] { background-color: #f2ee0fc2 !important; color: white; }
.btn-fam[data-fam="3"] { background-color: #38cc2ea4 !important; color: white; }

.btn-random { background: #f39c12; color: white; }
.btn-danger { background: #e74c3c; color: white; padding: 8px 15px; font-size: 0.8em; }
#status { margin-top: 20px; font-size: 0.9em; color: #95a5a6; background: #fff; padding: 5px 15px; border-radius: 20px; border: 1px solid #eee; }


/* 進度條樣式 */
.progress-container {
    width: 420px;
    margin-bottom: 20px;
    background: white;
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 8px;
    font-weight: bold;
}

.progress-track {
    width: 100%;
    height: 10px;
    background: #ecf0f1;
    border-radius: 5px;
    overflow: hidden;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 強制覆蓋隨機按鈕啟動時的顏色 */
#btn-shuffle.active {
    background-color: #d35400 !important; /* 使用深橘色並加上 !important 確保優先權 */
    color: #ffffff !important;
    box-shadow: inset 0 4px 6px rgba(0,0,0,0.3); /* 內陰影讓按鈕看起來像被按下去 */
    transform: translateY(2px); /* 輕微下沈感 */
    border: 1px solid rgba(255,255,255,0.5);
}

/* 讓例句區域的喇叭更好看且好按 */
#btn-speak-example {
    background: #f1f2f6 !important;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: transform 0.1s;
}
#btn-speak-example:active {
    transform: scale(0.9);
    background: #dfe4ea !important;
}

/* 熟度標籤基礎樣式 */
.fam-badge {
    position: absolute;
    bottom: 15px;
    left: 20px;
    font-size: 0.8rem;
    padding: 10px 15px;
    border-radius: 12px;
    font-weight: bold;
    color: white;
    background: #bdc3c7; /* 預設灰色（未標記） */
    transition: all 0.3s ease;
}
/* 根據不同熟度給予不同顏色 */
.fam-lvl-1 { background: #f30e12c6 !important; } /* 熟度 1: 橘色 */
.fam-lvl-2 { background: #f2ee0fc2 !important; } /* 熟度 2: 藍色 */
.fam-lvl-3 { background: #38cc2ea4 !important; } /* 熟度 3: 綠色 */

/* --- 貼在檔案最底部：手機版專用樣式 --- */
@media (max-width: 600px) {
    /* 1. 全域修正：確保所有元件的寬度計算都包含內距 */
    * {
        box-sizing: border-box;
    }
    /* 確保控制區容器至少有三排空間 */
    .controls {
        grid-template-rows: auto auto auto !important;
        gap: 10px !important;
    }

    /* 2. 工具列：改用 Grid 網格系統，強制 2x2 對齊 */
    .toolbar {
        display: grid !important; /* 強制切換為網格佈局 */
        grid-template-columns: 1fr 1fr; /* 平分為左右兩欄 */
        gap: 10px;
        width: 92vw; /* 縮減寬度，避免貼邊 */
        max-width: 400px;
        padding: 15px;
        margin: 0 auto 15px auto; /* 置中 */
        background: white;
    }

    /* 讓「更新單字庫」標籤單獨佔領最上方的一整橫列 */
    .upload-section {
        grid-column: span 2; 
        justify-content: flex-start;
        margin-bottom: 5px;
        border-bottom: 1px solid #f0f0f0;
        padding-bottom: 10px;
    }

    /* 統一工具列按鈕的大小 */
    .toolbar .btn {
        width: 100%; /* 填滿網格欄位 */
        margin: 0;
        padding: 10px 5px;
        font-size: 0.9rem; /* 縮小字體以防溢出 */
        display: flex;
        justify-content: center;
        align-items: center;
        height: 45px; /* 固定高度讓按鈕整齊 */
    }

    /* 3. 進度條：修正「太大」與「寬度失控」的問題 */
    .progress-container {
        width: 92vw;
        max-width: 400px;
        margin: 0 auto 15px auto; /* 置中 */
        padding: 12px 15px;
    }

    .progress-info {
        font-size: 0.75rem; 
    }

    /* 4. 單字卡：確保與上方元件對齊 */
    .card-container {
        width: 92vw;
        max-width: 400px;
        height: 38vh; /* 稍微縮短高度，適合手機手感 */
        margin: 0 auto 15px auto;
    }

    /* 5. 底部控制區：重新定義為 3 顆在上、2 顆在下的佈局 */
    .controls {
        width: 92vw;
        max-width: 400px;
        margin: 0 auto 20px auto;
        display: grid !important;
        /* 將寬度切為 6 等分，方便整除 2 和 3 */
        grid-template-columns: repeat(6, 1fr) !important; 
        gap: 10px !important;
    }
    /* 熟度按鈕 (1, 2, 3) */
    .btn-fam {
        grid-column: span 2 !important;
        grid-row: 1 !important;
        padding: 15px 5px !important;
        font-size: 0.95rem !important;
    }

    #btn-quiz {
        grid-column: span 6 !important; /* 橫跨全部 6 欄 */
        grid-row: 3 !important;        /* 強制排在第三排 */
        margin-top: 5px;               /* 與上方按鈕增加一點間距 */
        height: 50px;                  /* 增加高度更方便點擊 */
        font-size: 1.1rem !important;
        border-radius: 10px;
    }

    /* 上一個、下一個按鈕 */
    .btn-nav {
        grid-column: span 3 !important;
        grid-row: 2 !important;
        padding: 15px 5px !important;
        font-size: 1rem !important;
    }
    
    .controls .btn {
        padding: 12px 8px;
        font-size: 0.9rem;
        flex: 1 1 30%; /* 讓按鈕在手機上可以三三一排或適度縮放 */
    }

    /* 隱藏頂部原本的程式註解文字，保持手機版乾淨 */
    body > text {
        display: none !important;
    }
}