/* dankcards — "party table": a bright tablecloth, paper cards, tomato + sunflower + teal.
   System fonts only. Light/dark via prefers-color-scheme, overridable by [data-theme]. */
:root {
  --bg: #fdf6ea;
  --bg-cloth: rgba(229, 72, 47, .07);
  --surface: #ffffff;
  --surface-2: #fff4dc;
  --ink: #2a2118;
  --muted: #6f6253;
  --line: #2a2118;
  --soft-line: #e6d8c2;
  --accent: #d63d25;
  --accent-ink: #ffffff;
  --sun: #ffc83d;
  --teal: #0f7d72;
  --error-bg: #fde4df;
  --error-ink: #8f1d0c;
  --shadow: 3px 3px 0 var(--line);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1713; --bg-cloth: rgba(255, 200, 61, .05); --surface: #27211b; --surface-2: #322a20;
    --ink: #f6ecdc; --muted: #c0b19c; --line: #0c0907; --soft-line: #4a3f33;
    --accent: #ff6a4d; --accent-ink: #1b1713; --sun: #ffcf57; --teal: #4fc7b8;
    --error-bg: #4a1f17; --error-ink: #ffd2c8; --shadow: 3px 3px 0 #000;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1713; --bg-cloth: rgba(255, 200, 61, .05); --surface: #27211b; --surface-2: #322a20;
  --ink: #f6ecdc; --muted: #c0b19c; --line: #0c0907; --soft-line: #4a3f33;
  --accent: #ff6a4d; --accent-ink: #1b1713; --sun: #ffcf57; --teal: #4fc7b8;
  --error-bg: #4a1f17; --error-ink: #ffd2c8; --shadow: 3px 3px 0 #000;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 var(--font);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    repeating-linear-gradient(0deg, var(--bg-cloth) 0 22px, transparent 22px 44px),
    repeating-linear-gradient(90deg, var(--bg-cloth) 0 22px, transparent 22px 44px);
}
a { color: var(--teal); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1240px; margin: 0 auto; padding: 10px 16px;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font: 800 1.15rem/1 var(--font-display); color: var(--ink); text-decoration: none; letter-spacing: -.01em;
}
.brand-dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); box-shadow: inset -4px -4px 0 rgba(0, 0, 0, .18), 0 0 0 2px var(--line);
}
.theme-toggle {
  font: 600 .85rem var(--font); color: var(--ink); background: var(--surface);
  border: 2px solid var(--line); border-radius: 999px; padding: 4px 12px; cursor: pointer;
}

.layout { max-width: 1240px; margin: 0 auto; padding: 0 16px 32px; }
h1 {
  font: 800 1.7rem/1.15 var(--font-display); letter-spacing: -.02em; margin: 4px 0 6px;
}
.lede { margin: 0 0 12px; color: var(--muted); font-size: .98rem; }
.hint { font-weight: 500; color: var(--muted); font-size: .85rem; }
.hint.short { color: var(--error-ink); background: var(--error-bg); border-radius: 6px; padding: 0 5px; }

.panel {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 650; font-size: .92rem; margin: 0 0 10px; }
.field label { font-weight: 650; }
textarea, input[type="text"], input[type="number"], select {
  font: 16px/1.4 var(--font); color: var(--ink); background: var(--surface-2);
  border: 2px solid var(--soft-line); border-radius: 10px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 7.5em; }
textarea:focus, input:focus, select:focus { border-color: var(--teal); outline: none; }
.field-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field-row > .field { margin-bottom: 10px; }
.field.grow { flex: 1 1 140px; }
.field.num { flex: 0 0 90px; }
.list-pick select { font-weight: 500; }

