/**
 * 外研版教材单词 · 纸质练习 / PDF 导出
 * 参照 Peek Otter print-worksheets 设计，适配 FLTRP 视觉主题
 */
@import url('https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap');

:root {
  --pw-paper: #fffef8;
  --pw-ink: #1f2937;
  --pw-muted: #5c6b7a;
  --pw-accent-maze: #2b7cb8;
  --pw-accent-spell: #e86f00;
  --pw-accent-connect: #2d6a2e;
  --pw-accent-quiz: #7c4dff;
  --pw-accent-memory: #e91e8c;
  --pw-accent-sentence: #3d5afe;
  --pw-accent-pick: #ff9100;
  --pw-gold: #ffd24a;
  --pw-green-light: #e8f7e3;
  --pw-sky-light: #e3f4fc;
  --pw-orange-light: #fff3e0;
  --pw-pink-light: #fce4ec;
  --pw-purple-light: #ede7f6;
}

/* ── 页面与工具栏 ── */
body.print-worksheet-page {
  background: #eceff1;
}

body.print-worksheet-page::before,
body.print-worksheet-page::after {
  display: none;
}

.pw-toolbar {
  max-width: 52rem;
  margin: 0 auto 1rem;
  background: #fff;
  border-radius: var(--radius, 18px);
  padding: 1.1rem 1.25rem;
  border-left: 5px solid var(--fltrp-green, #6cc24a);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.pw-toolbar h1 {
  font-family: var(--font, 'Fredoka', sans-serif);
  font-size: 1.3rem;
  color: var(--fltrp-green-dark, #2d6a2e);
  margin-bottom: 0.45rem;
}

.pw-toolbar .pw-desc {
  font-size: 0.88rem;
  color: var(--pw-muted);
  line-height: 1.55;
  margin-bottom: 0.65rem;
}

.pw-toolbar .pw-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin: 0.5rem 0;
}

.pw-toolbar label {
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  transition: background 0.15s;
}

.pw-toolbar label:hover {
  background: var(--pw-green-light);
}

.pw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.35rem;
}

.pw-chip {
  font-size: 0.76rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid #cfd8dc;
  border-radius: 999px;
  background: linear-gradient(135deg, #fafafa, #f0f4f8);
  color: var(--pw-ink);
}

.pw-chip-count {
  font-size: 0.85rem;
  color: var(--pw-muted);
  margin: 0.35rem 0;
}

#printArea {
  max-width: 52rem;
  margin: 0 auto;
}

.pw-empty {
  text-align: center;
  padding: 2rem;
  color: #78909c;
}

/* ── 练习纸页面 ── */
.pw-sheet {
  position: relative;
  background: var(--pw-paper);
  padding: 8mm 10mm 10mm;
  margin-bottom: 1rem;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.07);
  overflow: hidden;
  min-height: 260mm;
  box-sizing: border-box;
}

