/* ================= 基础设置 & 全局字体 ================= */
* { 
    -webkit-tap-highlight-color: transparent; 
    box-sizing: border-box;
}

html, body { 
    height: 100%; 
    margin: 0;
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #334155;
}

body {
    /* 更清新、柔和的蓝紫渐变背景 */
    background: linear-gradient(135deg, #e0f2fe 0%, #f3e8ff 100%);
    background-attachment: fixed;
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    overflow-x: hidden;
}

/* ================= 动画定义 ================= */
@keyframes shake {
    0%,100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}
.shake { animation: shake 0.4s ease; }

@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes fadeOut { from { opacity:1; } to { opacity:0; } }
@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

#app > div {
    animation: pageFadeIn 0.3s ease-out forwards;
}

/* ================= Toast 提示 ================= */
.toast-layer {
    position: fixed; inset: 0; pointer-events: none;
    display: flex; align-items: flex-end; justify-content: center;
    padding-bottom: 80px; z-index: 9999;
}
.toast-box {
    background: rgba(15, 23, 42, 0.85); 
    color: #fff;
    backdrop-filter: blur(4px);
    padding: 14px 32px; 
    border-radius: 999px;
    font-size: 16px; font-weight: 600;
    max-width: 80vw; text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.toast-show { animation: fadeIn 0.25s forwards; }
.toast-hide { animation: fadeOut 0.25s forwards; }

/* ================= 首页单元卡片 ================= */
.home-item {
    cursor: pointer; 
    background-color: #ffffff;
    border-radius: 1.25rem; 
    padding: 2rem 0;
    font-weight: 700;
    color: #3b82f6;
    box-shadow: 0 8px 20px rgba(148, 163, 184, 0.15);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    border: 2px solid transparent;
}
.home-item:active { 
    transform: scale(0.95); 
    box-shadow: 0 4px 10px rgba(148, 163, 184, 0.1); 
    border-color: #bfdbfe;
}

/* ================= 课文跟读句子高亮 ================= */
.sentence-item {
    cursor: pointer;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
    user-select: none;
    border: 1px solid transparent;
}
.sentence-item:active { background-color: #f8fafc; }
.sentence-item.sentence-playing { 
    background-color: #eff6ff !important; 
    border-color: #93c5fd;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}
.sentence-item.sentence-played { 
    background-color: #f8fafc !important; 
    border-color: #e2e8f0;
}

/* ================= 连连看选项效果 ================= */
.match-selected-wrap { position: relative; z-index: 2; }
.match-selected-wrap::before {
    content: ""; position: absolute; inset: -6px;
    border-radius: 16px; border: 2px solid var(--ring-color);
    box-shadow: 0 0 16px 4px var(--ring-color);
    pointer-events: none; z-index: -1;
    animation: glowPulse 1.2s ease-in-out infinite;
}
@keyframes glowPulse {
    0%,100% { box-shadow: 0 0 12px 2px var(--ring-color); }
    50% { box-shadow: 0 0 20px 6px var(--ring-color); }
}
#connectSvgLayer {
    position: absolute; inset: 0; pointer-events: none;
    z-index: 1; overflow: visible;
}

/* ================= 弹窗底层 ================= */
.exit-modal-backdrop {
    position: fixed; inset: 0;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10000; display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.exit-modal-card {
    background: #ffffff; border-radius: 1.5rem;
    width: 100%; max-width: 340px; padding: 2rem;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    animation: pageFadeIn 0.3s ease-out;
}
.exit-modal-card button {
    border-radius: 12px;
    font-weight: 600;
}

/* ================= 密码框 ================= */
.pwd-box {
    width: 46px; height: 54px; 
    border: 2px solid #e2e8f0; 
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 800; color: #1e293b; background: #f8fafc;
    transition: all 0.2s;
}
.pwd-box.active { 
    border-color: #3b82f6; 
    background: #fff;
    box-shadow: 0 0 0 4px rgba(59,130,246,0.15); 
}
.pwd-box.filled { background: #eff6ff; color: #3b82f6; }

/* ================= 单词卡片（连词成句） ================= */
.word-chip {
    display: inline-block;
    padding: 10px 18px;
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    color: #334155;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s;
    margin: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.word-chip:active {
    transform: scale(0.93);
    background: #f8fafc;
    border-color: #cbd5e1;
}
.word-chip.placed {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}
.word-chip.correct {
    background: #dcfce7;
    border-color: #4ade80;
    color: #15803d;
}
.word-chip.wrong {
    background: #fee2e2;
    border-color: #f87171;
    color: #b91c1c;
}

/* ================= 答题区 ================= */
.answer-zone {
    min-height: 100px;
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    padding: 10px;
    background: #f8fafc;
    display: flex; flex-wrap: wrap; align-items: flex-start;
    align-content: flex-start; box-sizing: border-box; overflow: hidden;
    transition: all 0.3s;
}
.answer-zone.filled {
    border-style: solid; border-color: #93c5fd; background: #eff6ff;
}
.answer-zone.correct { border-color: #4ade80; background: #f0fdf4; }
.answer-zone.wrong { border-color: #f87171; background: #fef2f2; }
.word-pool {
    min-height: 100px; display: flex; flex-wrap: wrap; align-items: flex-start;
    align-content: flex-start; box-sizing: border-box; overflow: hidden;
    padding-top: 10px;
}

/* ================= 单词跟读高亮 ================= */
.word-read-row { 
    transition: all 0.2s ease; 
    border-radius: 12px;
    border: 1px solid transparent;
}
.word-read-row.playing { 
    background-color: #eff6ff !important; 
    border-color: #93c5fd;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}
.word-read-row.played { 
    background-color: #f8fafc !important; 
    border-color: #e2e8f0;
}

/* ================= 听写输入框 ================= */
.dict-row input {
    border-radius: 12px;
    font-weight: 700;
    color: #334155;
    transition: all 0.2s;
}
.dict-row input:focus {
    box-shadow: 0 0 0 4px rgba(59,130,246,0.15);
}
.dict-input-error {
    border-color: #f87171 !important; 
    background-color: #fef2f2 !important; 
    animation: shake 0.4s ease;
}

/* ================= 听力理解选项 ================= */
.listen-option { 
    cursor: pointer; 
    border-radius: 16px;
    padding: 16px;
    font-weight: 600;
    transition: all 0.2s; 
    user-select: none; 
    box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}
.listen-option:active { transform: scale(0.98); }
.listen-option.correct { 
    background: #dcfce7 !important; border-color: #4ade80 !important; color: #15803d !important; 
    box-shadow: 0 4px 12px rgba(74, 222, 128, 0.2);
}
.listen-option.wrong { 
    background: #fee2e2 !important; border-color: #f87171 !important; color: #b91c1c !important; 
    box-shadow: 0 4px 12px rgba(248, 113, 113, 0.2);
}
.listen-option.disabled { pointer-events: none; }

.audio-pulse {
    animation: pulseAudio 1.5s ease-in-out infinite;
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.3);
}
@keyframes pulseAudio { 
    0%,100% { transform: scale(1); } 
    50% { transform: scale(1.08); } 
}
.audio-pulse.playing { animation: none; transform: scale(1.05); }

/* ================= 侧边栏 ================= */
.sidebar-mask {
    position: fixed; inset: 0; 
    background-color: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    z-index: 10001; opacity:0; pointer-events: none; transition: opacity 0.3s ease;
}
.sidebar-mask.show { opacity:1; pointer-events:auto; }

.grade-sidebar {
    position: fixed; top:0; left:0; bottom:0; width:280px; background:#ffffff;
    border-top-right-radius: 24px;
    border-bottom-right-radius: 24px;
    box-shadow: 8px 0 32px rgba(0,0,0,0.1); z-index:10002;
    transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 24px 20px; overflow-y:auto;
}
.grade-sidebar.show { transform: translateX(0); }
.sidebar-title { 
    font-size:20px; font-weight:800; color:#1e293b;
    margin-bottom:24px; padding-bottom:16px; border-bottom:1px solid #f1f5f9; 
}

.grade-item {
    padding: 16px 20px; 
    border-radius: 14px; 
    margin-bottom: 12px;
    font-weight: 700;
    color: #475569;
    cursor: pointer; 
    background: #f8fafc;
    transition: all 0.2s;
}
.grade-item:active { transform: scale(0.96); }
.grade-item.active { 
    background: #eff6ff; 
    color: #1d4ed8; 
    border: 2px solid #bfdbfe;
    cursor: not-allowed; pointer-events: none; 
}
.sidebar-close-btn { 
    position:absolute; top:24px; right:20px; 
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; cursor: pointer; color:#94a3b8; background: #f1f5f9;
}
.sidebar-close-btn:active { background: #e2e8f0; }

/* ================= 其他细节覆盖 ================= */
button {
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.2s;
}
button:active { transform: scale(0.96); }

.hidden { display: none !important; }
.btn-disabled { opacity: 0.5; pointer-events: none; }
.btn-loading::after {
    content: ""; display: inline-block;
    width: 14px; height: 14px; margin-left: 8px;
    border: 2px solid currentColor; border-right-color: transparent;
    border-radius: 50%; animation: spin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 让白底卡片都有大圆角和柔和阴影 */
.bg-white.rounded-xl, 
.bg-white.rounded-2xl {
    border-radius: 1.25rem !important;
    box-shadow: 0 8px 24px rgba(148, 163, 184, 0.12) !important;
    border: 1px solid rgba(255, 255, 255, 0.6);
}

/* ================= 底部弹窗：防止遮挡 ================= */
.dict-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.dict-row input { width: 100%; min-width: 0; }
.dict-row button {
    width: 100%; white-space: nowrap; flex-shrink: 0;
}
@media (min-width: 480px) {
    .dict-row { flex-direction: row; align-items: stretch; }
    .dict-row input { flex: 1 1 auto; }
    .dict-row button { width: auto; }
}