fieldset.seg { border: 0; padding: 0; flex-direction: row; gap: 0; }
fieldset.seg legend { padding: 0; margin-bottom: 4px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block; padding: 7px 13px; border: 2px solid var(--line); margin-left: -2px;
  background: var(--surface-2); font-weight: 700; min-width: 52px; text-align: center;
}
.seg label:first-of-type span { border-radius: 10px 0 0 10px; margin-left: 0; }
.seg label:last-of-type span { border-radius: 0 10px 10px 0; }
.seg input:checked + span { background: var(--sun); color: #2a2118; }
.seg input:focus-visible + span { outline: 3px solid var(--teal); outline-offset: 1px; position: relative; }

.field.check { flex-direction: row; align-items: center; gap: 8px; padding: 8px 0; cursor: pointer; }
.field.check input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.field.check.off { opacity: .5; cursor: not-allowed; }

.error {
  background: var(--error-bg); color: var(--error-ink); border-radius: 10px;
  padding: 8px 10px; margin: 0 0 10px; font-weight: 600; font-size: .92rem;
}
.actions { display: flex; }
.btn {
  font: 700 1rem var(--font); color: var(--ink); background: var(--surface-2);
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer;
  box-shadow: 2px 2px 0 var(--line);
}
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { flex: 1; background: var(--accent); color: var(--accent-ink); font-size: 1.08rem; padding: 12px 16px; }
.print-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; align-items: end;
  margin-top: 12px; padding-top: 12px; border-top: 2px dashed var(--soft-line);
}
.print-row .field { margin: 0; }
.print-row .wide, .print-row .pdf-note { grid-column: 1 / -1; }
.pdf-note { margin: 0; color: var(--error-ink); }

