:root {
  --bg: #faf9f7;
  --panel: #ffffff;
  --ink: #1c1b19;
  --muted: #7a756d;
  --line: #e6e2db;
  --accent: #b4562f;
  --ok: #3f7d52;
  --warn: #c08a2e;
  --bad: #b3453c;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --panel: #1f1f24;
    --ink: #ece9e4;
    --muted: #97918a;
    --line: #34343b;
    --accent: #e08a5f;
    --ok: #6fb583;
    --warn: #d8ab5b;
    --bad: #e0796e;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 ui-sans-serif, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- nav ---------- */
nav#tabs {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 2px;
  padding: 8px 12px calc(8px + env(safe-area-inset-top, 0px));
  padding-top: max(8px, env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
nav#tabs button {
  flex: 1; padding: 9px 4px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 15px; cursor: pointer;
}
nav#tabs button.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.07); }

main { max-width: 720px; margin: 0 auto; padding: 16px 14px 64px; }
.tab { display: none; }
.tab.on { display: block; }

h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
h2:first-child { margin-top: 4px; }
h3 { margin: 0 0 14px; font-size: 18px; }

/* ---------- controls ---------- */
.bar { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.bar.wrap { flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 14px; }
.center { text-align: center; margin: 14px 0; }
code { background: var(--panel); padding: 1px 5px; border-radius: 5px; font-size: .88em; }

input, select, textarea, button {
  font: inherit; color: var(--ink);
}
/* input:not([type]) 是必须的 —— 不写 type 的 <input> 默认是 text，
   但属性选择器 [type=text] 匹配不到它，会退回浏览器默认宽度（约 20 字符）。
   编辑器里「词形变化」「近义词」两个框就是这么被截短的。 */
input:not([type]), input[type=text], input[type=search], input[type=password], input[type=number], select, textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.5; }
#q { flex: 2 1 180px; }
select { flex: 1 1 120px; }

button { cursor: pointer; }
button.big {
  padding: 13px 18px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
  width: 100%;
}
button.big:active { transform: translateY(1px); }
button.link, a.link {
  background: none; border: 0; color: var(--muted); text-decoration: none;
  padding: 8px 10px; border-radius: 8px; font-size: 14px;
}
button.link:hover, a.link:hover { background: var(--panel); color: var(--ink); }
button.link.danger { color: var(--bad); }

.switch { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.switch input { width: auto; }
.pill {
  background: var(--panel); border: 1px solid var(--line);
  padding: 4px 11px; border-radius: 999px; font-size: 13px; color: var(--muted);
}
kbd {
  font: inherit; font-size: 11px; opacity: .55; border: 1px solid currentColor;
  border-radius: 4px; padding: 0 4px; margin-left: 5px;
}

/* ---------- review card ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 22px; min-height: 230px;
  display: flex; flex-direction: column; justify-content: center;
  text-align: center; margin: 10px 0 16px;
}
.empty { color: var(--muted); }
/* 发音按钮跟在词后面，长句子时会自然换到末尾 */
.prompt-line {
  display: flex; flex-wrap: wrap;
  align-items: baseline; justify-content: center; gap: 10px;
}
.prompt { font-weight: 600; line-height: 1.35; word-break: break-word; }
/* 整句词条字号自动收一点，免得撑出去 */
.prompt:not(:empty) { font-size: clamp(19px, 5vw, 30px); }

.speak {
  flex: none;
  background: none; border: 0; padding: 4px 6px; border-radius: 8px;
  font-size: 19px; line-height: 1; opacity: .45;
  transition: opacity .15s, background .15s;
}
.speak:hover { opacity: 1; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.speak:active { transform: translateY(1px); }
.speak.playing { opacity: 1; }

#answer { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
/* 音标跟在单词下面，不藏在答案里 —— 考的是词义，不是发音 */
.phonetic { color: var(--accent); font-size: 16px; letter-spacing: .02em; margin-top: 6px; }
.phonetic[hidden] { display: none; }
.translation { font-size: 20px; margin-top: 6px; white-space: pre-wrap; }
.alt { color: var(--muted); font-size: 15px; margin-top: 3px; }
.definition { color: var(--muted); font-size: 14px; margin-top: 10px; white-space: pre-wrap; text-align: left; }
.example { color: var(--muted); font-size: 14px; margin-top: 8px; font-style: italic; text-align: left; }
.meta { color: var(--muted); font-size: 12px; margin-top: 16px; }

.actions { margin: 4px 0; }
/* 打分行常驻，「显示答案」在它上面；答案展开后上面那个按钮消失 */
#grade-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
#btn-reveal:not([hidden]) + #grade-row { margin-top: 8px; }
.grade {
  padding: 14px 6px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); font-weight: 600; font-size: 15px;
}
.grade.forgot { color: var(--bad); }
.grade.vague  { color: var(--warn); }
.grade.know   { color: var(--ok); }
.grade:active { transform: translateY(1px); }
.row-links { display: flex; justify-content: center; gap: 4px; margin-top: 10px; }

/* ---------- library ---------- */
.item {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px;
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
}
.item:hover { border-color: var(--accent); }
.item .main { flex: 1; min-width: 0; }
.item .w { font-weight: 600; word-break: break-word; }
.item .p { color: var(--accent); font-size: 13px; margin-left: 6px; font-weight: 400; }
.item .t { color: var(--muted); font-size: 14px; margin-top: 2px; white-space: pre-wrap; }
.item .s { color: var(--muted); font-size: 11px; margin-top: 5px; }

/* 日志里的释义默认盖住，点一下掀开。只在日历这一处 —— 词库列表要的是能扫读。
   用 blur 而不是 visibility，占位高度不变，掀开时列表不会跳。
   select-none 是必须的：不然划一下就把答案选出来了。

   fit-content 是为了让盒子收到文字宽度：默认撑满整行，
   右边一大片空白也能点，糊出来的条也比文字长一截。
   别改成 inline-block —— .item .w 是 inline-flex，两个行内级元素会挤到同一行去。 */
#cal-day .item .t { width: fit-content; max-width: 100%; }
#cal-day .item .t.veil {
  filter: blur(5px);
  user-select: none; -webkit-user-select: none;
  cursor: pointer;
}
#cal-day .item .t.veil:hover { filter: blur(4px); }
.item .badge {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.hot { color: var(--bad); border-color: currentColor; }
.badge.due { color: var(--warn); border-color: currentColor; }
.badge.new { color: var(--ok); border-color: currentColor; }

/* ---------- stats ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 12px; text-align: center;
}
.stat b { display: block; font-size: 24px; font-weight: 700; }
.stat span { color: var(--muted); font-size: 12px; }
#heat { display: flex; gap: 3px; align-items: flex-end; height: 78px; overflow-x: auto; padding-bottom: 4px; }
#heat div { flex: 1 0 8px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .8; }

/* ---------- 日历 ---------- */
/* 宽屏上不让格子摊成大方块，日历该是紧凑的 */
#cal-week, #cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  max-width: 520px; margin-left: auto; margin-right: auto;
}
#cal-week { color: var(--muted); font-size: 12px; text-align: center; margin-bottom: 6px; }

#cal-grid button {
  /* 正方形格子：aspect-ratio 比撑高度的 padding 技巧干净，
     而且格子里还要竖着放日期和次数两行 */
  aspect-ratio: 1; width: 100%; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); font: inherit; cursor: pointer;
}
#cal-grid button.blank { visibility: hidden; cursor: default; }
#cal-grid button.today { border-color: var(--accent); }
#cal-grid button.on { outline: 2px solid var(--accent); outline-offset: -2px; }
#cal-grid button:disabled { cursor: default; opacity: .55; }
#cal-grid .d { font-size: 13px; }
#cal-grid .n { font-size: 11px; color: var(--muted); }
/* 复习量用底色深浅表示，四档就够看出「哪几天在用功」 */
#cal-grid button.lv1 { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
#cal-grid button.lv2 { background: color-mix(in srgb, var(--accent) 26%, var(--panel)); }
#cal-grid button.lv3 { background: color-mix(in srgb, var(--accent) 44%, var(--panel)); }
#cal-grid button.lv4 { background: color-mix(in srgb, var(--accent) 64%, var(--panel)); color: #fff; }
#cal-grid button.lv4 .n { color: rgba(255,255,255,.85); }
#cal-summary { margin-top: 10px; }

