* {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  background: linear-gradient(180deg, #eef7ee 0%, #f4f6fb 220px, #f4f6fb 100%);
  color: #1e293b;
}

/* ---- maker form -------------------------------------------------------- */

#mathsaic_options {
  max-width: 1020px;
  margin: 0 auto;
  padding: 24px 20px 8px;
}
#mathsaic_puzzle {
  padding: 10px;
}

.hero {
  background: linear-gradient(120deg, #16a34a, #0d9488);
  color: white;
  border-radius: 16px;
  padding: 22px 26px;
  box-shadow: 0 8px 24px rgba(13, 148, 136, 0.28);
}
.hero h1 {
  font-size: 27px;
  margin: 0 0 8px;
}
.hero .intro {
  margin: 0;
  max-width: 760px;
  line-height: 1.5;
  color: #e7f9ee;
}

.card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  padding: 18px 22px 20px;
  margin: 18px 0;
}
.card h2 {
  font-size: 19px;
  margin: 0 0 12px;
}
.card .hint {
  margin: 0 0 10px;
  color: #475569;
}

.field input[type="text"],
.field input[type="number"],
.field select {
  padding: 7px 10px;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  font-size: 15px;
  background: white;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
}
input[type="checkbox"] {
  accent-color: #16a34a;
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
}

/* Each checkbox + its label is one clickable pill ("chip"): the box leads
   its own word, the pill border groups them as a single unit, and the
   whole pill fills green when on — so a box can never be mistaken for
   belonging to the neighboring label. */
.op-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}
label.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 9px;
  background: white;
  border: 1.5px solid #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s ease, border-color 0.1s ease;
}
label.check:hover {
  border-color: #16a34a;
}
label.check:has(input:checked) {
  background: #dcfce7;
  border-color: #16a34a;
  font-weight: 600;
}

.player-row {
  border: 1px solid #e2e8f0;
  border-left: 6px solid #0d9488;
  border-radius: 12px;
  background: #f8fafc;
  padding: 12px 14px;
  margin: 10px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
}
.player-row:nth-child(even) {
  border-left-color: #f59e0b;
}
.player-head {
  font-weight: 700;
  width: 100%;
  font-size: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field {
  white-space: nowrap;
}
.color-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.color-label {
  font-size: 13px;
  color: #475569;
}
.swatches {
  display: inline-flex;
  gap: 4px;
}
.theme-swatch {
  width: 28px;
  height: 19px;
  border-radius: 5px;
  cursor: pointer;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.theme-swatch.selected {
  outline: 3px solid #111827;
  outline-offset: 1px;
}
.word-row {
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-add {
  background: white;
  color: #15803d;
  border: 2px solid #16a34a;
  font-size: 14px;
  font-weight: 700;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.btn-add:hover {
  background: #f0fdf4;
}
.btn-delete {
  background: white;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
  flex: none;
}
.btn-delete:hover {
  background: #fef2f2;
}

.create-row {
  text-align: center;
  margin: 22px 0 8px;
}
.btn-primary {
  background: linear-gradient(120deg, #16a34a, #0d9488);
  color: white;
  border: none;
  font-size: 18px;
  font-weight: 700;
  padding: 13px 30px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(13, 148, 136, 0.4);
}

/* ---- puzzle tables (unchanged mechanics, cleaner type) ------------------- */

table {
  border-collapse: collapse;
}
table.wrapper {
  border-right: 1px solid black;
}
td {
  padding: 0px;
  height: 20px;
}
.letters td, .key td {
  height: 50px;
  width: 50px;
  padding: 0px;
  text-align: center;
  font-size: 12px;
  border-style: solid;
  border-width: 1px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.key td {
  font-weight: 700;
  font-size: 14px;
}
.letters td {
  border-right: none;
  cursor: pointer;
}
table.key {
  margin-bottom: 50px;
}

/* ---- scavenger hunt output ------------------------------------------- */

.print-note {
  max-width: 800px;
  margin: 12px auto;
  padding: 12px 16px;
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 16px;
}
.btn-print {
  background: #16a34a;
  color: white;
  border: none;
  font-size: 15px;
  font-weight: 700;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-print:hover {
  background: #15803d;
}

.hunt-page {
  position: relative;
  max-width: 800px;
  min-height: 560px;
  margin: 18px auto;
  padding: 30px 20px 70px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hunt-puzzle {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hunt-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 22px;
  text-align: center;
  font-size: 16px;
}

.hunt-final {
  align-items: flex-start;
}
.hunt-final h2 {
  margin: 10px 0;
}
.instructions {
  font-size: 16px;
  line-height: 1.5;
  margin: 0 0 20px;
}
.answer-word {
  display: flex;
  gap: 44px;
  align-items: flex-start;
  margin-bottom: 22px; /* blank line between words */
}
.answer-line {
  font-size: 18px;
  line-height: 1.45;
}
.answer-letter {
  display: inline-block;
  width: 28px;
  font-weight: bold;
}
.answer-footer {
  color: #333;
}
.answer-instruction {
  font-size: 16px;
  font-weight: 600;
  border-left: 4px solid #16a34a;
  padding: 4px 0 4px 12px;
  margin-top: 2px;
}

@media print {
  body {
    background: white;
  }
  #mathsaic_options,
  .print-note {
    display: none;
  }
  #mathsaic_puzzle {
    padding: 0;
  }
  /* Footer placement: do NOT size print pages with 100vh (phone print
     pipelines measure vh taller than the printable area, which split the
     page box and stranded the bottom-anchored footer on its own sheet).
     Instead the stylesheet sets its own @page margins, and each puzzle
     page is a box of fixed physical height — 248mm, safely shorter than
     the printable height of both Letter (259mm at these margins) and A4
     (277mm) — with the footer anchored to the bottom of the box. The
     leftover slack plus break-inside: avoid keep the footer on the same
     sheet as its puzzle, near the bottom of the page. */
  @page {
    size: auto;
    margin: 10mm;
  }
  .hunt-page {
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    max-width: none;
    height: auto;
    min-height: 0;
    padding: 10px 0 0;
    display: block;
    page-break-after: always;
    break-after: page;
  }
  /* puzzle pages get the fixed physical height; the final page may
     legitimately be long, so it sizes to content and breaks naturally */
  .hunt-page:not(.hunt-final) {
    height: 248mm;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .hunt-footer {
    position: absolute;
    bottom: 0;
    margin-top: 0;
    text-align: center;
  }
  .hunt-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }
}
