:root {
  --paper: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --ink: #1c2321;
  --muted: #6e7570;
  --faint: #9aa09a;
  --line: #e3e1d7;
  --accent: #0f6e56;
  --accent-dark: #085041;
  --accent-soft: #e4f3ed;
  --warn: #993c1d;
  --shadow: 0 1px 2px rgba(28, 35, 33, 0.04), 0 6px 18px rgba(28, 35, 33, 0.04);
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 500; }

button, input, select, textarea { font-family: inherit; font-size: 14px; color: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 32px;
  background: rgba(246, 245, 241, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }

.mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 18px;
}

.brand-text h1 { font-size: 16px; letter-spacing: 0.02em; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; background: #efeee8; padding: 3px; border-radius: 10px; }

.tab {
  border: 0;
  background: transparent;
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s ease;
}

.tab:hover { color: var(--ink); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

/* ---------- 视图 ---------- */
main { padding: 24px 32px 48px; max-width: 1240px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ---------- 卡片与列表 ---------- */
.lib-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.side-col { display: grid; gap: 18px; }
.card-saved { grid-column: 1 / -1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2 { font-size: 15px; }
.hint { font-size: 12px; color: var(--faint); }

.note { margin: 10px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

.stack { display: grid; gap: 8px; }

input[type="text"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

input[type="text"]:focus, select:focus { border-color: var(--accent); background: #fff; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover { border-color: #cbc8bb; background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.ghost { background: transparent; }

.chips { display: flex; gap: 8px; margin-bottom: 12px; }

.chip {
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

.chip.active { background: var(--accent-soft); border-color: #a9d8c6; color: var(--accent-dark); }

.searchrow { display: flex; gap: 8px; margin-bottom: 12px; }
.searchrow input { flex: 1; }

.list {
  display: grid;
  gap: 6px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
}

.item:hover { background: var(--surface-2); border-color: var(--line); }

.item-body { flex: 1; min-width: 0; }
.item-title {
  font-size: 13.5px;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.item-sub { margin-top: 3px; font-size: 11.5px; color: var(--faint); }
.item-tag {
  font-size: 11px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.item-del {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.item-del:hover { color: var(--warn); background: #fbeae4; }

.empty { color: var(--faint); font-size: 13px; padding: 10px 2px; }

.skeleton {
  height: 46px;
  border-radius: 10px;
  background: linear-gradient(90deg, #f1efe8 25%, #f8f7f2 50%, #f1efe8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.drop {
  border: 1px dashed #cfccbe;
  border-radius: 12px;
  padding: 26px 16px;
  text-align: center;
  display: grid;
  gap: 6px;
  cursor: pointer;
  background: var(--surface-2);
  transition: all 0.15s ease;
}
.drop strong { font-weight: 500; font-size: 13.5px; }
.drop span { font-size: 12px; color: var(--faint); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- 练习台 ---------- */
.practice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.reader {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 24px 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 150px);
}

.reader-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.reader-title h2 { font-size: 15px; line-height: 1.4; }
.reader-title p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
#chapterSelect { width: auto; max-width: 240px; }

.sentences {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px 8px 0;
  scroll-behavior: smooth;
}

.sent {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.75;
  padding: 7px 12px 7px 14px;
  border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  color: #3a423f;
  transition: background 0.12s ease, color 0.12s ease;
}

.sent:hover { background: var(--surface-2); }

.sent.current {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent-dark);
}

.sent.speaking { background: #f2f8f5; border-left-color: #9ecfbb; }
.sent.done::after {
  content: "已读";
  font-family: var(--sans);
  font-size: 10.5px;
  color: var(--accent);
  margin-left: 8px;
  vertical-align: 2px;
  opacity: 0.8;
}

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 6px 0; font-size: 12px; color: var(--muted); }

.reader-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.progress { flex: 1; height: 4px; background: #edebe3; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }

.console {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  align-content: start;
}

.now { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.now-label { font-size: 11px; color: var(--faint); margin-bottom: 6px; letter-spacing: 0.06em; }
.now p { margin: 0; font-family: var(--serif); font-size: 15px; line-height: 1.6; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; }

.field { display: grid; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.field label b { color: var(--ink); font-weight: 500; }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: #efeee8; padding: 3px; border-radius: 9px; }
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 4px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

.rec-box {
  display: grid;
  grid-template-columns: 1fr 62px auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.rec-btn {
  border: 1px solid #e6c9be;
  background: #fdf3ef;
  color: var(--warn);
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.rec-btn:hover { background: #fbe8e0; }
.rec-btn.on { background: var(--warn); border-color: var(--warn); color: #fff; }

.meter { height: 6px; background: #e9e6dc; border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.08s linear; }

.rec-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.compare { font-size: 12px; color: var(--muted); line-height: 1.7; min-height: 18px; }
.compare b { color: var(--accent-dark); font-weight: 500; }

.keys { font-size: 11px; color: var(--faint); text-align: center; letter-spacing: 0.02em; }

.empty-state { text-align: center; padding: 90px 20px; }
.empty-state h2 { font-size: 17px; margin-bottom: 8px; }
.empty-state p { color: var(--muted); margin: 0 0 20px; }

/* ---------- 记录 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat span { display: block; font-size: 26px; font-family: var(--serif); }
.stat label { font-size: 12px; color: var(--muted); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: #2c3330;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  max-width: 520px;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1020px) {
  .lib-grid { grid-template-columns: 1fr; }
  .practice { grid-template-columns: 1fr; }
  .reader { height: auto; max-height: 58vh; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  main { padding: 18px; }
  .topbar { padding: 12px 18px; }
}

/* ---------- 翻译 ---------- */
.now-label { display: flex; align-items: center; justify-content: space-between; }
.mini {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.mini:hover { border-color: #cbc8bb; color: var(--ink); }
.mini.on { background: var(--accent-soft); border-color: #a9d8c6; color: var(--accent-dark); }
.mini.solid { background: var(--accent); border-color: var(--accent); color: #fff; }
.mini.solid:hover { background: var(--accent-dark); }
.mini:disabled { opacity: 0.5; cursor: default; }

.trans {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 13px;
  line-height: 1.7;
  color: #4d5652;
}
.trans.loading { color: var(--faint); }
.trans-hint { margin: 6px 0 0; font-size: 11.5px; color: var(--faint); }

.trans-line {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.65;
  color: #6b736e;
  padding: 2px 12px 6px 17px;
  margin-top: -4px;
}

.btn.small { padding: 6px 10px; font-size: 12px; }

.w { cursor: pointer; border-radius: 3px; transition: background 0.1s ease; }
.w:hover { background: #e8f1fa; box-shadow: 0 1px 0 #bcd6ef; }
.w.wsel { background: #fdf0c9; box-shadow: 0 1px 0 #e6cf8a; }

.wordcard {
  position: fixed;
  width: 296px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(28, 35, 33, 0.14);
  padding: 12px 14px 10px;
  z-index: 80;
}
.wc-head { display: flex; align-items: baseline; gap: 8px; }
.wc-head b { font-family: var(--serif); font-size: 19px; }
.wc-head span { font-size: 12px; color: var(--muted); font-family: var(--serif); }
.wc-x { margin-left: auto; border: 0; background: transparent; color: var(--faint); cursor: pointer; font-size: 12px; }
.wc-x:hover { color: var(--ink); }
.wc-body { margin: 8px 0 10px; max-height: 220px; overflow-y: auto; }
.wc-zh { font-size: 13.5px; line-height: 1.75; color: var(--ink); }
.wc-zh .idx { color: var(--faint); font-size: 11px; margin-right: 4px; }
.wc-en { margin-top: 8px; font-size: 12px; line-height: 1.6; color: var(--muted); }
.wc-en .pos { color: var(--accent-dark); font-style: italic; margin-right: 4px; }
.wc-empty { font-size: 12.5px; color: var(--faint); line-height: 1.6; }
.wc-foot { display: flex; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; }

.card-tools { display: flex; gap: 6px; }

.word-row { display: flex; align-items: baseline; gap: 10px; }
.word-row b { font-family: var(--serif); font-size: 15px; min-width: 78px; }
.word-row span { font-size: 12.5px; color: var(--muted); flex: 1; }

/* ---------- 翻译引擎面板 ---------- */
.engine-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: default;
}
.engine-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d6d3c6;
  flex: none;
}
.engine-row .dot.ok { background: var(--accent); }
.engine-row .dot.down { background: #d8a493; }
.engine-row b {
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}
.engine-row .kinds { font-size: 11.5px; color: var(--faint); }
.engine-row .state { margin-left: auto; font-size: 12px; color: var(--muted); }
.engine-row .state.ok { color: var(--accent-dark); }
.engine-row .state.down { color: #b08b7c; }
.engine-row .state.unknown { color: var(--faint); }
.engine-row.active { background: #f7faf5; }
.engine-row .dot.retry { background: #e0c489; }
.engine-row .state.retry { color: #a8853f; }

/* ---------- 手机 / iPhone 适配 ---------- */
@media (max-width: 640px) {
  html, body { font-size: 15px; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 14px 12px;
  }
  .brand { gap: 10px; }
  .brand-text p { display: none; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 8px 6px; font-size: 13.5px; text-align: center; }

  main { padding: 12px 12px calc(28px + env(safe-area-inset-bottom)); }

  /* 练习页：让整页滚动，而不是在小框里再套滚动条 */
  .reader { height: auto; max-height: none; }
  .sentences { overflow: visible; max-height: none; padding: 6px 6px 6px 0; }
  .sent { font-size: 17.5px; line-height: 1.7; padding: 10px 12px; }
  .console { padding: 14px; gap: 12px; }
  .row3 .btn, .row2 .btn { padding: 11px 8px; }
  .rec-btn { padding: 15px; font-size: 15px; }
  .keys { display: none; }

  /* iOS：输入框字号小于 16px 时聚焦会自动放大页面 */
  input, select, textarea { font-size: 16px; }

  /* 查词浮层改成贴底的整宽卡片 */
  .wordcard {
    left: 10px !important;
    right: 10px;
    width: auto;
    max-width: none;
    top: auto !important;
    bottom: calc(12px + env(safe-area-inset-bottom));
    max-height: 62vh;
  }
  .wc-body { max-height: 42vh; }

  .toast { width: calc(100vw - 24px); max-width: none; }
  .stat-grid { gap: 10px; grid-template-columns: repeat(2, 1fr); }
  .card { padding: 14px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
}
