/* ==========================================================================
   口算题卡 · 共享样式（移动端 + PC 端 + 打印）
   ========================================================================== */

:root {
  --primary: #0d9488;
  --primary-600: #0f766e;
  --primary-soft: #ecfdf5;
  --bg: #f4f7f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --border: #e5e9f0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 20px rgba(15, 23, 42, .06);

  --teal: #0d9488;
  --blue: #2563eb;
  --orange: #ea580c;
  --purple: #7c3aed;

  --q-size: 16px;
  --q-weight: 400;
  --q-cols: 4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- 顶部导航 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--primary-600);
}
.brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--teal), #14b8a6);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(13, 148, 136, .35);
}
.brand small {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 2px;
}
.topbar .spacer { flex: 1; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  transition: transform .05s ease, box-shadow .15s ease, background .15s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(13, 148, 136, .32);
}
.btn-primary:hover { background: var(--primary-600); }
.btn-ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: #f8fafc; }
.btn-lg { padding: 12px 20px; font-size: 15px; border-radius: 12px; }
.btn-icon { padding: 9px; }

/* ---------- 首页 hero ---------- */
.hero {
  padding: 40px 0 28px;
  text-align: center;
}
.hero h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: .5px;
}
.hero h1 .accent {
  color: var(--primary);
}
.hero p {
  margin: 0 auto;
  max-width: 560px;
  color: var(--muted);
  font-size: 15px;
}
.hero .search {
  margin: 22px auto 0;
  max-width: 420px;
  position: relative;
}
.hero .search input {
  width: 100%;
  padding: 13px 18px 13px 44px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.hero .search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .15);
}
.hero .search .icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

/* ---------- 分类分组 ---------- */
.section {
  margin: 20px 0 26px;
  scroll-margin-top: 80px;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 2px;
  margin-bottom: 14px;
}
.section-head .badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
}
.section-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
}
.section-head .sub {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.section-head .count {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  background: #eef1f5;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* 分组主题色 */
.section-teal .badge { background: var(--teal); }
.section-blue .badge { background: var(--blue); }
.section-orange .badge { background: var(--orange); }
.section-purple .badge { background: var(--purple); }

/* ---------- 分类卡片网格 ---------- */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.cat {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 500;
  transition: border-color .15s ease, box-shadow .15s ease, transform .12s ease;
}
.cat:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.cat .arrow {
  margin-left: auto;
  color: #cbd5e1;
  font-size: 13px;
  transition: color .15s ease, transform .15s ease;
}
.cat:hover .arrow { color: var(--primary); transform: translateX(2px); }
.cat.is-hidden { display: none; }

.no-result {
  display: none;
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 14px;
}
.no-result.show { display: block; }

/* ---------- 详情页 ---------- */
.toolbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}
.toolbar .title {
  font-size: 17px;
  font-weight: 700;
  margin-right: 4px;
}
.toolbar .title-sub {
  font-size: 12px;
  color: var(--muted);
  margin-right: 12px;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.chip-group {
  display: flex;
  background: #eef1f5;
  border-radius: 10px;
  padding: 3px;
}
.chip-group button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 8px;
}
.chip-group button.active {
  background: #fff;
  color: var(--primary-600);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}
.checkbox input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.field-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.field-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.opts {
  display: flex;
  align-items: center;
  gap: 8px;
}
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- 试卷卡片 ---------- */
.sheet-wrap {
  margin: 18px auto 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
}
.pages {
  flex: 0 0 auto;
  width: 210mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  transform-origin: top center;
}
.sheet {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  margin: 0;
  padding: 13mm 12mm;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sheet-title {
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 6px;
}
.sheet-meta {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  font-size: 11px;
  color: var(--text);
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px dashed #cbd5e1;
}
.sheet-meta .field {
  display: inline-flex;
  gap: 4px;
}
.sheet-meta .line {
  flex: 1;
  border-bottom: 1px solid #94a3b8;
  min-width: 40px;
  height: 1em;
  align-self: flex-end;
}
.sheet-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
}

/* —— 页面水印（生成时间，右上/右下，屏幕与打印均显示） —— */
.wm {
  position: absolute;
  font-size: 10px;
  color: #b6c2d1;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}
.wm-tr { top: 5mm; right: 6mm; }
.wm-br { bottom: 4mm; right: 6mm; }

.sheet-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--q-cols, 4), 1fr);
  gap: 4px 16px;
}
.q {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: var(--q-size, 16px);
  font-weight: var(--q-weight, 400);
  padding: 4px 2px;
  break-inside: avoid;
}
.q-text { white-space: normal; }
.q-blank {
  flex: 1;
  min-width: 30px;
  border-bottom: 1.5px solid #94a3b8;
  height: 1em;
  transform: translateY(2px);
}
.q-ans {
  color: #e11d48;
  font-weight: 700;
}
.fill-ans {
  color: #e11d48;
  font-weight: 700;
}

/* ---------- 移动端打印悬浮按钮 ---------- */
.float-print {
  display: none;
}

/* ---------- 页脚 ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 0 32px;
}

/* ---------- 微信内打开提示 ---------- */
.wc-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff7ed;
  color: #9a3412;
  border-bottom: 1px solid #fed7aa;
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.5;
}
.wc-banner.show { display: flex; }
.wc-banner button {
  border: none;
  background: transparent;
  color: #9a3412;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}

.wc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, .5);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.wc-overlay.show { display: flex; }
.wc-modal {
  background: #fff;
  border-radius: 16px;
  max-width: 360px;
  width: 100%;
  padding: 24px 20px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .3);
  animation: wc-pop .18s ease;
}
.wc-modal h2 { margin: 0 0 10px; font-size: 18px; }
.wc-modal p { margin: 0 0 20px; font-size: 14px; color: var(--muted); line-height: 1.7; }
.wc-modal p b { color: var(--text); }
.wc-actions { display: flex; gap: 10px; }
.wc-actions .btn { flex: 1; }
@keyframes wc-pop {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 响应式 ---------- */
@media (min-width: 640px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 900px) {
  .hero h1 { font-size: 36px; }
  .cat-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 599px) {
  .toolbar-inner { flex-direction: column; align-items: stretch; }
  .toolbar .title-sub { display: block; margin: 0 0 6px; }
  .controls { flex-direction: column; align-items: stretch; margin-left: 0; }
  .opts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .opts .field-group { flex-direction: column; align-items: flex-start; gap: 4px; }
  .opts .chip-group { width: 100%; }
  .opts .chip-group button { flex: 1; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .actions .checkbox { justify-content: center; }
  .actions .btn-primary { grid-column: 1 / -1; }
  .float-print {
    display: flex;
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 14px;
    z-index: 60;
    box-shadow: 0 8px 22px rgba(13, 148, 136, .4);
  }
}

/* ==========================================================================
   打印样式
   ========================================================================== */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
  .topbar, .toolbar, .float-print, .footer { display: none !important; }
  .sheet-wrap {
    margin: 0;
    display: block;
    height: auto !important;
    overflow: visible;
  }
  .pages {
    display: block;
    width: auto;
    gap: 0;
    transform: none !important;
  }
  .sheet {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 0;
    transform: none !important;
    box-shadow: none;
    border: none;
    border-radius: 0;
    break-after: page;
    page-break-after: always;
  }
  .sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }
  @page {
    size: A4;
    margin: 13mm 12mm;
  }
}
