/* Plain CSS, no frameworks. Colours live in the variables below; the dark
   theme only swaps their values. */

:root {
  color-scheme: light dark;

  --paper: #f5f0e6;
  --sheet: #fffdf8;
  --ink: #24211c;
  --muted: #736b5e;
  --line: #ddd3c1;
  --hover: #efe6d4;
  --in-play: rgba(76, 175, 80, 0.16); /* numbers not crossed out */
  --in-play-hover: rgba(76, 175, 80, 0.3);
  --strike: #b3261e;
  --button: #24211c;
  --button-ink: #fffdf8;
  --good: #2f6b3a;
  --decrypt: #2f6b3a;     /* "Decrypt message": green */
  --decrypt-ink: #ffffff;
  --bad: #b3261e;
  --warn: #8a5300;
  /* The clue dock's number buttons: white, and dark once pinned, in both themes */
  --pin: #ffffff;
  --pin-hover: #efe6d4;
  --pin-ink: #24211c;
  --pinned: #24211c;
  --pinned-ink: #ffffff;

  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171613;
    --sheet: #201e1a;
    --ink: #ebe5d9;
    --muted: #a0978a;
    --line: #3a362f;
    --hover: #2d2a24;
    --in-play: rgba(132, 208, 148, 0.14);
    --in-play-hover: rgba(132, 208, 148, 0.26);
    --strike: #ff7b6f;
    --button: #ebe5d9;
    --button-ink: #171613;
    --good: #84d094;
    --decrypt: #84d094;
    --decrypt-ink: #171613;
    --bad: #ff7b6f;
    --warn: #f2b44c;
  }
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.5;
}

.page-header,
.layout,
.action-bar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* ---- Header ---- */

.page-header {
  padding-top: 32px;
}

h1 {
  margin: 0 0 12px;
  text-align: center;
  font-size: 1rem; /* the size of the text around it */
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.5;
}

/* The story so far, in a slightly larger italic */
.story {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-style: italic;
}

.intro {
  margin: 0;
  color: var(--muted);
}

.noscript {
  color: var(--bad);
}

/* ---- The book: a card under the puzzle, and a smaller one after a correct answer ---- */

/* The whole card is one link, cover included */
.book-card {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 62ch;
  padding: 10px 14px 10px 10px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
}

.book-card[hidden] {
  display: none;
}

@media (hover: hover) {
  .book-card:hover {
    border-color: var(--muted);
  }
}

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

.book-cover {
  flex: none;
  width: 44px; /* phones; wide screens set their own size */
  height: auto;
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.book-card-action {
  font-weight: bold;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* "The Puzzle Book" over the card: PC screens only, where it sits beside the
   other sections' headings */
.book-heading {
  display: none;
}

@media (min-width: 860px) and (min-height: 600px) {
  .book-heading {
    display: block;
  }
}

.book-card-compact {
  flex-basis: 100%;
  max-width: none;
  padding: 6px 10px 6px 6px;
  gap: 10px;
  font-size: 0.95rem;
}

.book-card-compact .book-cover {
  width: 28px;
}

/* "Want a bigger challenge?": PC screens only; phones go straight to the point.
   Phones have no book card under the puzzle, only the one in the bottom bar
   after a correct answer, which then lists what the book has. */
.book-question {
  display: none;
}

@media not all and (min-width: 860px) and (min-height: 600px) {
  .book {
    display: none;
  }

  /* ...and before the puzzle of the day (at the start, in the warmup and after
     Reset) the same small card sits at the very bottom, under the buttons. It
     goes while the puzzle of the day is on, and comes back once it's solved. */
  body:not(.clues-shown) #book-suggestion {
    display: flex;
    padding: 6px 10px 6px 6px;
    font-size: 1rem;
    line-height: 1.3;
  }

  body:not(.clues-shown) #book-suggestion .book-cover {
    width: 72px;
  }

  /* In the warmup it shrinks back to a slim card, leaving room for the clue */
  body.warmup:not(.clues-shown) #book-suggestion {
    padding: 4px 8px 4px 4px;
    font-size: 0.8rem;
  }

  body.warmup:not(.clues-shown) #book-suggestion .book-cover {
    width: 22px;
  }
}

@media (min-width: 860px) and (min-height: 600px) {
  .book-question {
    display: inline;
  }

  .book-facts {
    display: none;
  }

  .book-card-compact .book-cover {
    width: 36px;
  }
}

