/* ==========================================
   基础重置与变量
   ========================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #8a919f;
  --primary: #2f6feb;
  --correct: #1A3B5D;
  --wrong: #e5484d;
  --border: #e3e6eb;
  --slot-bg: #ffffff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0; padding: 0; height: 100vh; overflow: hidden;
}

/* ==========================================
   侧边栏与折叠逻辑
   ========================================== */
.app-container { display: flex; height: 100vh; width: 100vw; }

.sidebar {
  width: 220px;
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  transition: width 0.3s ease;
}

.sidebar.collapsed { width: 64px; }

.logo {
  font-size: 20px; font-weight: bold; color: var(--primary);
  padding: 24px; border-bottom: 1px solid var(--border);
  text-align: center; white-space: nowrap; overflow: hidden;
}
.sidebar.collapsed .logo { display: none; } /* 折叠时隐藏Logo */

.nav-btn {
  background: none; border: none; text-align: left;
  padding: 16px 24px; font-size: 16px; color: var(--text);
  cursor: pointer; transition: all 0.2s ease; width: 100%;
  display: flex; align-items: center; gap: 12px; white-space: nowrap;
}
.nav-btn:hover { background: #f5f6f8; }
.nav-btn.active {
  background: #eef4ff; color: var(--primary);
  font-weight: bold; border-right: 3px solid var(--primary);
}
.sidebar.collapsed .nav-btn {
  justify-content: center; padding: 16px 0; border-right: none;
}
.sidebar.collapsed .nav-btn .text { display: none; } /* 折叠时隐藏文字 */

/* 折叠按钮 */
.toggle-btn {
  position: absolute; bottom: 20px; right: -14px;
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff; border: 1px solid var(--border);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--muted); z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1); transition: transform 0.3s;
}
.sidebar.collapsed .toggle-btn { transform: rotate(180deg); }

/* ==========================================
   主内容区
   ========================================== */
.main-content {
  flex: 1; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column; align-items: center;
}
.view { display: none; width: 100%; max-width: 520px; flex-direction: column; gap: 16px; }
.view.active { display: flex; }