/* 当天的评分占比。跟在标题后面另起一行，字号压小 —— 它是标题的补充，不是标题 */
#cal-day-title .g-row {
  display: block; margin-top: 5px;
  font-size: 13px; font-weight: 400;
}
#cal-day-title .g-sep { color: var(--line); margin: 0 7px; }

/* 三档可点，点了只看那一档。用 button 而不是 span —— 键盘能聚焦、读屏能识别 */
#cal-day-title .g-pick {
  font: inherit; background: none; border: 1px solid transparent;
  border-radius: 999px; padding: 1px 8px; cursor: pointer;
}
#cal-day-title .g-pick:hover { border-color: currentColor; }
/* 选中：底色填上。只描边的话跟 hover 分不清 */
#cal-day-title .g-pick.on {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 14%, transparent);
}
#cal-day-title .g-forgot { color: var(--bad); }
#cal-day-title .g-vague  { color: var(--warn); }
#cal-day-title .g-know   { color: var(--ok); }

/* 难度等级。用主题色跟旁边那些状态徽章（新/到期/错N）区分开 ——
   它说的是词本身，不是它当前的复习状态 */
.badge.lv { color: var(--accent); border-color: currentColor; font-weight: 600; letter-spacing: .3px; }

.badge.know { color: var(--ok); border-color: currentColor; }
.badge.vague { color: var(--warn); border-color: currentColor; }
.badge.forgot { color: var(--bad); border-color: currentColor; }

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
#modal[hidden] { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh; overflow-y: auto;
}
.sheet label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.sheet label input, .sheet label textarea { margin-top: 4px; }
.sheet label.inline { display: flex; align-items: center; gap: 8px; }
.sheet label.inline input { width: auto; margin: 0; }
.sheet .bar { flex-wrap: wrap; margin-top: 16px; }
.sheet .bar button.big { width: auto; flex: 1 1 100px; }

