/* ==========================================================================
   拾词 — stylesheet
   Mobile first, no framework. Light and dark themes both supported.
   ========================================================================== */

:root {
  --brand: #3b5bdb;
  --brand-soft: #edf2ff;
  --brand-ink: #21356f;
  --accent: #f59f00;
  --ok: #12b886;
  --ok-soft: #e6fcf5;
  --bad: #f03e3e;
  --bad-soft: #fff5f5;

  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #fafbfe;
  --line: #e6e8f0;
  --ink: #17203a;
  --ink-2: #4a5470;
  --muted: #8b93a9;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(23, 32, 58, .04), 0 6px 18px rgba(23, 32, 58, .06);
  --shadow-lg: 0 -8px 40px rgba(23, 32, 58, .14);

  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #7f9cf5;
    --brand-soft: #232a45;
    --brand-ink: #cdd8ff;
    --ok-soft: #12312a;
    --bad-soft: #33191c;
    --bg: #0f1220;
    --surface: #181c2e;
    --surface-2: #1f2438;
    --line: #2a3049;
    --ink: #edf0fb;
    --ink-2: #c2c9de;
    --muted: #7f88a3;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .35);
    --shadow-lg: 0 -8px 40px rgba(0, 0, 0, .5);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- boot */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
  background: var(--bg);
  z-index: 100;
}
.boot-mark {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: .22em;
  background: linear-gradient(135deg, var(--brand), #7048e8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  padding-left: .22em;
}
.boot-bar {
  width: min(240px, 70vw);
  height: 4px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
  margin: 0 auto;
}
.boot-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--brand), #7048e8);
  transition: width .25s ease;
}
.boot-note { color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- shell */

#app { display: flex; flex-direction: column; min-height: 100dvh; }

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.appbar.scrolled { border-bottom-color: var(--line); }
.appbar-row { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.appbar h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: .01em;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.appbar .sub { font-size: 12px; color: var(--muted); margin-top: -2px; }

.iconbtn {
  border: 0;
  background: var(--surface);
  color: var(--ink);
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 17px;
  box-shadow: var(--shadow);
  cursor: pointer;
  flex: none;
}
.iconbtn:active { transform: scale(.94); }
.iconbtn.plain { background: transparent; box-shadow: none; }

.view {
  flex: 1;
  padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0;
  background: none;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}
.tab .glyph { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: .65; transition: .18s; }
.tab.on { color: var(--brand); font-weight: 600; }
.tab.on .glyph { filter: none; opacity: 1; transform: translateY(-1px); }

/* ---------------------------------------------------------------- blocks */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card.tight { padding: 12px; }
.card.flush { padding: 0; overflow: hidden; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 20px 2px 10px;
}
.section-title h2 { font-size: 14px; font-weight: 700; color: var(--ink-2); letter-spacing: .06em; }
.section-title .link { font-size: 13px; color: var(--brand); cursor: pointer; background: none; border: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty .big { font-size: 40px; margin-bottom: 10px; opacity: .55; }

/* ---------------------------------------------------------------- buttons */

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--ink);
  transition: transform .12s, opacity .12s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.primary { background: linear-gradient(135deg, var(--brand), #5f6fd8); color: #fff; box-shadow: 0 4px 14px rgba(59, 91, 219, .28); }
.btn.ghost { background: var(--surface-2); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.block { display: block; width: 100%; text-align: center; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.7;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.warn { background: #fff4e6; color: #d9480f; border-color: transparent; }
.chip.pos { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }

/* ---------------------------------------------------------------- search */

.searchbox {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: 1.5px solid transparent;
  transition: border-color .18s;
}
.searchbox:focus-within { border-color: var(--brand); }
.searchbox input {
  flex: 1;
  border: 0;
  outline: 0;
  background: none;
  font-size: 16px;
  min-width: 0;
}
.searchbox .glass { font-size: 17px; opacity: .5; }
.searchbox .clear { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 2px; }

.seg {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 14px;
}
.seg button {
  flex: 1;
  border: 0;
  background: none;
  padding: 8px 6px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }

/* ---------------------------------------------------------------- entries */

.entry {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 9px;
  cursor: pointer;
}
.entry:active { transform: scale(.992); }
.entry .head { flex: 1; min-width: 0; }
.entry .word { font-size: 17px; font-weight: 700; letter-spacing: .01em; overflow-wrap: anywhere; }
.entry .phon { font-size: 12px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.entry .gloss { font-size: 13.5px; color: var(--ink-2); margin-top: 3px; }
.entry .meta { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
.entry .go { color: var(--muted); font-size: 16px; align-self: center; }

.rank {
  flex: none;
  width: 62px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}
.rank b { display: block; font-size: 13px; color: var(--ink-2); }

/* ---------------------------------------------------------------- detail */

.detail-word {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.detail-word h2 { font-size: 27px; font-weight: 750; letter-spacing: -.01em; word-break: break-word; }
.detail-phon { color: var(--muted); font-size: 14px; margin-bottom: 12px; }

.sense {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.sense:first-child { border-top: 0; }
.sense .poscol { flex: none; width: 58px; padding-top: 1px; }
.sense .defs { flex: 1; min-width: 0; }
.sense .def { font-size: 15px; }
.sense .def + .def { margin-top: 3px; }
.sense .domain { font-size: 11px; color: var(--muted); margin-left: 4px; }

.pick {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1.5px solid transparent;
  background: var(--surface-2);
  margin-bottom: 6px;
}
.pick.on { border-color: var(--brand); background: var(--brand-soft); }
.pick .box {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: transparent;
  margin-top: 1px;
}
.pick.on .box { background: var(--brand); border-color: var(--brand); color: #fff; }
.pick .txt { flex: 1; font-size: 14.5px; }

.forms { display: grid; gap: 7px; }
.form-row { display: flex; gap: 10px; font-size: 14px; }
.form-row .k { flex: none; width: 92px; color: var(--muted); font-size: 13px; }
.form-row .v { font-weight: 600; word-break: break-word; }

.example { padding: 11px 0; border-top: 1px solid var(--line); }
.example:first-of-type { border-top: 0; padding-top: 4px; }
.ex-en { font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.ex-en b { color: var(--brand); font-weight: 700; }
.ex-zh { font-size: 13.5px; color: var(--muted); margin-top: 3px; line-height: 1.55; }

/* ---------------------------------------------------------------- study */

.study-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - var(--safe-t) - 150px); }

.study-top { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.progress { flex: 1; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), #7048e8); transition: width .3s; }

.study-card {
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 26px 20px;
  text-align: center;
  margin: 14px 0 18px;
  min-height: 168px;
  display: grid;
  place-content: center;
  gap: 8px;
}
.study-card .prompt { font-size: 34px; font-weight: 750; letter-spacing: -.01em; word-break: break-word; }
.study-card .prompt.zh { font-size: 27px; }
.study-card .phon { color: var(--muted); font-size: 14px; }
.study-card .hint { color: var(--muted); font-size: 13px; }

.speaker {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 0;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 38px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  cursor: pointer;
}
.speaker:active { transform: scale(.94); }
.speaker.playing { animation: pulse 1s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 91, 219, .35); }
  50% { box-shadow: 0 0 0 14px rgba(59, 91, 219, 0); }
}

.options { display: grid; gap: 10px; }
.option {
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: .15s;
  overflow-wrap: anywhere;
}
.option:active { transform: scale(.985); }
.option .idx {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.correct .idx { background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .idx { background: var(--bad); color: #fff; }
.option.dim { opacity: .5; }

.study-foot { margin-top: auto; padding-top: 16px; }

.feedback {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  margin-bottom: 12px;
  font-size: 14px;
}
.feedback.ok { background: var(--ok-soft); color: #0b7285; }
.feedback.bad { background: var(--bad-soft); color: #c92a2a; }

/* ---------------------------------------------------------------- me */

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 13px 10px;
  text-align: center;
}
.stat b { display: block; font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.stat span { font-size: 11.5px; color: var(--muted); }

.heat { display: flex; gap: 4px; align-items: flex-end; height: 62px; }
.heat i {
  flex: 1;
  border-radius: 4px;
  background: var(--brand-soft);
  display: block;
  min-height: 4px;
}
.heat i.on { background: linear-gradient(180deg, var(--brand), #7048e8); }

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}
.setting-row:first-child { border-top: 0; }
.setting-row .label { flex: 1; font-size: 15px; }
.setting-row .label small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.setting-row select, .setting-row input[type="time"], .setting-row input[type="number"] {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 14px;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 99px;
  background: var(--line);
  border: 0;
  cursor: pointer;
  transition: background .2s;
  flex: none;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(20px); }

/* ---------------------------------------------------------------- sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 32, .45);
  z-index: 60;
  opacity: 0;
  transition: opacity .2s;
  display: flex;
  align-items: flex-end;
}
.sheet-backdrop.open { opacity: 1; }
.sheet-panel {
  width: 100%;
  max-height: 88dvh;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  padding-bottom: var(--safe-b);
}
.sheet-panel.open { transform: translateY(0); }
.sheet-grabber { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 8px auto 2px; flex: none; }
.sheet-head { padding: 10px 20px 4px; flex: none; }
.sheet-head h3 { font-size: 17px; font-weight: 700; }
.sheet-body { padding: 12px 20px; overflow: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 20px 16px; border-top: 1px solid var(--line); flex: none; }

/* ---------------------------------------------------------------- toast */

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  z-index: 80;
  display: grid;
  justify-items: center;
  pointer-events: none;
}
.toast {
  background: #1f2438;
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 14px;
  max-width: 84vw;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: .22s;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .3);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { background: #0ca678; }
.toast.bad { background: #e03131; }

/* ---------------------------------------------------------------- misc */

.banner {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff4e6, #ffe8cc);
  color: #a9500a;
  font-size: 13.5px;
  margin-bottom: 12px;
}
@media (prefers-color-scheme: dark) {
  .banner { background: linear-gradient(135deg, #33270f, #3d2d12); color: #ffc078; }
}
.banner .x { border: 0; background: none; color: inherit; font-size: 16px; cursor: pointer; opacity: .7; }

.divider { height: 1px; background: var(--line); margin: 12px 0; }

@media (min-width: 620px) {
  .view, .appbar { max-width: 640px; margin-left: auto; margin-right: auto; width: 100%; }
  .sheet-panel { max-width: 560px; margin: 0 auto; border-radius: 22px; margin-bottom: 24px; }
  .sheet-backdrop { align-items: center; }
}