/* 顶部导航区域 */
.top-nav-area { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.word-nav {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
}

.word-nav-btn {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; color: var(--muted);
  cursor: pointer; display: flex; align-items: center; gap: 6px;
  max-width: 45%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.word-nav-btn span { color: #1A3B5D; font-weight: 600; font-size: 14px; }
.word-nav-btn:hover:not(:disabled) { background: #f5f6f8; border-color: #d0d4db; }
.word-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.topbar { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); width: 100%; }

/* ==========================================
   卡片与格子
   ========================================== */
.card {
  background: var(--card); border-radius: 16px; padding: 28px 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  display: flex; flex-direction: column; align-items: center; gap: 20px; width: 100%;
}
.mode-tag { font-size: 12px; padding: 4px 12px; border-radius: 20px; background: #eef4ff; color: var(--primary); font-weight: bold; }
.mode-tag.listen { background: #fff4e6; color: #f59e0b; }
.mode-tag.write { background: #fdf2f8; color: #ec4899; }
.mode-tag.review { background: #fce7f3; color: #db2777; }

.meaning { font-size: 28px; font-weight: 600; text-align: center; line-height: 1.4; }
.meta-row { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 36px; }
.phonetic { font-size: 18px; color: var(--muted); font-family: "Lucida Sans Unicode", sans-serif; }
.phonetic:empty { display: none; }

.speak-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.speak-btn:active { background: #eef4ff; }

.word-zone { position: relative; width: 100%; display: flex; justify-content: center; min-height: 64px; }
.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.slot {
  width: 44px; height: 56px; border-radius: 10px; background: #ffffff;
  border: 1px solid #e3e6eb; display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 600; line-height: 1; color: #000000;
}
.slot-hint { color: #8a919f !important; }
.slot.correct { color: #000000; border-color: #000000; }
.slot.wrong { color: var(--wrong); border-color: var(--wrong); }
.slot.active { border: 2px solid var(--primary); }

.hidden-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 10; }
.hint { font-size: 14px; color: var(--muted); min-height: 20px; text-align: center; transition: color 0.2s; }

.actions { display: flex; gap: 12px; width: 100%; margin-top: 8px; }
.btn { flex: 1; padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: #fff; font-size: 16px; cursor: pointer; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* 列表视图 */
.view-title { font-size: 24px; margin-bottom: 4px; }
.view-desc { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.list-container { display: flex; flex-direction: column; gap: 12px; }
.list-item { background: #fff; border-radius: 12px; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 4px rgba(0,0,0,0.05); border: 1px solid var(--border); }
.list-info { display: flex; flex-direction: column; gap: 4px; }
.list-word { font-size: 18px; font-weight: 600; color: #1A3B5D; }
.list-meaning { font-size: 14px; color: var(--muted); }
.list-item .btn { flex: none; width: auto; padding: 8px 12px; font-size: 16px; border-radius: 8px; }

/* 手机端适配 */
@media (max-width: 768px) {
  .app-container { 
    flex-direction: column; 
    height: 100dvh; /* 适配手机浏览器地址栏 */
  }
  
  /* 侧边栏变成顶部导航条 */
  .sidebar { 
    width: 100%; 
    flex-direction: row; 
    border-right: none; 
    border-bottom: 1px solid var(--border); 
    overflow-x: auto; 
    transition: none; 
    height: 56px; 
    flex-shrink: 0;
  }
  
  /* 隐藏 Logo 和折叠按钮 */
  .logo, .toggle-btn { display: none; }
  
  /* 让按钮容器水平排列 */
  .sidebar nav {
    display: flex;
    flex-direction: row;
    width: 100%;
    justify-content: space-around; /* 按钮均匀分布 */
  }
  
  /* 调整按钮样式 */
  .nav-btn { 
    justify-content: center; 
    padding: 0 16px; 
    white-space: nowrap;
    flex: none;
    border-right: none !important;
    border-bottom: 3px solid transparent;
  }
  
  /* 选中状态改为底部边框 */
  .nav-btn.active { 
    border-right: none; 
    border-bottom: 3px solid var(--primary); 
  }
  
  .sidebar.collapsed { width: 100%; } 
  .sidebar.collapsed .nav-btn { justify-content: center; padding: 0 16px; }
  .sidebar.collapsed .nav-btn .text { display: block; }

  .main-content { 
    padding: 16px; 
    padding-bottom: 20px;
  }
  
  .card { padding: 20px 16px; }

  /* 虚拟键盘显示 */
  .virtual-keyboard { display: block; }
  .hidden-input { display: none; }
}

/* 顶部栏文字调整 */
.topbar { 
  display: flex; 
  justify-content: space-between; 
  font-size: 13px; 
  color: var(--muted); 
  width: 100%; 
}
#dailyProgress {
  font-weight: bold;
  color: var(--primary);
}

/* 设置弹窗 */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.show {
  display: flex;
}
.modal-content {
  background: #fff;
  padding: 24px;
  border-radius: 16px;
  width: 90%;
  max-width: 320px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.modal-content h3 {
  font-size: 18px;
  margin-bottom: 16px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
.form-group label {
  font-size: 14px;
  color: var(--muted);
}
.form-group input {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  outline: none;
}
.form-group input:focus {
  border-color: var(--primary);
}
.modal-actions {
  display: flex;
  gap: 12px;
}

/* ==========================================
   虚拟键盘 (仅在手机端显示)
   ========================================== */
.virtual-keyboard {
  display: none; /* 电脑端默认隐藏 */
  width: 100%;
  max-width: 520px;
  margin-top: 16px;
  background: #e3e6eb; 
  padding: 8px 4px;
  border-radius: 12px;
  user-select: none; 
}

.vk-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}
.vk-row:last-child { margin-bottom: 0; }

.vk-key {
  flex: 1;
  height: 46px;
  background: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 500;
  color: #000;
  box-shadow: 0 1px 1px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation; 
}
.vk-key:active { background: #d1d5db; }

.vk-key.vk-action {
  flex: 1.5; 
  background: #d1d5db;
  font-size: 16px;
}
.vk-key.vk-action:active { background: #9ca3af; }

@media (max-width: 768px) {
  .virtual-keyboard { display: block; }
  .hidden-input { display: none; } /* 禁用手机自带键盘 */
  .main-content { padding-bottom: 20px; }
}