:root {
  --bg: #f7f3ec;
  --panel: #ffffff;
  --ink: #243033;
  --muted: #667579;
  --line: #e5ded4;
  --accent: #5f7cc8;
  --accent-soft: #e3ebff;
  --accent-2: #80b7a2;
  --shadow: 0 20px 50px rgba(48, 39, 28, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, #fff1d8 0, transparent 34%),
    radial-gradient(circle at top right, #eaf1ff 0, transparent 28%),
    var(--bg);
  color: var(--ink);
}

h1, h2, h3, p { margin-top: 0; }
button { font: inherit; }

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 34px clamp(18px, 5vw, 64px) 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(34px, 5vw, 62px);
  line-height: 0.98;
  letter-spacing: -0.065em;
}

.subtitle {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-weight: 540;
}

.primary-btn,
.secondary-btn {
  border-radius: 15px;
  border: 1px solid var(--line);
  cursor: pointer;
  font-weight: 850;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.primary-btn:hover,
.secondary-btn:hover { transform: translateY(-1px); }

.primary-btn {
  padding: 14px 18px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 12px 26px rgba(36,48,51,0.22);
  white-space: nowrap;
}

.secondary-btn {
  padding: 11px 14px;
  background: #fff;
  color: var(--ink);
}

.full { width: 100%; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(315px, 420px) 1fr;
  gap: 24px;
  padding: 20px clamp(18px, 5vw, 64px) 56px;
  align-items: start;
}

.control-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  display: grid;
  gap: 16px;
  padding-right: 8px;
  scrollbar-width: thin;
}

.panel-card,
.preview-area {
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(229,222,212,0.94);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.panel-card { padding: 22px; }
.panel-card h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: -0.02em; }

label {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  color: #405054;
  font-size: 13px;
  font-weight: 850;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 13px;
  color: var(--ink);
  font: inherit;
}

textarea { resize: vertical; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.button-row { display: grid; gap: 10px; margin-top: 16px; }

.hidden { display: none !important; }

.mini-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  font-weight: 650;
}

.template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.puzzle-card {
  width: 100%;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at top right, var(--accent-soft) 0 42px, transparent 44px),
    #fff;
  border-radius: 20px;
  padding: 14px;
  text-align: left;
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(48,39,28,0.07);
}

.puzzle-card.active {
  border: 2px solid var(--accent);
  box-shadow: 0 14px 28px rgba(48,39,28,0.12);
}

.puzzle-card strong {
  display: block;
  font-size: 15px;
  margin-bottom: 5px;
}

.puzzle-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 700;
}

.info-list {
  display: grid;
  gap: 10px;
  font-size: 13px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  color: var(--muted);
  font-weight: 750;
}

.info-row strong { color: var(--ink); text-align: right; }

.preview-area {
  padding: 22px;
  min-height: 760px;
  overflow: auto;
}

.preview-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.preview-toolbar h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.03em;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

.page-status {
  padding: 10px 13px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
}

.puzzle-preview {
  display: grid;
  gap: 22px;
  justify-items: center;
  padding: 14px 0 30px;
}

.page {
  position: relative;
  width: 8.5in;
  height: 11in;
  padding: 0.42in;
  padding-bottom: 0.58in;
  background: #fffdf9;
  border-radius: 14px;
  box-shadow: 0 16px 45px rgba(52,43,34,0.16);
  overflow: hidden;
  page-break-after: always;
  display: flex;
  flex-direction: column;
}

.letter-size .page { width: 8.5in; height: 11in; }
.a4-size .page { width: 8.27in; height: 11.69in; }
.a5-size .page { width: 5.83in; height: 8.27in; padding: 0.28in; padding-bottom: 0.45in; }

.page::before {
  content: "";
  position: absolute;
  inset: 13px;
  border: 2px solid var(--puzzle-line, #d9e3ff);
  border-radius: 22px;
  pointer-events: none;
}

.page-header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid var(--puzzle-line, #d9e3ff);
  padding-bottom: 12px;
  margin-bottom: 18px;
  flex: 0 0 auto;
}

.page-header h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.045em;
}

