/* ===========================================================
   作业小助手 —— 主样式（平板优先，触控友好）
   =========================================================== */

/* 楷体网页字体（子集化，约 2.3 MB）。
   安卓手机 / 部分平板没有系统楷体，会退回宋体/黑体，字形和笔顺跟电脑对不上；
   这里带上自己的一份，保证所有设备一致。用 `npm run build:font` 重新生成。 */
@font-face {
  font-family: "HanziKai";
  src: url("../fonts/kaiti-subset.woff2") format("woff2");
  font-display: swap;
}

:root {
  --c-bg: #f5f7fa;
  --c-surface: #ffffff;
  --c-surface-2: #f0f3f7;
  --c-border: #dce3ec;
  --c-text: #1a2332;
  --c-text-dim: #64748b;
  --c-primary: #4f83d1;
  --c-primary-dark: #3a68ae;
  --c-primary-soft: #e8f1fb;
  --c-ok: #2f9e6f;
  --c-ok-soft: #e6f7f0;
  --c-bad: #dc3545;
  --c-bad-soft: #fdeaec;
  --c-warn: #f59e0b;
  --c-warn-soft: #fef3e2;
  --c-coin: #f59e0b;
  --c-parent: #8b5cf6;
  --c-parent-soft: #f3edfd;

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-pill: 999px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --shadow-1: 0 2px 8px rgba(15, 23, 42, .06);
  --shadow-2: 0 4px 20px rgba(15, 23, 42, .08);
  --shadow-3: 0 10px 40px rgba(15, 23, 42, .12);

  --topbar-h: 60px;
  --tabbar-h: 68px;
  --tap: 48px;

  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
          "Helvetica Neue", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
  --font-hanzi: "HanziKai", "Kaiti SC", "STKaiti", "KaiTi", "Kaiti TC", "PingFang SC",
                "Microsoft YaHei", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 600; }

button { font-family: inherit; font-size: inherit; color: inherit; }

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* < 16px 会让 iPad 自动放大 */
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-primary);
  color: #fff;
  border-radius: 0 0 var(--r-md) 0;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--c-primary);
  outline-offset: 2px;
}

/* ---------------- 启动遮罩 ---------------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--sp-4);
  background: var(--c-bg);
  z-index: 50;
}
.boot[hidden] { display: none; }
.boot__spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
.boot__text { margin: 0; color: var(--c-text-dim); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .boot__spinner { animation-duration: 3s; }
}

.boot--error .boot__spinner { display: none; }
.boot__err {
  max-width: 32rem;
  padding: var(--sp-4);
  background: var(--c-bad-soft);
  border: 1px solid var(--c-bad);
  border-radius: var(--r-md);
  color: #8c2a27;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------- 布局 ---------------- */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.app[hidden] { display: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--topbar-h);
  padding: var(--sp-2) var(--sp-4);
  padding-top: max(var(--sp-2), env(safe-area-inset-top));
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
}

.topbar__back {
  flex: none;
  min-height: 40px;
  padding: 0 var(--sp-3) 0 var(--sp-2);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  cursor: pointer;
}
.topbar__back::before { content: '‹'; margin-right: 4px; font-size: 1.3em; line-height: 1; }
.topbar__back[hidden] { display: none; }

