/* =========================================================
   泰语口语复习 App —— Claude 暖米白风格
   配色变量集中在 :root，方便后续整体换肤
   ========================================================= */
:root {
  --bg:       #F7F3EA;  /* 页面背景：温暖米白 */
  --card:     #FFFDF8;  /* 卡片背景 */
  --text:     #2B2118;  /* 正文：深棕黑 */
  --text-weak:#8A7A68;  /* 弱文字 */
  --accent:   #C96F4A;  /* 强调：暖橙 */
  --border:   #E7DED2;  /* 轻边框 */

  /* 评分语义色（在暖色系基础上做区分） */
  --forgot:   #C0594B;  /* 忘了 */
  --fuzzy:    #C99A4A;  /* 模糊 */
  --known:    #6E8B5B;  /* 认识 */

  --radius:   18px;     /* 统一圆角 */
  --gap:      14px;     /* 统一间距 */

  /* iPhone 安全区 */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- 基础重置 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* 禁止整页橡皮筋滚动影响布局，但允许列表内滚动 */
body { overscroll-behavior-y: none; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input  { font-family: inherit; }

/* ---------- App 容器 ---------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* ---------- 顶部标题栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--safe-top) + 14px) 20px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ---------- 内容主区 ---------- */
#main {
  flex: 1;
  /* 给底部导航留出空间（导航高 ~64px + 安全区） */
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* 页面默认隐藏，active 显示 */
.page { display: none; padding: var(--gap); }
.page.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* =========================================================
   底部固定导航
   ========================================================= */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -2px 10px rgba(43, 33, 24, 0.04);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 8px;
  color: var(--text-weak);
  transition: color .15s;
}
.tab-icon  { font-size: 20px; line-height: 1; filter: grayscale(0.3); }
.tab-label { font-size: 11px; }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { filter: none; }

/* =========================================================
   通用卡片与列表
   ========================================================= */
.card-list { display: flex; flex-direction: column; gap: var(--gap); }

.entry-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(43, 33, 24, 0.03);
}
.entry-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.entry-zh    { font-size: 18px; font-weight: 700; }
.entry-roman { font-size: 16px; color: var(--accent); margin-top: 4px; font-weight: 600; }
.entry-thai  { font-size: 16px; color: var(--text-weak); margin-top: 2px; }
.entry-note  { font-size: 14px; color: var(--text-weak); margin-top: 8px; }

/* 类型 / 分类 小徽标 */
.badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(201, 111, 74, 0.10);
  color: var(--accent);
  white-space: nowrap;
  font-weight: 600;
}
.badge-cat { background: rgba(138, 122, 104, 0.12); color: var(--text-weak); }

/* 例句块 */
.example {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.example .ex-roman { color: var(--accent); font-weight: 600; font-size: 14px; }
.example .ex-zh    { font-size: 13px; }
.example .ex-thai  { font-size: 13px; color: var(--text-weak); }

/* 标签行 */
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 11px; color: var(--text-weak); background: var(--bg); border: 1px solid var(--border); padding: 1px 8px; border-radius: 999px; }

/* 卡片上的收藏星 */
.card-fav { font-size: 18px; color: var(--text-weak); padding: 2px 4px; }
.card-fav.on { color: var(--accent); }

/* =========================================================
   1. 复习页 —— 翻转卡片
   ========================================================= */
.review-wrap { display: flex; flex-direction: column; align-items: center; padding-top: 6px; }
.review-hint { color: var(--text-weak); font-size: 13px; margin-bottom: 14px; }

.flip-card {
  width: 100%;
  max-width: 420px;
  height: 340px;
  perspective: 1200px;
  cursor: pointer;
}
.flip-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform .5s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 3px 14px rgba(43, 33, 24, 0.06);
  overflow-y: auto;
}
.flip-front { gap: 14px; }
.flip-type {
  font-size: 12px; color: var(--accent); font-weight: 700;
  border: 1px solid var(--border); padding: 3px 12px; border-radius: 999px;
  background: rgba(201,111,74,.08);
}
.flip-zh   { font-size: 34px; font-weight: 700; }
.flip-tap  { font-size: 12px; color: var(--text-weak); }

.flip-back { transform: rotateY(180deg); justify-content: center; gap: 8px; }
.flip-roman { font-size: 28px; font-weight: 700; color: var(--accent); }
.flip-thai  { font-size: 24px; color: var(--text); }
.flip-note  { font-size: 14px; color: var(--text-weak); }
.flip-examples { width: 100%; margin-top: 6px; }

/* 收藏按钮 */
.fav-toggle {
  margin: 16px 0 4px;
  font-size: 14px;
  color: var(--text-weak);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px;
  background: var(--card);
}
.fav-toggle.on { color: var(--accent); border-color: var(--accent); }