.page-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.pill {
  align-self: start;
  background: var(--puzzle-soft, #eaf0ff);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.puzzle-body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: 18px;
}

.footer-note {
  position: absolute;
  z-index: 1;
  bottom: 24px;
  left: 0;
  right: 0;
  text-align: center;
  color: #a0a0a0;
  font-size: 10px;
  font-weight: 700;
}

/* Word search */
.wordsearch-layout {
  grid-template-columns: 1fr 1.9in;
  align-items: start;
}

.word-grid {
  display: grid;
  border: 2px solid var(--puzzle-line);
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  aspect-ratio: 1;
}

.word-cell {
  display: grid;
  place-items: center;
  border-right: 1px solid var(--puzzle-line);
  border-bottom: 1px solid var(--puzzle-line);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.answer-highlight {
  background: color-mix(in srgb, var(--puzzle-accent), transparent 82%);
}

.word-list-box {
  border: 2px solid var(--puzzle-line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255,255,255,0.76);
}

.word-list-box h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.word-list {
  display: grid;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}

/* Sudoku */
.sudoku-wrap {
  display: grid;
  place-items: center;
  flex: 1;
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 6.5in;
  height: 6.5in;
  border: 3px solid var(--ink);
  background: #fff;
}

.sudoku-cell {
  display: grid;
  place-items: center;
  border-right: 1px solid #b9c2c7;
  border-bottom: 1px solid #b9c2c7;
  font-size: 30px;
  font-weight: 800;
}

.sudoku-cell:nth-child(3n) { border-right: 3px solid var(--ink); }
.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 3px solid var(--ink); }

.sudoku-cell.given { color: var(--ink); }
.sudoku-cell.empty { color: transparent; }

/* Maze */
.maze-wrap {
  display: grid;
  place-items: center;
  flex: 1;
}

.maze-grid {
  display: grid;
  width: 6.7in;
  height: 6.7in;
  background: #fff;
  border: 3px solid var(--ink);
}

.maze-cell {
  position: relative;
  background: #fff;
}

.maze-cell.wall-top { border-top: 2px solid var(--ink); }
.maze-cell.wall-right { border-right: 2px solid var(--ink); }
.maze-cell.wall-bottom { border-bottom: 2px solid var(--ink); }
.maze-cell.wall-left { border-left: 2px solid var(--ink); }

.maze-cell.solution::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: var(--puzzle-accent);
  opacity: 0.42;
}

.maze-labels {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 900;
  color: var(--puzzle-accent);
  margin: 0 auto;
  width: 6.7in;
}

/* Crossmath */
.crossmath-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  width: 6.5in;
  height: 6.5in;
  margin: 0 auto;
  border: 2px solid var(--puzzle-line);
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
}

.cross-cell {
  display: grid;
  place-items: center;
  border-right: 1px solid var(--puzzle-line);
  border-bottom: 1px solid var(--puzzle-line);
  font-size: 28px;
  font-weight: 900;
}

.cross-cell.blank {
  color: transparent;
  background: #fff;
}

.cross-cell.symbol {
  color: var(--muted);
  background: var(--puzzle-soft);
}

.cross-cell.result {
  color: var(--puzzle-accent);
}

/* Logic */
.logic-layout {
  grid-template-columns: 1fr 2.75in;
  align-items: start;
}

.logic-clues,
.logic-answer {
  border: 2px solid var(--puzzle-line);
  border-radius: 18px;
  padding: 16px;
  background: rgba(255,255,255,0.78);
}

.logic-clues h3,
.logic-answer h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.logic-clues ol {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
  font-size: 14px;
  line-height: 1.45;
  font-weight: 650;
}

.logic-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: #fff;
}

.logic-table th,
.logic-table td {
  border: 1px solid var(--puzzle-line);
  padding: 8px;
  text-align: center;
  height: 36px;
}

