/* 田字格全部样式（首页、笔顺页、自由练习、打印） */
@font-face { font-family: "TZKai"; src: url(../fonts/FandolKai.woff2) format("woff2"); font-display: block; }
@font-face { font-family: "TZPinyin"; src: url(../fonts/Andika-pinyin.woff2) format("woff2"); font-display: block; }

:root {
  --line: #3a9a5b;
  --ink: #1d1d1f;
  --paper: #fffefa;
  --bg: #f6f4ee;
  --ui: #ffffff;
  --muted: #6e6e73;
  --accent: #2f7d4a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif; }
button, select, input, textarea { font: inherit; color: inherit; touch-action: manipulation; }

header {
  position: sticky; top: 0; z-index: 5;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 10px calc(14px + env(safe-area-inset-left));
  background: rgba(246, 244, 238, .94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid #e3dfd3;
}
#input {
  width: 100%; min-height: 64px; max-height: 30vh; resize: vertical;
  padding: 10px 14px; border: 1.5px solid #d8d3c4; border-radius: 12px; background: var(--ui);
  font-size: 22px; line-height: 1.4; font-family: "TZKai", "Kaiti SC", "STKaiti", serif; outline: none;
}
#input:focus { border-color: var(--accent); }
.tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-top: 10px; }
.seg { display: inline-flex; background: #e9e6dc; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 12px; min-height: 40px; border-radius: 8px; font-size: 15px; white-space: nowrap; }
.seg button.on { background: var(--ui); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.field { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--ink); }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 10px; padding: 8px 16px; min-height: 40px; font-size: 15px; }
.btn.ghost { background: #e9e6dc; color: var(--ink); }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; color: var(--muted); }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); }

main { padding: 18px calc(14px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left)); }
#sheet { background: var(--paper); border-radius: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); padding: 22px 0 10px; }
#sheet svg { display: block; margin: 0 auto 18px; overflow: visible; }
.hint { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 0; }
#a2hs { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; padding: 10px 12px 10px 16px; text-align: left;
  background: #fff7e6; color: #6b4a00; border-radius: 12px; font-size: 15px; line-height: 1.5; }
#a2hs[hidden] { display: none; }
#a2hs span { flex: 1; }
#a2hs .btn { flex: none; font-size: 15px; }
#offline[hidden] { display: none; }
.cell { cursor: pointer; }
#sheet { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
#sheet text { pointer-events: none; }
.cell.fixed .py { fill: #c2410c; }
.cell.trace.fixed .py { fill: #f0b08a; }
body:not([data-layout=copy]) .copy-only { display: none; }

#pop { position: fixed; z-index: 20; display: none; min-width: 240px; max-width: 320px;
  background: var(--ui); border-radius: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.2); padding: 14px; }
#pop.show { display: block; }
#pop .han { font-family: "TZKai", "Kaiti SC", serif; font-size: 44px; text-align: center; line-height: 1.1; }
#pop .cands { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
#pop .cands button { font-family: "TZPinyin", sans-serif; font-size: 22px; min-width: 64px; min-height: 44px;
  border: 1.5px solid #d8d3c4; background: #fff; border-radius: 10px; }
#pop .cands button.on { border-color: var(--accent); background: #e8f3ec; }
#pop .custom { display: flex; gap: 6px; }
#pop .custom input { flex: 1; min-width: 0; font-size: 17px; padding: 8px 10px; border: 1.5px solid #d8d3c4; border-radius: 10px; }
#pop .note { font-size: 12px; color: var(--muted); margin-top: 6px; }
#veil { position: fixed; inset: 0; z-index: 15; display: none; }
#veil.show { display: block; }

