/* 词境 - mobile-first */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --primary: #4f46e5;
  --primary-weak: #eef2ff;
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1f2333;
  --muted: #8a90a6;
  --ok: #16a34a;
  --bad: #dc2626;
  --radius: 16px;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.55;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar {
  padding: calc(env(safe-area-inset-top) + 12px) 18px 10px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
}
.topbar-title { font-size: 20px; font-weight: 700; }
.topbar-sub { font-size: 12px; font-weight: 400; opacity: .8; margin-left: 6px; }
.topbar-stats { font-size: 13px; opacity: .95; margin-top: 2px; }

/* ---------- main & cards ---------- */
main { flex: 1; padding: 14px 14px 90px; }
.view.hidden { display: none; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(30, 30, 80, .06);
}
.card h2 { font-size: 16px; margin-bottom: 10px; }
.tag {
  font-size: 11px; background: var(--primary-weak); color: var(--primary);
  border-radius: 8px; padding: 1px 8px; margin-left: 8px; vertical-align: 2px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-block; border: none; cursor: pointer;
  border-radius: 12px; padding: 10px 18px; font-size: 15px;
  background: #e8e9f3; color: var(--text); font-family: inherit;
  transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: #fff; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-plain { background: transparent; color: var(--muted); }
.btn-danger { background: #fee2e2; color: var(--bad); }
.btn-big { width: 100%; padding: 14px; font-size: 16px; margin-top: 10px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }
.file-btn, .file-btn-inline { display: flex; align-items: center; justify-content: center; text-align: center; }
.file-btn-inline { padding: 10px 18px; }

/* ---------- forms ---------- */
textarea, input[type="text"] {
  width: 100%; border: 1.5px solid #dfe1ee; border-radius: 12px;
  padding: 12px; font-size: 16px; font-family: inherit; margin-bottom: 4px;
  background: #fafafe;
}
textarea:focus, input:focus { outline: none; border-color: var(--primary); }
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; font-size: 15px;
}
.setting-row select { padding: 6px 10px; border-radius: 10px; border: 1.5px solid #dfe1ee; font-size: 15px; }

/* ---------- status card ---------- */
.status-card { background: linear-gradient(135deg, #eef2ff, #f5f3ff); }
.status-row { display: flex; gap: 8px; text-align: center; }
.status-row .st { flex: 1; background: #fff; border-radius: 12px; padding: 8px 4px; }
.status-row .st b { display: block; font-size: 20px; color: var(--primary); }
.status-row .st span { font-size: 12px; color: var(--muted); }

/* ---------- passages ---------- */
.passage { margin-bottom: 14px; }
.passage-head { display: flex; justify-content: space-between; align-items: baseline; }
.passage-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.passage-text { font-size: 16.5px; line-height: 1.8; }
.passage-text tw { font-weight: 700; color: var(--primary); background: var(--primary-weak); border-radius: 4px; padding: 0 3px; }
.psg-actions { display: flex; gap: 8px; margin-top: 12px; }
.psg-actions .btn { padding: 8px 14px; font-size: 14px; }
.translation { margin-top: 10px; border-top: 1px dashed #e3e4f0; padding-top: 10px; font-size: 14.5px; color: #4b5069; }
.word-notes { margin-top: 12px; border-top: 1px dashed #e3e4f0; padding-top: 10px; }
.word-note { margin-bottom: 8px; font-size: 14px; }
.word-note b { color: var(--primary); }
.word-note .eg { color: var(--muted); display: block; font-style: italic; }

/* cloze */
.cloze-input {
  display: inline-block; border: none; border-bottom: 2px solid var(--primary);
  background: #f6f7ff; border-radius: 6px 6px 0 0;
  font-family: inherit; font-size: 15.5px; text-align: center;
  padding: 2px 4px; margin: 0 2px; color: var(--text);
  min-width: 70px; width: 8ch; max-width: 45vw;
}
.cloze-input:focus { outline: none; background: #eef2ff; }
.cloze-input.right { color: var(--ok); border-bottom-color: var(--ok); background: #f0fdf4; }
.cloze-input.wrong { color: var(--bad); border-bottom-color: var(--bad); background: #fef2f2; }
.cloze-result-summary { margin-top: 12px; font-size: 15px; }
.cloze-result-summary .r-ok { color: var(--ok); }
.cloze-result-summary .r-bad { color: var(--bad); }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }
.word-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip {
  background: var(--primary-weak); color: var(--primary);
  border-radius: 999px; padding: 4px 12px; font-size: 14px;
}
.word-chip .del { margin-left: 6px; opacity: .5; }
#ocrPreview { max-width: 100%; border-radius: 12px; margin: 10px 0; border: 1px solid #e3e4f0; }
.ocr-word {
  display: inline-flex; align-items: center; gap: 5px;
  background: #f6f7ff; border: 1px solid #dfe1ee; border-radius: 10px;
  padding: 5px 10px; margin: 4px 6px 4px 0; font-size: 15px; cursor: pointer;
}
.ocr-word.off { opacity: .35; text-decoration: line-through; }

/* word list */
.word-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(30,30,80,.05);
}
.word-item .w { font-weight: 700; font-size: 16px; }
.word-item .meta { font-size: 12px; color: var(--muted); text-align: right; }
.badge { border-radius: 8px; padding: 1px 8px; font-size: 11px; margin-left: 6px; }
.badge.due { background: #fef3c7; color: #b45309; }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.new { background: #e0e7ff; color: #4338ca; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px;
  display: flex; background: #fff; border-top: 1px solid #e8e9f3;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  flex: 1; border: none; background: none; padding: 8px 0 6px;
  font-size: 11.5px; color: var(--muted); font-family: inherit; cursor: pointer;
}
.tab .tab-ico { display: block; font-size: 20px; margin-bottom: 1px; }
.tab.active { color: var(--primary); font-weight: 600; }

/* ---------- loading & toast ---------- */
#loading {
  position: fixed; inset: 0; background: rgba(20, 20, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#loading.hidden { display: none; }
.loading-box {
  background: #fff; border-radius: 18px; padding: 26px 34px; text-align: center;
  font-size: 15px; max-width: 78vw;
}
.spinner {
  width: 34px; height: 34px; margin: 0 auto 12px;
  border: 3.5px solid #e0e7ff; border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,50,.92); color: #fff; padding: 10px 20px;
  border-radius: 999px; font-size: 14px; opacity: 0; transition: .25s; z-index: 200;
  max-width: 80vw; text-align: center; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* desktop: keep phone-like column */
@media (min-width: 700px) {
  body { background: #e9eaf5; }
  #app { box-shadow: 0 0 30px rgba(40,40,90,.12); background: var(--bg); }
  .tabbar { border-radius: 0; }
}
