* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f7f5f0;
  --paper: #fffdf8;
  --ink: #2a2622;
  --accent: #c8392f;
  --accent-soft: #f3d6cf;
  --grid: #d8c5b8;
  --muted: #8a857d;
  --line: #e6ded2;
  --shadow: 0 18px 50px rgba(40, 30, 20, 0.12), 0 4px 12px rgba(40, 30, 20, 0.06);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "微软雅黑", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding: 28px 16px 56px;
  background-image:
    radial-gradient(circle at 18% 12%, rgba(200, 57, 47, 0.06), transparent 45%),
    radial-gradient(circle at 82% 88%, rgba(58, 90, 150, 0.05), transparent 45%);
  -webkit-font-smoothing: antialiased;
}
header {
  max-width: 960px;
  margin: 0 auto 28px;
  text-align: center;
}
h1 {
  font-size: clamp(26px, 4.5vw, 40px);
  font-weight: 700;
  letter-spacing: 3px;
}
h1 .accent { color: var(--accent); }
.subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 8px;
  letter-spacing: 1px;
}
main {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}
.stage-wrap {
  position: relative;
  width: min(72vmin, 540px);
  height: min(72vmin, 540px);
}
.stage {
  position: absolute;
  inset: 0;
  background: var(--paper);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 22px;
}
/* 田字格 dashed grid */
.grid-overlay {
  position: absolute;
  inset: 22px;
  border: 2px dashed var(--grid);
  border-radius: 10px;
  pointer-events: none;
  z-index: 1;
}
.grid-overlay::before,
.grid-overlay::after {
  content: '';
  position: absolute;
  background: var(--grid);
}
.grid-overlay::before {
  /* horizontal center line */
  left: 0; right: 0;
  top: 50%;
  height: 0;
  border-top: 1.5px dashed var(--grid);
  background: transparent;
}
.grid-overlay::after {
  /* vertical center line */
  top: 0; bottom: 0;
  left: 50%;
  width: 0;
  border-left: 1.5px dashed var(--grid);
  background: transparent;
}
/* 主页主字 SVG：铺满 stage 内容区，可接收 pointer 事件 */
#main-svg {
  position: absolute;
  inset: 22px;
  width: calc(100% - 44px);
  height: calc(100% - 44px);
  z-index: 2;
  touch-action: none;
  cursor: crosshair;
}
/* 整字完成时闪一下 */
.char-done-flash {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  pointer-events: none;
  background: rgba(46, 139, 87, 0);
  transition: background .3s;
  z-index: 5;
}
.char-done-flash.flash { background: rgba(46, 139, 87, 0.18); }

/* 参考字：浮在 stage 右上角，小尺寸 */
.reference-char {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 84px;
  height: 84px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(40, 30, 20, 0.08);
  padding: 6px;
  z-index: 6;
  pointer-events: none;
}
.reference-char svg { width: 100%; height: 100%; display: block; }
.reference-char .reference-label {
  position: absolute;
  bottom: -10px;
  right: 8px;
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  padding: 0 6px;
  letter-spacing: 1px;
}

/* 开关按钮 */
.toggles {
  display: flex;
  gap: 8px;
  padding-left: 6px;
  margin-left: 4px;
  border-left: 1px solid var(--line);
}
.toggle {
  height: 42px;
  padding: 0 14px;
  font-size: 14px;
  border-radius: 10px;
  background: #fff;
  border: 1.5px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  letter-spacing: 1px;
}
.toggle.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ---- 字形渲染样式（char-renderer 通用） ---- */
.cr-full-stroke { fill: var(--ink); }

.cr-outline-stroke { fill: var(--accent-soft); }
.cr-done-stroke { fill: var(--ink); transition: fill .25s; }

