/* ========== 基础 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2f6fed;
  --primary-dark: #1d5ad6;
  --text: #2c3340;
  --text-light: #7a8494;
  --bg: #eef1f5;
  --card-bg: #ffffff;
  --border: #dde3ec;
  --grid-line: #4a4a4a;
  --grid-guide: #e05a5a;
  --trace-gray: #bfbfbf;
  --trace-red: #e8a0a0;
  --step-done: #333333;
  --step-current: #e4572e;
  --step-future: #dcdcdc;
}

html {
  font-size: 16px;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ========== 操作面板 ========== */
#panel {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 8px;
}

.panel-header h1 {
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 18px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(20, 30, 50, 0.06);
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.input-row {
  display: flex;
  gap: 10px;
}

#charInput {
  flex: 1;
  min-width: 0;
  font-size: 1.15rem;
  letter-spacing: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

#charInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

.btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  padding: 10px 22px;
  transition: background 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.primary:disabled {
  background: #9db9f2;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-light);
  width: 100%;
}

.btn.ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.preset-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-label {
  color: var(--text-light);
  font-size: 0.85rem;
}

.preset {
  border: 1px solid var(--border);
  background: #f6f8fb;
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  letter-spacing: 2px;
}

.preset:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #eef4ff;
}

/* 配置区 */
.config-card {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.config-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.config-item label {
  font-size: 0.82rem;
  color: var(--text-light);
}

.config-item select,
.config-item input[type="number"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.95rem;
  outline: none;
  background: #fff;
  width: 110px;
}

.check-item label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem !important;
  color: var(--text) !important;
  padding: 9px 0;
  cursor: pointer;
}

.check-item input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.regenerate-item {
  flex: 1;
}

.action-buttons {
  flex-direction: row !important;
  gap: 10px !important;
}

.action-buttons .btn {
  padding: 8px 16px;
}

.status-msg {
  min-height: 24px;
  padding: 0 4px;
  font-size: 0.88rem;
  color: #c0392b;
}

.status-msg.info {
  color: var(--text-light);
}

/* ========== 笔顺步骤区 ========== */
.steps-section {
  max-width: 900px;
  margin: 10px auto 24px;
  padding: 0 16px;
}

.step-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(20, 30, 50, 0.06);
}

.step-card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.step-char-big {
  font-size: 1.25rem;
  font-weight: 700;
}

.stroke-count {
  font-size: 0.85rem;
  color: #fff;
  background: var(--primary);
  border-radius: 999px;
  padding: 2px 10px;
}

.demo-play-btn {
  margin-left: auto;
  border: 1px solid var(--border);
  background: #f6f8fb;
  border-radius: 999px;
  padding: 4px 14px;
  cursor: pointer;
  font-size: 0.85rem;
}

.demo-play-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.step-demo-box svg {
  width: 150px;
  height: 150px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.step-chips-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.step-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.step-chip svg {
  width: 52px;
  height: 52px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.step-chip .chip-label {
  font-size: 0.72rem;
  color: var(--text-light);
}

.char-missing {
  color: #c0392b;
  font-size: 0.88rem;
  padding: 4px 0;
}

/* ========== 字帖页面 ========== */
#sheetArea {
  display: flex;
  justify-content: center;
  padding: 0 12px 30px;
}

.sheet-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: 0 2px 14px rgba(20, 30, 50, 0.15);
  padding: 12mm 14mm;
  display: flex;
  flex-direction: column;
}

.sheet-title-bar {
  text-align: center;
  font-size: 15pt;
  font-weight: 700;
  letter-spacing: 4px;
  margin-bottom: 6mm;
}

.name-date-row {
  display: flex;
  justify-content: space-between;
  font-size: 11pt;
  color: #333;
  margin-bottom: 6mm;
}

.empty-hint {
  text-align: center;
  color: #aab3c0;
  margin-top: 80mm;
  font-size: 13pt;
}

.practice-unit {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 8mm;
}

.unit-rows {
  display: flex;
  flex-direction: column;
  gap: 2mm;
}

/* 笔顺拆分条（打印） */
.stroke-seq-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.2mm;
  margin-bottom: 1.8mm;
}

.seq-label {
  font-size: 9pt;
  color: #333;
  margin-right: 1.5mm;
}

.seq-item {
  position: relative;
  display: inline-block;
}

.seq-item svg {
  display: block;
  width: 9mm;
  height: 9mm;
  border: 0.25mm solid #cccccc;
  background: #fff;
}

.seq-num {
  position: absolute;
  top: -1mm;
  right: -0.5mm;
  font-style: normal;
  font-size: 6.5pt;
  line-height: 1;
  font-weight: 700;
  color: #c0392b;
  background: #fff;
  padding: 0 1px;
  border-radius: 2px;
}

.grid-row {
  display: flex;
  justify-content: space-between;
}

.cell-svg {
  display: block;
}

footer.page-footer {
  text-align: center;
  color: var(--text-light);
  font-size: 0.78rem;
  padding: 0 16px 26px;
}

/* ========== 移动端适配 ========== */
@media (max-width: 640px) {
  #panel {
    padding: 16px 12px 4px;
  }

  .panel-header h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.82rem;
    margin-bottom: 14px;
  }

  .card {
    padding: 12px;
  }

  .input-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .input-row .btn.primary {
    flex: 1;
  }

  .config-card {
    gap: 10px;
  }

  .config-item {
    flex: 1 1 40%;
  }

  .config-item select,
  .config-item input[type="number"] {
    width: auto;
    min-width: 0;
    flex: 1;
    font-size: 1rem; /* ≥16px，避免 iOS 聚焦时自动放大 */
  }

  .action-buttons {
    flex: 1 1 100%;
  }

  .action-buttons .btn {
    flex: 1;
    padding: 10px 8px;
  }

  .steps-section {
    padding: 0 12px;
  }

  .step-demo-box svg {
    width: 100%;
    max-width: 150px;
    height: auto;
    aspect-ratio: 1;
  }

  .step-chip svg {
    width: 46px;
    height: 46px;
  }

  #sheetArea {
    padding: 0 8px 20px;
  }
}

/* ========== 打印样式 ========== */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .no-print,
  footer.page-footer {
    display: none !important;
  }

  #sheetArea {
    display: block;
    padding: 0;
    height: auto !important;
    overflow: visible !important;
  }

  .sheet-page {
    width: auto;
    min-height: 0;
    padding: 0;
    box-shadow: none;
    transform: none !important;
  }
}
