/* --- 基础设置与手机端优先 --- */
:root {
    --primary-color: #3b82f6; /* 蓝色 */
    --secondary-color: #fca5a5; /* 红色 */
    --bg-color: #f3f4f6; /* 浅灰背景 */
    --card-bg: #ffffff; /* 卡片白底 */
    --text-color: #1f2937; /* 深色文本 */
    --radius: 12px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    padding-bottom: 50px;
}

/* --- 头部导航 --- */
header {
    background-color: var(--primary-color);
    color: white;
    padding: 15px 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 1.8rem;
    margin-bottom: 10px;
}

nav a {
    color: white;
    text-decoration: none;
    padding: 5px 10px;
    margin-right: 10px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

nav a:hover, nav a.active {
    background-color: #2563eb;
}

/* --- 容器与控制区 --- */
.container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 15px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
    align-items: center;
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: 8px 15px;
    box-shadow: var(--shadow);
    flex-grow: 1;
    max-width: 300px;
}

.search-box i {
    color: var(--primary-color);
    margin-right: 10px;
}

#searchInput {
    border: none;
    outline: none;
    font-size: 1rem;
    width: 100%;
}

.progress-box {
    background-color: #e0f2fe;
    color: #0c4a6e;
    padding: 10px 15px;
    border-radius: var(--radius);
    font-weight: bold;
    font-size: 0.95rem;
}

.primary-btn, .secondary-btn, .quiz-option-btn {
    padding: 10px 15px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s, transform 0.1s;
    white-space: nowrap; /* 防止按钮文本换行 */
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}

.primary-btn:hover {
    background-color: #2563eb;
}

.secondary-btn {
    background-color: #cbd5e1;
    color: var(--text-color);
}

.secondary-btn:hover {
    background-color: #94a3b8;
}

/* --- 单词卡片网格 --- */
.word-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

/* --- 卡片样式与翻转 --- */
.word-card-container {
    perspective: 1000px; /* 3D 视角 */
    height: 300px; /* 固定高度，确保对齐 */
}

.word-card {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    cursor: pointer;
}

.word-card.flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden; /* 隐藏背面 */
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-radius: var(--radius);
    background-color: var(--card-bg);
    overflow: auto;
}

/* 正面样式 */
.card-front {
    justify-content: center;
    align-items: center;
    text-align: center;
    border-top: 5px solid var(--primary-color);
}

.card-front h2 {
    font-size: 2.5rem;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.card-front .ipa {
    font-size: 1.2rem;
    color: #64748b;
    margin-bottom: 15px;
}

.card-front .pos-cn {
    font-size: 1.1rem;
    color: #475569;
    font-weight: 500;
}

.card-front .speaker-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 1.5rem;
    color: var(--primary-color);
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    transition: color 0.1s;
}

.card-front .speaker-btn:hover {
    color: #2563eb;
}

/* 背面样式 */
.card-back {
    transform: rotateY(180deg);
    background-color: #eff6ff; /* 浅蓝背景 */
    border-top: 5px solid var(--secondary-color);
}

.card-back h3 {
    color: var(--primary-color);
    margin-bottom: 8px;
    font-size: 1.2rem;
}

.card-back p {
    margin-bottom: 15px;
    font-size: 0.95rem;
}

.card-back .example-en {
    font-style: italic;
    color: #334155;
}

.card-back .example-cn {
    color: #64748b;
    font-size: 0.9rem;
}

/* 已学习状态 */
.word-card.learned {
    opacity: 0.6;
    border: 2px solid green !important;
}

.word-card.learned .card-front {
    border-top-color: green;
}

/* --- 分页控件 --- */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 30px;
}

.pagination button {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.pagination button:hover:not(:disabled) {
    background-color: #2563eb;
}

.pagination button:disabled {
    background-color: #94a3b8;
    cursor: not-allowed;
}

#pageInfo {
    font-weight: bold;
    color: var(--text-color);
}

/* --- 模态框 (Quiz Modal) --- */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    padding-top: 60px;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close-btn:hover, .close-btn:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.quiz-options {
    display: flex;
    justify-content: space-around;
    gap: 15px;
    margin-top: 15px;
}

.quiz-option-btn {
    flex-grow: 1;
    background-color: #10b981;
    color: white;
    font-size: 1rem;
}

.quiz-option-btn:hover {
    background-color: #059669;
}

/* Quiz Specific Styles */
#quizArea h3 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    text-align: center;
}

.choice-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    background-color: #e0f2fe;
    color: var(--text-color);
    border: 1px solid #90cdf4;
    border-radius: 8px;
    text-align: left;
    transition: background-color 0.2s;
    cursor: pointer;
}

.choice-btn:hover {
    background-color: #bfdbfe;
}

.choice-btn.correct {
    background-color: #10b981;
    color: white;
}

.choice-btn.incorrect {
    background-color: var(--secondary-color);
    color: white;
}

/* Spelling Test */
.spelling-input {
    width: 100%;
    padding: 10px;
    margin: 10px 0 15px;
    border: 2px solid #ccc;
    border-radius: 8px;
    font-size: 1.1rem;
    text-align: center;
}

#submitAnswerBtn {
    display: block;
    width: 100%;
    background-color: var(--primary-color);
    color: white;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

#submitAnswerBtn:hover {
    background-color: #2563eb;
}

/* Quiz Result Display */
#quizResult {
    margin-top: 15px;
    padding: 10px;
    background-color: #f0fdf4;
    border: 1px solid #dcfce7;
    border-radius: 8px;
    text-align: center;
}

#quizResult.fail {
    background-color: #fee2e2;
    border: 1px solid #fecaca;
}

.quiz-footer button {
    margin-top: 15px;
}

/* --- 响应式调整 (平板及桌面) --- */
@media (min-width: 600px) {
    .word-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 900px) {
    .word-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .container {
        padding: 0 20px;
    }
}

/* --- 48音标页样式 (phonetics.html 专用) --- */
.phonetic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.phonetic-card {
    background-color: var(--card-bg);
    padding: 15px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.phonetic-symbol {
    font-size: 3rem;
    font-weight: bold;
    color: var(--primary-color);
    line-height: 1;
    margin-bottom: 5px;
}

.phonetic-type {
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 10px;
}

.phonetic-example {
    font-style: italic;
    color: #334155;
    font-size: 0.95rem;
}

.phonetic-speaker-btn {
    font-size: 1.3rem;
    color: #10b981;
    background: none;
    border: none;
    cursor: pointer;
    margin-top: 10px;
    transition: color 0.1s;
}
.phonetic-speaker-btn:hover {
    color: #059669;
}
.phonetic-search-box {
    margin-bottom: 20px;
}
.phonetic-search-box input {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    display: block;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: var(--radius);
    font-size: 1rem;
}