.preview-h { font: 800 1.25rem/1.2 var(--font-display); margin: 24px 0 10px; }
.preview-h .hint { display: block; font-family: var(--font); margin-top: 2px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.empty { color: var(--muted); }

/* ---- a bingo card (screen and print share this) ---- */
.card {
  container-type: inline-size;
  background: #fffdf8; color: #2a2118; border: 2px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
/* cqi on the card's own padding would resolve against the page, so space the children instead */
.card > * { margin: 3.5cqi 3.5cqi 0; }
.card > :last-child { margin-bottom: 2.5cqi; }
.card-title {
  font: 900 9cqi/1 var(--font-display); text-align: center; letter-spacing: .08em;
  color: #fff; background: #d63d25; border-radius: 3cqi; padding: 2.4cqi 2cqi 2cqi;
  overflow-wrap: anywhere;
}
.grid { display: grid; border: 2px solid #2a2118; border-radius: 6px; overflow: hidden; }
.grid.n3 { grid-template-columns: repeat(3, 1fr); --n: 3; }
.grid.n4 { grid-template-columns: repeat(4, 1fr); --n: 4; }
.grid.n5 { grid-template-columns: repeat(5, 1fr); --n: 5; }
.cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center; text-align: center;
  border-right: 1.5px solid #2a2118; border-bottom: 1.5px solid #2a2118;
  padding: 1cqi; font-size: calc(16cqi / var(--n)); line-height: 1.1; font-weight: 650;
  overflow: hidden; overflow-wrap: break-word; hyphens: manual;
}
/* longest single word decides the size, so "Sparklers" shrinks instead of splitting */
.cell.l9 { font-size: calc(13cqi / var(--n)); }
.cell.l11 { font-size: calc(11cqi / var(--n)); }
.cell.l14 { font-size: calc(9cqi / var(--n)); overflow-wrap: anywhere; }
.cell.many { line-height: 1.02; }
.grid.n3 .cell:nth-child(3n), .grid.n4 .cell:nth-child(4n), .grid.n5 .cell:nth-child(5n) { border-right: 0; }
.grid.n3 .cell:nth-child(n+7), .grid.n4 .cell:nth-child(n+13), .grid.n5 .cell:nth-child(n+21) { border-bottom: 0; }
.cell.free span {
  display: flex; align-items: center; justify-content: center; width: 82%; aspect-ratio: 1;
  border-radius: 50%; background: #ffc83d; font-weight: 900; letter-spacing: .04em;
  box-shadow: inset -0.6cqi -0.6cqi 0 rgba(0, 0, 0, .15);
}
.card-foot { font-size: 2.6cqi; color: #6f6253; text-align: right; }

/* ---- how-to ---- */
.howto { max-width: 70ch; margin-top: 36px; }
.howto h2 { font: 800 1.35rem/1.2 var(--font-display); margin: 0 0 8px; }
.howto h3 { font-size: 1.02rem; margin: 18px 0 4px; }
.howto p { margin: 0 0 10px; }
.small { font-size: .88rem; color: var(--muted); }
/* ---- themed pages: visible word lists ---- */
.wordlists { max-width: 70ch; margin-top: 28px; }
.wordlists h2 { font: 800 1.35rem/1.2 var(--font-display); margin: 0 0 4px; }
.wordlists h3 { font-size: 1.02rem; margin: 14px 0 6px; }
.wordlists-grid { display: grid; gap: 4px 28px; }
.wordlist {
  columns: 2; column-gap: 20px; margin: 0; padding: 10px 12px 10px 30px;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.wordlist li { break-inside: avoid; padding: 1px 0; }

/* ---- Christmas: pine-green card header, berry-red free space (cards are always light paper) ---- */
.t-christmas .card-title { background: #17673a; color: #fff; box-shadow: inset 0 -1.2cqi 0 #c22a2a; }
.t-christmas .cell.free span { background: #c22a2a; color: #fff; }
.t-christmas .wordlist { border-top: 6px solid #c22a2a; }
.t-christmas .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #17673a; }

/* ---- Thanksgiving: rust card header with a gold stripe, gold free space (cards are always light paper) ---- */
.t-thanksgiving .card-title { background: #8a3a12; color: #fff; box-shadow: inset 0 -1.2cqi 0 #d9961a; }
.t-thanksgiving .cell.free span { background: #f2c14e; color: #2a2118; }
.t-thanksgiving .wordlist { border-top: 6px solid #b4531c; }
.t-thanksgiving .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #6b7a24; }

/* ---- Baby shower: dusty-blue card header with a blush stripe, blush free space (cards are always light paper) ---- */
.t-baby-shower .card-title { background: #4a6a8a; color: #fff; box-shadow: inset 0 -1.2cqi 0 #e7a9b6; }
.t-baby-shower .cell.free span { background: #f6d3da; color: #2a2118; }
.t-baby-shower .wordlist { border-top: 6px solid #e7a9b6; }
.t-baby-shower .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #9cc3b2; }

/* ---- Bridal shower: deep-mauve card header with a champagne stripe, champagne free space (cards are always light paper) ---- */
.t-bridal-shower .card-title { background: #74405e; color: #fff; box-shadow: inset 0 -1.2cqi 0 #d8b86e; }
.t-bridal-shower .cell.free span { background: #f1e2bd; color: #2a2118; }
.t-bridal-shower .wordlist { border-top: 6px solid #d8b86e; }
.t-bridal-shower .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #9aae8c; }

/* ---- Halloween: deep-purple card header with a pumpkin stripe, pumpkin free space (cards are always light paper) ---- */
.t-halloween .card-title { background: #4b2770; color: #fff; box-shadow: inset 0 -1.2cqi 0 #f07f1a; }
.t-halloween .cell.free span { background: #f07f1a; color: #2a2118; }
.t-halloween .wordlist { border-top: 6px solid #f07f1a; }
.t-halloween .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #8a5cc2; }
/* ---- 1-75 number bingo: B-I-N-G-O header row joined to the grid, big numbers, teal card header ---- */
.board75 { display: flex; flex-direction: column; }
.board75 .grid-head {
  display: grid; grid-template-columns: repeat(5, 1fr); background: #2a2118; color: #fff;
  border: 2px solid #2a2118; border-bottom: 0; border-radius: 6px 6px 0 0;
  font: 900 9cqi/1 var(--font-display); text-align: center; padding: 1.6cqi 0 1.2cqi;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.board75 .grid { border-radius: 0 0 6px 6px; }
.cell.num { font-size: calc(36cqi / var(--n)); font-weight: 800; font-variant-numeric: tabular-nums; }
.t-numbers .card-title { background: #0f7d72; color: #fff; box-shadow: inset 0 -1.2cqi 0 #ffc83d; }
/* ---- 1-90 UK tickets: 3 rows x 9, wide cards, shaded blanks, one ticket per row on a phone ---- */
.t-numbers90 .cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); }
.grid.t90 { grid-template-columns: repeat(9, 1fr); --n: 9; }
.grid.t90 .cell { padding: 0; }
.grid.t90 .cell.num { font-size: 5.4cqi; }
.grid.t90 .cell.gap { background: #e9e0cf; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.grid.t90 .cell:nth-child(9n) { border-right: 0; }
.grid.t90 .cell:nth-child(n+19) { border-bottom: 0; }
.card.ticket .card-title { font-size: 5cqi; padding: 1.4cqi 2cqi 1.2cqi; border-radius: 2cqi; }
.card.ticket > * { margin: 2.2cqi 2.2cqi 0; }
.card.ticket > :last-child { margin-bottom: 1.6cqi; }
.card.ticket .card-foot { font-size: 2.2cqi; }
.board { border-collapse: collapse; width: 100%; table-layout: fixed; }
.board th, .board td { border: 1px solid var(--line); text-align: center; padding: 6px 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.board th { background: #2a2118; color: #fff; font-family: var(--font-display); }
fieldset.seg.modes { display: grid; grid-template-columns: 1fr 1fr; }
.seg.modes label, .seg.modes span { height: 100%; }
.seg.modes span { display: flex; align-items: center; justify-content: center; padding: 7px 10px; line-height: 1.2; }

.foot { max-width: 1240px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: .85rem; border-top: 2px dashed var(--soft-line); }
.print-area { display: none; }

@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 400px 1fr; gap: 0 32px; align-items: start; }
  .maker { position: sticky; top: 12px; }
  .preview { grid-column: 2; grid-row: 1 / span 2; }
  .preview-h { margin-top: 8px; }
  .howto { grid-column: 1 / -1; }
  .wordlists { grid-column: 1 / -1; max-width: none; }
  .wordlists-grid { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 2rem; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
}

/* ---- print: only the print area, cards 1 / 2 / 4 per page or the caller sheet ---- */
@media print {
  :root { color-scheme: light; }
  body { background: #fff !important; color: #000; font-size: 11pt; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; }
  .card { box-shadow: none; border-color: #000; border-radius: 3mm; -webkit-print-color-adjust: exact; print-color-adjust: exact; break-inside: avoid; }
  .grid, .cell { border-color: #000; }
  .sheet {
    display: grid; break-after: page; page-break-after: always; break-inside: avoid;
    width: 100%; justify-items: center; align-items: center; overflow: hidden;
  }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .slot { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
  /* printable height = paper height - 2 x 10 mm margin, minus a little slack so a sheet never spills */
  .paper-letter .sheet { height: 255mm; }
  .paper-a4 .sheet { height: 273mm; }
  .paper-letter.landscape .sheet { height: 192mm; }
  .paper-a4.landscape .sheet { height: 186mm; }
  .pp1 .card { width: 178mm; }
  .pp2 .sheet { grid-template-columns: 1fr 1fr; gap: 8mm; }
  .pp2 .card { width: 118mm; }
  .pp4 .sheet { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 6mm; }
  .pp4 .card { width: 88mm; }
  .paper-a4.pp1 .card { width: 175mm; }
  .paper-a4.pp4 .card { width: 86mm; }
  /* 90-ball: one strip of 6 tickets per portrait page; cells wider than tall so 6 fit */
  .pp6 .sheet { grid-template-rows: repeat(6, 1fr); gap: 1.5mm; }
  .pp6 .card { width: 160mm; border-radius: 2mm; }
  .paper-a4.pp6 .card { width: 170mm; }
  .pp6 .grid.t90 .cell { aspect-ratio: 2.2; }
  .pp6 .card.ticket .card-title { font-size: 2.4cqi; padding: .5cqi 1cqi; }
  .pp6 .card.ticket > * { margin: 1cqi 1cqi 0; }
  .pp6 .card.ticket > :last-child { margin-bottom: 1cqi; }
  .pp6 .card.ticket .card-foot { font-size: 1.8cqi; }
  .board.b90 td { padding: 5mm 0; font-size: 18pt; }
  .caller h2 { font: 800 18pt/1.2 var(--font-display); margin: 0 0 2mm; }
  .caller-meta { margin: 0 0 5mm; color: #444; font-size: 10pt; }
  .caller ol { columns: 3; column-gap: 8mm; margin: 0; padding-left: 7mm; font-size: 11pt; }
  .caller li { break-inside: avoid; padding: 1.2mm 0; border-bottom: .3mm solid #ccc; }
  .caller.tally ol { columns: 2; }
  .caller.tally li { padding: 2.2mm 0; border-bottom-color: #888; }
  .board-sheet { break-after: page; page-break-after: always; }
  .board th, .board td { border: .4mm solid #000; padding: 4mm 0; font-size: 16pt; }
  .board th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tick { display: inline-block; width: 4mm; height: 4mm; border: .4mm solid #000; margin-right: 2mm; vertical-align: -0.6mm; }
}

/* ---- Sight words: chalkboard-green card header with a pencil-yellow stripe; one colour per reading level (cards are always light paper) ---- */
.t-sight-words .card-title { background: #2f5d50; color: #fff; box-shadow: inset 0 -1.2cqi 0 #f2c230; }
.t-sight-words .cell.free span { background: #f2c230; color: #2a2118; }
.t-sight-words .wordlist { border-top: 6px solid #f2c230; }
.t-sight-words .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #3f8f6e; }
.t-sight-words .wordlists-grid > div:nth-child(3) .wordlist { border-top-color: #d0573a; }
.t-sight-words .wordlists-grid > div:nth-child(4) .wordlist { border-top-color: #3b6fb6; }

/* ---- New Year's Eve: midnight-blue card header with a gold stripe, gold free space (cards are always light paper) ---- */
.t-new-years-eve .card-title { background: #1b2a52; color: #fff; box-shadow: inset 0 -1.2cqi 0 #d4a72c; }
.t-new-years-eve .cell.free span { background: #e9c75b; color: #1b2a52; }
.t-new-years-eve .wordlist { border-top: 6px solid #d4a72c; }
.t-new-years-eve .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #4a64a8; }

/* ---- Road trip: road-sign green card header with a white edge line, sign-yellow free space (cards are always light paper) ---- */
.t-road-trip .card-title { background: #1d6b45; color: #fff; box-shadow: inset 0 -1.2cqi 0 #f2c230; }
.t-road-trip .cell.free span { background: #f2c230; color: #1d3b2c; }
.t-road-trip .wordlist { border-top: 6px solid #1d6b45; }
.t-road-trip .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #f2c230; }

/* ---- Winter: deep ice-blue card header with a pale frost stripe, frost-blue free space (cards are always light paper) ---- */
.t-winter .card-title { background: #1f4e79; color: #fff; box-shadow: inset 0 -1.2cqi 0 #a9d4ee; }
.t-winter .cell.free span { background: #cfe8f6; color: #1f4e79; }
.t-winter .wordlist { border-top: 6px solid #1f4e79; }
.t-winter .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #a9d4ee; }

/* ---- Hanukkah: deep blue card header with a candle-gold stripe, pale gold free space (cards are always light paper) ---- */
.t-hanukkah .card-title { background: #1b3f8b; color: #fff; box-shadow: inset 0 -1.2cqi 0 #e0b84a; }
.t-hanukkah .cell.free span { background: #f6e7b8; color: #1b3f8b; }
.t-hanukkah .wordlist { border-top: 6px solid #1b3f8b; }
.t-hanukkah .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #e0b84a; }

/* ---- Office: charcoal card header with a sticky-note yellow stripe, pale yellow free space (cards are always light paper) ---- */
.t-office .card-title { background: #2f3a45; color: #fff; box-shadow: inset 0 -1.2cqi 0 #f4d35e; }
.t-office .cell.free span { background: #fbeeb0; color: #2f3a45; }
.t-office .wordlist { border-top: 6px solid #2f3a45; }
.t-office .wordlists-grid > div:nth-child(2) .wordlist { border-top-color: #f4d35e; }
