:root {
  color-scheme: light;
  --paper: #f6f3ea;
  --ink: #111111;
  --amber: #e09b2d;
  --rule: rgb(17 17 17 / 24%);
  --gutter: clamp(1rem, 5vw, 3rem);
  font-family: system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  line-height: 1.5;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
}

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

.site-header,
main {
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.site-header {
  padding-top: clamp(1.5rem, 6vw, 4rem);
}

.site-header h1 {
  width: fit-content;
  margin: 0;
  font-size: clamp(2.75rem, 8vw, 5.5rem);
  line-height: 0.98;
  letter-spacing: -0.08em;
}

.intro {
  max-width: 53ch;
  margin: 1rem 0 clamp(1.75rem, 4vw, 3rem);
  font-size: clamp(1rem, 2.3vw, 1.2rem);
}

.book-count {
  margin: 0;
  padding-block: 0.75rem;
  border-top: 2px solid var(--ink);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

#book-message {
  margin: 0 0 1rem;
}

.puzzle-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.puzzle-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--rule);
}

.puzzle-link {
  display: block;
  margin: 0;
  text-decoration: none;
}

.puzzle-link::after {
  position: absolute;
  inset: 0;
  content: "";
}

.puzzle-link:focus-visible {
  outline: none;
}

.puzzle-link:focus-visible::after {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.puzzle-link:hover .card-title,
.puzzle-link:focus-visible .card-title {
  text-decoration: underline;
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.16em;
}

.preview {
  display: grid;
  min-height: 9.75rem;
  padding: 1rem;
  place-items: center;
  border-bottom: 1px solid var(--rule);
}

.card-summary {
  padding: 0.8rem 0.9rem;
}

.card-title {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.25;
}

.card-title,
.byline,
.play-header {
  overflow-wrap: anywhere;
}

.card-best,
.card-solved {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
}

.card-solved {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-weight: 650;
}

.tick {
  font-size: 1.1em;
}

.byline {
  margin: 0;
  font-size: 0.92rem;
}

.card-author {
  padding: 0 0.9rem 0.8rem;
}

.card-author a {
  position: relative;
}

.book-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.4rem;
  margin-top: clamp(1.5rem, 4vw, 2.5rem);
  padding-block: 0.85rem 1.75rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
}

.play {
  margin-top: clamp(1rem, 3vw, 2rem);
  padding: clamp(1rem, 3vw, 1.75rem) 0 2rem;
  border-top: 2px solid var(--ink);
  text-align: center;
}

.play-header h2 {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 0.3rem;
  font-size: clamp(1.6rem, 5vw, 2.65rem);
  letter-spacing: -0.04em;
  line-height: 1.12;
}

.puzzle-note {
  max-width: 58ch;
  margin: 0.55rem auto 0;
  white-space: pre-line;
}

.counters {
  margin: 0.7rem 0 0.85rem;
  font-size: 0.94rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  aspect-ratio: var(--columns) / var(--rows);
  background: var(--paper);
}

.board--preview {
  width: min(100%, calc(var(--columns) * 1.25rem), calc(7.5rem * var(--columns) / var(--rows)));
}

.board--play {
  width: min(100%, 34rem, calc(var(--columns) * 3.5rem));
  width: min(100%, 34rem, calc(var(--columns) * 3.5rem), calc(58svh * var(--columns) / var(--rows)));
  margin-inline: auto;
  touch-action: none;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 0.5px rgb(17 17 17 / 13%);
}

.tile--wall {
  background: var(--ink);
  box-shadow: none;
}

.tile--mark::before {
  position: absolute;
  width: 48%;
  aspect-ratio: 1;
  border: clamp(1px, 0.3vw, 3px) solid var(--amber);
  border-radius: 50%;
  content: "";
}

.board--preview .tile--mark::before {
  border-width: 1px;
}

.piece {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.piece::before {
  display: block;
  aspect-ratio: 1;
  content: "";
}

.piece--keeper::before {
  width: 36%;
  border-radius: 50%;
  background: var(--ink);
}

.piece--crate::before,
.piece--covered::before {
  width: 73%;
  border: clamp(1px, 0.25vw, 2px) solid var(--ink);
  background: var(--amber);
}

.board--preview .piece::before {
  border-width: 1px;
}

.piece--covered::before {
  border-radius: 24%;
  background: var(--ink);
}

.piece--covered::after {
  position: absolute;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--amber);
  content: "";
}

.slide-u { --from-y: 100%; }
.slide-d { --from-y: -100%; }
.slide-l { --from-x: 100%; }
.slide-r { --from-x: -100%; }

:is(.slide-u, .slide-d, .slide-l, .slide-r) {
  z-index: 1;
  animation: move-piece 80ms ease-out both;
}

@keyframes move-piece {
  from { transform: translate(var(--from-x, 0), var(--from-y, 0)); }
  to { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  :is(.slide-u, .slide-d, .slide-l, .slide-r) {
    animation: none;
  }
}

.play-actions,
.direction-pad {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem auto 0;
}

button {
  min-width: 44px;
  min-height: 44px;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:not([aria-disabled="true"]):hover {
  box-shadow: inset 0 0 0 1px var(--ink);
}

button[aria-disabled="true"] {
  border-color: var(--rule);
  cursor: default;
}

.next-button {
  background: var(--amber);
}

.direction-pad {
  display: none;
}

.direction-pad button {
  padding: 0;
  font-size: 1.25rem;
  touch-action: manipulation;
}

@media (max-width: 44rem) {
  .direction-pad {
    display: flex;
  }
}

.result {
  margin: 0.95rem auto 0;
  font-weight: 650;
}

.result p {
  margin: 0.15rem 0;
}

.result p + p {
  font-size: 0.9rem;
  font-weight: 400;
}

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