:root {
  --board: #26232d;
  --board-edge: #15131a;
  --H: min(calc(100vw - 32px), 520px);
  /* Square board, sized from the height first so it fits on a phone. */
  --B: min(calc(100vw - 32px), 520px, calc(100dvh - 250px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  --spring: cubic-bezier(0.3, 1.45, 0.5, 1);
}
body {
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

.app {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 16px);
}

/* Header */
.top { width: var(--H); display: flex; align-items: center; gap: 8px; }
.brand { display: flex; flex-direction: column; margin-right: auto; line-height: 1.05; min-width: 0; }
.brand > a { font-weight: 800; font-size: 22px; letter-spacing: -0.03em; color: inherit; text-decoration: none; white-space: nowrap; }
.brand span a { font-size: 13px; font-weight: 600; color: var(--muted); }

.scores { margin-top: auto; width: var(--B); display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
.score label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.score output { display: block; font-size: 40px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.score.best { text-align: right; }
.score.best output { font-size: 26px; color: var(--muted); }
.mid { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0 8px 2px; text-align: center; }
.mode { font-size: 13px; font-weight: 700; color: var(--muted); }
.clock { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Board */
.board-wrap { position: relative; width: var(--B); flex: none; touch-action: none; }
.board {
  position: relative; padding: 6px;
  background: var(--board); border-radius: 18px;
  box-shadow: 0 6px 0 var(--board-edge), 0 18px 30px rgba(31, 29, 36, 0.18);
}
.tiles { position: relative; width: 100%; aspect-ratio: 1; }
.tile {
  position: absolute; left: 0; top: 0; cursor: grab;
  transition: transform 0.42s var(--spring);
  will-change: transform;
}
.tile .face {
  position: absolute; inset: 2px; border-radius: 6px;
  background-color: #34303d; background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.tile.dragging { transition: none; z-index: 10; cursor: grabbing; }
.tile.dragging .face { box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45), 0 0 0 3px #fff; }
.tile.target .face { box-shadow: 0 0 0 3px var(--c2); }
.tile.lift { z-index: 5; }
.tiles.done .tile .face { inset: 0; border-radius: 0; box-shadow: none; transition: inset 0.3s ease, border-radius 0.3s ease; }

.peek-img, .solved-img {
  position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px);
  border-radius: 6px; object-fit: cover; pointer-events: none;
}
.peek-img { opacity: 0.92; animation: fadeIn 0.15s ease-out; }
.solved-img { display: block; overflow: hidden; }
.solved-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.solved-img.show { animation: solvedIn 0.7s var(--spring) both; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes solvedIn {
  0% { transform: scale(0.94); filter: brightness(1.4); }
  100% { transform: scale(1); filter: brightness(1); }
}

.under { width: var(--B); display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: auto; }
.peek { color: var(--muted); border-color: var(--muted); touch-action: none; }
.peek:active, .peek.on { background: var(--muted); color: var(--paper); }
.help { margin: 0; text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); }

/* Cheer */
.cheer { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; pointer-events: none; }
.cheer-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 82%; }
.cheer.show .cheer-inner { animation: cheer 1600ms ease-out both; }
@keyframes cheer {
  0% { transform: scale(0.5) rotate(-6deg); opacity: 0; }
  12% { transform: scale(1.06) rotate(1deg); opacity: 1; }
  20% { transform: scale(1) rotate(0); }
  84% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.96) translateY(-14px); opacity: 0; }
}
.cheer-title {
  font-weight: 800; font-size: clamp(34px, 10vw, 54px); letter-spacing: -0.03em; line-height: 1;
  color: #fff; text-align: center;
  text-shadow: 0 3px 0 var(--ink), 0 0 18px rgba(0, 0, 0, 0.45);
}

#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }

/* Dialogs */
.over-photo { margin: 14px auto 0; background: #fff; padding: 8px 8px 10px; border-radius: 12px; transform: rotate(-2deg); max-width: 70%; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2); }
.over-photo img { display: block; width: 100%; aspect-ratio: 1; max-height: 34dvh; object-fit: cover; border-radius: 6px; }
.over-photo figcaption { margin-top: 8px; font-weight: 700; }
.over-photo figcaption:empty { display: none; }
#over-stats { margin: 12px 0 0; }
.over-scores { display: grid; grid-template-columns: 1fr 1fr; margin: 12px 0 18px; }
.over-scores label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.over-scores b { font-size: 36px; font-weight: 800; }

.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.size {
  font: inherit; color: var(--ink); background: var(--paper-2); cursor: pointer;
  border: 2px solid var(--paper-2); border-radius: 12px; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.size b { font-size: 16px; }
.size span { font-size: 13px; color: var(--muted); font-weight: 600; }
.size[aria-checked="true"] { border-color: var(--ink); background: #fff; }
.daily-box { margin-top: 16px; padding-top: 14px; border-top: 2px solid var(--paper-2); }
.daily-box .hint { margin-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  .tile { transition-duration: 0.01ms; }
  .cheer.show .cheer-inner, .solved-img.show { animation-duration: 0.01ms; }
}