/* 整字完成：done 变绿，outline 也变淡绿 */
svg.char-complete .cr-done-stroke { fill: #2e8b57; }
svg.char-complete .cr-outline-stroke { fill: #cfe8d8; }

/* 下一笔提示：细虚线 + 起点圆点 + 终点箭头 */
.cr-hint-line {
  stroke: #ff9800;
  stroke-width: 8;
  stroke-dasharray: 14 14;
  stroke-linecap: round;
  fill: none;
  opacity: 0.9;
}
.cr-hint-start { fill: #ff9800; }
.cr-hint-arrow {
  stroke: #ff9800;
  stroke-width: 10;
  stroke-linecap: round;
  fill: none;
}

/* 笔顺动画：每笔 fill 用 mask 控制逐渐写出 */
.cr-anim-fill {
  fill: var(--ink);
}

.status-bar {
  min-height: 26px;
  font-size: 15px;
  color: var(--muted);
  text-align: center;
  letter-spacing: 1px;
  display: flex;
  gap: 18px;
  justify-content: center;
  align-items: center;
}
.status-bar .stroke-count {
  color: var(--accent);
  font-weight: 600;
}
.status-bar .err { color: var(--accent); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
  padding: 16px 20px;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(40, 30, 20, 0.06);
  max-width: 100%;
}
input[type="text"]#char-input {
  width: 110px;
  height: 42px;
  font-size: 22px;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
  font-family: "STKaiti", "KaiTi", "楷体", serif;
}
input[type="text"]#char-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(200, 57, 47, 0.12);
}
button {
  height: 42px;
  padding: 0 18px;
  font-size: 15px;
  border: none;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform .08s ease, background .15s, box-shadow .15s, color .15s;
  border: 1.5px solid var(--line);
  letter-spacing: 1px;
  user-select: none;
}
button:hover { background: #faf7f1; border-color: var(--grid); }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { background: #b83127; border-color: #b83127; }
button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 6px;
  border-left: 1px solid var(--line);
  margin-left: 4px;
}
.speed-control label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 1px;
}
input[type="range"]#speed {
  width: 110px;
  accent-color: var(--accent);
}
#speed-label {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  min-width: 38px;
  text-align: right;
}
.hint {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  max-width: 460px;
  line-height: 1.6;
  letter-spacing: 0.5px;
}
.hint b { color: var(--accent); font-weight: 600; }
/* 顶部导航：跳转配置页 */
.top-nav {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.btn-link {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  background: #fff;
  transition: background .15s, border-color .15s;
}
.btn-link:hover { background: #faf7f1; border-color: var(--grid); }

/* 级别 / 段 / 汉字 选择器 */
.picker {
  width: 100%;
  max-width: 720px;
  background: var(--paper);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: 0 6px 20px rgba(40, 30, 20, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.picker-row,
.char-grid-wrap {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.picker-label {
  flex-shrink: 0;
  width: 44px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 1px;
  padding-top: 8px;
  text-align: right;
}
.level-tabs,
.section-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}
.level-tabs button,
.section-tabs button {
  height: 34px;
  padding: 0 14px;
  font-size: 14px;
}
.level-tabs button.active,
.section-tabs button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.char-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}
.char-grid button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 22px;
  font-family: "STKaiti", "KaiTi", "楷体", serif;
  border-radius: 8px;
  background: #fff;
}
.char-grid button:hover { background: #faf7f1; border-color: var(--grid); }
.char-grid button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.char-grid .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 10px 4px;
}
footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 24px;
  letter-spacing: 0.5px;
}
footer a { color: var(--accent); text-decoration: none; }

/* ===== 触摸设备（平板/手机）适配：保证点击目标 ≥ 44px ===== */
@media (pointer: coarse) {
  button,
  .btn-link,
  input[type="text"] {
    min-height: 44px;
  }
  .controls { gap: 14px; }
  .speed-control { padding-left: 10px; }
  .examples button,
  .char-grid button {
    width: 50px;
    height: 50px;
    font-size: 24px;
  }
}

/* ===== 平板横屏：放宽主区域，调整字格 ===== */
@media (min-aspect-ratio: 13/10) and (min-width: 900px) {
  body { padding: 24px 24px 48px; }
  main { gap: 22px; }
  .stage-wrap {
    width: min(60vmin, 520px);
    height: min(60vmin, 520px);
  }
  .picker { max-width: 820px; }
}

/* ===== 横屏配置页：网格更宽 ===== */
@media (min-width: 1100px) {
  .config-main { max-width: 1100px; }
  .levels { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
}