.logic-table th {
  background: var(--puzzle-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Themes */
.style-clean { --puzzle-accent: #5f7cc8; --puzzle-soft: #eaf0ff; --puzzle-line: #d7e1ff; }
.style-school { --puzzle-accent: #4f8cc9; --puzzle-soft: #e4f3ff; --puzzle-line: #cfe3f7; }
.style-soft { --puzzle-accent: #c98091; --puzzle-soft: #fde8ee; --puzzle-line: #efd0d9; }
.style-ink { --puzzle-accent: #27313a; --puzzle-soft: #f2f2f2; --puzzle-line: #cfd4d8; }

/* A5 */
.a5-size .page-header h2 { font-size: 20px; }
.a5-size .page-header p, .a5-size .pill { font-size: 9px; }
.a5-size .puzzle-body { gap: 10px; }
.a5-size .wordsearch-layout,
.a5-size .logic-layout { grid-template-columns: 1fr; }
.a5-size .word-grid { max-width: 4.95in; }
.a5-size .word-cell { font-size: 11px; }
.a5-size .word-list-box { padding: 9px; }
.a5-size .word-list { grid-template-columns: repeat(2, 1fr); font-size: 8px; gap: 4px 8px; }
.a5-size .sudoku-grid { width: 4.75in; height: 4.75in; }
.a5-size .sudoku-cell { font-size: 18px; }
.a5-size .maze-grid { width: 4.8in; height: 4.8in; }
.a5-size .maze-labels { width: 4.8in; font-size: 10px; }
.a5-size .crossmath-grid { width: 4.8in; height: 4.8in; }
.a5-size .cross-cell { font-size: 19px; }
.a5-size .logic-clues { padding: 10px; }
.a5-size .logic-clues ol { font-size: 9px; gap: 6px; }
.a5-size .logic-table { font-size: 8px; }
.a5-size .logic-table th, .a5-size .logic-table td { padding: 4px; height: 23px; }
.a5-size .footer-note { bottom: 16px; font-size: 7px; }

/* Page visibility */
.single-mode .page { display: none; }
.single-mode .page.active-page { display: flex; }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel { position: static; max-height: none; overflow-y: visible; padding-right: 0; }
  .site-header { flex-direction: column; align-items: flex-start; }
  .page { transform: scale(0.82); transform-origin: top center; margin-bottom: -1.75in; }
}

@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .preview-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { justify-content: flex-start; }
  .page { transform: scale(0.54); margin-bottom: -4.9in; }
}

@media print {
  body { background: #fff; }
  .site-header,
  .control-panel,
  .preview-toolbar { display: none !important; }
  .app-shell,
  .preview-area,
  .puzzle-preview { display: block; padding: 0; margin: 0; box-shadow: none; border: 0; background: #fff; }
  .page {
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    transform: none !important;
    break-after: page;
    page-break-after: always;
  }
  .single-mode .page { display: flex; }
  .letter-size .page { width: 8.5in; height: 11in; }
  .a4-size .page { width: 8.27in; height: 11.69in; }
  .a5-size .page { width: 5.83in; height: 8.27in; }
}


/* ============================================================
   v5: Keep puzzles large; move Word Search words under grid
   The goal is NOT to shrink the puzzle. We use the page space better.
============================================================ */

/* Word Search: large grid + compact comma word list below */
.wordsearch-large-layout {
  display: grid;
  grid-template-columns: 1fr !important;
  grid-template-rows: auto auto;
  align-items: start;
  justify-items: center;
  gap: 0.14in;
}

.wordsearch-large-layout .word-grid {
  width: min(100%, 7.05in);
  max-width: 7.05in;
  max-height: none;
}

.compact-word-list {
  width: min(100%, 7.05in);
  max-height: none;
  padding: 0.11in 0.14in;
  border-radius: 14px;
}

.compact-word-list h3 {
  margin: 0 0 0.06in;
  font-size: 12px;
}

.word-list-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.02in 0.06in;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1.25;
}

.word-list-inline span {
  display: inline-block;
}

.word-list-inline .comma {
  margin-left: -0.04in;
  color: var(--muted);
}

/* Screen preview grid sizes: full but not clipped */
.letter-size .wordsearch-large-layout .word-grid {
  width: 7.05in;
}

.a4-size .wordsearch-large-layout .word-grid {
  width: 6.85in;
}

.a5-size .wordsearch-large-layout .word-grid {
  width: 4.95in;
}

.letter-size .compact-word-list {
  width: 7.05in;
}

.a4-size .compact-word-list {
  width: 6.85in;
}

.a5-size .compact-word-list {
  width: 4.95in;
  padding: 0.06in 0.08in;
}

.a5-size .word-list-inline {
  font-size: 6.5px;
  gap: 0.01in 0.04in;
}

.a5-size .compact-word-list h3 {
  display: none;
}

/* Keep Sudoku/Maze/Crossmath large on screen */
.letter-size .sudoku-grid,
.letter-size .maze-grid,
.letter-size .crossmath-grid {
  width: 7.15in;
  height: 7.15in;
}

.letter-size .maze-labels {
  width: 7.15in;
}

.a4-size .sudoku-grid,
.a4-size .maze-grid,
.a4-size .crossmath-grid {
  width: 7.00in;
  height: 7.00in;
}

.a4-size .maze-labels {
  width: 7.00in;
}

.a5-size .sudoku-grid,
.a5-size .maze-grid,
.a5-size .crossmath-grid {
  width: 4.95in;
  height: 4.95in;
}

.a5-size .maze-labels {
  width: 4.95in;
}

/* Print: use small page margins, but keep puzzle large */
@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }

  .site-header,
  .control-panel,
  .preview-toolbar {
    display: none !important;
  }

  .app-shell,
  .preview-area,
  .puzzle-preview {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    overflow: visible !important;
  }

  .page {
    display: flex !important;
    margin: 0 !important;
    padding: 0.22in !important;
    padding-bottom: 0.30in !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    transform: none !important;
    overflow: hidden !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    page-break-after: always !important;
  }

  .page:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }

  .answer-page {
    break-before: auto !important;
    page-break-before: auto !important;
  }

  .letter-size .page {
    width: 8.5in !important;
    height: 11in !important;
  }

  .a4-size .page {
    width: 8.27in !important;
    height: 11.69in !important;
  }

  .a5-size .page {
    width: 5.83in !important;
    height: 8.27in !important;
    padding: 0.16in !important;
    padding-bottom: 0.24in !important;
  }

  .page::before {
    inset: 0.07in !important;
    border-width: 1.25px !important;
  }

  .page-header {
    padding-bottom: 0.06in !important;
    margin-bottom: 0.10in !important;
    border-bottom-width: 1px !important;
  }

  .page-header h2 {
    font-size: 18px !important;
    line-height: 1.05 !important;
  }

  .page-header p,
  .pill {
    font-size: 7px !important;
  }

  .pill {
    padding: 0.045in 0.08in !important;
  }

  .footer-note {
    bottom: 0.08in !important;
    font-size: 6px !important;
  }

  .puzzle-body {
    gap: 0.08in !important;
    overflow: hidden !important;
  }

  /* Word search print: large grid, words below */
  .letter-size .wordsearch-large-layout .word-grid {
    width: 7.35in !important;
    max-width: 7.35in !important;
  }

  .a4-size .wordsearch-large-layout .word-grid {
    width: 7.10in !important;
    max-width: 7.10in !important;
  }

  .a5-size .wordsearch-large-layout .word-grid {
    width: 4.95in !important;
    max-width: 4.95in !important;
  }

  .letter-size .compact-word-list {
    width: 7.35in !important;
    padding: 0.07in 0.10in !important;
  }

  .a4-size .compact-word-list {
    width: 7.10in !important;
    padding: 0.07in 0.10in !important;
  }

  .a5-size .compact-word-list {
    width: 4.95in !important;
    padding: 0.04in 0.06in !important;
  }

  .compact-word-list h3 {
    font-size: 9px !important;
    margin-bottom: 0.035in !important;
  }

  .word-list-inline {
    font-size: 7.5px !important;
    gap: 0.005in 0.035in !important;
  }

  .a5-size .word-list-inline {
    font-size: 5.4px !important;
  }

  .word-cell {
    font-size: 16px !important;
  }

  .a4-size .word-cell {
    font-size: 15px !important;
  }

  .a5-size .word-cell {
    font-size: 7.4px !important;
  }

  /* Other puzzles: keep large */
  .letter-size .sudoku-grid,
  .letter-size .maze-grid,
  .letter-size .crossmath-grid {
    width: 7.35in !important;
    height: 7.35in !important;
  }

  .letter-size .maze-labels {
    width: 7.35in !important;
  }

  .a4-size .sudoku-grid,
  .a4-size .maze-grid,
  .a4-size .crossmath-grid {
    width: 7.10in !important;
    height: 7.10in !important;
  }

  .a4-size .maze-labels {
    width: 7.10in !important;
  }

  .a5-size .sudoku-grid,
  .a5-size .maze-grid,
  .a5-size .crossmath-grid {
    width: 4.95in !important;
    height: 4.95in !important;
  }

  .a5-size .maze-labels {
    width: 4.95in !important;
  }

  .sudoku-cell {
    font-size: 29px !important;
  }

  .a4-size .sudoku-cell {
    font-size: 28px !important;
  }

  .a5-size .sudoku-cell {
    font-size: 16px !important;
  }

  .cross-cell {
    font-size: 29px !important;
  }

  .a4-size .cross-cell {
    font-size: 28px !important;
  }

  .a5-size .cross-cell {
    font-size: 16px !important;
  }
}


/* ============================================================
   v7 Safari print fix: large puzzle + no extra blank pages
   This version does NOT shrink the puzzle grid.
   Instead, the printable .page wrapper is slightly shorter than the paper,
   while the puzzle itself remains large. This prevents Safari from creating
   a blank overflow page after each puzzle page.
============================================================ */

@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .site-header,
  .control-panel,
  .preview-toolbar {
    display: none !important;
  }

  .app-shell,
  .preview-area,
  .puzzle-preview {
    display: block !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  .page {
    display: flex !important;
    position: relative !important;
    margin: 0 auto !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    transform: none !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    contain: layout paint !important;

    break-before: auto !important;
    page-break-before: auto !important;
    break-after: auto !important;
    page-break-after: auto !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Only add a break BETWEEN real pages. */
  .page:not(:last-child) {
    break-after: page !important;
    page-break-after: always !important;
  }

  .answer-page {
    break-before: auto !important;
    page-break-before: auto !important;
  }

  /*
    Safari blank-page fix:
    The paper is Letter 8.5 x 11, but the page content box is 10.25in tall.
    This leaves safe non-printing breathing room without reducing the puzzle grid.
  */
  .letter-size .page {
    width: 8.5in !important;
    height: 10.25in !important;
    padding: 0.16in !important;
    padding-bottom: 0.22in !important;
  }

  .a4-size .page {
    width: 8.27in !important;
    height: 10.90in !important;
    padding: 0.16in !important;
    padding-bottom: 0.22in !important;
  }

  .a5-size .page {
    width: 5.83in !important;
    height: 7.72in !important;
    padding: 0.11in !important;
    padding-bottom: 0.16in !important;
  }

  .page::before {
    inset: 0.05in !important;
    border-width: 1px !important;
    border-radius: 0.14in !important;
  }

  .page-header {
    padding-bottom: 0.04in !important;
    margin-bottom: 0.055in !important;
    border-bottom-width: 1px !important;
  }

  .page-header h2 {
    font-size: 15px !important;
    line-height: 1.05 !important;
  }

  .page-header p,
  .pill {
    font-size: 6px !important;
  }

  .pill {
    padding: 0.03in 0.055in !important;
  }

  .footer-note {
    display: none !important;
  }

  .puzzle-body {
    gap: 0.045in !important;
    overflow: hidden !important;
    min-height: 0 !important;
  }

  /* Word Search: large grid with compact comma-separated words below. */
  .wordsearch-large-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto !important;
    justify-items: center !important;
    align-items: start !important;
    gap: 0.045in !important;
  }

  .letter-size .wordsearch-large-layout .word-grid {
    width: 7.55in !important;
    max-width: 7.55in !important;
  }

  .a4-size .wordsearch-large-layout .word-grid {
    width: 7.30in !important;
    max-width: 7.30in !important;
  }

  .a5-size .wordsearch-large-layout .word-grid {
    width: 5.08in !important;
    max-width: 5.08in !important;
  }

  .letter-size .compact-word-list {
    width: 7.55in !important;
    padding: 0.035in 0.065in !important;
  }

  .a4-size .compact-word-list {
    width: 7.30in !important;
    padding: 0.035in 0.065in !important;
  }

  .a5-size .compact-word-list {
    width: 5.08in !important;
    padding: 0.025in 0.04in !important;
  }

  .compact-word-list h3 {
    display: none !important;
  }

  .word-list-inline {
    font-size: 6.5px !important;
    line-height: 1.05 !important;
    gap: 0.002in 0.03in !important;
  }

  .a5-size .word-list-inline {
    font-size: 5px !important;
  }

  .word-cell {
    font-size: 16px !important;
  }

  .a4-size .word-cell {
    font-size: 15.5px !important;
  }

  .a5-size .word-cell {
    font-size: 7.4px !important;
  }

  /* Sudoku / Maze / Crossmath stay large. */
  .letter-size .sudoku-grid,
  .letter-size .maze-grid,
  .letter-size .crossmath-grid {
    width: 7.45in !important;
    height: 7.45in !important;
  }

  .letter-size .maze-labels {
    width: 7.45in !important;
  }

  .a4-size .sudoku-grid,
  .a4-size .maze-grid,
  .a4-size .crossmath-grid {
    width: 7.22in !important;
    height: 7.22in !important;
  }

  .a4-size .maze-labels {
    width: 7.22in !important;
  }

  .a5-size .sudoku-grid,
  .a5-size .maze-grid,
  .a5-size .crossmath-grid {
    width: 5.02in !important;
    height: 5.02in !important;
  }

  .a5-size .maze-labels {
    width: 5.02in !important;
  }

  .sudoku-cell {
    font-size: 29px !important;
  }

  .a5-size .sudoku-cell {
    font-size: 16px !important;
  }

  .cross-cell {
    font-size: 29px !important;
  }

  .a5-size .cross-cell {
    font-size: 16px !important;
  }

  /* Logic puzzle fit without shrinking the main text too much. */
  .letter-size .logic-layout,
  .a4-size .logic-layout {
    grid-template-columns: minmax(0, 1fr) 2.35in !important;
    gap: 0.10in !important;
  }

  .logic-clues,
  .logic-answer {
    padding: 0.08in !important;
  }

  .logic-clues ol {
    font-size: 10.5px !important;
    gap: 0.045in !important;
  }

  .logic-table th,
  .logic-table td {
    padding: 0.035in !important;
    height: 0.24in !important;
  }
}


/* ============================================================
   v8 Centered print placement
   Keeps the puzzle grid large, but centers the printed page block
   vertically on the selected sheet instead of sitting at the top.
============================================================ */

@media print {
  /* The .page box is intentionally a little shorter than the physical paper
     to avoid Safari creating blank overflow pages. These margins center that
     shorter page box visually on the sheet. */
  .letter-size .page {
    margin: 0.36in auto 0 auto !important;
  }

  .a4-size .page {
    margin: 0.38in auto 0 auto !important;
  }

  .a5-size .page {
    margin: 0.26in auto 0 auto !important;
  }

  /* Make sure only real pages break; do not add extra blank pages. */
  .page {
    break-before: auto !important;
    page-break-before: auto !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }

  .page:not(:last-child) {
    break-after: page !important;
    page-break-after: always !important;
  }

  .page:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}


/* ============================================================
   v9 Sheet Studio-style sidebar polish
   Adds main landing page link and collapsible left-panel sections.
============================================================ */
.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255,255,255,0.86);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(48,39,28,0.08);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
  white-space: nowrap;
}

