/* Psst — a note passed across a desk.
   Everything on the paper sits on a 32px ruled-line rhythm. */

:root {
  --desk: #1d2f5e;
  --desk-deep: #131f42;
  --desk-text: #b9c6e6;
  --paper: #fbfcfe;
  --rule: #cfddf3;
  --margin: #f08a9b;
  --graphite: #252a3a;
  --graphite-soft: #6b7388;
  --pen: #2443c4;
  --hit: #7fe0ee; /* highlighter: right letter, right spot */
  --near: #e8590c; /* orange pen: in the word, wrong spot */
  --blank: #b4c4e4; /* a slot not yet written in */

  --line: 32px;
  --shift: 8px; /* how far the rules are nudged up so text sits on them */
  --gutter: 56px;

  --hand: "Kalam", "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--desk);
  color: var(--graphite);
  font: 400 17px / var(--line) var(--sans);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 24px 12px 0;
}

h1,
h2,
p,
ul,
ol,
form {
  margin: 0;
  padding: 0;
}

ul,
ol {
  list-style: none;
}

a {
  color: var(--pen);
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 3px solid var(--near);
  outline-offset: 3px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── The sheet ─────────────────────────────────────────────────────────── */

.paper {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--line) * 2) 28px calc(var(--line) * 2) calc(var(--gutter) + 30px);
  border-radius: 3px;
  background:
    linear-gradient(
      90deg,
      transparent calc(var(--gutter) - 1px),
      var(--margin) calc(var(--gutter) - 1px),
      var(--margin) calc(var(--gutter) + 1px),
      transparent calc(var(--gutter) + 1px)
    ),
    repeating-linear-gradient(
        180deg,
        transparent 0 calc(var(--line) - 1px),
        var(--rule) calc(var(--line) - 1px) var(--line)
      )
      0 calc(var(--shift) * -1),
    var(--paper);
  box-shadow:
    0 1px 0 rgb(255 255 255 / 0.6) inset,
    0 28px 50px -18px rgb(5 10 30 / 0.7);
}

/* Punch holes */
.paper::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 14px;
  width: 22px;
  background:
    radial-gradient(circle, var(--desk) 0 9px, transparent 10px) center 96px / 22px 22px no-repeat,
    radial-gradient(circle, var(--desk) 0 9px, transparent 10px) center 50% / 22px 22px no-repeat,
    radial-gradient(circle, var(--desk) 0 9px, transparent 10px) center calc(100% - 96px) / 22px 22px
      no-repeat;
  pointer-events: none;
}

.desk-note {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 8px 28px;
  color: var(--desk-text);
  font-size: 14px;
  line-height: 22px;
  text-align: center;
}

.desk-note a {
  color: inherit;
}

/* ── Type ──────────────────────────────────────────────────────────────── */

.wordmark {
  display: inline-block;
  font: 700 32px / var(--line) var(--hand);
  color: var(--pen);
  text-decoration: none;
  transform: rotate(-2deg);
}

.title {
  font: 700 84px / calc(var(--line) * 3) var(--hand);
  color: var(--pen);
  letter-spacing: -0.01em;
  transform: rotate(-2deg) translateY(10px);
  transform-origin: left center;
}

.heading {
  padding-top: var(--line);
  font: 700 32px / var(--line) var(--hand);
  color: var(--pen);
  text-wrap: balance;
}

.subheading {
  margin-top: var(--line);
  font: 700 26px / var(--line) var(--hand);
  color: var(--pen);
}

.lead {
  max-width: 30em;
}

.quiet {
  color: var(--graphite-soft);
  font-size: 15px;
}

.hand {
  font: 400 24px / var(--line) var(--hand);
}

.gap {
  margin-top: var(--line);
}

/* ── Form ──────────────────────────────────────────────────────────────── */

.field {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  column-gap: 12px;
  align-items: start;
}

.field label,
.field .label {
  font: 700 22px / var(--line) var(--hand);
  color: var(--pen);
}

.field small {
  grid-column: 2;
  color: var(--graphite-soft);
  font-size: 14px;
  line-height: var(--line);
}

.input {
  width: 100%;
  height: var(--line);
  padding: 0 2px;
  border: 0;
  border-radius: 0;
  color: var(--graphite);
  font: 400 24px / var(--line) var(--hand);
  /* The underline is drawn exactly on top of the paper's rule. */
  background: linear-gradient(var(--graphite-soft), var(--graphite-soft)) 0
    calc(var(--line) - var(--shift) - 1px) / 100% 1px no-repeat;
}

.input::placeholder {
  color: #a9b2c7;
  opacity: 1;
}

.input:focus {
  outline: none;
  background-image: linear-gradient(var(--pen), var(--pen));
  background-size: 100% 2px;
}