.topbar__title {
  flex: 1 1 auto;
  font-size: 19px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__right {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.coin-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px var(--sp-3);
  background: linear-gradient(135deg, #fef3e2 0%, #fde68a 100%);
  border: 1px solid #fcd34d;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #92400e;
  box-shadow: 0 2px 8px rgba(245, 158, 11, .15);
}
.coin-chip[hidden] { display: none; }
.coin-chip__icon { color: var(--c-coin); font-size: 14px; }
.coin-chip--bump { animation: bump .45s ease; }
@keyframes bump {
  0%, 100% { transform: scale(1); }
  35% { transform: scale(1.22); }
}

/* 连接状态：只在断开或有待保存数据时显示 */
.net-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px var(--sp-3);
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.net-chip[hidden] { display: none; }
.net-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.net-chip--offline {
  background: var(--c-bad-soft);
  border: 1px solid #f2c4c2;
  color: #a8332f;
}
.net-chip--offline .net-chip__dot { background: var(--c-bad); }
.net-chip--syncing {
  background: var(--c-warn-soft);
  border: 1px solid #f0d8a4;
  color: #8a5f10;
}
.net-chip--syncing .net-chip__dot {
  background: var(--c-warn);
  animation: net-pulse 1.1s ease-in-out infinite;
}
@keyframes net-pulse {
  50% { opacity: .25; }
}
@media (prefers-reduced-motion: reduce) {
  .net-chip--syncing .net-chip__dot { animation: none; }
}
.net-chip__btn {
  margin-left: 2px;
  padding: 2px 8px;
  background: #fff;
  border: 1px solid currentColor;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
}

/* 遥控判分：等待孩子那边响应 */
.remote-wait {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--c-text-dim);
}
.remote-wait__spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-parent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.remote-peer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--c-ok-soft);
  border: 1px solid #b6e2cd;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 600;
  color: #1d6d4c;
}
.remote-peer--waiting {
  background: var(--c-warn-soft);
  border-color: #f0d8a4;
  color: #8a5f10;
}

