/* ============================================================
   Subject Overlay, Stats Drawer, Home Hub
   - .subject-overlay : fixed full-screen page for 语文/数学/英语
   - .subject-card    : home grid tile that launches a subject
   - .stats-drawer    : right-side slide-in drawer for player/lvl/cal
   - .checkin-stats-btn : 📊 floating button on 打卡 page
   - .home-hub        : new home layout container
   Not scoped (uses base tokens). Zero leakage via specific selectors.
   ============================================================ */

/* ============ Subject Overlay ============ */
.subject-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;          /* above bottom-nav (50) */
  background: var(--md-surface, #FEF7FF);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
body.subject-english .subject-overlay.subject-english,
body.subject-chinese .subject-overlay.subject-chinese,
body.subject-math    .subject-overlay.subject-math {
  display: block;
  animation: subject-slide-in 240ms cubic-bezier(0.2, 0, 0, 1);
}
@keyframes subject-slide-in {
  from { transform: translateX(30px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* Subject app bar (Chinese / Math) */
.sub-appbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--md-surface, #FEF7FF);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--md-outline-variant, #CAC4D0);
  min-height: 56px;
}
.sub-back {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  color: var(--md-on-surface, #1D1B20);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.sub-back:active { background: rgba(0,0,0,0.06); }
.sub-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--md-on-surface, #1D1B20);
  flex: 1;
}
.sub-chips {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--md-surface, #FEF7FF);
  border-bottom: 1px solid var(--md-outline-variant, #CAC4D0);
  scrollbar-width: none;
}
.sub-chips::-webkit-scrollbar { display: none; }
.sub-chip {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 9999px;
  border: 1px solid var(--md-outline, #79747E);
  background: transparent;
  color: var(--md-on-surface-variant, #49454F);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.sub-chip.sub-chip-selected {
  background: var(--md-secondary-container, #E8DEF8);
  border-color: transparent;
  color: var(--md-on-secondary-container, #1D192B);
  font-weight: 600;
}
.sub-page { display: none; padding: 12px; }
.sub-page.sub-active { display: block; animation: sub-fade 200ms ease; }
@keyframes sub-fade { from { opacity: 0; } to { opacity: 1; } }


/* ============ Home Hub (new home layout) ============ */
.home-hub {
  padding: 0;
}
.home-compact-header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.home-compact-avatar {
  font-size: 28px;
  line-height: 1;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  border-radius: 50%;
  flex-shrink: 0;
}
.home-compact-info {
  flex: 1;
  min-width: 0;
}
.home-compact-lv {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  display: inline-block;
}
.home-compact-score {
  font-size: 13px;
  color: var(--text);
  margin-left: 8px;
}
.home-compact-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}
.home-compact-bar > div {
  height: 100%;
  background: var(--primary);
  transition: width 0.4s;
}

/* Subject grid 2×2 */
.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px 14px 8px;
}
.subject-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 14px 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.subject-card:active { transform: scale(0.97); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.subject-card .sc-icon {
  font-size: 36px;
  line-height: 1;
}
.subject-card .sc-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.subject-card .sc-sub {
  font-size: 11px;
  color: var(--gray);
}
.subject-card.sc-english { background: linear-gradient(135deg, #F3EDF7 0%, #EADDFF 100%); }
.subject-card.sc-chinese { background: linear-gradient(135deg, #FAF6EC 0%, #EFE3C2 100%); }
.subject-card.sc-math    { background: linear-gradient(135deg, #E8EFFA 0%, #C9D9F2 100%); }
.subject-card.sc-more    { background: #F5F5F5; color: var(--gray); }

/* Home progress strip */
.home-strip {
  margin: 4px 14px 16px;
  padding: 14px;
  background: white;
  border-radius: 14px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.home-strip-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.home-strip-go {
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.home-strip-go:active { transform: scale(0.96); }


/* ============ Stats Drawer (right slide-in) ============ */
.checkin-stats-btn {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--border);
  font-size: 20px;
  line-height: 1;
  color: var(--primary);
  cursor: pointer;
  z-index: 40;
  display: none;   /* only on 打卡 page */
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
body.tab-checkin .checkin-stats-btn { display: flex; }

.drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 70;
}
.stats-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 85%;
  max-width: 480px;
  background: var(--bg, #F8F6FC);
  z-index: 71;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  padding-top: env(safe-area-inset-top);
  box-shadow: -4px 0 16px rgba(0,0,0,0.12);
}
body.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
body.drawer-open .stats-drawer { transform: translateX(0); }

.drawer-handle {
  position: sticky;
  top: 0;
  background: var(--bg, #F8F6FC);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.drawer-handle-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.drawer-handle-close {
  width: 44px; height: 44px;
  border: none; background: transparent;
  font-size: 20px; color: var(--gray);
  cursor: pointer;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.drawer-handle-close:active { background: rgba(0,0,0,0.06); }
#drawerBody { padding: 10px 12px 80px; }


/* ============ Generic subject-page primitives ============ */
.zh-tile-grid,
.math-unit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}
.zh-tile {
  background: var(--md-surface-container-low, #F7F2FA);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid var(--md-outline-variant, #CAC4D0);
}
.zh-tile:active { background: var(--md-surface-container-high, #ECE6F0); }
.zh-tile-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--md-on-surface, #1D1B20);
}
.zh-tile-sub {
  font-size: 12px;
  color: var(--md-on-surface-variant, #49454F);
  margin-top: 2px;
}

/* hanzi flashcard grid */
.hanzi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0;
}
@media (min-width: 480px) {
  .hanzi-grid { grid-template-columns: repeat(5, 1fr); }
}
.hanzi-cell {
  aspect-ratio: 1;
  background: var(--md-surface-container-low, #FFFFFF);
  border: 1px solid var(--md-outline-variant, #CAC4D0);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--md-on-surface, #1D1B20);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  font-family: "Kaiti SC", "STKaiti", "PingFang SC", serif;
  transition: all 0.15s;
}
.hanzi-cell:active { transform: scale(0.93); }
.hanzi-cell.hanzi-mastered {
  background: var(--md-success-container, #E8F5E9);
  border-color: var(--md-success, #2E7D32);
  color: var(--md-on-success-container, #1B5E20);
}
.hanzi-cell.hanzi-error {
  background: var(--md-error-container, #F9DEDC);
  border-color: var(--md-error, #B3261E);
}
.hanzi-detail {
  background: var(--md-surface-container, #F3EDF7);
  border-radius: 14px;
  padding: 16px;
  margin: 10px 0;
  text-align: center;
}
.hanzi-detail-char {
  font-size: 80px;
  font-family: "Kaiti SC", "STKaiti", "PingFang SC", serif;
  color: var(--md-primary, #6750A3);
  line-height: 1.1;
}
.hanzi-detail-py {
  font-size: 18px;
  color: var(--md-on-surface-variant, #49454F);
  margin-top: 4px;
  font-style: italic;
}
.hanzi-detail-words {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.hanzi-detail-words .chip {
  background: var(--md-secondary-container, #E8DEF8);
  color: var(--md-on-secondary-container, #1D192B);
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 13px;
}

/* hanzi canvas for 描红 */
.hanzi-canvas-wrap {
  background: white;
  border: 1px solid var(--md-outline-variant, #CAC4D0);
  border-radius: 14px;
  padding: 10px;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hanzi-canvas-wrap canvas {
  background: #FFFAF0;
  background-image:
    linear-gradient(to right, rgba(180,80,80,0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(180,80,80,0.18) 1px, transparent 1px);
  background-size: 100% 50%, 50% 100%;
  background-position: 0 0, 0 0;
  background-repeat: no-repeat;
  border: 2px solid var(--md-outline, #79747E);
  border-radius: 8px;
  touch-action: none;
}
.hanzi-canvas-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.hanzi-canvas-actions button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 9999px;
  border: 1px solid var(--md-outline, #79747E);
  background: transparent;
  color: var(--md-on-surface, #1D1B20);
  font-size: 13px;
  cursor: pointer;
}
.hanzi-canvas-actions button.primary {
  background: var(--md-primary, #6750A3);
  color: var(--md-on-primary, #FFFFFF);
  border-color: transparent;
}

/* Dictation (听写) mode */
.dictation-progress {
  text-align: center;
  font-size: 14px;
  color: var(--md-on-surface-variant, #49454F);
  margin: 8px 0;
}
.dictation-current {
  background: var(--md-surface-container, #F3EDF7);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  margin: 10px 0;
}
.dictation-current .num { font-size: 14px; color: var(--md-on-surface-variant); }
.dictation-current .char {
  font-size: 64px;
  font-family: "Kaiti SC", "STKaiti", serif;
  color: var(--md-primary, #6750A3);
  line-height: 1.1;
}
.dictation-current .py { font-size: 16px; color: var(--md-on-surface-variant); }
.dictation-actions {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px;
}
.dictation-actions button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 9999px;
  border: 1px solid var(--md-outline);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--md-on-surface);
  display: inline-flex; align-items: center; gap: 4px;
}
.dictation-actions button.ok    { background: var(--md-success, #2E7D32); color: white; border-color: transparent; }
.dictation-actions button.err   { background: var(--md-error, #B3261E);   color: white; border-color: transparent; }
.dictation-actions button.replay{ background: var(--md-secondary-container, #E8DEF8); border-color: transparent; }

/* Poem card */
.poem-card {
  background: var(--md-surface-container-low, #F7F2FA);
  border: 1px solid var(--md-outline-variant, #CAC4D0);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 8px 0;
  cursor: pointer;
  transition: background 0.15s;
}
.poem-card:active { background: var(--md-surface-container-high, #ECE6F0); }
.poem-card.expanded .poem-body { display: block; }
.poem-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.poem-title { font-size: 16px; font-weight: 600; color: var(--md-on-surface, #1D1B20); }
.poem-meta  { font-size: 12px; color: var(--md-on-surface-variant, #49454F); }
.poem-body  { display: none; margin-top: 10px; }
.poem-text {
  font-family: "Kaiti SC", "STKaiti", "PingFang SC", serif;
  font-size: 17px;
  line-height: 1.7;
  color: var(--md-on-surface, #1D1B20);
  white-space: pre-line;
  text-align: center;
}
.poem-trans {
  margin-top: 10px;
  font-size: 13px;
  color: var(--md-on-surface-variant, #49454F);
  line-height: 1.6;
}
.poem-actions {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  margin-top: 10px;
}
.poem-actions button {
  min-height: 36px; padding: 0 14px;
  border-radius: 9999px; border: 1px solid var(--md-outline);
  background: transparent; color: var(--md-on-surface);
  cursor: pointer; font-size: 13px;
}
.poem-actions button.done { background: var(--md-success, #2E7D32); color: white; border-color: transparent; }
.poem-actions button.play { background: var(--md-primary, #6750A3); color: white; border-color: transparent; }

/* Idiom card */
.idiom-card {
  background: var(--md-surface-container-low, #F7F2FA);
  border: 1px solid var(--md-outline-variant, #CAC4D0);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 6px 0;
  cursor: pointer;
}
.idiom-head { display: flex; align-items: center; gap: 8px; }
.idiom-w { font-size: 17px; font-weight: 600; color: var(--md-primary, #6750A3); }
.idiom-cat {
  font-size: 11px; padding: 2px 8px;
  background: var(--md-secondary-container, #E8DEF8);
  color: var(--md-on-secondary-container, #1D192B);
  border-radius: 9999px;
}
.idiom-p { font-size: 12px; color: var(--md-on-surface-variant); font-style: italic; margin-top: 2px; }
.idiom-detail { display: none; margin-top: 8px; }
.idiom-card.expanded .idiom-detail { display: block; }
.idiom-m { font-size: 13px; color: var(--md-on-surface, #1D1B20); line-height: 1.6; }
.idiom-e { font-size: 12px; color: var(--md-on-surface-variant); margin-top: 4px; line-height: 1.6; }

/* Math unit card */
.math-unit-card {
  background: var(--md-surface-container-low, #F7F2FA);
  border: 1px solid var(--md-outline-variant, #CAC4D0);
  border-radius: 14px;
  padding: 14px;
  margin: 8px 0;
  cursor: pointer;
}
.math-unit-num {
  font-size: 11px;
  color: var(--md-on-surface-variant);
  font-weight: 600;
  letter-spacing: 0.5px;
}
.math-unit-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--md-on-surface, #1D1B20);
  margin-top: 2px;
}
.math-unit-body { display: none; margin-top: 10px; }
.math-unit-card.expanded .math-unit-body { display: block; }
.math-point {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 13px;
  color: var(--md-on-surface, #1D1B20);
  line-height: 1.55;
  margin: 4px 0;
}
.math-point .dot {
  flex-shrink: 0;
  width: 6px; height: 6px;
  background: var(--md-primary, #2E5BBA);
  border-radius: 50%;
  margin-top: 7px;
}
.math-practice-btn {
  margin-top: 10px;
  width: 100%;
  min-height: 44px;
  background: var(--md-primary-container, #D8E2FA);
  color: var(--md-on-primary-container, #0E1F4A);
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.math-practice-btn:active { transform: scale(0.98); }

/* Math placeholder banner */
.math-placeholder-banner {
  background: #FFF3E0;
  border: 1px dashed #FFB74D;
  color: #5D4037;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  margin: 8px 0;
  line-height: 1.5;
}
.math-placeholder-banner button {
  margin-top: 6px;
  padding: 6px 12px;
  background: #FFB74D;
  color: white;
  border: none;
  border-radius: 9999px;
  font-size: 12px;
  cursor: pointer;
  min-height: 32px;
}

/* Math oral-practice overlay */
.math-oral {
  background: white;
  border-radius: 14px;
  padding: 16px;
  margin: 8px 0;
  border: 1px solid var(--md-outline-variant, #CAC4D0);
}
.math-oral-q {
  text-align: center;
  font-size: 36px;
  font-weight: 600;
  color: var(--md-on-surface, #1D1B20);
  font-family: "PingFang SC", monospace;
  margin: 16px 0;
}
.math-oral-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 12px 0;
}
.math-oral-choice {
  min-height: 56px;
  border-radius: 12px;
  background: var(--md-surface-container-high, #ECE6F0);
  color: var(--md-on-surface, #1D1B20);
  border: 2px solid transparent;
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  font-family: monospace;
  transition: all 0.15s;
}
.math-oral-choice:active { transform: scale(0.97); }
.math-oral-choice.correct { background: var(--md-success-container, #E8F5E9); border-color: var(--md-success, #2E7D32); color: var(--md-on-success-container, #1B5E20); }
.math-oral-choice.wrong   { background: var(--md-error-container, #F9DEDC);   border-color: var(--md-error, #B3261E); }
.math-oral-meta {
  display: flex; justify-content: space-between; font-size: 12px; color: var(--md-on-surface-variant); margin-top: 8px;
}

/* Syllable King (English) */
.king-banner {
  background: linear-gradient(135deg, #FFE082 0%, #FFB74D 100%);
  color: #4A2C00;
  padding: 12px;
  border-radius: 12px;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.55;
}
.king-banner-title { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.king-rule {
  display: flex; gap: 6px; align-items: flex-start;
  margin: 3px 0;
}
.king-rule .tag {
  flex-shrink: 0;
  font-weight: 700;
  background: rgba(255,255,255,0.5);
  padding: 0 4px;
  border-radius: 4px;
}
.king-word {
  background: var(--md-surface-container, #F3EDF7);
  border-radius: 14px;
  padding: 24px 12px;
  text-align: center;
  margin: 12px 0;
}
.king-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  align-items: center;
}
.king-tile {
  width: 38px; height: 48px;
  background: white;
  border: 2px solid var(--md-outline, #79747E);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: var(--md-on-surface, #1D1B20);
  font-family: monospace;
  cursor: pointer;
  user-select: none;
}
.king-gap {
  width: 18px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 22px;
  color: var(--md-primary, #6750A3);
  font-weight: 700;
  border-radius: 6px;
}
.king-gap.active {
  background: var(--md-primary-container, #EADDFF);
  color: var(--md-on-primary-container, #21005D);
}
.king-actions {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px;
}
.king-actions button {
  min-height: 44px; padding: 0 18px;
  border-radius: 9999px; border: 1px solid var(--md-outline);
  background: transparent; color: var(--md-on-surface);
  cursor: pointer; font-size: 14px;
}
.king-actions button.primary {
  background: var(--md-primary, #6750A3);
  color: white;
  border-color: transparent;
}
.king-progress {
  display: flex; justify-content: space-between; font-size: 12px; color: var(--md-on-surface-variant);
  margin-top: 6px;
}
.king-feedback {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  margin-top: 6px;
  min-height: 32px;
}
.king-feedback.ok  { color: var(--md-success, #2E7D32); background: var(--md-success-container, #E8F5E9); }
.king-feedback.bad { color: var(--md-error, #B3261E);   background: var(--md-error-container, #F9DEDC); }