.input--word {
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}

.input--word::placeholder {
  letter-spacing: 0.32em;
}

.input--link {
  font: 500 15px / var(--line) ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--pen);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--line);
}

.stepper output {
  min-width: 1.4em;
  text-align: center;
  font: 700 24px / var(--line) var(--hand);
}

.stepper button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--pen);
  border-radius: 50%;
  background: var(--paper);
  color: var(--pen);
  font: 700 18px / 1 var(--sans);
  cursor: pointer;
}

.stepper button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0 12px;
  margin-top: var(--line);
}

.btn {
  height: 48px;
  margin: 8px 0;
  padding: 0 22px;
  border: 2px solid var(--pen);
  border-radius: 10px 14px 11px 15px / 14px 10px 15px 11px;
  background: var(--paper);
  color: var(--pen);
  font: 700 21px / 44px var(--hand);
  text-decoration: none;
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 120ms ease;
}

a.btn {
  display: inline-block;
}

.btn--main {
  background: var(--pen);
  color: var(--paper);
  transform: rotate(-1deg);
}

.btn:hover {
  transform: translateY(-2px) rotate(-1deg);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* ── Messages ──────────────────────────────────────────────────────────── */

.msg {
  min-height: var(--line);
  color: var(--near);
  font: 700 21px / var(--line) var(--hand);
}

/* ── Board ─────────────────────────────────────────────────────────────── */

.board {
  --cell: 52px;
  --row: calc(var(--line) * 2);
  --size: 42px;
  --drop: 9px;
  container-type: inline-size;
  margin-top: var(--line);
}

.board--flush {
  margin-top: 0;
}

.board--mini {
  --cell: 26px;
  --row: var(--line);
  --size: 23px;
  --drop: 0px;
  margin-top: 0;
}

.row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, var(--cell)));
  column-gap: 6px;
  height: var(--row);
  /* Room for the wordmark above and the sticky keyboard below when scrolled into view. */
  scroll-margin: 72px 0 236px;
}

.board--mini .row {
  column-gap: 2px;
}

/* Guess numbers live in the margin, like numbered lines. */
.row__no {
  position: absolute;
  left: -26px;
  bottom: 2px;
  width: 18px;
  text-align: right;
  font: 400 17px / var(--line) var(--hand);
  color: var(--margin);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  height: var(--row);
}

.cell__letter {
  position: relative;
  z-index: 1;
  font: 700 min(var(--size), calc(100cqw / var(--n) * 0.72)) / 1 var(--hand);
  transform: translateY(var(--drop));
  text-transform: uppercase;
}

/* Blank to fill in */
.row--open .cell::after,
.row--next .cell::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: calc(var(--shift) - 2px);
  height: 3px;
  border-radius: 2px;
  background: var(--blank);
}

.row--open .cell::after {
  background: var(--pen);
}

.row--open .cell--caret::after {
  animation: blink 1.1s steps(2, start) infinite;
}

.row--shake {
  animation: shake 320ms ease;
}

/* Right spot: highlighter */
.cell[data-mark="h"]::before {
  content: "";
  position: absolute;
  inset: 22% 3% 6%;
  border-radius: 9px 4px 10px 5px / 5px 10px 4px 9px;
  background: var(--hit);
  transform: rotate(-2deg);
}

.board--mini .cell[data-mark="h"]::before {
  inset: 8% 2% 18%;
  border-radius: 5px 3px 6px 3px;
}

/* Wrong spot: circled in orange pen */
.cell__ring {
  position: absolute;
  inset: 14% -2% -2%;
  width: 104%;
  height: 88%;
  overflow: visible;
  fill: none;
  stroke: var(--near);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}

.board--mini .cell__ring {
  inset: 0 -4% 6%;
  width: 108%;
  height: 94%;
  stroke-width: 3.4;
}

/* Not in the word: struck out */
.cell[data-mark="m"] .cell__letter {
  color: #a3abbd;
}

.cell[data-mark="m"]::before {
  content: "";
  position: absolute;
  z-index: 2;
  left: 12%;
  right: 12%;
  top: calc(50% + var(--drop));
  height: 2.5px;
  border-radius: 2px;
  background: var(--graphite-soft);
  transform: rotate(-14deg);
}

.board--mini .cell[data-mark="m"]::before {
  height: 2px;
}

/* The newest guess gets marked letter by letter. */
.row--fresh .cell[data-mark="h"]::before {
  animation: swipe 260ms ease-out both;
  animation-delay: calc(var(--i) * 170ms);
}

.row--fresh .cell__ring {
  animation: draw 320ms ease-out both;
  animation-delay: calc(var(--i) * 170ms);
}