@media (min-width: 640px) {
  #modal { align-items: center; }
  .sheet { border-radius: 18px; }
}

/* ---------- 登录页 ---------- */
body.login-page {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
#login {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 32px 26px; width: 100%; max-width: 340px; text-align: center;
}
#login h1 { margin: 0 0 22px; font-size: 22px; letter-spacing: .04em; }
#login input { margin-bottom: 14px; text-align: center; }
.err { color: var(--bad); font-size: 14px; margin-top: 12px; min-height: 20px; }

/* ---------- 每日进度 ---------- */
#progress-bar { margin: 4px 0 14px; }
.pg-text {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: var(--muted); margin-bottom: 6px;
}
#pg-streak { font-weight: 600; color: var(--accent); }
.pg-track { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.pg-fill {
  height: 100%; width: 0%; background: var(--accent);
  border-radius: 999px; transition: width .35s ease;
}
.pg-fill.done { background: var(--ok); }
.grow { flex: 1; }

/* ---------- 徽标列 ---------- */
.item .badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 10px; font-size: 14px;
  max-width: 90vw; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 100;
}
#toast.on { opacity: .95; transform: translate(-50%, 0); }

/* 上一个 / 删除 —— 按钮变多了，小屏上允许换行 */
.row-links { flex-wrap: wrap; }
.row-links button:disabled { opacity: .3; cursor: default; }
.row-links button:disabled:hover { background: none; color: var(--muted); }

/* 词库列表和编辑弹层里的小发音按钮 */
.speak.sm { font-size: 14px; padding: 2px 5px; margin-left: 7px; vertical-align: baseline; }
.item .w { display: inline-flex; align-items: baseline; flex-wrap: wrap; }
.field-row { display: flex; gap: 6px; align-items: center; }
.field-row input { flex: 1; }
.field-row .speak { flex: none; font-size: 17px; }

/* 新增/编辑弹层的提示行 */
#e-hint:not(:empty) { margin: -8px 0 14px; font-size: 13px; }
.sheet label[hidden], .sheet .bar button[hidden] { display: none; }

/* 例句：英文一行、中文一行，居中不斜体，比释义弱一档 */
.example {
  color: var(--ink); opacity: .75; font-size: 14px; font-style: normal;
  margin-top: 12px; text-align: center; white-space: pre-line; line-height: 1.55;
}
/* 提示：易混词那类，用强调色标出来 */
.note {
  color: var(--accent); font-size: 13px; margin-top: 10px;
  text-align: left; white-space: pre-wrap;
}
.note:not(:empty)::before { content: '💡 '; }

/* 发音设置里的语速滑块 */
input[type=range] { accent-color: var(--accent); width: auto; }
.switch input[type=range] { min-width: 90px; }

/* 等级 + 来源：音标下面的一排小标签，翻开答案前也在 */
.tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tags[hidden] { display: none; }
.tag {
  border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 9px; font-size: 11px; color: var(--muted); line-height: 1.6;
}
/* 等级是这两个里更常看的，给点颜色区分开 */
.tag.cefr { color: var(--accent); border-color: var(--accent); font-weight: 600; letter-spacing: .3px; }

/* 词形变化：答案区里的一排小卡 */
.forms { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.forms[hidden] { display: none; }
.rel-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.rel {
  display: inline-flex; align-items: baseline; gap: 5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; font-size: 13px; color: var(--ink);
}
.rel:hover { border-color: var(--accent); }
.rel b { font-weight: 600; }
.rel i { color: var(--accent); font-style: normal; font-size: 11px; }
.rel span { color: var(--muted); font-size: 12px; }




/* 例句：英文带播放按钮，中文另起一行 */
.ex-en { display: inline; }
.ex-en .speak { vertical-align: baseline; }
.ex-cn { margin-top: 2px; opacity: .82; }
/* 多段例句（又是名词又是动词的词各一段）之间留条分隔线 */
.ex + .ex { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.ex-pos { color: var(--muted); font-weight: 600; font-size: .88em; }
.label-row { display: inline-block; margin-left: 4px; }

/* 划词菜单：选中英文单词后浮出来 */
#sel-menu {
  position: absolute; z-index: 60;
  display: flex; gap: 2px; padding: 3px;
  background: var(--ink); border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
}
#sel-menu[hidden] { display: none; }
#sel-menu button {
  border: 0; background: none; color: var(--bg);
  font-size: 13px; padding: 6px 10px; border-radius: 7px; white-space: nowrap;
}
#sel-menu button:hover { background: rgba(255,255,255,.16); }
#sel-menu button:disabled { opacity: .6; }
/* 小箭头指向选中的词 */
#sel-menu::after {
  content: ''; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}