.back-link:hover {
  transform: translateY(-1px);
  background: #fff;
  box-shadow: 0 14px 26px rgba(48,39,28,0.12);
}

.collapsible-panel {
  padding: 0;
  overflow: hidden;
}

.panel-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  cursor: pointer;
  user-select: none;
}

.panel-summary::-webkit-details-marker {
  display: none;
}

.panel-summary:hover {
  background: rgba(95,124,200,0.06);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.panel-heading h2,
.collapsible-panel h2 {
  margin: 0 0 4px;
}

.panel-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 750;
}

.step-number {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 950;
}

.panel-content {
  padding: 0 22px 22px;
}

.collapse-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(48,39,28,0.06);
}

.collapse-icon::before {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(45deg);
  margin-top: -2px;
  transition: transform 0.18s ease, margin 0.18s ease;
}

.collapsible-panel[open] .collapse-icon::before {
  transform: rotate(-135deg);
  margin-top: 3px;
}

.collapsible-panel:not([open]) {
  box-shadow: 0 14px 30px rgba(48,39,28,0.08);
}

.collapsible-panel:not([open]) .panel-summary {
  padding-bottom: 18px;
}

.collapsible-panel.hidden {
  display: none !important;
}

@media (max-width: 1120px) {
  .header-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .panel-summary {
    padding: 18px;
  }

  .panel-content {
    padding: 0 18px 18px;
  }

  .header-actions {
    width: 100%;
  }

  .back-link,
  .header-actions .primary-btn {
    width: 100%;
  }
}