.row--fresh .cell[data-mark="m"]::before {
  animation: strike 200ms ease-out both;
  animation-delay: calc(var(--i) * 170ms);
}

.row--fresh .cell[data-mark="m"] .cell__letter {
  animation: fade 200ms ease-out both;
  animation-delay: calc(var(--i) * 170ms);
}

@keyframes swipe {
  from {
    clip-path: inset(0 100% 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes strike {
  from {
    clip-path: inset(-10px 100% -10px 0);
  }
  to {
    clip-path: inset(-10px 0 -10px 0);
  }
}

@keyframes fade {
  from {
    color: var(--graphite);
  }
}

@keyframes blink {
  to {
    opacity: 0.15;
  }
}

@keyframes shake {
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* ── Key to the marks ──────────────────────────────────────────────────── */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0 22px;
  margin-top: var(--line);
  color: var(--graphite-soft);
  font-size: 15px;
}

.legend--tight {
  margin-top: 0;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--line);
}

.legend .board {
  width: 26px;
  container-type: normal;
}

.legend .cell__letter {
  font-size: 23px;
}

/* ── Outcome ───────────────────────────────────────────────────────────── */

.reveal {
  font: 400 26px / var(--line) var(--hand);
  overflow-wrap: anywhere;
}

.reveal cite {
  color: var(--graphite-soft);
  font-style: normal;
  white-space: nowrap;
}

/* ── Lists of notes ────────────────────────────────────────────────────── */

.notes li a {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  color: inherit;
  text-decoration: none;
}

.notes li a:hover .notes__who {
  text-decoration: underline;
  text-decoration-color: var(--pen);
  text-underline-offset: 4px;
}

.notes__who {
  font: 700 23px / var(--line) var(--hand);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes__word {
  font: 700 21px / var(--line) var(--hand);
  letter-spacing: 0.14em;
  color: var(--pen);
}

.notes__status {
  grid-column: 1 / -1;
  color: var(--graphite-soft);
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.readers > li {
  margin-top: var(--line);
}

.readers__name {
  font: 700 23px / var(--line) var(--hand);
}

.readers__name span {
  font: 400 15px / var(--line) var(--sans);
  color: var(--graphite-soft);
  margin-left: 8px;
}

/* ── Keyboard, on the desk ─────────────────────────────────────────────── */

.keys {
  position: sticky;
  bottom: 0;
  z-index: 5;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 0 max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--desk) 14px);
  touch-action: manipulation;
}

.keys[hidden] {
  display: none;
}

.keys .msg {
  width: fit-content;
  max-width: 100%;
  min-height: 0;
  margin: 0 auto 8px;
  padding: 2px 16px 0;
  border-radius: 18px;
  background: #c2410c;
  color: var(--paper);
  font-size: 19px;
  text-align: center;
  box-shadow: 0 6px 16px rgb(5 10 30 / 0.45);
}

.keys .msg:empty {
  display: none;
}

.keys__row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 6px;
}

.key {
  flex: 1 1 0;
  max-width: 48px;
  min-width: 0;
  height: 50px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  color: var(--graphite);
  box-shadow: 0 3px 0 var(--desk-deep);
  font: 700 21px / 50px var(--hand);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.key:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--desk-deep);
}

.key--wide {
  flex: 1.9 1 0;
  max-width: 92px;
  font-size: 18px;
  color: var(--pen);
}

.key[data-mark="h"] {
  background: var(--hit);
}

.key[data-mark="n"] {
  box-shadow:
    inset 0 0 0 3px var(--near),
    0 3px 0 var(--desk-deep);
}

.key[data-mark="m"] {
  background: #42558a;
  color: rgb(251 252 254 / 0.6);
  text-decoration: line-through;
  box-shadow: 0 3px 0 var(--desk-deep);
}

/* ── Small screens ─────────────────────────────────────────────────────── */

@media (max-width: 560px) {
  :root {
    --gutter: 18px;
  }

  #app {
    padding: 10px 8px 0;
  }

  .paper {
    padding: var(--line) 16px calc(var(--line) * 2) calc(var(--gutter) + 14px);
  }

  .paper::before,
  .row__no {
    display: none;
  }

  .title {
    font-size: 68px;
  }

  .heading {
    font-size: 28px;
  }

  .field {
    grid-template-columns: 1fr;
  }

  .field--inline {
    grid-template-columns: auto 1fr;
  }

  .actions .btn {
    flex: 1 1 auto;
    padding: 0 14px;
  }

  .input--link {
    font-size: 13px;
  }

  .field small {
    grid-column: 1;
  }

  .row {
    column-gap: 4px;
  }

  .key {
    height: 52px;
    line-height: 52px;
  }

  .keys__row {
    gap: 4px;
  }
}

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