.topbar__child {
  min-height: 40px;
  max-width: 8em;
  padding: 0 var(--sp-3);
  background: var(--c-primary-soft);
  border: 1px solid #c3d8f4;
  border-radius: var(--r-pill);
  color: var(--c-primary-dark);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.topbar__child[hidden] { display: none; }

.topbar__account {
  min-height: 40px;
  max-width: 8em;
  padding: 0 var(--sp-3);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  color: var(--c-text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.topbar__account[hidden] { display: none; }

/* 使用时长到点后的遮罩 */
.usage-block {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-content: center;
  background: rgba(35, 48, 63, .94);
  color: #fff;
  text-align: center;
  padding: var(--sp-5);
}
.usage-block__box { display: grid; gap: var(--sp-3); justify-items: center; max-width: 22rem; }
.usage-block__icon { font-size: 52px; line-height: 1; }
.usage-block h2 { margin: 0; }
.usage-block p { margin: 0; color: #cdd6e2; }

.main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-4) calc(var(--tabbar-h) + var(--sp-6));
}
.main:focus { outline: none; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  padding-bottom: max(var(--sp-1), env(safe-area-inset-bottom));
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
}
.tabbar:empty { display: none; }

.tab {
  flex: 1 1 0;
  max-width: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 60px;
  padding: var(--sp-1);
  background: none;
  border: 0;
  border-radius: var(--r-md);
  color: var(--c-text-dim);
  font-size: 13px;
  cursor: pointer;
}
.tab__icon { font-size: 20px; line-height: 1.1; }
.tab[aria-current="page"] {
  background: var(--c-primary-soft);
  color: var(--c-primary-dark);
  font-weight: 700;
}
.tab--parent[aria-current="page"] {
  background: var(--c-parent-soft);
  color: var(--c-parent);
}

/* ---------------- 通用组件 ---------------- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--sp-5);
  transition: box-shadow .2s ease, transform .2s ease;
}
.card:hover {
  box-shadow: var(--shadow-2);
}
.card + .card { margin-top: var(--sp-5); }
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.card__title { 
  font-size: 19px; 
  font-weight: 700;
  color: var(--c-text);
}
.card__sub { 
  margin: 4px 0 0; 
  color: var(--c-text-dim); 
  font-size: 14px;
  line-height: 1.5;
}

.section-title {
  margin: var(--sp-6) 0 var(--sp-4);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--c-text-dim);
}
.section-title:first-child { margin-top: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  user-select: none;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, .08);
  border-color: var(--c-text-dim);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn--primary { 
  background: var(--c-primary); 
  border-color: var(--c-primary); 
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 131, 209, .2);
}
.btn--primary:hover:not(:disabled) { 
  background: var(--c-primary-dark); 
  border-color: var(--c-primary-dark);
  box-shadow: 0 4px 16px rgba(79, 131, 209, .3);
}
.btn--parent { 
  background: var(--c-parent); 
  border-color: var(--c-parent); 
  color: #fff;
  box-shadow: 0 2px 8px rgba(139, 92, 246, .2);
}
.btn--parent:hover:not(:disabled) {
  background: #7c3aed;
  box-shadow: 0 4px 16px rgba(139, 92, 246, .3);
}
.btn--ok { 
  background: var(--c-ok); 
  border-color: var(--c-ok); 
  color: #fff;
  box-shadow: 0 2px 8px rgba(47, 158, 111, .2);
}
.btn--ok:hover:not(:disabled) {
  background: #27805b;
  box-shadow: 0 4px 16px rgba(47, 158, 111, .3);
}
.btn--bad { 
  background: var(--c-bad); 
  border-color: var(--c-bad); 
  color: #fff;
  box-shadow: 0 2px 8px rgba(220, 53, 69, .2);
}
.btn--bad:hover:not(:disabled) {
  background: #bb2d3b;
  box-shadow: 0 4px 16px rgba(220, 53, 69, .3);
}
.btn--ghost { 
  background: transparent; 
  box-shadow: none;
}
.btn--ghost:hover:not(:disabled) {
  background: var(--c-surface-2);
}
.btn--danger-text { 
  background: transparent; 
  border-color: transparent; 
  color: var(--c-bad);
  box-shadow: none;
}
.btn--sm { min-height: 38px; padding: 0 var(--sp-4); font-size: 14px; }
.btn--lg { 
  min-height: 56px; 
  padding: 0 var(--sp-6); 
  font-size: 18px; 
  border-radius: var(--r-lg);
  font-weight: 700;
}
.btn--block { display: flex; width: 100%; }
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}
.btn-row--end { justify-content: flex-end; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-dim);
  white-space: nowrap;
}
.chip--ok { background: var(--c-ok-soft); border-color: #b8e6d2; color: #1d6d4c; }
.chip--bad { background: var(--c-bad-soft); border-color: #f5c2c7; color: #a8332f; }
.chip--warn { background: var(--c-warn-soft); border-color: #fcd34d; color: #92400e; }
.chip--info { background: var(--c-primary-soft); border-color: #bfdbfe; color: var(--c-primary-dark); }
.chip--coin { background: var(--c-warn-soft); border-color: #fcd34d; color: #92400e; }

.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.empty {
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
  color: var(--c-text-dim);
  background: var(--c-surface);
  border: 2px dashed var(--c-border);
  border-radius: var(--r-lg);
}
.empty__title { 
  font-weight: 700; 
  color: var(--c-text); 
  margin-bottom: var(--sp-3);
  font-size: 17px;
}

.field { display: block; margin-bottom: var(--sp-4); }
.field__label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 15px; }
.field__hint { margin: 5px 0 0; font-size: 13px; color: var(--c-text-dim); }
.field__err { margin: 5px 0 0; font-size: 13px; color: var(--c-bad); font-weight: 600; }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}
.textarea { min-height: 7em; resize: vertical; line-height: 1.7; }
.input--num { max-width: 8em; font-variant-numeric: tabular-nums; }
.input--inline { display: inline-block; width: auto; }

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.row--between { justify-content: space-between; }
.spacer { flex: 1 1 auto; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--c-surface-2);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row__text { flex: 1 1 auto; }
.switch-row__title { font-weight: 600; }
.switch-row__hint { font-size: 13px; color: var(--c-text-dim); }

.switch {
  position: relative;
  flex: none;
  width: 54px;
  height: 32px;
}
.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.switch__track {
  position: absolute;
  inset: 0;
  background: #c9d3e2;
  border-radius: var(--r-pill);
  transition: background-color .15s ease;
  pointer-events: none;
}
.switch__track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 26px; height: 26px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-1);
  transition: transform .15s ease;
}
.switch input:checked + .switch__track { background: var(--c-ok); }
.switch input:checked + .switch__track::after { transform: translateX(22px); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--c-primary); outline-offset: 2px; }

.list { list-style: none; margin: 0; padding: 0; }
.list__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--c-surface-2);
}
.list__item:last-child { border-bottom: 0; }
.list__main { flex: 1 1 auto; min-width: 0; }
.list__title { font-weight: 600; }
.list__sub { font-size: 13px; color: var(--c-text-dim); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--c-surface-2);
  white-space: nowrap;
}
.table th { color: var(--c-text-dim); font-size: 13px; font-weight: 700; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.progress {
  height: 12px;
  background: var(--c-surface-2);
  border-radius: var(--r-pill);
  overflow: hidden;
  border: 1px solid var(--c-border);
  box-shadow: inset 0 1px 3px rgba(15, 23, 42, .05);
}
.progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--c-primary) 0%, #6b9fe3 100%);
  border-radius: inherit;
  transition: width .4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(79, 131, 209, .3);
}
.progress__bar--ok { 
  background: linear-gradient(90deg, var(--c-ok) 0%, #3bb883 100%);
  box-shadow: 0 1px 2px rgba(47, 158, 111, .3);
}
.progress__bar--bad { 
  background: linear-gradient(90deg, var(--c-bad) 0%, #e35d6a 100%);
  box-shadow: 0 1px 2px rgba(220, 53, 69, .3);
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--sp-4); }
.stat {
  padding: var(--sp-4);
  background: var(--c-surface-2);
  border-radius: var(--r-md);
  text-align: center;
  border: 1px solid var(--c-border);
}
.stat__value { 
  font-size: 28px; 
  font-weight: 700; 
  font-variant-numeric: tabular-nums; 
  line-height: 1.2;
  color: var(--c-text);
}
.stat__label { 
  font-size: 13px; 
  color: var(--c-text-dim);
  margin-top: 4px;
  font-weight: 600;
}

/* ---------------- Toast ---------------- */

.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--sp-5));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
  width: max-content;
  max-width: min(90vw, 30rem);
}
.toast {
  padding: var(--sp-3) var(--sp-5);
  background: #23303f;
  color: #fff;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-3);
  font-weight: 600;
  text-align: center;
  animation: toast-in .2s ease;
}
.toast--ok { background: var(--c-ok); }
.toast--bad { background: var(--c-bad); }
.toast--coin { background: var(--c-coin); color: #40300a; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
}

