/* ==========================================================================
   页面布局
   --------------------------------------------------------------------------
   只放 components.css 里没有的、属于"页面骨架"层面的样式。
   组件级样式一律回到 design/components.css 改，这里不重复定义。
   ========================================================================== */

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

/* 顶栏与底栏吸附，中间内容滚动 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-8);
  outline: none;
}
.app-main:focus-visible { box-shadow: none; }

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  /* 兼容 iPhone 底部安全区 */
  padding-bottom: env(safe-area-inset-bottom, 0);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0));
}

/* ---------- 区块 ---------- */
.section { margin-bottom: var(--space-8); }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.section__title {
  font-size: var(--text-h2);
  font-weight: var(--weight-semibold);
}
.section__sub {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

/* 通用横向排布工具，替代散落各处的 inline style */
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-muted); font-size: var(--text-sm); }

.pwa-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.status-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--ink-muted);
}
.status-dot.is-ready { background: var(--status-good); }

.sync-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
}
.sync-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

/* ---------- Toast 容器 ---------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--space-4) + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
}
.toast-host .toast {
  animation: toast-in var(--dur-base) var(--ease);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- 首页今日卡 ---------- */
.today {
  background: linear-gradient(135deg, var(--primary-wash), transparent 70%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}
.today__figure {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.today__num {
  font-size: 2.75rem;
  font-weight: var(--weight-bold);
  line-height: 1;
  letter-spacing: -0.02em;
}

/* 单词卡翻页区：左右各一个按钮，中间是进度 */
.deck-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.deck-nav__pos {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- 分类详情摘要 ---------- */
.cat-summary {
  position: relative;
  margin-bottom: var(--space-5);
  padding: var(--space-2) 0 var(--space-4) var(--space-4);
}
.cat-summary::before {
  content: "";
  position: absolute;
  top: var(--space-2);
  bottom: var(--space-4);
  left: 0;
  width: 3px;
  border-radius: var(--radius-full);
  background: var(--cat-color);
}
.cat-summary__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}
.cat-summary__label {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}
.cat-summary__count {
  margin-top: 2px;
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.cat-summary__count strong {
  color: var(--ink);
  font-size: var(--text-h2);
  font-weight: var(--weight-semibold);
}
.cat-summary__percent {
  color: var(--ink);
  font-size: var(--text-h2);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

/* ---------- 设置页 ---------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-row__label { font-weight: var(--weight-medium); }
.setting-row__desc {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  margin-top: 2px;
}

/* 分段选择器：主题、口音、练习模式共用 */
.seg {
  display: inline-flex;
  background: var(--surface-sunken);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}
.seg__btn {
  position: relative;
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: 6px var(--space-4);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.seg__btn.is-active {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
/* 分段按钮左右紧挨着，命中区只能往上下扩，不能往左右扩 */
.seg__btn::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 44px;
  transform: translateY(-50%);
}

/* 数字输入 */
.num-input {
  width: 76px;
  padding: 8px var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--text-body);
  text-align: center;
}
.text-input {
  width: 100%;
  padding: 10px var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--text-body);
}

/* ---------- 练习页 ---------- */
.quiz-progress {
  display: flex;
  gap: 4px;
  margin-bottom: var(--space-5);
}
.quiz-progress__seg {
  flex: 1;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
}
.quiz-progress__seg.is-done { background: var(--primary); }
.quiz-progress__seg.is-now  { background: var(--primary-wash-strong); }

.quiz-prompt {
  text-align: center;
  padding: var(--space-6) 0 var(--space-8);
}
.quiz-prompt__word {
  font-size: var(--text-display);
  font-weight: var(--weight-bold);
  letter-spacing: -0.01em;
  word-break: break-word;
}
.quiz-prompt__ipa {
  font-family: var(--font-ipa);
  color: var(--ink-muted);
  font-size: var(--text-body);
  margin-top: var(--space-2);
}
.quiz-prompt__hint {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  margin-top: var(--space-3);
}

/* 拼写题：真实 input 透明地盖在字母格上。
   这样移动端能正常唤起键盘、桌面端能正常粘贴，而视觉上只看见字母格。
   不用"监听 document 键盘事件"的做法——那在手机上根本调不出输入法。 */
.spell-wrap { position: relative; }
.spell-wrap .spell { justify-content: center; }
.spell-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  background: transparent;
  font-size: 16px; /* 小于 16px iOS 会自动放大页面 */
  cursor: pointer;
}
.spell-input:focus { outline: none; }
/* 输入框获得焦点时，给字母格整体一个焦点环，键盘用户能看出光标在哪 */
.spell-wrap:focus-within .spell { box-shadow: var(--focus-ring); border-radius: var(--radius-md); }

/* ---------- 统计页 ---------- */
.dist-row {
  display: grid;
  grid-template-columns: 56px 1fr 44px;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
}
.dist-row__bar {
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  overflow: hidden;
}
.dist-row__fill {
  /* 必须显式 block。这个填充在 HTML 里是 <span>，父元素 .dist-row__bar 是普通块容器，
     不会像 grid/flex 那样把子元素 blockify，span 就保持 inline；
     而 width / height 对非替换行内元素不生效，六条填充会全部画不出来。
     旁边的 .dist-row__bar 侥幸没事，是因为它是 .dist-row 这个 grid 的直接子元素。 */
  display: block;
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--primary);
}
.dist-row__num {
  text-align: right;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

/* 分类进度列表 */
.catbar {
  display: grid;
  grid-template-columns: 1fr 64px;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.catbar:last-child { border-bottom: none; }

@media (min-width: 768px) {
  .app-main { padding-left: var(--space-6); padding-right: var(--space-6); }
}
