/* Wren Puzzles. Large, calm and high-contrast: body text 7:1, other text 4.5:1, borders 3:1
   in both colour themes (checked by the smoke test). Nothing is smaller than 1rem (18px). */

:root {
  color-scheme: light;
  --bg: #fbf8f3;
  --surface: #ffffff;
  --text: #1f1a14;
  --muted: #4a4036;
  --accent: #7a3f20;
  --border: #8f8478;
  --primary: #2f5d8a;
  --on-primary: #ffffff;
  --found: #f5d78e;
  --on-found: #1f1a14;
  --focus: #2f5d8a;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #1b1714;
  --surface: #26211c;
  --text: #f2ece4;
  --muted: #d6ccbf;
  --accent: #f0b48c;
  --border: #8c8174;
  --primary: #9cc3ea;
  --on-primary: #10202f;
  --found: #6b5420;
  --on-found: #f2ece4;
  --focus: #9cc3ea;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #1b1714;
    --surface: #26211c;
    --text: #f2ece4;
    --muted: #d6ccbf;
    --accent: #f0b48c;
    --border: #8c8174;
    --primary: #9cc3ea;
    --on-primary: #10202f;
    --found: #6b5420;
    --on-found: #f2ece4;
    --focus: #9cc3ea;
  }
}

html {
  font-size: 112.5%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html[data-text='large'] {
  font-size: 125%;
}
html[data-text='xl'] {
  font-size: 143.75%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

h1,
h2 {
  line-height: 1.25;
  margin: 1.5rem 0 0.75rem;
}
h1 {
  font-size: 2rem;
}
h2 {
  font-size: 1.4rem;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.wrap {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.skip {
  position: absolute;
  left: -999px;
}
.skip:focus {
  left: 1rem;
  top: 1rem;
  background: var(--surface);
  padding: 0.5rem 1rem;
  z-index: 10;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* Header */
.site-header {
  border-bottom: 2px solid var(--border);
  background: var(--surface);
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1.5rem;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
}
.site-header nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-header nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text);
  font-weight: 600;
}
.site-header nav a[aria-current='page'] {
  text-decoration-thickness: 3px;
}
.display {
  margin-left: auto;
}
.display summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 600;
}
.display-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  padding: 0.5rem 0;
}
.display fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}
.display legend {
  font-weight: 700;
  padding: 0;
}
.choice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  cursor: pointer;
}
.choice input {
  width: 1.4rem;
  height: 1.4rem;
  margin: 0;
  accent-color: var(--primary);
}
@media (max-width: 40rem) {
  .display {
    margin-left: 0;
    width: 100%;
  }
}

/* Breadcrumbs */
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}
.breadcrumbs li + li::before {
  content: '›';
  margin: 0 0.5rem;
}

/* Page headings */
.hero h1,
.page-hero h1 {
  margin-top: 1rem;
}
.lede {
  font-size: 1.15rem;
  max-width: 42rem;
}

/* Puzzle cards (home, 404, related) */
.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
  gap: 1rem;
  list-style: none;
  margin: 1.5rem 0;
  padding: 0;
}
.puzzle-card {
  display: block;
  height: 100%;
  padding: 1rem 1.25rem;
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.puzzle-card strong {
  display: block;
  font-size: 1.35rem;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.puzzle-card .desc {
  display: block;
  margin-top: 0.25rem;
}

/* Text pages and explanations */
.prose,
.explain {
  max-width: 42rem;
}
.prose li,
.explain li {
  margin: 0.35rem 0;
}
.meta-line {
  margin-top: 2rem;
}

.page-body {
  display: grid;
  gap: 0 3rem;
  margin-top: 2rem;
}
@media (min-width: 64rem) {
  .page-body {
    grid-template-columns: minmax(0, 42rem) minmax(14rem, 1fr);
  }
  .page-aside {
    position: sticky;
    top: 1rem;
    align-self: start;
  }
}
.toc {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--border);
}
.toc-title {
  font-weight: 700;
  margin: 0;
}
.toc ol {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

.mini-grid {
  border-collapse: collapse;
  margin: 1rem 0;
}
.mini-grid caption {
  caption-side: bottom;
  text-align: left;
  padding-top: 0.5rem;
  max-width: 20rem;
}
.mini-grid td {
  width: 2.4rem;
  height: 2.4rem;
  border: 2px solid var(--border);
  text-align: center;
  font-weight: 700;
  font-size: 1.2rem;
}
.mini-grid td.hit {
  background: var(--found);
  color: var(--on-found);
  text-decoration: underline;
  text-decoration-thickness: 3px;
}

/* The puzzle block: puzzle and buttons together, with only plain text after it. */
.puzzle-block {
  margin: 1rem 0 0;
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
}
@media (max-width: 40rem) {
  .puzzle-block {
    padding: 0.75rem 0;
    border-width: 2px 0;
    border-radius: 0;
  }
}
.puzzle-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
}
.field {
  min-width: 0;
  max-width: 100%;
}
.field label {
  display: block;
  font-weight: 700;
}
select {
  min-height: 44px;
  max-width: 100%;
  padding: 0.35rem 0.5rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
}
.puzzle-title {
  font-weight: 700;
  font-size: 1.1rem;
  margin: 1rem 0 0.75rem;
}
.print-head {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.4rem 1rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
}
.btn-primary {
  color: var(--on-primary);
  background: var(--primary);
  border-color: var(--primary);
}
.new-day {
  margin-bottom: 0.75rem;
}
.puzzle-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.5rem;
}
.message {
  min-height: 1.6em;
  font-weight: 700;
  margin: 0.75rem 0;
}