/* ---------------- 弹窗 ---------------- */

.modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: rgba(35, 48, 63, .5);
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  width: 100%;
  max-width: 34rem;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-5);
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
}
.modal--wide { max-width: 52rem; }
.modal__title { font-size: 20px; margin-bottom: var(--sp-2); }
.modal__body { margin-bottom: var(--sp-5); }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--sp-3); flex-wrap: wrap; }

/* ---------------- 数学练习 ---------------- */

.quiz {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.quiz__bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--c-text-dim);
}
.quiz__bar .progress { flex: 1 1 140px; }
.quiz__timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--c-text); }

.problem {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  min-height: 26vh;
  padding: var(--sp-5) var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  font-size: clamp(38px, 8vw, 64px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.problem--ok { background: var(--c-ok-soft); border-color: var(--c-ok); }
.problem--bad { background: var(--c-bad-soft); border-color: var(--c-bad); }

.answer-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.2em;
  min-height: 1.5em;
  padding: 0 var(--sp-2);
  background: var(--c-primary-soft);
  border: 3px solid var(--c-primary);
  border-radius: var(--r-md);
  color: var(--c-primary-dark);
}
.answer-box--empty { color: #9db6dc; }
.answer-box--active { animation: pulse-border 1.4s ease-in-out infinite; }
@keyframes pulse-border {
  50% { border-color: #9db6dc; }
}
@media (prefers-reduced-motion: reduce) {
  .answer-box--active { animation: none; }
}
.answer-slot { display: inline-flex; align-items: baseline; gap: 6px; }
.answer-slot__label { font-size: .38em; color: var(--c-text-dim); font-weight: 600; }

.feedback {
  min-height: 2.4em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-size: 19px;
  font-weight: 700;
  text-align: center;
}
.feedback--ok { color: var(--c-ok); }
.feedback--bad { color: var(--c-bad); }

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  max-width: 26rem;
  margin: 0 auto;
  width: 100%;
}
.numpad__key {
  min-height: 62px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform .06s ease, background-color .1s ease;
}
.numpad__key:active { transform: scale(.95); background: var(--c-surface-2); }
.numpad__key--wide { grid-column: span 2; }
.numpad__key--fn { font-size: 18px; background: var(--c-surface-2); }
.numpad__key--ok { background: var(--c-ok); border-color: var(--c-ok); color: #fff; font-size: 20px; }
.numpad__key--ok:disabled { opacity: .4; }

/* ---------------- 识字 ---------------- */

.hanzi-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.hanzi-stage__pinyin {
  min-height: 1.6em;
  font-size: 22px;
  color: var(--c-text-dim);
  letter-spacing: .06em;
}
.hanzi-stage__char {
  font-family: var(--font-hanzi);
  font-size: clamp(96px, 26vw, 200px);
  line-height: 1.1;
  font-weight: 500;
}
.hanzi-stage__word {
  font-family: var(--font-hanzi);
  font-size: clamp(48px, 12vw, 96px);
  line-height: 1.3;
  text-align: center;
}
.hanzi-stage__sentence {
  font-family: var(--font-hanzi);
  font-size: clamp(28px, 5.6vw, 46px);
  line-height: 1.9;
  text-align: center;
  max-width: 22em;
}
.hanzi-stage__tools { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: center; }

.writer-box {
  width: min(280px, 70vw);
  aspect-ratio: 1;
  background:
    linear-gradient(var(--c-border), var(--c-border)) center/100% 1px no-repeat,
    linear-gradient(var(--c-border), var(--c-border)) center/1px 100% no-repeat,
    var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
}
.writer-box svg { display: block; }
.writer-box__msg { padding: var(--sp-3); font-size: 14px; color: var(--c-text-dim); text-align: center; }

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
  max-width: 34rem;
  margin: 0 auto;
  width: 100%;
}
.choice {
  min-height: 104px;
  display: grid;
  place-items: center;
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  font-family: var(--font-hanzi);
  font-size: clamp(40px, 9vw, 56px);
  cursor: pointer;
  transition: transform .07s ease;
}
.choice:active:not(:disabled) { transform: scale(.96); }
.choice--ok { background: var(--c-ok-soft); border-color: var(--c-ok); }
.choice--bad { background: var(--c-bad-soft); border-color: var(--c-bad); }
.choice:disabled { cursor: default; }
.choice--dim { opacity: .45; }

/* 家长判分区：两个按钮离得远，避免误触 */
.judge {
  display: flex;
  gap: var(--sp-7);
  justify-content: center;
  flex-wrap: wrap;
  padding: var(--sp-4) 0;
}
.judge__btn {
  flex: 0 1 190px;
  min-height: 96px;
  border-radius: var(--r-lg);
  border: 3px solid transparent;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  transition: transform .07s ease;
}
.judge__btn:active { transform: scale(.96); }
.judge__btn--ok { background: var(--c-ok-soft); border-color: var(--c-ok); color: #1d6d4c; }
.judge__btn--bad { background: var(--c-bad-soft); border-color: var(--c-bad); color: #a8332f; }

.judge-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-parent-soft);
  border: 1px solid #d5c8f0;
  border-radius: var(--r-md);
  color: #57408c;
  font-size: 14px;
  font-weight: 600;
}

/* 遥控判分：学生端显示的「上一题对/错」反馈 */
.remote-feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: 20px;
  font-weight: 700;
  animation: feedback-pop .25s ease-out;
}
.remote-feedback > span { font-size: 24px; line-height: 1; }
.remote-feedback--ok { background: var(--c-ok-soft); color: #1f7a54; border: 1px solid var(--c-ok); }
.remote-feedback--bad { background: var(--c-bad-soft); color: #a8332f; border: 1px solid var(--c-bad); }
@keyframes feedback-pop {
  from { transform: scale(.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.word-tags { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.word-tag {
  padding: 6px var(--sp-3);
  background: var(--c-surface-2);
  border-radius: var(--r-pill);
  font-family: var(--font-hanzi);
  font-size: 20px;
  cursor: pointer;
  user-select: none;
  transition: transform .08s ease, background-color .12s ease;
}
.word-tag:active { transform: scale(.93); background: var(--c-primary-soft); }
.word-tag::after { content: '🔊'; font-size: 12px; margin-left: 4px; opacity: .45; vertical-align: super; }

/* 小喇叭图标：点一下读这段文字 */
.speak-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  vertical-align: middle;
  transition: transform .08s ease, background-color .12s ease;
}
.speak-icon:active { transform: scale(.88); background: var(--c-primary-soft); }

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: var(--sp-2);
}
.char-cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  cursor: pointer;
  padding: 2px;
}
.char-cell__char { font-family: var(--font-hanzi); font-size: 30px; line-height: 1.1; }
.char-cell__py { font-size: 11px; color: var(--c-text-dim); }
.char-cell--sel { border-color: var(--c-primary); border-width: 2px; background: var(--c-primary-soft); }
.char-cell--mastered { background: var(--c-ok-soft); }
.char-cell--review { background: var(--c-warn-soft); }
.char-cell__dot {
  position: absolute;
  top: 4px; right: 5px;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.char-cell__dot--mastered { background: var(--c-ok); }
.char-cell__dot--review { background: var(--c-warn); }
.char-cell__dot--new { background: var(--c-text-dim); }

/* ---------------- 结算 ---------------- */

.result {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
}
.result__icon { font-size: 60px; line-height: 1; }
.result__title { font-size: 27px; margin: var(--sp-3) 0; }
.result__rate {
  font-size: 52px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.result--ok .result__rate { color: var(--c-ok); }
.result--bad .result__rate { color: var(--c-bad); }
.result__note { color: var(--c-text-dim); }
.result__coins {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-4) auto 0;
  padding: var(--sp-3) var(--sp-5);
  background: var(--c-warn-soft);
  border: 2px solid #f0d8a4;
  border-radius: var(--r-pill);
  font-size: 22px;
  font-weight: 700;
  color: #8a5f10;
}

.wrong-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.wrong-item {
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-bad-soft);
  border: 1px solid #f2c4c2;
  border-radius: var(--r-sm);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}
.wrong-item__hanzi { font-family: var(--font-hanzi); font-size: 22px; }
.wrong-item s { color: var(--c-bad); }

/* ---------------- 商店 ---------------- */

.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-4); }
.shop-item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  text-align: center;
}
.shop-item__emoji { font-size: 46px; line-height: 1.1; }
.shop-item__name { font-weight: 700; }
.shop-item__desc { font-size: 13px; color: var(--c-text-dim); flex: 1 1 auto; }
.shop-item__price {
  font-size: 20px;
  font-weight: 700;
  color: #8a5f10;
  font-variant-numeric: tabular-nums;
}
.shop-item--locked { opacity: .6; }

/* ---------------- 家长端 ---------------- */

.parent-tint {
  --c-primary: var(--c-parent);
  --c-primary-dark: #63489f;
  --c-primary-soft: var(--c-parent-soft);
}
.parent-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  background: var(--c-parent-soft);
  border: 1px solid #d5c8f0;
  border-radius: var(--r-md);
  color: #57408c;
  font-size: 14px;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
  max-width: 22rem;
  margin: var(--sp-4) auto 0;
}
.pin-dots {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
  min-height: 24px;
}
.pin-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--c-parent);
}
.pin-dot--filled { background: var(--c-parent); }

