:root {
  --print-soft: #e8f9f5;
  --print-warm: #fff0ec;
  --print-blue: #eaf2ff;
}

.hyakumasu-print-page,
.hyakumasu-print-page button,
.hyakumasu-print-page select,
.hyakumasu-print-page input {
  touch-action: manipulation;
}

.print-notebook {
  min-height: 100vh;
}

.print-back-link {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 44px;
  padding: 7px 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.print-builder {
  padding: clamp(12px, 2.6vw, 28px);
}

.print-builder-heading {
  margin-bottom: 18px;
}

.print-builder-heading h1 {
  margin: 3px 0 5px;
  color: var(--ink);
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
}

.print-builder-heading > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.print-builder-layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 30px);
  align-items: start;
}

.print-settings {
  display: grid;
  gap: 0;
  padding: 0 16px 16px;
  border: 2px solid var(--ink);
  border-radius: 18px 15px 20px 16px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 3px 4px 0 var(--ink);
}

.print-fieldset {
  min-width: 0;
  margin: 0;
  padding: 17px 0;
  border: 0;
  border-bottom: 1.5px solid #d9e0ea;
}

.print-fieldset legend {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  margin: 0 0 11px;
  padding: 0;
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
}

.print-fieldset legend span {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow-soft);
  font-size: 13px;
}

.print-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.print-mode-grid button,
.print-segment button,
.print-color-segment button,
.new-questions-button,
.print-primary-button {
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  -webkit-user-select: none;
  user-select: none;
}

.print-mode-grid button {
  min-height: 52px;
  padding: 8px;
  border: 2px solid var(--ink);
  border-radius: 13px 10px 15px 11px;
  background: var(--button-bg, white);
  box-shadow: 2px 3px 0 var(--ink);
  font-size: 16px;
}

.print-mode-grid button:nth-child(1) { --button-bg: var(--print-soft); }
.print-mode-grid button:nth-child(2) { --button-bg: var(--print-warm); }
.print-mode-grid button:nth-child(3) { --button-bg: var(--yellow-soft); }
.print-mode-grid button:nth-child(4) { --button-bg: var(--print-blue); }

.print-mode-grid button[aria-pressed="true"] {
  outline: 4px solid rgba(72, 201, 176, .25);
  transform: translateY(-2px);
  box-shadow: 3px 5px 0 var(--ink);
}

.print-pattern-row {
  display: grid;
  gap: 8px;
}

.print-segment {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  padding: 5px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: white;
  box-shadow: 2px 3px 0 var(--ink);
}

.print-segment button {
  display: grid;
  gap: 3px;
  align-content: center;
  min-height: 54px;
  padding: 7px;
  border: 2px solid transparent;
  border-radius: 11px;
  background: white;
}

.print-segment button strong {
  font-size: 14px;
}

.print-segment button small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.print-segment button.is-selected {
  border-color: var(--ink);
  background: var(--print-soft);
  box-shadow: inset 0 -3px 0 rgba(32, 50, 77, .14);
}

.print-segment button:not(.is-selected) {
  color: var(--muted);
}

.print-fixed-select {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 0 10px;
  border: 2px solid #d5dde9;
  border-radius: 12px;
  background: #f7f9fc;
  opacity: .48;
}

.print-fixed-select.is-active {
  border-color: var(--ink);
  background: white;
  box-shadow: 2px 3px 0 var(--ink);
  opacity: 1;
}

.print-fixed-select span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.print-fixed-select select {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
}

.new-questions-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-self: start;
  min-height: 44px;
  margin-top: 9px;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 12px;
}

.new-questions-button[hidden] {
  display: none;
}

.answer-toggle {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 3px 10px;
  align-items: center;
  min-height: 56px;
  cursor: pointer;
}

.answer-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.answer-toggle > span {
  position: relative;
  grid-row: 1 / span 2;
  width: 49px;
  height: 28px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: #dfe5ed;
  box-shadow: 1.5px 2px 0 var(--ink);
  transition: background .14s ease;
}

.answer-toggle > span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: white;
  content: "";
  transition: transform .14s ease;
}

.answer-toggle input:checked + span {
  background: var(--mint);
}

.answer-toggle input:checked + span::after {
  transform: translateX(21px);
}

.answer-toggle strong {
  align-self: end;
  font-size: 15px;
}

.answer-toggle small {
  grid-column: 2;
  align-self: start;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.qr-toggle {
  padding-top: 9px;
  border-top: 1px solid #e1e6ee;
}

.print-color-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 50px;
  padding-top: 10px;
  border-top: 1px solid #e1e6ee;
}

.print-color-row > strong {
  font-size: 13px;
  white-space: nowrap;
}

.print-color-segment {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: white;
  box-shadow: 1.5px 2px 0 var(--ink);
}

.print-color-segment button {
  min-height: 44px;
  padding: 5px 7px;
  border: 1.5px solid transparent;
  border-radius: 8px;
  background: white;
  font-size: 12px;
}

.print-color-segment button.is-selected {
  border-color: var(--ink);
  background: var(--print-soft);
  box-shadow: inset 0 -2px 0 rgba(32, 50, 77, .14);
}