/* 评分按钮行 */
.rate-row { display: flex; gap: 10px; width: 100%; max-width: 420px; margin-top: 14px; }
.rate-btn {
  flex: 1;
  padding: 14px 0;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  transition: transform .1s, opacity .15s;
}
.rate-btn:active { transform: scale(0.96); }
.rate-forgot { background: var(--forgot); }
.rate-fuzzy  { background: var(--fuzzy); }
.rate-known  { background: var(--known); }

/* =========================================================
   2. 词库页 —— 搜索 / 筛选
   ========================================================= */
.search-box { margin-bottom: 12px; }
#lib-search {
  width: 100%;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 15px;
  color: var(--text);
  outline: none;
}
#lib-search:focus { border-color: var(--accent); }
#lib-search::placeholder { color: var(--text-weak); }

/* 横向滚动的筛选 chip 行 */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  font-size: 13px;
  padding: 7px 15px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-weak);
  transition: all .15s;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.empty-tip { text-align: center; color: var(--text-weak); padding: 40px 0; font-size: 14px; }

/* =========================================================
   4. 组句页 —— 句型驱动填空
   ========================================================= */
.build-step-label { font-size: 13px; color: var(--text-weak); margin: 4px 0 8px; font-weight: 600; }

.build-workspace { margin-top: 6px; }

/* 句型模板卡 */
.build-template-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.bt-zh    { font-size: 17px; font-weight: 700; }
.bt-roman { font-size: 15px; color: var(--accent); font-weight: 600; margin-top: 4px; }
.bt-note  { font-size: 13px; color: var(--text-weak); margin-top: 8px; }

/* 槽位行 */
.slot-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  min-height: 60px;
}
.slot {
  font-size: 16px;
  padding: 9px 14px;
  border-radius: 12px;
  line-height: 1.2;
  font-weight: 600;
}
/* 固定词：不可点 */
.slot-fixed { background: var(--bg); color: var(--text-weak); border: 1px dashed var(--border); }
/* 空槽位 */
.slot.empty { background: var(--bg); color: var(--text-weak); border: 1px dashed var(--accent); }
/* 已填槽位 */
.slot.filled { background: rgba(201,111,74,.10); color: var(--accent); border: 1px solid var(--border); }
/* 当前高亮槽位 */
.slot.active { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }

/* 选词区 */
.word-pool { margin-bottom: 16px; }
.pool-title { font-size: 13px; color: var(--text-weak); margin-bottom: 10px; }
.block-row { display: flex; flex-wrap: wrap; gap: 8px; }
.block-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 15px;
  color: var(--text);
  transition: transform .1s;
  text-align: center;
  line-height: 1.3;
}
.block-btn:active { transform: scale(0.95); }
.block-btn .bb-roman { color: var(--accent); font-weight: 700; display: block; }
.block-btn .bb-zh    { font-size: 11px; color: var(--text-weak); display: block; }

/* 操作按钮 */
.build-ops { display: flex; gap: 10px; margin-bottom: 16px; }
.build-op {
  flex: 1;
  padding: 11px 0;
  font-size: 14px;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}
.build-op:active { transform: scale(0.97); }

/* 三层输出 */
.build-output {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.bo-roman { font-size: 22px; font-weight: 800; color: var(--accent); }
.bo-zh    { font-size: 16px; margin-top: 6px; }
.bo-words-label { font-size: 12px; color: var(--text-weak); margin-top: 14px; margin-bottom: 6px; }
.bo-words { display: flex; flex-direction: column; gap: 4px; }
.bo-word  { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
.bw-roman { color: var(--accent); font-weight: 700; min-width: 92px; }
.bw-eq    { color: var(--text-weak); }
.bw-zh    { color: var(--text); }

/* =========================================================
   5. 我的页 —— 统计 + 操作
   ========================================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-num   { font-size: 28px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 13px; color: var(--text-weak); margin-top: 4px; }

.me-title { font-size: 15px; margin-bottom: 12px; }
.me-actions { display: flex; flex-direction: column; gap: 10px; }
.me-btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  transition: transform .1s;
}
.me-btn:active { transform: scale(0.98); }
.me-btn-file { display: block; cursor: pointer; }
.me-btn-danger { color: var(--forgot); border-color: rgba(192,89,75,.4); }
.me-note { font-size: 12px; color: var(--text-weak); margin-top: 12px; text-align: center; line-height: 1.7; }

/* =========================================================
   Toast 轻提示
   ========================================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 50;
  white-space: nowrap;
}
.toast.show { opacity: 0.95; transform: translateX(-50%) translateY(0); }
