:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e6e8ee;
  --brand: #2f6df6;
  --brand-soft: #eaf0ff;
  --ok: #12a06a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  overflow-x: hidden;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

.app { max-width: 720px; margin: 0 auto; padding-bottom: calc(72px + var(--safe-b)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(246, 247, 249, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar .spacer { flex: 1; }
.pill {
  font-size: 12px; color: var(--muted); background: #eef0f4;
  padding: 3px 9px; border-radius: 999px;
}
.pill.ok { color: var(--ok); background: #e7f6ef; }
.pill.bad { color: var(--bad); background: #fdecec; }

.page { display: none; padding: 14px 16px 8px; }
.page.active { display: block; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  margin-bottom: 12px;
}
.card h2 { font-size: 15px; margin: 0 0 6px; font-weight: 650; }
.card p.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 10px 14px; border-radius: 12px; font-weight: 550;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.block { width: 100%; padding: 13px; font-size: 16px; }
.btn.tiny { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; }

.entry {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 10px; text-align: left;
}
.entry .icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand-soft); font-size: 20px;
}
.entry .t { font-weight: 600; }
.entry .d { color: var(--muted); font-size: 13px; }
.entry .arrow { margin-left: auto; color: #c3c8d2; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
}
.chip.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
label.field input, label.field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; background: #fff; outline: none;
}
label.field input:focus, label.field textarea:focus { border-color: var(--brand); }

/* ---------- 对话 ---------- */
.chat-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.chat-head .theme { font-weight: 600; font-size: 14px; }
.words-inplay { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.wchip {
  font-size: 12px; padding: 3px 8px; border-radius: 8px;
  background: #f1f4fb; color: #3654a6;
}

.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 86px; }
.bubble {
  max-width: 88%; padding: 11px 13px; border-radius: 16px;
  white-space: pre-wrap; word-break: break-word; font-size: 15.5px;
}
.bubble.mia { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.me { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble .fx { display: block; margin-top: 8px; padding-top: 7px; border-top: 1px dashed #dbe2f2; color: var(--ok); font-size: 14px; }
.bubble .cn { display: block; margin-top: 8px; color: var(--muted); font-size: 13.5px; }
.bubble mark { background: #fff2b8; color: inherit; padding: 0 2px; border-radius: 4px; }

.composer {
  position: fixed; left: 0; right: 0; bottom: calc(62px + var(--safe-b)); z-index: 30;
  background: rgba(246, 247, 249, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: 10px 12px;
}
.composer .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; height: 44px; max-height: 120px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 14px; background: #fff; outline: none;
}
.composer .send { width: 44px; height: 44px; border-radius: 14px; border: none; background: var(--brand); color: #fff; font-size: 18px; }

/* ---------- 短文 ---------- */
.passage { font-size: 16.5px; line-height: 1.75; }
.passage h3 { font-size: 17px; margin: 0 0 10px; }
.passage mark { background: #fff2b8; padding: 0 2px; border-radius: 4px; }
.passage p { margin: 0 0 12px; }
.questions { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.questions div { margin-bottom: 6px; }

/* ---------- 词库 ---------- */
.stats { display: flex; gap: 8px; margin-bottom: 12px; }
.stat { flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 19px; }
.stat span { font-size: 12px; color: var(--muted); }

.wordlist { list-style: none; margin: 0; padding: 0; }
.wordlist li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
}
.wordlist li:last-child { border-bottom: none; }
.wordlist .w { font-weight: 600; }
.wordlist .m { color: var(--muted); font-size: 13.5px; flex: 1; }
.lv { width: 44px; height: 5px; border-radius: 3px; background: #eceef3; overflow: hidden; flex: none; }
.lv i { display: block; height: 100%; background: var(--ok); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1 1 0; min-width: 0; border: none; background: none; padding: 9px 0 8px;
  color: var(--muted); font-size: 11.5px; display: grid; justify-items: center; gap: 2px;
}
.tabs button .i { font-size: 18px; line-height: 1; }
.tabs button.on { color: var(--brand); }

.toast {
  position: fixed; left: 50%; bottom: calc(130px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(22, 24, 29, .92); color: #fff; padding: 10px 16px;
  border-radius: 12px; font-size: 14px; max-width: 88vw; z-index: 90;
  white-space: pre-line; text-align: left;
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.toast.show { opacity: 1; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 18, 24, .38); z-index: 80;
  display: none; align-items: flex-end;
}
.modal-mask.show { display: flex; }
.sheet {
  width: 100%; max-width: 720px; margin: 0 auto; background: #fff;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  max-height: 88vh; overflow: auto;
}
.sheet h3 { margin: 0 0 4px; font-size: 16px; }
.sheet .sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.sheet textarea { width: 100%; min-height: 150px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.sheet .file { margin: 10px 0 14px; font-size: 13px; color: var(--muted); }
code.fmt { background: #f3f4f7; padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.spin {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff;
  animation: sp .7s linear infinite; vertical-align: -2px;
}
@keyframes sp { to { transform: rotate(360deg); } }
.muted { color: var(--muted); font-size: 13px; }

.steps {
  background: #f6f8fe; border: 1px solid #e3ebfd; border-radius: 12px;
  padding: 10px 12px; margin: 4px 0 12px; font-size: 13px; line-height: 1.75; color: #3b4658;
}
.steps b { color: #1e2635; }
.steps > div { margin-top: 2px; }

/* 词库那一排按钮：别把「导入单词」拆成两行 */
#page-words .row { flex-wrap: wrap; gap: 8px; }
#page-words .row .btn { white-space: nowrap; flex: 0 0 auto; padding: 10px 14px; }

/* 划句翻译弹层（和导入弹窗的 .sheet 区分开） */
.tsheet { position: fixed; inset: 0; background: rgba(16, 22, 35, .45); display: none; align-items: flex-end; z-index: 220; }
.tsheet.on { display: flex; }
.tsheet-inner { width: 100%; max-height: 72vh; overflow: auto; background: #fff; border-radius: 18px 18px 0 0;
  padding: 18px 18px 22px; box-shadow: 0 -8px 30px rgba(20, 30, 50, .18); }
.tsheet-label { font-size: 12px; color: #8a93a5; margin: 10px 0 4px; letter-spacing: .04em; }
.tsheet-en { font-size: 15px; line-height: 1.55; color: #2a3345; }
.tsheet-zh { font-size: 16px; line-height: 1.7; color: #111827; font-weight: 500; }
.sent { border-radius: 4px; }
.sent:active { background: #eef3ff; }
.zh-all { margin-top: 14px; padding-top: 12px; border-top: 1px dashed #dfe4ee;
  font-size: 15px; line-height: 1.75; color: #2b3242; white-space: pre-wrap; }

.bubble .say {
  float: right; margin: 2px 0 0 8px; border: none; background: transparent;
  font-size: 15px; opacity: .55; cursor: pointer; padding: 2px 4px;
}
.bubble .say:active { opacity: 1; }

.word-head { display: flex; align-items: center; gap: 8px; padding-bottom: 4px; }
.word-big { font-size: 26px; font-weight: 700; color: #111827; letter-spacing: .01em; flex: 1; }
.word-head .say { border: 1px solid #d7dded; background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; color: #2b55d6; }
.word-ph { font-size: 14px; color: #6b7488; margin: 2px 0 6px; }
.word-senses > div { font-size: 15px; line-height: 1.7; color: #1f2937; }
.word-senses .pos { color: #8a93a5; font-size: 12px; margin-right: 6px; }
.word-examples > div { background: #f6f8fe; border: 1px solid #e6ecfb; border-radius: 12px; padding: 9px 11px; margin-bottom: 8px; }
.word-examples .en { font-size: 14.5px; line-height: 1.6; color: #172033; }
.word-examples .zh { font-size: 13px; line-height: 1.6; color: #5b6478; margin-top: 3px; }
.word-examples .spk { float: right; border: none; background: transparent; font-size: 15px; color: #2b55d6; }
.word-mnemonic { font-size: 14px; line-height: 1.7; color: #3a4356; }
.word-coll { font-size: 13px; color: #3f4a60; line-height: 1.8; }
.word-tip { font-size: 12px; margin-top: 10px; }
.wordlist li.wrow { cursor: pointer; }
.wordlist li.wrow:active { background: #eef2fe; }

/* 短文里点单词：小卡片，不铺满屏幕 */
.wd { cursor: pointer; }
.wd:active { background: #e8efff; border-radius: 4px; }
#wsheet.mini { align-items: center; justify-content: center; }
#wsheet.mini .tsheet-inner {
  width: 90%; max-width: 420px; max-height: 72vh;
  border-radius: 18px; margin: 0 auto; box-shadow: 0 18px 48px rgba(16, 22, 35, .28);
}

/* 挖空 & 语法点 */
.cloze {
  display: inline-block; min-width: 58px; padding: 0 8px; margin: 0 2px;
  border-bottom: 2px solid #2f6fed; background: #eef3ff; border-radius: 4px;
  color: #2f6fed; font-weight: 600; text-align: center; cursor: pointer;
}
.cloze.done { background: #e8f7ee; border-bottom-color: #12a150; color: #12a150; }
.gitem { padding: 10px 0; border-bottom: 1px dashed #e6eaf2; }
.gitem:last-child { border-bottom: none; }
.gtip { font-size: 15px; color: #1e2635; }
.gex { margin-top: 6px; font-size: 14px; color: #55617a; padding-left: 14px; border-left: 3px solid #dfe7f6; }

/* 句子语法解析 */
.gsent { font-size: 17px; line-height: 1.5; color: #1e2635; margin: 4px 0 12px; font-weight: 600; }
.gchunks { display: flex; flex-wrap: wrap; gap: 6px; }
.chunk { border-radius: 8px; padding: 3px 8px; font-size: 15px; background: #f3f5fa; }
.chunk .role { display: block; font-size: 11px; color: #7a879d; margin-top: 2px; }
.chunk[data-role="主语"] { background: #eaf2ff; }
.chunk[data-role="谓语"] { background: #ffeceb; }
.chunk[data-role="宾语"] { background: #eafaf0; }
.chunk[data-role="表语"] { background: #eafaf0; }
.chunk[data-role="状语"] { background: #f6f0ff; }
.chunk[data-role="定语"] { background: #fff6e5; }
.chunk[data-role="从句"] { background: #e9f6ff; }
.chunk[data-role="补语"] { background: #fdf0f7; }
.chunk[data-role="并列"] { background: #f4f4f6; }
.gpoints > div { padding: 8px 0; border-bottom: 1px dashed #e6eaf2; font-size: 14px; color: #2b3446; }
.gpoints > div:last-child { border-bottom: none; }
.gpoints b { color: #2f6fed; }
.gzh { margin-top: 12px; font-size: 15px; color: #3b4658; background: #f7f9fd; border-radius: 10px; padding: 10px 12px; }
.gbtn { cursor: pointer; font-size: 11px; margin-left: 3px; opacity: .5; vertical-align: super; user-select: none; }
.gbtn:active { opacity: 1; }