.print-color-segment button[data-color-mode="mono"].is-selected {
  background: #edf0f3;
}

.print-primary-button {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  margin-top: 16px;
  padding: 10px 16px;
  border: 2px solid var(--ink);
  border-radius: 14px 11px 16px 12px;
  background: var(--yellow);
  box-shadow: 3px 4px 0 var(--ink);
  font-size: 17px;
}

.print-hint {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}

.print-preview-panel {
  min-width: 0;
}

.print-guide {
  max-width: 920px;
  margin: clamp(16px, 3vw, 28px) auto 0;
  padding: clamp(16px, 3vw, 24px);
  border-top: 2px dashed #d7e0ea;
  color: var(--ink);
}

.print-guide h2 {
  margin: 3px 0 8px;
  font-size: clamp(20px, 3.2vw, 28px);
  line-height: 1.25;
}

.print-guide > p:not(.eyebrow) {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.85;
}

.print-guide-points {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.print-guide-points article {
  padding: 12px 13px;
  border: 1.5px solid #d9e0ea;
  border-radius: 14px;
  background: rgba(255, 255, 255, .74);
}

.print-guide-points h3,
.print-faq h3 {
  margin: 0 0 5px;
  font-size: 15px;
  line-height: 1.35;
}

.print-guide-points p,
.print-faq p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.7;
}

.print-faq {
  margin-top: 14px;
  border: 1.5px solid #d9e0ea;
  border-radius: 14px;
  background: rgba(255, 255, 255, .7);
}

.print-faq summary {
  min-height: 44px;
  padding: 11px 13px;
  cursor: pointer;
  font-weight: 900;
}

.print-faq > div {
  display: grid;
  gap: 10px;
  padding: 0 13px 13px;
}

.screen-preview {
  display: grid;
  gap: 18px;
  min-width: 0;
  padding: 14px;
  border: 1.5px solid #ccd5e2;
  background: #e9edf2;
  overflow: hidden;
}

.paper-frame {
  position: relative;
  width: 100%;
}

.paper-stage {
  width: 794px;
  height: 1123px;
  transform: scale(var(--paper-scale, .72));
  transform-origin: top left;
}

.worksheet-sheet {
  position: relative;
  box-sizing: border-box;
  width: 794px;
  height: 1123px;
  padding: 45px 45px 36px;
  background: #fff;
  box-shadow: 0 5px 20px rgba(32, 50, 77, .18);
  color: #152238;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
}

.worksheet-sheet.is-monochrome .sheet-kicker,
.worksheet-sheet.is-monochrome .worksheet-cell.is-corner {
  color: #152238;
}

.worksheet-sheet.is-monochrome .sheet-kind,
.worksheet-sheet.is-monochrome .worksheet-cell.is-corner,
.worksheet-sheet.is-monochrome .worksheet-cell.is-head {
  background: #eef0f2;
}

.worksheet-sheet.is-monochrome .worksheet-cell.is-answer {
  background: white;
}

.answer-qr {
  position: absolute;
  right: 45px;
  bottom: 42px;
  display: grid;
  gap: 4px;
  justify-items: center;
  width: 100px;
  color: #152238;
  text-align: center;
}

.answer-qr a {
  display: block;
  color: inherit;
  line-height: 0;
}

.answer-qr svg {
  display: block;
  width: 82px;
  height: 82px;
  background: white;
}

.answer-qr strong {
  font-size: 11px;
}

.sheet-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 13px;
  border-bottom: 3px solid #20324d;
}

.sheet-kicker {
  margin: 0 0 3px;
  color: #ef654f;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

.sheet-top h2 {
  margin: 0;
  font-size: 29px;
  line-height: 1.1;
  letter-spacing: 0;
}

.sheet-kind {
  min-width: 98px;
  padding: 8px 10px;
  border: 2px solid #20324d;
  background: #e8f9f5;
  font-size: 15px;
  font-weight: 900;
  text-align: center;
}

.answer-sheet .sheet-kind {
  background: #fff3ce;
}

.sheet-fields {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 24px;
  margin: 15px 0 12px;
}

.sheet-field {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: end;
  font-size: 13px;
  font-weight: 800;
}

.sheet-field i {
  display: block;
  height: 20px;
  border-bottom: 1.5px solid #20324d;
}

.sheet-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 800;
}

.sheet-score-fields {
  display: flex;
  gap: 16px;
  white-space: nowrap;
}

.sheet-score-fields i {
  display: inline-block;
  width: 33px;
  height: 16px;
  border-bottom: 1.5px solid #20324d;
  vertical-align: bottom;
}

.worksheet-grid {
  display: grid;
  grid-template-columns: repeat(11, 62px);
  grid-template-rows: repeat(11, 62px);
  width: 682px;
  margin: 0 auto;
  border-top: 2px solid #20324d;
  border-left: 2px solid #20324d;
}

.worksheet-cell {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  min-width: 0;
  border-right: 1.5px solid #20324d;
  border-bottom: 1.5px solid #20324d;
  font-size: 16px;
  font-weight: 700;
}