h2 {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---- Layout: clues above the register on phones, beside it on wide screens ---- */

.layout {
  display: grid;
  /* minmax(0, ...) lets the register scroll sideways inside its sheet on very
     narrow phones, instead of stretching the whole page */
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
  padding-top: 28px;
  padding-bottom: 28px;
}

/* "Wide" means wide AND tall enough for the clue column to stay in view;
   phones held sideways keep the phone layout. Same breakpoint further down. */
@media (min-width: 860px) and (min-height: 600px) {
  .layout {
    grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
    align-items: start;
  }

  .clues {
    position: sticky;
    top: 16px;
  }

  .book {
    grid-column: 1 / -1; /* under both columns, until there's room for a third */
  }

  .book .book-cover {
    width: 96px;
  }
}

/* Very wide screens: the book gets its own column right of the register and,
   like the clues, stays in view while scrolling. */
@media (min-width: 1200px) and (min-height: 600px) {
  .page-header,
  .layout,
  .action-bar-inner {
    max-width: 1280px;
  }

  .layout {
    /* the clue column as wide as the book's, so the register sits in the middle */
    grid-template-columns: 260px minmax(0, 1fr) 260px;
  }

  .book {
    grid-column: auto;
    position: sticky;
    top: 16px;
  }

  .book .book-card {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }

  .book .book-cover {
    width: 100%;
  }
}

/* ---- Clues ---- */

.clue-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.clue-list[hidden] {
  display: none;
}

/* Until "Puzzle of the Day" is clicked, a box with the buttons stands in for
   the clues. In the warmup the clues show under it. Each button has a line
   above it saying what it does: "Warmup Puzzle" first, then "Puzzle of the
   Day". The buttons share a column as wide as the wider one, so they're the
   same width; the lines span the whole box. */
.clues-cover {
  display: grid;
  grid-template-columns: max-content 1fr;
  padding: 14px 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.clues-cover[hidden] {
  display: none;
}

.clues-cover p {
  grid-column: 1 / -1;
  margin: 0 0 8px;
  color: var(--muted);
}

/* "Download today's puzzle as a PDF", under the cover's buttons */
.pdf-offer {
  margin-top: 8px;
}

.pdf-offer a {
  color: var(--ink);
}

/* The header's copy is for phones, which don't show the clue cover */
@media (min-width: 860px) and (min-height: 600px) {
  .pdf-offer-phone {
    display: none;
  }
}

.clues-cover .button {
  grid-column: 1;
  justify-self: stretch;
}

/* Room between the warmup and the puzzle of the day */
.clues-cover .warmup-button {
  margin-bottom: 16px;
}

/* The cover's text: one set before the puzzle starts, another during the
   warmup. The line about the warmup only shows for a puzzle that has one. */
.cover-text-warmup,
.warmup .cover-text,
body:not(.has-warmup) .warmup-offer {
  display: none;
}

.warmup .cover-text-warmup {
  display: block;
}

.warmup .clues-cover {
  margin-bottom: 12px;
}

/* ---- The warmup ---- */

/* "Warmup Puzzle": only for a puzzle that has one, before the puzzle of the day
   starts, and not during the warmup itself. On phones it's in the action bar,
   on wide screens in the clue column. */
.warmup-button {
  display: none;
}

.has-warmup:not(.clues-shown):not(.warmup) .warmup-button {
  display: inline-block;
}

@media (min-width: 860px) and (min-height: 600px) {
  body.has-warmup:not(.clues-shown):not(.warmup) .warmup-bar-button {
    display: none;
  }
}

/* Phones: Reset has nothing to undo before the puzzle of the day starts, so
   it makes room for "Warmup Puzzle" and "Puzzle of the Day" until then */
@media not all and (min-width: 860px) and (min-height: 600px) {
  body:not(.clues-shown) #reset-button {
    display: none;
  }

  /* ...and "Warmup Puzzle" and "Puzzle of the Day" share the bar's full
     width (in the warmup, "Puzzle of the Day" has it to itself). On the
     narrowest phones a label wraps rather than overflowing. */
  body:not(.clues-shown) .actions {
    flex-basis: 100%;
    flex-wrap: nowrap;
    margin-left: 0;
  }

  body:not(.clues-shown) .actions .button {
    flex: 1 1 0;
    min-width: 0;
    padding-left: 6px;
    padding-right: 6px;
    white-space: normal;
    text-wrap: balance;
  }
}

/* The warmup's numbers take the register's place; the register and the
   message come back with the puzzle of the day */
.warmup-sheet,
.warmup .daily-sheet,
.warmup .message,
.warmup .clues-submit-button,
.warmup .dock-submit-button {
  display: none;
}

.warmup .warmup-sheet {
  display: block;
}

.warmup .register-digits {
  visibility: hidden; /* the warmup's numbers aren't from these decimals */
}

.warmup-intro,
.warmup-done {
  margin: 4px 8px 10px;
  color: var(--muted);
}

.warmup-done {
  margin: 10px 8px 4px;
  color: var(--good);
  font-weight: bold;
}

.warmup-done[hidden] {
  display: none;
}

.warmup-clue {
  padding: 0 8px 0 4px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.9rem;
  font-weight: normal;
  text-align: left;
  white-space: nowrap;
}

.warmup-skip {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.9rem;
  text-align: left !important;
}

.warmup-table tbody tr > * {
  padding-top: 3px;
  padding-bottom: 3px;
}

/* A clue about the key's row, column or neighbours: a small page, 3 rows of 3 or more,
   laid out like the register */
.warmup-page-note {
  margin: 2px 0 4px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.85rem;
  text-align: left;
}

.warmup-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* The warmup's numbers aren't blurred like the register's (the blur rule
   further down leaves them out), and can be clicked */
