:root {
  --bg: #efede6;
  --paper: #f7f4ee;
  --ink: #0a0a0a;
  --blue: #26ccff;
  --blue-light: rgba(38, 204, 255, 0.28);
  --muted: rgba(10, 10, 10, 0.52);
  --grid: rgba(10, 10, 10, 0.09);
  --sans: "Archivo", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 4px 4px 0 var(--ink);
  --intro-stagger: 20ms;
  --intro-board: 50ms;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  letter-spacing: -0.035em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

.noise,
.grid-bg,
.dither {
  pointer-events: none;
  position: fixed;
  inset: 0;
}

.grid-bg {
  z-index: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: -1px -1px;
}

.dither {
  z-index: 1;
  opacity: 0.18;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8'><rect width='1' height='1' fill='%23000'/><rect x='4' y='2' width='1' height='1' fill='%23000'/><rect x='2' y='4' width='1' height='1' fill='%23000'/><rect x='6' y='6' width='1' height='1' fill='%23000'/></svg>");
  background-size: 8px 8px;
  mix-blend-mode: multiply;
}

.noise {
  z-index: 2;
  opacity: 0.07;
  filter: url(#grain);
}

.app {
  position: relative;
  z-index: 3;
  width: min(680px, calc(100% - 24px));
  max-width: 680px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 0 calc(32px + env(safe-area-inset-bottom));
}

main {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.mono {
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: -0.04em;
  text-transform: uppercase;
}

.topbar,
.stats,
.actions,
.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar {
  margin-bottom: 10px;
  font-size: clamp(11px, 2.9vw, 14px);
  opacity: 0;
  animation: fade-in 0.18s steps(2) forwards;
}

.topbar > div:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mark {
  display: block;
  width: 13px;
  height: 13px;
  background: var(--blue);
  flex-shrink: 0;
}

.brand {
  margin: 4px 0 14px;
  width: 100%;
  opacity: 0;
  animation: fade-in 0.18s steps(2) forwards;
  animation-delay: 20ms;
}

.brand h1 {
  font-size: 48px;
  font-weight: 800;
  font-stretch: 82%;
  font-variation-settings: "wdth" 82;
  line-height: 0.9;
  letter-spacing: -0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  width: 100%;
}

.brand h1 em {
  font-style: normal;
  color: var(--blue);
}

.stats {
  border: 2px solid var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  width: 100%;
  animation: panel-enter 0.22s steps(3) both;
  animation-delay: 35ms;
}

.stat {
  flex: 1 1 0;
  padding: 10px 12px;
  min-width: 0;
  opacity: 0;
  animation: fade-in 0.12s steps(2) forwards;
  animation-delay: calc(35ms + 80ms);
}

.stat:nth-child(2) {
  animation-delay: calc(35ms + 90ms);
}

.stat:nth-child(3) {
  animation-delay: calc(35ms + 100ms);
}

.stat + .stat {
  border-left: 2px solid var(--ink);
}

.stat b {
  display: block;
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 800;
  letter-spacing: -0.07em;
  line-height: 1;
  white-space: nowrap;
}

.stat span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: -0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.board-shell {
  position: relative;
  width: 100%;
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  margin: 0 0 8px;
  min-height: 0;
  animation: shell-enter 0.22s steps(3) both;
  animation-delay: var(--intro-board);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  width: 100%;
  user-select: none;
}

.cell {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  aspect-ratio: 1;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  padding: 0;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.board.is-intro .cell {
  animation: cell-enter 0.22s steps(3) both;
  animation-delay: calc(var(--intro-board) + var(--stagger, 0) * var(--intro-stagger));
}

@media (max-width: 759px) {
  .stats {
    margin-bottom: 10px;
  }

  .stat {
    padding: 6px 8px;
  }

  .stat b {
    font-size: clamp(16px, 4.2vw, 20px);
  }

  .stat span {
    font-size: 9px;
  }

  .rules {
    display: none;
  }

  .footer {
    margin-top: 4px;
  }

  .cell {
    aspect-ratio: auto;
    min-height: 112px;
  }

  .prompt {
    -webkit-line-clamp: 9;
    line-clamp: 9;
  }

  .board.is-intro .cell {
    animation: none;
  }

  .board.is-intro .cell:not(.filled) .cell-body {
    animation: none;
  }

  .board.is-intro .cell.filled .photo,
  .board.is-intro .cell.filled::after {
    animation: none;
  }
}

@keyframes fade-in {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes panel-enter {
  0%,
  30% {
    background-color: var(--blue);
    color: var(--paper);
  }

  100% {
    background-color: var(--paper);
    color: var(--ink);
  }
}

@keyframes shell-enter {
  0%,
  30% {
    background-color: var(--blue);
  }

  100% {
    background-color: var(--paper);
  }
}

@keyframes cell-enter {
  0%,
  55% {
    background-color: var(--blue);
  }

  100% {
    background-color: var(--paper);
  }
}

.board.is-intro .cell:not(.filled) .cell-body {
  opacity: 0;
  animation: cell-body-reveal 0.01s steps(1) both;
  animation-delay: calc(var(--intro-board) + var(--stagger, 0) * var(--intro-stagger) + 220ms);
}

@keyframes cell-body-reveal {
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .topbar,
  .brand,
  .stats,
  .stat,
  .board-shell,
  .footer {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .stats,
  .board-shell {
    background: var(--paper);
    color: var(--ink);
  }

  .cell {
    animation: none;
    background: var(--paper);
    color: var(--ink);
  }

  .board.is-intro .cell:not(.filled) .cell-body,
  .board.is-intro .cell.filled .photo,
  .board.is-intro .cell.filled::after {
    animation: none;
    opacity: 1;
  }
}

.cell:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: -3px;
}

.cell:not(.filled):hover,
.cell:not(.filled):active {
  background: var(--blue-light);
}

.cell:not(.filled):hover .prompt,
.cell:not(.filled):active .prompt {
  color: var(--ink);
}

.cell-body {
  position: relative;
  z-index: 1;
  height: 100%;
  padding: 8px 7px 7px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cell-body-split {
  display: grid;
  grid-template-rows: 1fr 1px 1fr;
  gap: 0;
  padding: 0;
}

.split-divider {
  background: rgba(10, 10, 10, 0.16);
  width: 100%;
  margin: 0;
}

.cell-body-split .prompt-top {
  padding: 7px 7px 5px;
  align-self: start;
}

.cell-body-split .prompt-bottom {
  padding: 5px 7px 7px;
  align-self: end;
}

.prompt {
  color: var(--ink);
  font-size: clamp(10px, 2.65vw, 14px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  line-clamp: 6;
  overflow: hidden;
}

.prompt-top,
.prompt-bottom {
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.cell.filled .cell-body {
  display: none;
}

.photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.cell.filled .photo {
  display: block;
}

.board.is-intro .cell.filled .photo {
  opacity: 0;
  animation: cell-photo-enter 0.01s steps(1) both;
  animation-delay: calc(var(--intro-board) + var(--stagger, 0) * var(--intro-stagger) + 220ms);
}

.board.is-intro .cell.filled::after {
  opacity: 0;
  animation: cell-photo-enter 0.01s steps(1) both;
  animation-delay: calc(var(--intro-board) + var(--stagger, 0) * var(--intro-stagger) + 220ms);
}

@keyframes cell-photo-enter {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

.cell.filled::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(38, 204, 255, 0);
  z-index: 2;
  pointer-events: none;
  transition: background 0.12s steps(2);
}

.cell.filled:hover::before,
.cell.filled:active::before {
  background: rgba(38, 204, 255, 0.2);
}

.cell.filled::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: var(--blue);
  z-index: 3;
}

.rules {
  margin: 16px 0 14px;
  font-family: var(--mono);
  font-size: clamp(11px, 3vw, 12px);
  font-weight: 500;
  letter-spacing: -0.045em;
  text-transform: uppercase;
  line-height: 1.45;
  max-width: 100%;
}

.rules strong {
  font-weight: 700;
}

.actions {
  gap: 8px;
  flex-shrink: 0;
}

.footer {
  flex-shrink: 0;
  opacity: 0;
  animation: fade-in 0.18s steps(2) forwards;
  animation-delay: 320ms;
}

.btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.05em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--ink);
}

.btn.primary {
  background: var(--blue);
  color: var(--paper);
  flex: 1;
}

.btn.ghost {
  background: transparent;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.04em;
  text-transform: uppercase;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.42);
  z-index: 30;
  display: none;
}

.overlay.open {
  display: block;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  background: var(--paper);
  border-top: 3px solid var(--ink);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(110%);
  transition: transform 0.18s steps(4);
}

.sheet.open {
  transform: translateY(0);
}

.sheet h2 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.07em;
  text-transform: uppercase;
  line-height: 0.9;
  margin-bottom: 6px;
}

.sheet p {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: -0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.sheet-actions .btn {
  flex: 1;
}

.busy {
  cursor: wait;
}

.busy .cell {
  pointer-events: none;
}

@media (min-width: 760px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .app {
    width: min(680px, calc(100% - 80px));
    max-width: 680px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: calc(10px + env(safe-area-inset-top)) 0 calc(10px + env(safe-area-inset-bottom));
    overflow: hidden;
  }

  main {
    flex: 1;
    min-height: 0;
    gap: 6px;
  }

  .topbar {
    margin-bottom: 0;
    font-size: 14px;
    flex-shrink: 0;
  }

  .mark {
    width: 14px;
    height: 14px;
  }

  .brand {
    margin: 0;
    flex-shrink: 0;
  }

  .stats {
    margin-bottom: 0;
    flex-shrink: 0;
    box-shadow: 3px 3px 0 var(--ink);
  }

  .stat {
    padding: 8px 12px;
  }

  .stat b {
    font-size: 24px;
  }

  .stat span {
    font-size: 11px;
  }

  .board-shell {
    flex: 1 1 0;
    min-height: 0;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    container-type: size;
    overflow: hidden;
  }

  .board {
    width: min(100cqw, 100cqh);
    aspect-ratio: 1;
    height: auto;
    max-width: 100%;
    max-height: 100%;
  }

  .cell-body {
    padding: 8px 6px 6px;
    gap: 5px;
  }

  .rules {
    margin: 0;
    font-size: 11px;
    line-height: 1.3;
  }

  .rules br {
    display: none;
  }

  .footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .btn {
    padding: 10px 14px;
    font-size: 13px;
    box-shadow: 3px 3px 0 var(--ink);
  }
}

@media (min-width: 1200px) {
  .app {
    width: min(720px, calc(100% - 120px));
    max-width: 720px;
  }

  .topbar {
    font-size: 15px;
  }

  .stat b {
    font-size: 28px;
  }

  .stat span {
    font-size: 12px;
  }

  .rules {
    font-size: 12px;
  }

  .btn {
    font-size: 14px;
    padding: 11px 16px;
  }
}

@media (min-width: 760px) and (max-height: 820px) {
  .app {
    padding-top: calc(6px + env(safe-area-inset-top));
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }

  main {
    gap: 4px;
  }

  .stat b {
    font-size: 22px;
  }

  .stat {
    padding: 6px 10px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .rules {
    font-size: 10px;
  }
}

@media (max-width: 380px) {
  .app {
    width: calc(100% - 16px);
  }

  .stat {
    padding: 5px 5px;
  }

  .stat b {
    font-size: 15px;
  }

  .stat span {
    font-size: 8px;
  }

  .topbar {
    font-size: 10px;
  }

  .actions {
    flex-direction: column;
  }

  .actions .btn {
    width: 100%;
  }

  .btn.primary {
    flex: none;
  }
}

@media (max-height: 740px) {
  .stats {
    margin-bottom: 10px;
  }
}