.worksheet-cell.is-head,
.worksheet-cell.is-corner {
  background: #f0f4f8;
  font-size: 18px;
  font-weight: 900;
}

.worksheet-cell.is-corner {
  background: #e8f9f5;
  color: #ef654f;
  font-size: 25px;
}

.worksheet-cell.is-answer {
  background: #fffdf7;
}

.division-list {
  display: grid;
  grid-template-rows: repeat(25, 1fr);
  grid-template-columns: repeat(4, 1fr);
  grid-auto-flow: column;
  gap: 0 20px;
  height: 760px;
  padding: 4px 2px 0;
}

.division-item {
  display: grid;
  grid-template-columns: 25px 1fr;
  gap: 3px;
  align-items: center;
  min-width: 0;
  border-bottom: 1px dotted #8d98a8;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.division-item b {
  color: #67748a;
  font-size: 10px;
}

.division-answer {
  display: inline-block;
  min-width: 30px;
  text-align: center;
}

.sheet-footer {
  position: absolute;
  right: 45px;
  bottom: 18px;
  left: 45px;
  display: flex;
  justify-content: space-between;
  color: #67748a;
  font-size: 9px;
  font-weight: 700;
}

.print-pages {
  display: none;
}

.print-back-link:focus-visible,
.print-mode-grid button:focus-visible,
.print-segment button:focus-visible,
.print-color-segment button:focus-visible,
.print-fixed-select select:focus-visible,
.new-questions-button:focus-visible,
.answer-toggle input:focus-visible + span,
.print-primary-button:focus-visible {
  outline: 5px solid rgba(72, 136, 229, .3);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  .print-builder-layout {
    grid-template-columns: 1fr;
  }
  .print-settings {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 16px;
  }
  .print-fieldset {
    border-bottom: 0;
  }
  .print-primary-button,
  .print-hint {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .print-app-frame .app-header {
    padding-bottom: 7px;
  }
  .print-app-frame .brand-logo.compact {
    width: min(132px, 38vw);
  }
  .print-back-link {
    padding-inline: 4px;
    font-size: 12px;
  }
  .print-builder {
    padding: 8px 6px 16px;
  }
  .print-builder-heading {
    margin-bottom: 12px;
  }
  .print-builder-heading h1 {
    font-size: 28px;
  }
  .print-builder-heading > p:last-child {
    font-size: 11px;
  }
  .print-settings {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0 11px 12px;
  }
  .print-fieldset {
    padding: 13px 0;
    border-bottom: 1.5px solid #d9e0ea;
  }
  .print-fieldset legend {
    margin-bottom: 8px;
    font-size: 15px;
  }
  .print-mode-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }
  .print-mode-grid button {
    min-height: 48px;
    padding: 5px 2px;
    font-size: 13px;
  }
  .print-segment button {
    min-height: 50px;
  }
  .print-segment button strong {
    font-size: 13px;
  }
  .answer-toggle {
    min-height: 48px;
  }
  .print-primary-button {
    min-height: 52px;
    margin-top: 13px;
  }
  .screen-preview {
    padding: 8px;
  }
  .print-guide {
    padding: 16px 8px 4px;
  }
  .print-guide-points {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 5mm;
  }

  html,
  body {
    width: 200mm;
    height: auto !important;
    min-height: 0 !important;
    margin: 0;
    padding: 0;
    background: white !important;
    overflow: visible;
  }

  .screen-only,
  .screen-preview {
    display: none !important;
  }

  .print-app-frame,
  .print-notebook {
    display: block;
    width: 200mm;
    height: auto;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: white !important;
    box-shadow: none;
    overflow: visible;
  }

  .print-notebook::before,
  .print-notebook::after {
    display: none !important;
  }

  .print-pages {
    display: block;
  }

  .paper-frame,
  .paper-stage {
    width: 200mm !important;
    height: 287mm !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    overflow: hidden;
  }

  .worksheet-sheet {
    width: 200mm;
    height: 287mm;
    padding: 12mm 12mm 9mm;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .paper-frame:last-child .worksheet-sheet {
    break-after: auto;
    page-break-after: auto;
  }

  .worksheet-grid {
    grid-template-columns: repeat(11, 16mm);
    grid-template-rows: repeat(11, 16mm);
    width: 176mm;
  }

  .worksheet-cell {
    font-size: 11pt;
  }

  .worksheet-cell.is-head,
  .worksheet-cell.is-corner {
    font-size: 12pt;
  }

  .worksheet-cell.is-corner {
    font-size: 17pt;
  }

  .division-list {
    height: 191mm;
    gap: 0 5mm;
  }

  .answer-qr {
    right: 12mm;
    bottom: 11mm;
    gap: 1mm;
    width: 26mm;
  }

  .answer-qr svg {
    width: 22mm;
    height: 22mm;
  }

  .answer-qr strong {
    font-size: 7pt;
  }

  .division-item {
    grid-template-columns: 6mm 1fr;
    font-size: 9.5pt;
  }

  .division-item b {
    font-size: 7pt;
  }

  .sheet-footer {
    right: 12mm;
    bottom: 5mm;
    left: 12mm;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