.pw-sheet::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--fltrp-green, #6cc24a) 0%, var(--fltrp-green, #6cc24a) 40%, var(--fltrp-orange, #ff8f1f) 100%);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-sheet--maze::before { background: linear-gradient(90deg, #2b7cb8, #5eb8e5); }
.pw-sheet--spell::before { background: linear-gradient(90deg, #e86f00, #ffb347); }
.pw-sheet--connect::before { background: linear-gradient(90deg, #2d6a2e, #6cc24a); }
.pw-sheet--quiz::before { background: linear-gradient(90deg, #7c4dff, #b388ff); }
.pw-sheet--memory::before { background: linear-gradient(90deg, #e91e8c, #f48fb1); }
.pw-sheet--sentence::before { background: linear-gradient(90deg, #3d5afe, #82b1ff); }
.pw-sheet--pick::before { background: linear-gradient(90deg, #ff9100, #ffd24a); }

.pw-sheet-hdr {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 2px solid var(--pw-gold);
  padding-bottom: 6px;
  margin-bottom: 8px;
  margin-top: 2px;
}

.pw-sheet-hdr h2 {
  font-family: var(--font, 'Fredoka', sans-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fltrp-green-dark, #2d6a2e);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pw-sheet-hdr .pw-meta {
  font-size: 0.82rem;
  color: #78909c;
  text-align: right;
}

.pw-name-line {
  font-size: 0.88rem;
  margin-bottom: 8px;
  color: var(--pw-ink);
}

.pw-name-line span {
  display: inline-block;
  min-width: 8rem;
  border-bottom: 1.5px solid #90a4ae;
}

/* ── 单词迷宫 ── */
.pw-maze-targets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.pw-maze-target {
  text-align: center;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 8px 6px;
  background: linear-gradient(180deg, #fff 0%, var(--pw-sky-light) 100%);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-maze-target:nth-child(1) { border-color: #00b4d8; background: linear-gradient(180deg, #fff 0%, #e0f7fa 100%); }
.pw-maze-target:nth-child(2) { border-color: #e91e8c; background: linear-gradient(180deg, #fff 0%, #fce4ec 100%); }
.pw-maze-target:nth-child(3) { border-color: #3d5afe; background: linear-gradient(180deg, #fff 0%, #e8eaf6 100%); }
.pw-maze-target:nth-child(4) { border-color: #ff9100; background: linear-gradient(180deg, #fff 0%, #fff3e0 100%); }

.pw-maze-target img {
  width: 100%;
  max-height: 108px;
  object-fit: contain;
}

.pw-maze-target .pw-num {
  font-family: var(--font, 'Fredoka', sans-serif);
  font-size: 1rem;
  font-weight: 700;
  color: var(--pw-accent-maze);
  width: 1.75rem;
  height: 1.75rem;
  line-height: 1.75rem;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--pw-accent-maze);
  margin: 0 auto 6px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-maze-target .pw-zh {
  font-size: 0.9rem;
  color: var(--pw-muted);
  margin-top: 4px;
}

.pw-maze-grid {
  display: grid;
  gap: 4px;
  width: 100%;
  max-width: 178mm;
  margin: 0 auto;
  border: 3px solid #37474f;
  border-radius: 8px;
  padding: 6px;
  background: #37474f;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-maze-cell {
  aspect-ratio: 1;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font, 'Fredoka', sans-serif);
  font-weight: 700;
  font-size: clamp(1.1rem, 2.8vw, 1.75rem);
  text-transform: uppercase;
  border-radius: 3px;
}

.pw-maze-cell:nth-child(odd) { background: #fafafa; }

/* ── 字母排序 ── */
.pw-spell-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.pw-spell-item {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 16px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px dashed #cfd8dc;
}

.pw-spell-item:last-child { border-bottom: none; }

.pw-spell-item img {
  width: 108px;
  height: 86px;
  object-fit: contain;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  padding: 4px;
  background: #fff;
}

.pw-spell-zh {
  font-size: 1rem;
  color: var(--pw-muted);
  margin-bottom: 8px;
}

.pw-spell-letters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.pw-spell-letters span {
  width: 2.35rem;
  height: 2.35rem;
  border: 2px solid #90caf9;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Patrick Hand', cursive;
  font-size: 1.55rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e3f2fd, #fff);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-spell-letters span:nth-child(4n+1) { border-color: #81c784; background: linear-gradient(135deg, #e8f5e9, #fff); }
.pw-spell-letters span:nth-child(4n+2) { border-color: #ffb74d; background: linear-gradient(135deg, #fff3e0, #fff); }
.pw-spell-letters span:nth-child(4n+3) { border-color: #f48fb1; background: linear-gradient(135deg, #fce4ec, #fff); }

.pw-spell-write {
  font-size: 0.95rem;
  color: #546e7a;
}

.pw-spell-line {
  display: inline-block;
  min-width: 14rem;
  border-bottom: 2.5px solid #37474f;
  margin-left: 6px;
  height: 1.85rem;
  vertical-align: bottom;
}

/* ── 图片单词连线 ── */
.pw-connect-hdr {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 10px 0;
  font-weight: 700;
  font-size: 1rem;
  color: var(--pw-ink);
}

.pw-connect-hdr div:first-child { color: var(--pw-accent-maze); }
.pw-connect-hdr div:last-child { color: var(--pw-accent-spell); }

.pw-connect-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 12px 0;
}

.pw-connect-item {
  border: 2px solid #cfd8dc;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  min-height: 168px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-connect-item--img {
  background: linear-gradient(135deg, #e3f4fc 0%, #fff 100%);
  border-color: #5eb8e5;
}

.pw-connect-item--word {
  background: linear-gradient(135deg, #fff8e1 0%, #fff 100%);
  border-color: #ffb74d;
}

.pw-connect-item img {
  height: 140px;
  max-width: 100%;
  object-fit: contain;
}

.pw-connect-word {
  font-family: var(--font, 'Fredoka', sans-serif);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--pw-ink);
}

/* ── 选择题 ── */
.pw-quiz-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.pw-quiz-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px dashed #cfd8dc;
  align-items: start;
}

.pw-quiz-item:last-child { border-bottom: none; }

.pw-quiz-item img {
  width: 96px;
  height: 76px;
  object-fit: contain;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  padding: 4px;
  background: #fff;
}

.pw-quiz-q {
  font-size: 1.1rem;
  margin-bottom: 8px;
  line-height: 1.4;
}

.pw-quiz-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.pw-quiz-opt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 8px;
  border: 2px solid #b0bec5;
  border-radius: 12px;
  font-size: 1.02rem;
  background: #fff;
  min-width: 7.5rem;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-quiz-opt .pw-opt-letter {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}

.pw-quiz-opt:nth-child(1) .pw-opt-letter { background: #00b4d8; }
.pw-quiz-opt:nth-child(2) .pw-opt-letter { background: #e91e8c; }
.pw-quiz-opt:nth-child(3) .pw-opt-letter { background: #3d5afe; }
.pw-quiz-opt:nth-child(4) .pw-opt-letter { background: #ff9100; }

/* ── 看单词选图（游戏九纸质版）── */
.pw-pick-item {
  padding: 18px 0;
  border-bottom: 1px dashed #cfd8dc;
}

.pw-pick-item:last-child { border-bottom: none; }

.pw-pick-word {
  font-family: var(--font, 'Fredoka', sans-serif);
  font-size: 1.65rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 14px;
  color: var(--pw-accent-pick);
}

.pw-pick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.pw-pick-opt {
  border: 2px solid #cfd8dc;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  background: #fff;
  min-height: 138px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-pick-opt:nth-child(1) { border-color: #00b4d8; background: linear-gradient(180deg, #e0f7fa, #fff); }
.pw-pick-opt:nth-child(2) { border-color: #e91e8c; background: linear-gradient(180deg, #fce4ec, #fff); }
.pw-pick-opt:nth-child(3) { border-color: #3d5afe; background: linear-gradient(180deg, #e8eaf6, #fff); }
.pw-pick-opt:nth-child(4) { border-color: #ff9100; background: linear-gradient(180deg, #fff3e0, #fff); }

.pw-pick-opt img {
  max-height: 118px;
  max-width: 100%;
  object-fit: contain;
}

.pw-pick-opt .pw-opt-letter {
  position: absolute;
  top: 6px;
  left: 8px;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background: var(--pw-ink);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── 翻翻配对卡片 ── */
.pw-memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.pw-memory-card {
  border: 2px dashed #90a4ae;
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  min-height: 128px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-memory-card:nth-child(odd) {
  border-color: #5eb8e5;
  background: linear-gradient(180deg, #e3f4fc, #fff);
}

.pw-memory-card:nth-child(even) {
  border-color: #ffb74d;
  background: linear-gradient(180deg, #fff8e1, #fff);
}

.pw-memory-card img {
  max-height: 88px;
  max-width: 100%;
  object-fit: contain;
}

.pw-memory-card .pw-card-word {
  font-family: var(--font, 'Fredoka', sans-serif);
  font-weight: 700;
  font-size: 1.05rem;
  margin-top: 6px;
}

/* ── 句子排序（每页 4 句） ── */
/* 使用正常文档流 + 固定尺寸，禁止 flex 拉伸，避免打印重叠 */
.pw-sheet--sentence {
  overflow: visible;
}

.pw-sheet--sentence > .pw-sheet-hdr {
  margin-bottom: 6px;
  padding-bottom: 4px;
}

.pw-sheet--sentence > .pw-name-line {
  margin-bottom: 8px;
}

.pw-sheet--sentence > .pw-sheet-footer {
  margin-top: 8px;
  clear: both;
}

.pw-sentence-item {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  align-items: start;
  padding: 0;
  margin: 0;
  border-bottom: 1px dashed #cfd8dc;
  box-sizing: border-box;
  overflow: visible;
  position: relative;
  page-break-inside: avoid;
  break-inside: avoid;
}

.pw-sentence-item + .pw-sentence-item {
  margin-top: 1cm;
  padding-top: 0;
}

.pw-sentence-item:last-child {
  border-bottom: none;
}

.pw-sentence-img {
  display: block;
  width: 140px;
  height: 105px;
  object-fit: contain;
  border: 2px solid #cfd8dc;
  border-radius: 10px;
  padding: 3px;
  background: #fff;
  box-sizing: border-box;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-sentence-img--empty {
  width: 140px;
  height: 105px;
  background: linear-gradient(135deg, #eceff1, #fff);
  border: 2px dashed #cfd8dc;
  border-radius: 10px;
  box-sizing: border-box;
}

.pw-sentence-body {
  display: block;
  min-width: 0;
  overflow: visible;
}

.pw-sentence-zh {
  font-size: 1.02rem;
  color: var(--pw-muted);
  margin: 0 0 6px;
  line-height: 1.4;
}

.pw-sentence-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 8px;
}

.pw-sentence-words span {
  padding: 5px 11px;
  border: 2px solid #90caf9;
  border-radius: 8px;
  font-size: 0.98rem;
  background: linear-gradient(135deg, #e3f2fd, #fff);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-sentence-words span:nth-child(3n+1) { border-color: #81c784; background: linear-gradient(135deg, #e8f5e9, #fff); }
.pw-sentence-words span:nth-child(3n+2) { border-color: #ffb74d; background: linear-gradient(135deg, #fff3e0, #fff); }

.pw-sentence-write {
  margin: 0;
  font-size: 0.92rem;
  color: #546e7a;
}

.pw-sentence-line {
  display: block;
  width: 100%;
  height: 3.8rem;
  margin-top: 6px;
  box-sizing: border-box;
  border: 2px solid #90a4ae;
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      transparent,
      transparent calc(1.35rem - 1px),
      #cfd8dc calc(1.35rem - 1px),
      #cfd8dc 1.35rem
    );
  background-size: 100% 1.35rem;
  background-position: 0 0.25rem;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-answer-key .pw-sentence-line {
  display: none;
}

.pw-answer-key .pw-sentence-write .pw-ans {
  display: block;
  margin-top: 6px;
  font-size: 1.02rem;
  line-height: 1.45;
}

/* ── 答案页 ── */
.pw-answer-key {
  background: linear-gradient(180deg, #f1f8e9 0%, var(--pw-paper) 30%);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pw-answer-key .pw-ans {
  font-family: var(--font, 'Fredoka', sans-serif);
  color: var(--fltrp-green-dark, #2d6a2e);
  font-weight: 700;
}

.pw-hint {
  text-align: center;
  font-size: 0.76rem;
  color: #78909c;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dotted #e0e0e0;
}

.pw-sheet-footer {
  text-align: center;
  font-size: 0.68rem;
  color: #b0bec5;
  margin-top: 8px;
}

/* ── 打印 ── */
@media print {
  body.print-worksheet-page,
  body.print-worksheet-print {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.print-worksheet-page::before,
  body.print-worksheet-page::after,
  body.print-worksheet-print::before,
  body.print-worksheet-print::after {
    display: none !important;
  }

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

  body.print-worksheet-print .container {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.print-worksheet-print .card {
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #printArea {
    max-width: none;
    margin: 0;
  }

  .pw-sheet {
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    padding: 6mm 8mm 8mm;
    min-height: auto;
    page-break-after: always;
    break-after: page;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pw-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .pw-maze-grid {
    max-width: 100%;
    width: 96%;
  }

  .pw-maze-cell {
    font-size: 1.7rem;
  }

  .pw-maze-target img {
    max-height: 118px;
  }

  .pw-spell-item img {
    width: 112px;
    height: 90px;
  }

  .pw-spell-letters span {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.65rem;
  }

  .pw-connect-item {
    min-height: 175px;
  }

  .pw-connect-item img {
    height: 148px;
  }

  .pw-quiz-item img {
    width: 100px;
    height: 80px;
  }

  .pw-pick-opt {
    min-height: 145px;
  }

  .pw-pick-opt img {
    max-height: 125px;
  }

  .pw-memory-card {
    min-height: 135px;
  }

  .pw-memory-card img {
    max-height: 92px;
  }

  .pw-sheet--sentence {
    min-height: auto !important;
    height: auto !important;
    overflow: visible !important;
  }

  .pw-sentence-item {
    grid-template-columns: 148px 1fr;
    gap: 12px;
    align-items: start;
    padding: 0;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .pw-sentence-item + .pw-sentence-item {
    margin-top: 1cm;
  }

  .pw-sentence-img,
  .pw-sentence-img--empty {
    width: 148px;
    height: 112px;
    min-height: 0;
  }

  .pw-sentence-body {
    min-height: 0;
    height: auto;
  }

  .pw-sentence-line {
    height: 4.2rem;
    min-height: 0;
    background-size: 100% 1.4rem;
    background-position: 0 0.28rem;
  }

  .pw-maze-target,
  .pw-maze-grid,
  .pw-spell-letters span,
  .pw-connect-item,
  .pw-quiz-opt,
  .pw-pick-opt,
  .pw-memory-card,
  .pw-sentence-words span,
  .pw-answer-key {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

@page {
  size: A4 portrait;
  margin: 6mm 8mm;
}
