/* django-wordsearch
 *
 * The colours are custom properties, which a site can set on .wordsearch to match
 * its own palette: --wordsearch-ink, -muted, -line, -surface (the grid's cells),
 * -input, -accent (links, buttons and the rings of a solution), -accent-on and
 * -page (behind the grid). The defaults follow the page's text colour and its
 * color-scheme (light or dark). The grid's letters are in the page's font.
 */

.wordsearch {
  --ws-ink: var(--wordsearch-ink, currentColor);
  --ws-muted: var(--wordsearch-muted, color-mix(in srgb, currentColor 70%, transparent));
  --ws-line: var(--wordsearch-line, color-mix(in srgb, currentColor 25%, transparent));
  --ws-surface: var(--wordsearch-surface, color-mix(in srgb, currentColor 5%, transparent));
  --ws-input: var(--wordsearch-input, Field);
  --ws-accent: var(--wordsearch-accent, light-dark(#1d4ed8, #93c5fd));
  --ws-accent-on: var(--wordsearch-accent-on, light-dark(#ffffff, #0b1220));
  --ws-page: var(--wordsearch-page, transparent);
  color: var(--ws-ink);
  line-height: 1.5;
}

.wordsearch h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin: 0 0 1rem; }
.wordsearch h2 { font-size: 1.125rem; font-weight: 600; line-height: 1.3; margin: 1.5rem 0 0.5rem; }
.wordsearch p { margin: 0.5rem 0; }
.wordsearch a { color: var(--ws-accent); }
.wordsearch-crumbs { font-size: 0.875rem; color: var(--ws-muted); margin-bottom: 1rem; }
.wordsearch-crumbs a { color: inherit; }
.wordsearch-muted { color: var(--ws-muted); font-size: 0.875rem; }

/* The forms. */
.wordsearch-form {
  display: grid; gap: 1.25rem; margin-top: 1.5rem; padding: 1.25rem;
  border: 1px solid var(--ws-line); border-radius: 0.75rem;
}
.wordsearch-form fieldset { border: 0; margin: 0; padding: 0; }
.wordsearch-field > label, .wordsearch-field > legend {
  display: block; margin-bottom: 0.25rem; padding: 0; font-weight: 500;
}
.wordsearch-row { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.wordsearch-columns { display: grid; gap: 1.25rem; }
@media (min-width: 40rem) { .wordsearch-columns { grid-template-columns: 1fr 1fr; } }
.wordsearch-choice { display: flex; align-items: center; gap: 0.5rem; }
.wordsearch-choice input { accent-color: var(--ws-accent); }
.wordsearch :is(textarea, input[type="number"], select) {
  box-sizing: border-box; font-size: inherit; line-height: inherit; color: var(--ws-ink);
  background: var(--ws-input); border: 1px solid var(--ws-line); border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
}
.wordsearch :is(input[type="number"], select) { font-family: inherit; }
.wordsearch textarea {
  width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: uppercase;
}
.wordsearch input[type="number"] { width: 6rem; }
.wordsearch :is(textarea, input, select):focus-visible {
  outline: 2px solid var(--ws-accent); outline-offset: 1px;
}
.wordsearch button {
  justify-self: start; padding: 0.625rem 1.5rem; border: 0; border-radius: 0.5rem;
  font: inherit; font-weight: 500; color: var(--ws-accent-on); background: var(--ws-accent);
  cursor: pointer;
}
.wordsearch button:hover { background: color-mix(in srgb, var(--ws-accent), var(--ws-ink) 20%); }

/* The results. */
.wordsearch-results { margin-top: 2rem; }
.wordsearch-message { font-weight: 500; color: var(--ws-accent); }
.wordsearch-grid svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.wordsearch-grid .ws-page { fill: var(--ws-page); }
.wordsearch-grid .ws-cells { fill: var(--ws-surface); }
.wordsearch-grid .ws-rings { stroke: var(--ws-accent); }
.wordsearch-grid :is(.ws-letters, .ws-words) { fill: var(--ws-ink); font-family: inherit; }
.wordsearch-words {
  columns: 2; column-gap: 1.5rem; margin: 0.5rem 0; padding: 0; list-style: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.875rem;
}
@media (min-width: 40rem) { .wordsearch-words { columns: 3; } }
.wordsearch-links { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin-top: 1.5rem; }
.wordsearch-solution { margin-top: 1.5rem; }
.wordsearch-solution summary { font-weight: 500; cursor: pointer; }
.wordsearch-solution .wordsearch-grid { margin-top: 1rem; }
.wordsearch-table { width: 100%; margin-top: 1.5rem; border-collapse: collapse; font-size: 0.875rem; text-align: left; }
.wordsearch-table :is(th, td) { padding: 0.375rem 1rem 0.375rem 0; vertical-align: top; }
.wordsearch-table th { font-weight: 600; }
.wordsearch-table tbody tr { border-top: 1px solid var(--ws-line); }
.wordsearch-table td:first-child {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap;
}

/* Printed, a puzzle is just its grid and its words. */
@media print {
  .wordsearch :is(.wordsearch-crumbs, .wordsearch-intro, .wordsearch-form, .wordsearch-links, .wordsearch-solution) {
    display: none;
  }
}