/* Word search */
.ws-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem 2rem;
}
@media (min-width: 56rem) {
  .ws-layout {
    grid-template-columns: auto minmax(12rem, 1fr);
    align-items: start;
  }
}
.board-wrap {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
}
.board {
  /* Cells are at least 24px and grow with the screen, up to about 50px. */
  --cell: max(1.35rem, min(2.75rem, calc((100vw - 2.5rem) / var(--n))));
  width: max-content;
  border: 2px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
}
.row {
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
}
.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cell);
  height: var(--cell);
  font-size: max(1rem, calc(var(--cell) * 0.55));
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.cell:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}
.cell.found {
  background: var(--found);
  color: var(--on-found);
}
.cell.revealed {
  box-shadow: inset 0 0 0 3px var(--accent);
}
.cell.start {
  background: var(--primary);
  color: var(--on-primary);
  border-radius: 50%;
}
.panel-title {
  font-weight: 700;
  margin: 0 0 0.5rem;
}
.word-list {
  /* Two columns on a phone; one when larger text would make long words overflow. */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5em), 1fr));
  gap: 0 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.word-list li {
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0.1rem 0;
}
.word-list li.found {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.answer-key {
  display: none;
}

/* Nonograms */
.ng-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1.5rem;
  margin: 0 0 0.75rem;
}
.ng-modes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.6rem;
}
.ng-tools-label {
  flex: 0 0 100%;
  font-weight: 700;
}
/* The chosen button is filled in and ticked, so colour is not the only sign. */
.ng-mode[aria-pressed='true'] {
  color: var(--on-primary);
  background: var(--primary);
  border-color: var(--primary);
}
.ng-mode[aria-pressed='true']::before {
  content: '\2713';
  margin-right: 0.4em;
}
.ng-board {
  /* Squares are at least 24px, even with the largest text, and grow with the screen up to about
     47px. --rcw is the width of the row clues, set by the page. */
  --cell: max(24px, min(2.6rem, calc((100vw - 2.5rem - var(--rcw)) / var(--n))));
  width: max-content;
  padding: 0.25rem 0;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
}
/* With Drag to paint ticked, a drag on the grid paints instead of scrolling. */
.ng-board.painting {
  touch-action: none;
}
.ng-row {
  display: flex;
}
.ng-head {
  align-items: flex-end;
}
.ng-corner {
  flex: none;
  width: var(--rcw);
}
.ng-clue {
  line-height: 1.15;
}
.ng-clue-col {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: var(--cell);
  padding-bottom: 0.25rem;
}
.ng-clue-row {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: flex-end;
  gap: 0.7ch;
  width: var(--rcw);
  padding-right: 0.7ch;
}
/* A matched clue is crossed out as well as dimmed. */
.ng-clue.done {
  color: var(--muted);
}
.ng-clue.done span {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.ng-cell {
  flex: none;
  border: 0 solid var(--border);
  border-right-width: 1px;
  border-bottom-width: 1px;
  background: var(--surface);
}
.ng-cell.edge-l {
  border-left-width: 2px;
}
.ng-cell.edge-t {
  border-top-width: 2px;
}
.ng-cell.edge-r,
.ng-cell.sep-r {
  border-right-width: 2px;
}
.ng-cell.edge-b,
.ng-cell.sep-b {
  border-bottom-width: 2px;
}
.ng-cell.filled {
  background: var(--text);
}
.ng-cell:focus-visible {
  box-shadow: inset 0 0 0 5px var(--surface);
}
.ng-example {
  border-collapse: collapse;
  margin: 1rem 0;
}
.ng-example caption {
  caption-side: bottom;
  text-align: left;
  padding-top: 0.5rem;
  max-width: 22rem;
}
.ng-example th {
  padding: 0.1rem 0.5rem;
}
.ng-example th[scope='row'] {
  text-align: right;
  white-space: nowrap;
}
.ng-example td {
  width: 2.4rem;
  height: 2.4rem;
  border: 2px solid var(--border);
}
.ng-example thead td {
  border: 0;
}
.ng-example td.fill {
  background: var(--text);
}

/* Footer */
.site-footer {
  margin-top: 4rem;
  border-top: 2px solid var(--border);
  background: var(--surface);
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 1rem 2rem;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
}
.footer-brand,
.footer-title {
  font-weight: 700;
  margin: 0;
}
.site-footer ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-footer li a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

/* Print: the puzzle on page one in large print; with answers, the key on page two.
   Always light colours, whatever the screen theme. */
@media print {
  @page {
    size: auto;
    margin: 0.5in;
  }
  /* Higher specificity than the dark-theme rules above. */
  :root:root:root {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --text: #000;
    --muted: #000;
    --accent: #000;
    --border: #000;
    --found: #fff;
    --on-found: #000;
    font-size: 12pt;
  }
  body {
    background: #fff;
    color: #000;
  }
  .site-header,
  .site-footer,
  .breadcrumbs,
  .page-hero,
  .puzzle-options,
  .puzzle-actions,
  .message,
  .new-day,
  .page-body,
  .skip,
  noscript,
  #ws-count,
  .ng-tools,
  #ng-count,
  .adsbygoogle,
  ins.adsbygoogle,
  .google-auto-placed,
  [id^='aswift'],
  [id^='google_ads'] {
    display: none !important;
  }
  .wrap {
    padding: 0;
  }
  .puzzle-block {
    border: 0;
    padding: 0;
    margin: 0;
    background: none;
  }
  .print-head {
    display: block;
    font-size: 14pt;
    margin: 0;
  }
  .puzzle-title,
  .print-title {
    font-size: 14pt;
    margin: 0 0 0.2in;
  }
  .ws-layout {
    display: block;
  }
  .board-wrap {
    overflow: visible;
  }
  .board {
    --cell: calc(6.5in / var(--n));
    border: 2px solid #000;
  }
  .cell {
    font-size: 20pt;
    background: none !important;
    color: #000 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
  .word-panel {
    margin-top: 0.25in;
  }
  .panel-title {
    font-size: 14pt;
  }
  .word-list {
    grid-template-columns: repeat(4, 1fr);
  }
  .word-list li {
    font-size: 16pt;
    text-decoration: none !important;
  }
  .word-list .tick {
    display: none;
  }
  .ng-board {
    --cell: calc(5.6in / var(--n));
    font-size: 14pt;
    padding: 0;
  }
  /* The printed puzzle is blank: none of the player's squares or crosses are printed. */
  .ng-cell,
  .ng-cell.filled {
    background: #fff !important;
    color: transparent !important;
    box-shadow: none !important;
  }
  .ng-clue.done {
    color: #000;
  }
  .ng-clue.done span {
    text-decoration: none;
  }
  .ng-key {
    display: grid;
    grid-template-columns: repeat(var(--n), calc(6in / var(--n)));
    width: max-content;
    border: 2px solid #000;
  }
  .ng-key span {
    height: calc(6in / var(--n));
    box-shadow: inset 0 0 0 1px #999;
  }
  .ng-key span.fill {
    background: #000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-answers .answer-key {
    display: block;
    break-before: page;
  }
  .key-grid {
    display: grid;
    grid-template-columns: repeat(var(--n), calc(6.5in / var(--n)));
    width: max-content;
    border: 2px solid #000;
  }
  .key-grid span {
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(6.5in / var(--n));
    font-size: 20pt;
    font-weight: 700;
    color: #888;
  }
  .key-grid span.hit {
    color: #000;
    background: #d4d4d4;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
