/* print.css — wordfind.fun 生成器 + 打印题面
   打印硬指标：A4 纵向，四边 13mm，网格内字母边长 ≥ 3.2mm，题面单页不跨页，答案页另起一页 */

:root {
  --ink: #14202b;
  --muted: #5b6b7a;
  --line: #dfe6ec;
  --paper: #ffffff;
  --accent: #1667c4;
  --found: #d8f0d2;
  --sel: #ffe9a8;
  --cell-mm: 12mm;
  --font-mm: 5.4mm;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  background: #f4f7fa;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- 页面骨架（屏幕） */

.shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
}

.brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
}
.brand span { color: var(--muted); font-weight: 500; }

/* ---------------------------------------------------------------- 首页文案（只屏幕） */

.page-title {
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.page-lede {
  font-size: 14px;
  line-height: 1.5;
  color: #2c3a47;
  margin: 0 0 10px;
}
.page-nav {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 20px;
}
.page-nav a { color: var(--accent); }

.home-copy {
  border-top: 1px solid var(--line);
  background: #fff;
}
.home-copy .wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 20px 72px;
}
.home-copy h2 {
  font-size: 20px;
  letter-spacing: -0.01em;
  margin: 32px 0 12px;
}
.home-copy h2:first-child { margin-top: 0; }
.home-copy p { font-size: 15px; line-height: 1.6; color: #28323c; margin: 0 0 14px; }
.home-copy .steps { padding-left: 20px; margin: 0 0 8px; }
.home-copy .steps li { font-size: 15px; line-height: 1.6; margin-bottom: 10px; color: #28323c; }
.home-copy .qa { border-bottom: 1px solid var(--line); padding: 12px 0; }
.home-copy .qa h3 { font-size: 15px; margin: 0 0 4px; }
.home-copy .qa p { margin: 0; color: #3a4652; }
.home-copy .home-list { padding-left: 20px; margin: 0 0 8px; }
.home-copy .home-list li { font-size: 15px; line-height: 1.6; color: #28323c; margin-bottom: 8px; }

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}

.panel + .panel { margin-top: 16px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

textarea, input[type="text"], select {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
}

textarea { min-height: 180px; resize: vertical; line-height: 1.55; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  cursor: pointer;
}
button:hover { border-color: #b9c7d4; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #0f56a8; }
button.block { width: 100%; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-stack { display: grid; gap: 8px; margin-top: 16px; }

.note { font-size: 12px; line-height: 1.6; color: var(--muted); margin: 10px 0 0; }
.warn { color: #b4470e; font-size: 12px; line-height: 1.55; margin: 10px 0 0; }

/* ---------------------------------------------------------------- 题面 */

.sheet-wrap { min-width: 0; }

/* 答案页只在打印时出现（联调时可手动加 body.with-answers 预览） */
.answer-sheet { display: none; }

.sheet {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 26px 20px;
}

.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.sheet-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}
.sheet-sub { font-size: 13px; color: var(--muted); margin: 0; }
.sheet-meta { font-size: 12px; color: var(--muted); text-align: right; }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 0;
  margin: 18px 0 20px;
  border: 2px solid var(--ink);
  width: 100%;
  max-width: 560px;
  aspect-ratio: var(--cols) / var(--rows);
  user-select: none;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid rgba(20, 32, 43, 0.14);
  border-bottom: 1px solid rgba(20, 32, 43, 0.14);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 600;
  font-size: clamp(9px, 1.55vw, 19px);
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  transition: background 90ms linear;
}
.grid .cell:nth-child(var(--cols)n) { border-right: 0; }

.cell.is-sel { background: var(--sel); }
.cell.is-found { background: var(--found); }
.cell.is-answer { box-shadow: inset 0 0 0 999px rgba(22, 103, 196, 0.12); }

.words { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; padding: 0; list-style: none; }
.words li {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 0;
  color: var(--ink);
}
.words li.is-found { text-decoration: line-through; color: var(--muted); }

.sheet-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

.status { font-size: 13px; color: var(--muted); margin: 0 0 12px; min-height: 20px; }
.status b { color: var(--ink); }

/* ---------------------------------------------------------------- 版式（屏幕与纸面同一套）
   这些规则必须在两种媒体下都生效：屏幕上量出来的高度要等于打印出来的高度，
   否则 JS 没法判断"这一页到底装不装得下"。 */

.sheet {
  width: var(--usable-mm, 184mm);
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 10px 28px rgba(16, 24, 40, 0.08);
}

.sheet-title { font-size: 20pt; }
.sheet-sub, .sheet-meta { font-size: 9pt; }

.grid {
  width: calc(var(--cell-mm) * var(--cols));
  max-width: var(--usable-mm, 184mm);
  margin: 5mm 0 6mm;
  border: 0.6mm solid #000;
  aspect-ratio: auto;
}
.grid .cell:nth-child(var(--cols)n) { border-right: 0.15mm solid #999; }

.cell {
  height: var(--cell-mm);
  font-size: var(--font-mm);
  border-right: 0.15mm solid #999;
  border-bottom: 0.15mm solid #999;
  color: #000;
  cursor: default;
  line-height: 1;
}
.cell.is-sel { background: transparent; }
.cell.is-found { background: transparent; }
.cell.is-answer { box-shadow: none; }
body.reveal .cell.is-answer { box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.1); }

.words { gap: 2mm 8mm; }
.words li { font-size: 10pt; }

.sheet-foot { font-size: 8pt; border-top: 0.2mm solid #ccc; }

/* 答案页：默认不出现，body.with-answers 时另起一页 */
.answer-sheet { display: none; }
body.with-answers .answer-sheet { display: block; padding-top: 2mm; }
body.with-answers .answer-sheet .cell.is-answer {
  text-decoration: underline;
  text-decoration-thickness: 0.35mm;
  text-underline-offset: 1mm;
  font-weight: 700;
}
.answer-key-list { display: block; columns: 3; column-gap: 6mm; }
.answer-key-list li { font-size: 8pt; color: #000; break-inside: avoid; }

/* 大格（22 格以上）压紧标题与词表，否则答案页会多出一行 */
body.dense .sheet-title { font-size: 16pt; }
body.dense .sheet-head { margin-bottom: 3mm; }
body.dense .sheet-sub { font-size: 8pt; }
body.dense .answer-key-list { columns: 4; column-gap: 5mm; }
body.dense .answer-key-list li { font-size: 7pt; }

/* ---------------------------------------------------------------- 打印 */

@media print {
  @page { size: A4 portrait; margin: 13mm; }

  html, body { background: #fff; }

  .shell { display: block; max-width: none; padding: 0; }
  .no-print { display: none !important; }

  .sheet {
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    /* 整张纸不设 avoid：25/30 格时整页高度接近纸高，avoid 会把页脚挤到下一页 */
    break-inside: auto;
  }
  .sheet-head { break-after: avoid; }
  .grid { break-inside: avoid; }
  .sheet-foot { break-before: avoid; break-inside: avoid; }

  body.with-answers .answer-sheet {
    break-before: page;
    break-inside: auto;
  }
}

/* --- WordPress: the theme's own chrome must not reach paper --------------- */
@media print {
  .site-header, #masthead, .site-footer, #colophon,
  .entry-header, .entry-meta, .post-navigation, .comments-area,
  .kadence-breadcrumbs, .wp-block-post-title { display: none !important; }
}