body.warmup .warmup-table .warmup-number {
  cursor: pointer;
  user-select: auto;
}

/* Only the picked clue's numbers show. Every clue's row sits in the same
   spot, the others hidden, so the box is as tall as the biggest example (a
   small page, if the warmup has one) whichever clue is picked. The clues go
   in order: a clue's row shows when it's picked, and is locked once the next
   one is. */
.warmup-table tbody {
  display: grid;
  align-content: start;
}

.warmup-table tbody tr {
  grid-area: 1 / 1;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
}

.warmup-table tbody .warmup-page {
  grid-column: 1 / -1;
}

.warmup-table tbody .warmup-skip {
  grid-column: 2 / -1;
}

/* A second pair of numbers goes under the first */
.warmup-table tbody .warmup-second-pair:nth-of-type(3) {
  grid-column: 2;
}

body.warmup .warmup-table tbody tr:not([data-step="current"]) {
  visibility: hidden;
}

/* No rule every five rows, as the register has: one row shows at a time */
.register-table.warmup-table tbody tr:nth-child(5n) > * {
  border-bottom: 0;
}

/* Phones never show this column: "Puzzle of the Day" is in the action bar at the
   bottom of the screen, and the clues are then read in the clue dock there.
   Wide screens show the clues here, beside the register. */
.clues {
  display: none;
}

@media (min-width: 860px) and (min-height: 600px) {
  .clues {
    display: block;
  }
}

