:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #4b5563;
  --line: #4b5563;
  --soft-line: #cbd5e1;
  --paper: #ffffff;
  --shade: #f3f4f6;
}

* {
  box-sizing: border-box;
}

html {
  background: #e5e7eb;
  color: var(--ink);
  font-family: "BIZ UDPGothic", "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  line-height: 1.55;
}

body {
  margin: 0 auto;
  max-width: 1100px;
  background: var(--paper);
}

.print-nav {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--soft-line);
  background: var(--shade);
}

.print-nav a {
  color: inherit;
}

.print-sheet {
  min-height: 270mm;
  padding: 14mm;
  break-after: page;
  page-break-after: always;
}

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

.sheet-kicker {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  font-size: 1.8rem;
  line-height: 1.3;
}

h2 {
  margin-top: 1.4rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--ink);
  font-size: 1.3rem;
}

h3 {
  margin-bottom: 0.4rem;
  font-size: 1.05rem;
}

.rule-card,
.state-card,
.challenge-card,
.facilitator-card,
.note-box {
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 0.8rem;
  background: var(--paper);
}

.rule-card ol {
  margin: 0;
  padding-left: 1.5rem;
}

.state-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 0.65rem;
  margin: 1rem 0;
}

.state-card {
  min-height: 34mm;
}

.state-card__label {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 800;
}

.blank-line {
  display: block;
  min-height: 1.7rem;
  border-bottom: 1px solid var(--line);
}

.candidate-strip {
  border: 1px dashed var(--line);
  padding: 0.65rem;
}

.chip-grid,
.direction-grid,
.challenge-grid {
  display: grid;
  gap: 0.6rem;
}

.chip-grid {
  grid-template-columns: repeat(5, 1fr);
}

.step-chip,
.direction-card {
  border: 2px dashed var(--ink);
  border-radius: 8px;
  text-align: center;
  break-inside: avoid;
  page-break-inside: avoid;
}

.step-chip {
  min-height: 30mm;
  padding: 0.65rem 0.3rem;
}

.step-chip strong {
  display: block;
  font-size: 1.6rem;
}

.direction-grid {
  grid-template-columns: repeat(4, 1fr);
}

.direction-card {
  min-height: 34mm;
  padding: 0.55rem;
}

.direction-card code {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.95rem;
}

.direction-card small {
  display: block;
  color: var(--muted);
}

.pair-grid {
  grid-template-columns: repeat(3, 1fr);
}

.challenge-grid {
  grid-template-columns: repeat(2, 1fr);
}

.challenge-card {
  break-inside: avoid;
  page-break-inside: avoid;
}

.challenge-card dl {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.25rem 0.5rem;
  margin: 0;
}

.challenge-card dt {
  font-weight: 800;
}

.challenge-card dd {
  margin: 0;
}

.record-table,
.score-grid,
.penalty-table,
.run-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.record-table th,
.record-table td,
.score-grid th,
.score-grid td,
.penalty-table th,
.penalty-table td,
.run-table th,
.run-table td {
  border: 1px solid var(--line);
  padding: 0.3rem;
  text-align: center;
}

.record-table td {
  height: 9mm;
}

.record-split {
  display: flex;
  gap: 4mm;
  align-items: flex-start;
}

.record-split .record-table td {
  height: 7mm;
}

.record-table .wide {
  width: 18%;
}

.score-grid {
  table-layout: fixed;
  font-size: 0.68rem;
}

.score-grid caption {
  margin-bottom: 0.4rem;
  font-weight: 800;
  text-align: left;
}

.score-grid th {
  background: var(--shade);
}

.formula {
  padding: 0.8rem;
  border: 2px solid var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.cut-note {
  border: 2px dashed var(--ink);
  padding: 0.55rem;
  text-align: center;
  font-weight: 800;
}

.small {
  font-size: 0.82rem;
}

.muted {
  color: var(--muted);
}

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

@media print {
  html,
  body {
    max-width: none;
    background: #fff;
  }

  .print-nav {
    display: none;
  }

  .print-sheet {
    min-height: auto;
    padding: 4mm;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}

@media (max-width: 760px) {
  .state-grid,
  .challenge-grid,
  .pair-grid {
    grid-template-columns: 1fr;
  }

  .direction-grid,
  .chip-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .print-sheet {
    min-height: auto;
    padding: 1rem;
  }
}