.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-height: 110px;
  padding: var(--sp-5);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  text-align: left;
  cursor: pointer;
  transition: all .2s ease;
}
.tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: var(--c-primary);
}
.tile:active { transform: translateY(0); }
.tile__icon { font-size: 32px; line-height: 1; }
.tile__title { font-weight: 700; font-size: 16px; }
.tile__sub { font-size: 13px; color: var(--c-text-dim); line-height: 1.5; }

.mini-tabs {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  padding-bottom: var(--sp-2);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* 分页与排序工具条 */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--c-surface-2);
}
.pager__left, .pager__right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.pager__info {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pager__count {
  font-weight: 400;
  color: var(--c-text-dim);
  font-size: 13px;
}
.pager__jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--c-text-dim);
  white-space: nowrap;
}

.sort-select {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.sort-select__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text-dim);
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}

/* 逐字注音预览 */
.py-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: var(--sp-2);
  background: var(--c-surface-2);
  border-radius: var(--r-sm);
  line-height: 1.2;
}
.py-preview__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 1.9em;
  padding: 2px 1px;
  border-radius: 4px;
}
.py-preview__item--missing { background: var(--c-bad-soft); }
.py-preview__item--not-in-lib { background: var(--c-warn-soft); }
.py-preview__py {
  font-size: 11px;
  color: var(--c-text-dim);
  white-space: nowrap;
  min-height: 1.2em;
}
.py-preview__char {
  font-family: var(--font-hanzi);
  font-size: 24px;
  line-height: 1.2;
}
.py-preview__char--punct { font-size: 16px; color: var(--c-text-dim); }
.py-preview__item--not-in-lib .py-preview__py { color: var(--c-bad); font-weight: 700; }
.mini-tab {
  flex: none;
  min-height: 40px;
  padding: 0 var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  font-size: 15px;
  font-weight: 600;
  color: var(--c-text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.mini-tab[aria-pressed="true"] {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}

.bar-chart { display: flex; flex-direction: column; gap: var(--sp-2); }
.bar-row { display: grid; grid-template-columns: 5.5em 1fr 4.5em; align-items: center; gap: var(--sp-2); font-size: 14px; }
.bar-row__track { height: 20px; background: var(--c-surface-2); border-radius: var(--r-sm); overflow: hidden; }
.bar-row__fill { height: 100%; background: var(--c-primary); border-radius: inherit; min-width: 2px; }
.bar-row__val { text-align: right; font-variant-numeric: tabular-nums; color: var(--c-text-dim); }

.day-strip { display: flex; gap: var(--sp-1); align-items: flex-end; height: 90px; }
.day-strip__col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; }
.day-strip__bar {
  width: 100%;
  max-width: 26px;
  margin-top: auto;
  background: var(--c-primary);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
}
.day-strip__label { font-size: 11px; color: var(--c-text-dim); }

/* 月历 */
.cal__nav { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.cal__title { font-weight: 700; font-variant-numeric: tabular-nums; }
.cal__head,
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 420px; margin: 0 auto; }
.cal__head { margin-bottom: 4px; }
.cal__dow { text-align: center; font-size: 12px; color: var(--c-text-dim); }
.cal__cell {
  aspect-ratio: 1 / 1;
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 13px;
}
.cal__cell--blank { background: transparent; }
.cal__cell--active { color: #fff; cursor: pointer; }
.cal__cell--today { outline: 2px solid var(--c-text); outline-offset: -2px; }
.cal__date { font-variant-numeric: tabular-nums; }
.cal__num { font-size: 11px; font-weight: 700; opacity: 0.9; }

/* ---------------- 响应式 ---------------- */

@media (min-width: 700px) {
  .choice-grid { grid-template-columns: repeat(4, 1fr); }
  .numpad { max-width: 30rem; }
}

@media (max-width: 420px) {
  .judge { gap: var(--sp-4); }
  .judge__btn { flex-basis: 140px; min-height: 84px; font-size: 20px; }
}

/* 屏幕上始终隐藏打印容器，它只在 @media print 里显示 */
.print-root { display: none; }

/* 打印时隐藏应用界面 */
@media print {
  .app, .toast-root, .modal-root, .skip-link, .boot { display: none !important; }
}