/* Each clue card is a button that pins the clue */
.clue {
  display: block;
  width: 100%;
  padding: 14px 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

@media (hover: hover) {
  .clue:hover {
    border-color: var(--muted);
  }
}

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

/* aria-pressed="true" means the clue is pinned */
.clue[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.clue-title,
.clue-quote,
.clue-rule {
  display: block;
}

.clue-title {
  margin-bottom: 4px;
  font-weight: bold;
}

.clue-quote {
  margin-bottom: 8px;
  color: var(--muted);
  font-style: italic;
}

/* Only the pinned clue's quote and rule can be read; the others' are blurred,
   keeping their cards the same size. The blur is see-through text with a soft
   shadow, not filter: blur: iPhone Safari gives every filtered element its own
   layer, and with many of them on the page it can run out of memory and keep
   reloading the page. */
.clue:not([aria-pressed="true"]) .clue-quote,
.clue:not([aria-pressed="true"]) .clue-rule {
  color: transparent;
  text-shadow: 0 0 8px var(--ink);
  user-select: none;
}

.clue:not([aria-pressed="true"]) .clue-quote {
  text-shadow: 0 0 8px var(--muted);
}

/* ---- Register ---- */

/* "Pi Register" on the left, the page's range of digits on the right */
/* Three cells: "Pi Register" left, "Day N" in the middle over the register's
   centre (the outer cells are equal widths), the digits right */
.register-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: baseline;
  gap: 0 12px;
  margin-bottom: 12px;
}

.register-header h2 {
  margin: 0;
}

/* "Day N", between "Pi Register" and the digits: small capitals too, in ink */
.register-day {
  margin: 0 -0.12em 0 0; /* drop the letter spacing after the last letter, so it centres exactly */
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Small capitals, like the section headings */
.register-digits {
  margin: 0;
  text-align: right;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sheet {
  padding: 8px;
  overflow-x: auto;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.register-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
}

.register-table td {
  padding: 1px;
  text-align: center;
}

/* A faint rule every five rows helps the eye keep its place. */
.register-table tbody tr:nth-child(5n):not(:last-child) > * {
  border-bottom: 1px solid var(--line);
}

.number {
  width: 100%;
  padding: 6px 2px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: clamp(0.75rem, 3.6vw, 1.05rem);
  letter-spacing: 0.02em;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom when tapping quickly */
}

/* Numbers still in play get a pale green background */
.number[aria-pressed="false"] {
  background: var(--in-play);
}

/* Hover only where there's a real pointer (on phones it would stick after a
   tap), and only while numbers can be crossed out */
@media (hover: hover) {
  .clues-shown:not(.solved) .number:hover {
    background: var(--hover);
  }

  .clues-shown:not(.solved) .number[aria-pressed="false"]:hover {
    background: var(--in-play-hover);
  }

  .warmup [data-step="current"] .warmup-number:hover {
    background: var(--hover);
  }

  .warmup [data-step="current"] .warmup-number[aria-pressed="false"]:hover {
    background: var(--in-play-hover);
  }
}

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

/* Once solved, the board is locked until Reset */
.solved .number {
  cursor: default;
}

/* Numbers can't be crossed out, or even read, until the clues are shown:
   they're blurred, with see-through text and a soft shadow (not filter: blur,
   which costs iPhone Safari a layer per number; see the clues' blur above) */
body:not(.clues-shown) .number:not(.warmup-number) {
  cursor: not-allowed;
  color: transparent;
  text-shadow: 0 0 8px var(--ink);
  user-select: none;
}

/* aria-pressed="true" means the number is crossed out: a line across its
   digits, rising from bottom left to top right. (A gradient "to bottom right"
   has its middle on the other diagonal, bottom left to top right.) */
.number[aria-pressed="true"] {
  color: var(--muted);
}

.number-digits {
  position: relative;
  display: inline-block;
}

.number[aria-pressed="true"] .number-digits::after {
  content: "";
  position: absolute;
  inset: 0 -2px;
  background: linear-gradient(to bottom right,
    transparent calc(50% - 1px),
    var(--strike) calc(50% - 1px),
    var(--strike) calc(50% + 1px),
    transparent calc(50% + 1px));
  pointer-events: none;
}

/* ---- The professor's message, under the register ---- */

.message {
  margin-top: 20px;
  scroll-margin-top: 16px; /* a little room above it when scrolled into view */
}

.register {
  scroll-margin-top: 16px;
}

/* Phones: the warmup scrolls the page to the register, which its few rows
   can't fill: at least a screen's height leaves room to scroll that far */
@media not all and (min-width: 860px) and (min-height: 600px) {
  body.warmup .register {
    min-height: 100vh;
  }
}

/* Solved: the register is hidden, so the congratulations and the decrypted
   message take its place */
.solved .sheet {
  display: none;
}

.solved .message {
  margin-top: 8px;
}

/* Wide screens: the register column stretches to the height of the clues,
   and the congratulations and message sit in the middle of it */
@media (min-width: 860px) and (min-height: 600px) {
  .solved .register {
    display: flex;
    flex-direction: column;
    align-self: stretch;
  }

  .solved .message {
    margin-top: auto;
    margin-bottom: auto;
    padding-bottom: 32px; /* sit a little above the true middle, which reads as centred */
  }
}

.message-result {
  margin: 0 0 16px;
  color: var(--good);
  font-size: 1.1rem;
  font-weight: bold;
}

.message-result:empty {
  display: none;
}

.message[hidden] {
  display: none;
}

.message-text {
  margin: 0;
  padding: 14px 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  white-space: pre-line; /* the message's line breaks show */
  overflow-wrap: anywhere;
}

/* Decrypted with the right key: it reads like a note */
.message[data-state="decrypted"] .message-text {
  border-color: var(--good);
  font-family: var(--serif);
  font-size: 1.1rem;
  letter-spacing: normal;
}

/* "Come back tomorrow", under the decrypted message */
.come-back {
  margin: 8px 0 0;
  color: var(--good);
  font-weight: bold;
}

.come-back[hidden] {
  display: none;
}

.message[data-state="failed"] .message-text {
  border-color: var(--bad);
  color: var(--muted);
}

/* ---- Action bar: stays at the bottom of the screen while scrolling ---- */

.action-bar {
  position: sticky;
  bottom: 0;
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.action-bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.remaining {
  flex: 1 1 auto;
  margin: 0;
}

/* The stopwatch, after the numbers-left count */
.stopwatch {
  margin-left: 12px;
  font-variant-numeric: tabular-nums; /* the time doesn't jiggle as it ticks */
  white-space: nowrap;
}

.stopwatch[hidden] {
  display: none;
}

/* The score, after the stopwatch. When a cross-out (or the answer) scores, a
   +2 or −1 shows beside it for a moment, without moving anything. */
.score {
  position: relative;
  margin-left: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.score[hidden] {
  display: none;
}

.score-change {
  position: absolute;
  left: 100%;
  margin-left: 6px;
  font-weight: bold;
}

.score-change[data-kind="good"] {
  color: var(--good);
}

.score-change[data-kind="bad"] {
  color: var(--warn);
}

/* The narrowest phones have no room beside the score: it shows just above it */
@media (max-width: 359px) {
  .score-change {
    right: 0;
    bottom: calc(100% - 4px);
    left: auto;
    margin-left: 0;
  }
}

.actions {
  display: flex;
  flex-wrap: wrap; /* on the narrowest phones a button moves to a second line */
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto; /* stays on the right, also when it wraps below the count */
}

/* Phones: the buttons get a row of their own, under the numbers-left count,
   stopwatch and score, so Reset never squeezes in beside them. They share
   its full width: Reset alone, or Reset and "Share my result" once solved. */
@media not all and (min-width: 860px) and (min-height: 600px) {
  .actions {
    flex-basis: 100%;
  }

  .actions .button {
    flex: 1 1 0;
  }
}

.button {
  padding: 10px 18px;
  border: 1px solid var(--button);
  border-radius: 6px;
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}

/* Phones: slimmer buttons, so "Puzzle of the Day", Reset and Submit fit on one line */
@media (max-width: 479px) {
  .actions {
    gap: 6px;
  }

  .button {
    padding: 10px 12px;
  }
}

@media (max-width: 379px) {
  .button {
    padding: 10px 9px;
    font-size: 0.95rem;
  }
}

.button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

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

.button-primary {
  background: var(--button);
  color: var(--button-ink);
  font-weight: bold;
}

/* "Decrypt message": green. On wide screens it sits in the clue column, under the
   clues; on phones in the clue dock at the bottom. */
.button-decrypt {
  background: var(--decrypt);
  border-color: var(--decrypt);
  color: var(--decrypt-ink);
  font-weight: bold;
}

.clues-submit-button {
  display: none;
  width: 100%;
  margin-top: 16px;
}

/* Phones: across the bottom of the clue dock */
.dock-submit-button {
  display: block;
  width: calc(100% - 6px); /* the dock has less padding on the right */
  margin-top: 6px;
}

@media (min-width: 860px) and (min-height: 600px) {
  .clues-shown .clues-submit-button {
    display: block; /* once the puzzle of the day starts, disabled until one number is left */
  }
}

/* "Puzzle of the Day" in the action bar: phones only, and only while the clues are hidden */
.clues-shown .show-clues-bar-button {
  display: none;
}

@media (min-width: 860px) and (min-height: 600px) {
  .show-clues-bar-button {
    display: none;
  }
}

/* "Share my result" takes the place of "Decrypt message" once the puzzle is solved */
.share-button,
.solved #submit-button,
.solved .clues-submit-button {
  display: none;
}

.solved .share-button {
  display: inline-block;
}

.button-secondary {
  background: transparent;
  color: var(--ink);
}

@media (hover: hover) {
  .button-secondary:not(:disabled):hover {
    background: var(--hover);
  }
}

/* Shown when a crossed-out number actually fits the pinned clue */
.warning {
  flex-basis: 100%;
  margin: 0;
  color: var(--warn);
}

.warning:empty {
  display: none;
}

/* Phones: while the puzzle (or the warmup) is in play, the warning keeps its
   place even with nothing to say, so the bar doesn't jump as warnings come and
   go. Two lines fit the longest warning. */
@media not all and (min-width: 860px) and (min-height: 600px) {
  .clues-shown:not(.solved) .warning,
  .warmup .warning {
    display: block;
    min-height: 3em;
  }
}

.result {
  flex-basis: 100%;
  margin: 0;
}

.result:empty {
  display: none;
}

.result[data-kind="correct"] {
  color: var(--good);
  font-weight: bold;
}

.result[data-kind="incorrect"],
.result[data-kind="error"] {
  color: var(--bad);
}

/* The clue dock sits at the top of the action bar on phones, so it stays in
   view while scrolling the register: a numbered button per clue, and the
   pinned clue's rule under them. */
.clue-dock {
  flex-basis: 100%;
  padding: 6px 6px 6px 12px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
}

/* In the dark theme the dock is as bright as the "Puzzle of the Day" button, with
   dark text, so the clues stand out at the bottom of the screen */
@media (prefers-color-scheme: dark) {
  .clue-dock {
    --ink: #24211c;
    --muted: #5e574c;
    --line: #cfc6b5;
    --hover: #ddd3c1;
    background: var(--button);
    border-color: var(--button);
    color: var(--ink);
  }
}

/* Hidden until the clues are shown, and on wide screens, where the clues stay
   beside the register */
body:not(.clues-shown):not(.warmup) .clue-dock {
  display: none;
}

/* Solved: nothing left to check, so no clue dock and no warnings */
.solved .clue-dock,
.solved .warning {
  display: none;
}

@media (min-width: 860px) and (min-height: 600px) {
  .clue-dock {
    display: none;
  }
}

.clue-dock-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.clue-dock-label {
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 359px) {
  .clue-dock-label {
    display: none; /* room for five numbers and × on one line */
  }
}

.quick-pins {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* aria-pressed="true" marks the pinned clue's number */
.quick-pin {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--pin);
  color: var(--pin-ink);
  font: inherit;
  font-family: var(--mono); /* level digits, unlike the serif's old-style ones */
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
}

.quick-pin[aria-pressed="true"] {
  background: var(--pinned);
  border-color: var(--ink); /* dark in the light theme, light in the dark one */
  color: var(--pinned-ink);
}

@media (hover: hover) {
  .quick-pin:not([aria-pressed="true"]):hover {
    background: var(--pin-hover);
  }
}

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

/* Every clue's text sits in the same spot, with only the pinned one showing:
   the box is as tall as the longest clue, so it keeps its size when switching */
.pinned-clue {
  display: grid;
  margin: 6px 0 2px;
  font-size: 0.95rem;
  line-height: 1.4;
}

.pinned-clue[hidden] {
  display: none;
}

.pinned-clue-text {
  grid-area: 1 / 1;
  margin: 0;
}

.pinned-clue-text:not([data-shown="true"]) {
  visibility: hidden;
}

.pinned-clue-title {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.unpin-button {
  flex: none;
  margin-left: auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

@media (hover: hover) {
  .unpin-button:hover {
    background: var(--hover);
    color: var(--ink);
  }
}

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

/* ---- PC screens: no scrolling needed ---- */

/* PC screens: everything from the title to the professor's message fits above
   the bottom bar on a 1080p screen without scrolling. Tighter spacing, and
   register rows that shrink with the window height. Last in the file, so
   it wins over the rules above. */
@media (min-width: 860px) and (min-height: 600px) {
  .page-header {
    padding-top: 16px;
  }

  h1 {
    margin-bottom: 4px;
  }

  .story {
    margin-bottom: 4px;
  }

  .layout {
    padding-top: 16px;
    padding-bottom: 16px;
  }

  h2,
  .register-header {
    margin-bottom: 8px;
  }

  .sheet {
    padding: 4px 8px;
  }

  /* About 858px of the window is title, headings, message, bottom bar and
     the rows' text; what's left pads the 20 rows, 1px to 6px above and below */
  .number {
    padding: clamp(1px, calc((100vh - 858px) / 40), 6px) 2px;
    line-height: 1.25;
  }

  .message {
    margin-top: 12px;
  }

  .message h2 {
    margin-bottom: 6px;
  }

  .message-text {
    padding: 8px 14px;
  }
}