/* ============================================================
   v13 True Crossmath grid
   Real row/column crossmath layout like the reference style:
   - 3x3 number cells
   - row operators and row totals
   - column operators and bottom totals
============================================================ */

.crossmath-wrap{
  display:grid;
  gap:0.14in;
  justify-items:center;
  align-content:start;
}

.crossmath-note{
  width:min(100%, 6.95in);
  color:var(--muted);
  font-size:13px;
  font-weight:750;
  text-align:center;
  line-height:1.4;
}

.crossmath-true-grid{
  display:grid;
  grid-template-columns:repeat(6, 1fr);
  width:6.85in;
  aspect-ratio:1;
  border:2px solid var(--puzzle-line);
  border-radius:18px;
  overflow:hidden;
  background:#fff;
}

.crossmath-box{
  display:grid;
  place-items:center;
  border-right:1px solid var(--puzzle-line);
  border-bottom:1px solid var(--puzzle-line);
  font-weight:900;
  min-width:0;
  min-height:0;
}

.crossmath-box:nth-child(6n){
  border-right:none;
}

.crossmath-true-grid .crossmath-box:nth-last-child(-n + 6){
  border-bottom:none;
}

.number-box{
  background:#fff;
  color:var(--ink);
  font-size:28px;
}

.op-box,
.spacer-box{
  background:var(--puzzle-soft);
  color:var(--muted);
  font-size:28px;
}

.result-box{
  background:#fff;
  color:var(--puzzle-accent);
  font-size:28px;
}

.spacer-box{
  color:transparent;
}

.blank-number{
  position:relative;
  color:transparent;
}

.blank-number::after{
  content:"";
  width:58%;
  border-bottom:2px solid #d7d7d7;
}

.a5-size .crossmath-note{
  width:min(100%, 4.95in);
  font-size:9px;
}

.a5-size .crossmath-true-grid{
  width:4.95in;
}

.a5-size .number-box,
.a5-size .op-box,
.a5-size .result-box{
  font-size:18px;
}

@media print{
  .crossmath-note{
    width:7.2in !important;
    font-size:9px !important;
  }

  .crossmath-true-grid{
    width:7.2in !important;
  }

  .number-box,
  .op-box,
  .result-box{
    font-size:24px !important;
  }

  .a5-size .crossmath-note{
    width:4.95in !important;
    font-size:7px !important;
  }

  .a5-size .crossmath-true-grid{
    width:4.95in !important;
  }

  .a5-size .number-box,
  .a5-size .op-box,
  .a5-size .result-box{
    font-size:16px !important;
  }
}
