*, *::before, *::after {
    box-sizing: border-box;
}
html {
    -webkit-text-size-adjust: 100%;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #f8fafc;
    color: #1e293b;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* 用可視高度並允許捲動：手機鍵盤彈出、橫向或內容變高時不會被裁掉 */
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    padding: clamp(12px, 4vw, 32px);
    padding-left: max(clamp(12px, 4vw, 32px), env(safe-area-inset-left));
    padding-right: max(clamp(12px, 4vw, 32px), env(safe-area-inset-right));
    padding-bottom: max(clamp(12px, 4vw, 32px), env(safe-area-inset-bottom));
}
.container {
    background: white;
    padding: clamp(20px, 5vw, 40px) clamp(16px, 5vw, 50px);
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    text-align: center;
    max-width: 520px;
    width: 100%;
}
h2 {
    margin: 0 0 clamp(16px, 4vw, 25px);
    color: #0f172a;
    font-size: clamp(18px, 4.6vw, 24px);
    line-height: 1.3;
}
.word-box {
    display: flex;
    flex-wrap: wrap; /* 長詞在窄螢幕可換行，不會橫向溢出 */
    justify-content: center;
    gap: clamp(8px, 2.4vw, 20px);
    margin-bottom: clamp(18px, 5vw, 35px);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.char-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.pinyin {
    font-size: clamp(11px, 3.4vw, 16px);
    color: #ea580c;
    margin-bottom: clamp(2px, 0.8vw, 4px);
    font-weight: 600;
    letter-spacing: 0.5px;
    white-space: nowrap;
    opacity: 0; /* 預設隱藏拼音 */
    transition: opacity 0.2s;
}
/* 小鶴雙拼碼：雙拼模式下與全拼並列顯示 */
.flypy {
    font-size: clamp(10px, 3vw, 14px);
    color: #0284c7;
    margin-bottom: clamp(4px, 1.4vw, 8px);
    font-weight: 600;
    letter-spacing: 1px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}
/* 桌機滑鼠移上去、或點一下（觸控裝置沒有 hover）都會顯示提示 */
.char-group:hover .pinyin,
.char-group:hover .flypy,
.word-box.reveal .pinyin,
.word-box.reveal .flypy {
    opacity: 1;
}
.char {
    /* --char-size 由 app.js 依字數與可用寬度算出：字少放大、字多自動縮小 */
    font-size: var(--char-size, clamp(38px, 14vw, 60px));
    font-weight: 600;
    color: #334155;
    line-height: 1.2;
}
input[type="text"] {
    width: 100%;
    padding: clamp(11px, 3vw, 14px) clamp(12px, 3.6vw, 18px);
    /* 至少 16px：iOS Safari 聚焦時才不會自動放大整個畫面 */
    font-size: clamp(16px, 4.4vw, 20px);
    border: 2px solid #cbd5e1;
    border-radius: 10px;
    outline: none;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.stats {
    margin-top: clamp(14px, 4vw, 20px);
    color: #64748b;
    font-size: clamp(12px, 3.4vw, 14px);
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    justify-content: space-between;
    align-items: center;
}
.reset-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: clamp(11px, 3vw, 12px);
    text-decoration: underline;
    padding: 8px 4px; /* 加大觸控點擊範圍 */
    margin: -8px -4px;
}
.reset-btn:hover {
    color: #ef4444;
}
/* 下一題：整寬按鈕，行動裝置好按 */
.next-btn {
    display: block;
    width: 100%;
    margin-top: clamp(16px, 4.4vw, 22px);
    padding: clamp(13px, 3.6vw, 15px) 18px;
    min-height: 52px;
    font-family: inherit;
    font-size: clamp(16px, 4.4vw, 18px);
    font-weight: 600;
    color: #fff;
    background: #3b82f6;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s, transform 0.15s;
}
.next-btn:hover { background: #2563eb; }
.next-btn:active { background: #1d4ed8; transform: translateY(1px); }
.next-btn:disabled { background: #cbd5e1; cursor: default; transform: none; }
.next-btn:focus-visible { outline: 2px solid #1e40af; outline-offset: 2px; }
/* 全拼／雙拼 提示模式切換 */
.mode-switch {
    display: inline-flex;
    margin-top: clamp(12px, 3.4vw, 16px);
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    overflow: hidden;
}
.mode-btn,
.script-btn {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    font-family: inherit;
    font-size: clamp(11px, 3vw, 13px);
    padding: 8px 16px;
    -webkit-tap-highlight-color: transparent;
}
.mode-btn + .mode-btn,
.script-btn {
    border-left: 1px solid #cbd5e1;
}
.mode-btn.active,
.script-btn.active {
    background: #3b82f6;
    color: #fff;
    font-weight: 600;
}
/* 橫向手機等高度很矮的情況：壓縮垂直留白，避免內容被擠出畫面 */
@media (max-height: 480px) {
    body { padding: 10px; }
    .container { padding: 16px clamp(14px, 4vw, 24px); }
    h2 { margin-bottom: 12px; }
    .word-box { margin-bottom: 14px; }
    .mode-switch { margin-top: 8px; }
    .next-btn { margin-top: 10px; min-height: 46px; }
}

.switch-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ── 詞庫分類選擇（新增）──────────────────────────── */
.category-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    margin-bottom: 14px;
    font-size: clamp(12px, 3.4vw, 14px);
    color: #475569;
}
.category-row label {
    font-weight: 600;
}
.category-row select {
    font-family: inherit;
    font-size: inherit;
    color: #1e293b;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 7px 10px;
    min-width: 9em;
    max-width: 60vw;
}
.category-row select:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
}

/* 載入失敗／限流時的提示 */
.word-box.error {
    color: #b91c1c;
    font-size: clamp(14px, 4vw, 17px);
    font-weight: 600;
}
