:root {
  color-scheme: light;
  --bg: #ece7dc;
  --paper: #fbf8f1;
  --ink: #1b1814;
  --muted: #6b6358;
  --line: #cbc2b3;
  --answer: #2455a4;
  --answer-tint: #e3eaf6;
  --board-font: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono",
    "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  /* The board is as wide as the screen allows, but no taller than the
     window minus the header and footer, so it fits without scrolling. */
  --sheet-width: min(100%, max(20rem, 100vh - 11rem));
}

@supports (height: 100svh) {
  :root {
    --sheet-width: min(100%, max(20rem, 100svh - 11rem));
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  padding: max(1rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: var(--sheet-width);
  margin: 0 auto;
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.controls,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.levels {
  display: inline-flex;
  margin: 0;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
}

.levels label {
  position: relative;
  cursor: pointer;
}

.levels input {
  position: absolute;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.levels span {
  display: block;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 550;
  line-height: 1.3;
}

.levels label:hover span {
  color: var(--ink);
}

.levels input:checked + span {
  background: var(--ink);
  color: var(--paper);
}

.levels input:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

button {
  appearance: none;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 550;
  line-height: 1.3;
  cursor: pointer;
}

button:hover {
  border-color: var(--ink);
}

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

button.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

button[aria-pressed="true"] {
  border-color: var(--answer);
  background: var(--answer-tint);
  color: var(--answer);
}

/* Keeps the button from shrinking while it reads "Copied". */
#copy {
  min-width: 7.5em;
}

.sheet {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.board-frame {
  container-type: inline-size;
}

/* Each cell draws only its right and bottom edges. With collapsed borders,
   zoomed-out or fractional-DPR screens round thin and thick lines to the
   same width, and the tie goes to the thin line, which hides the boxes. */
.board {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: var(--paper);
  font-family: var(--board-font);
  font-size: 3.7cqi;
  font-variant-numeric: slashed-zero;
  line-height: 1;
  text-align: center;
}

.board td {
  height: 6.25cqi;
  padding: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.board td:first-child {
  border-left: 2px solid var(--ink);
}

.board td:nth-child(4n) {
  border-right: 2px solid var(--ink);
}

.board tr:first-child td {
  border-top: 2px solid var(--ink);
}

.board tr:nth-child(4n) td {
  border-bottom: 2px solid var(--ink);
}

.board .clue {
  font-weight: 700;
}

.board .answer {
  color: var(--answer);
  font-weight: 400;
}

/* The status line's width changes with every board, so it gets its own row
   rather than pushing the buttons onto a new line now and then. */
.sheet-foot {
  display: grid;
  justify-items: start;
  gap: 0.5rem;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.print-link {
  display: none;
}

.noscript {
  margin: 0;
  max-width: 40ch;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media print {
  @page {
    margin: 1.5cm;
  }

  :root {
    --bg: #fff;
    --paper: #fff;
    --ink: #000;
    --muted: #444;
    --line: #999;
    --answer: #666;
  }

  body {
    padding: 0;
  }

  .app {
    width: 100%;
    max-width: 18cm;
  }

  .controls,
  .actions {
    display: none;
  }

  .print-link {
    display: block;
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    overflow-wrap: anywhere;
  }
}