.topline { display: flex; gap: 10px; align-items: stretch; }
.tabs { display: flex; flex-direction: column; gap: 6px; }
.tabs button { border: 0; border-radius: 12px; padding: 0 18px; flex: 1; min-height: 44px; font-size: 18px; font-weight: 600;
  background: #e9e6dc; color: var(--muted); }
.tabs button.on { background: var(--accent); color: #fff; }
.topline #input { flex: 1; }
body[data-tab=num] .han-only { display: none !important; }
body.sp-open { overflow: hidden; }
.rhyme { font-size: 13px; fill: #6e6e73; }

/* 笔顺页 */
#spPage { position: fixed; inset: 0; z-index: 12; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
#spPage[hidden] { display: none; }
.sp-top { display: flex; align-items: center; gap: 12px; min-height: 52px; }
.sp-top .btn { font-size: 17px; }
.sp-title { flex: 1; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
#spPage[data-kind=digit] #spChar { display: none; }
#spChar { font-family: "TZKai", "Kaiti SC", serif; font-size: 40px; line-height: 1; }
#spPy { font-family: "TZPinyin", sans-serif; font-size: 26px; }
#spCount { color: var(--muted); font-size: 16px; }
#spFix { font-size: 14px; padding: 6px 10px; min-height: 34px; }
.voice-toggle { font-size: 22px; width: 52px; }
.voice-toggle.off { opacity: .45; text-decoration: line-through; }
.sp-main { display: flex; gap: 22px; align-items: center; justify-content: center; margin-top: 8px; }
@media (orientation: portrait) { .sp-main { flex-direction: column; } }
#spStage { position: relative; flex: none; background: var(--paper); border-radius: 10px; touch-action: none; }
#spStage > * { position: absolute; left: 0; top: 0; }
#spOverlay { pointer-events: none; transition: opacity .4s; }
#spOverlay.faded { opacity: .3; }
.sp-side { display: flex; flex-direction: column; gap: 12px; min-width: 240px; max-width: 360px; }
@media (orientation: portrait) { .sp-side { flex-direction: row; flex-wrap: wrap; justify-content: center; max-width: none; } }
.sp-side .big { border: 0; border-radius: 16px; min-height: 64px; padding: 0 22px; font-size: 22px; font-weight: 700;
  background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.sp-side .big.on { background: var(--accent); color: #fff; }
#spRhyme { font-size: 24px; font-weight: 700; color: #c2410c; text-align: center; }
#spRhyme:empty { display: none; }
#spSay { font-size: 19px; color: var(--ink); text-align: center; min-height: 28px; width: 100%; }
#spSteps { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 20px auto 0; max-width: 1100px; }
.sp-step { border: 0; background: transparent; padding: 4px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sp-step svg { background: var(--paper); border-radius: 4px; }
.sp-step span { font-size: 13px; color: var(--muted); white-space: nowrap; }
.sp-step.cur { background: #fff3e0; box-shadow: 0 0 0 2px #f08c00; }
.sp-step.done span { color: var(--ink); }
#spCheer, #prCheer { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.6); font-size: 64px; font-weight: 800; color: #f08c00;
  text-shadow: 0 3px 0 #fff, 0 6px 18px rgba(0,0,0,.2); opacity: 0; pointer-events: none; z-index: 13; white-space: nowrap; }
#spCheer.show, #prCheer.show { animation: cheer 1.8s ease-out; }
@keyframes cheer { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.5); } 20% { opacity: 1; transform: translate(-50%,-50%) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%,-50%) scale(1); } 100% { opacity: 0; transform: translate(-50%,-60%) scale(1); } }
#pop, #veil { z-index: 30; }
#veil { z-index: 25; }

.practice-btn { border: 0; border-radius: 14px; background: #f08c00; color: #fff; font-size: 18px; font-weight: 700;
  padding: 0 16px; min-width: 100px; line-height: 1.35; box-shadow: 0 2px 6px rgba(240,140,0,.35); }

/* 自由练习 */
#prPage { position: fixed; inset: 0; z-index: 11; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; overscroll-behavior: none;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
#prPage[hidden] { display: none; }
body.pr-open { overflow: hidden; }
.pr-top { display: flex; align-items: center; gap: 12px; min-height: 52px; flex-wrap: wrap; }
.pr-top .btn { font-size: 17px; }
.pr-title { flex: 1; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
#prPy { font-family: "TZPinyin", sans-serif; font-size: 28px; }
#prPos { color: var(--muted); font-size: 16px; }
.pr-main { display: flex; gap: 22px; align-items: flex-start; justify-content: center; margin-top: 8px; }
#prStage { position: relative; flex: none; background: var(--paper); border-radius: 10px; touch-action: none; }
#prStage > * { position: absolute; left: 0; top: 0; }
#prCanvas { touch-action: none; }
#prTplLayer { pointer-events: none; }
#prStage.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pr-side { display: grid; gap: 12px; width: 320px; grid-template-columns: 1fr 1fr;
  grid-template-areas: "model model" "tpl tpl" "stars stars" "undo clear" "done done" "prev next" "hint hint"; }
@media (orientation: portrait) {
  .pr-main { flex-direction: column; align-items: center; }
  .pr-side { width: min(100%, 720px); grid-template-columns: 170px 1fr 1fr;
    grid-template-areas: "model tpl tpl" "model stars stars" "model undo clear" "prev done next" "hint hint hint"; }
}
#prModelBox { grid-area: model; display: flex; flex-direction: column; align-items: center; gap: 4px; }
#prModelBox span { font-size: 14px; color: var(--muted); }
#prModel svg { background: var(--paper); border-radius: 6px; display: block; }
#prTplSeg { grid-area: tpl; justify-self: center; align-self: center; }
#prTplSeg button { font-size: 17px; padding: 8px 16px; }
#prStarsBox { grid-area: stars; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
#prStars span { font-size: 30px; color: #d9d4c7; }
#prStars span.on { color: #f08c00; }
#prStars em { font-style: normal; color: #f08c00; font-weight: 700; margin-left: 4px; }
#prStarsBox label { font-size: 14px; color: var(--muted); }
#prStarsBox select { font-size: 15px; padding: 4px 6px; border-radius: 8px; border: 1px solid #d8d3c4; background: #fff; }
.pr-side .big { border: 0; border-radius: 16px; min-height: 60px; padding: 0 14px; font-size: 20px; font-weight: 700;
  background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.pr-side .big:disabled { opacity: .4; }
#prUndo { grid-area: undo; } #prClear { grid-area: clear; } #prPrev { grid-area: prev; } #prNext { grid-area: next; }
#prDone { grid-area: done; background: var(--accent); color: #fff; min-height: 72px; font-size: 24px; }
#prHint { grid-area: hint; justify-self: center; }
#prAttempts { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin: 18px auto 0; max-width: 1100px; }
#prAttempts .lbl { color: var(--muted); font-size: 15px; }
.thumb { background: var(--paper); border-radius: 4px; }
.thumb.unfinished { opacity: .45; outline: 2px dashed #c9c3b3; outline-offset: -2px; }
#prSummary { position: fixed; inset: 0; z-index: 14; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; padding: 20px; }
#prSummary[hidden] { display: none; }
.pr-sum-box { background: var(--bg); border-radius: 18px; width: min(100%, 960px); max-height: 90vh; overflow-y: auto; padding: 18px 22px; }
.pr-sum-box h2 { margin: 4px 0 10px; font-size: 26px; }
.pr-sum-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #e3dfd3; flex-wrap: wrap; cursor: pointer; }
.pr-sum-row .py { font-family: "TZPinyin", "PingFang SC", sans-serif; font-size: 20px; min-width: 56px; }
.pr-sum-row .cnt { margin-left: auto; color: var(--muted); font-size: 15px; }
.pr-sum-row .cnt.ok { color: var(--accent); font-weight: 700; }
.pr-sum-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.pr-sum-actions .btn { font-size: 17px; min-height: 48px; padding: 0 18px; }
#spPractice { background: #f08c00; color: #fff; }
#updateBar { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: #1d1d1f; color: #fff; border: 0; border-radius: 22px; padding: 10px 18px; font-size: 15px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#updateBar[hidden] { display: none; }
#toast { position: fixed; left: 50%; bottom: calc(70px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 41;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); background: #1d1d1f; color: #fff; border-radius: 14px;
  padding: 10px 12px 10px 18px; font-size: 16px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#toast[hidden], #toast button[hidden] { display: none; }
#toast button { background: #f08c00; color: #fff; border: 0; border-radius: 10px; padding: 8px 14px; min-height: 40px; font-size: 16px; flex: none; }

/* 打印：首页田字格按 A4 纸宽重新排版（body.printing，见脚本）；作业单（body.print-hw）只打印作业 */
body.printing #sheet { width: 700px; margin: 0 auto; }
.pr-sum-date { display: none; }
@page { margin: 12mm; }
@media print {
  header, .hint, #pop, #veil, #spPage, #prPage, #updateBar, #toast { display: none !important; }
  body, main, #sheet { background: #fff; box-shadow: none; padding: 0; margin: 0; }
  #sheet svg { break-inside: avoid; margin-bottom: 14px; }
  body.print-hw > *:not(#prPage) { display: none !important; }
  body.print-hw #prPage { display: block !important; position: static; padding: 0; overflow: visible; background: #fff; }
  body.print-hw #prPage > *:not(#prSummary) { display: none !important; }
  body.print-hw #prSummary { display: block; position: static; background: none; padding: 0; }
  body.print-hw .pr-sum-box { width: auto; max-height: none; overflow: visible; padding: 0; background: #fff; }
  body.print-hw .pr-sum-actions { display: none; }
  body.print-hw .pr-sum-date { display: block; color: #666; margin: -6px 0 6px; }
  .pr-sum-row { break-inside: avoid; }
}
