body {
  --grid-cell: min(140px, calc((100vw - 4px) / 3.5));
  padding: var(--page-top) 2px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.below-grid {
  width: calc(3.5 * var(--grid-cell));
  margin: 16px 0 0 calc(var(--grid-cell) / -4);
  text-align: right;
}
.grid {
  border-collapse: collapse;
  table-layout: fixed;
  margin-left: calc(var(--grid-cell) / -4);
}
.grid th, .grid td {
  width: var(--grid-cell);
  height: var(--grid-cell);
  box-sizing: border-box;
  padding: 8px;
  text-align: center;
  vertical-align: middle;
}
.grid td {
  border: 1px solid #ddd;
}
.grid th {
  font-weight: 500;
  font-size: 14px;
  color: #1c1c1c;
}
.grid thead th {
  height: calc(var(--grid-cell) / 2);
}
.grid .corner,
.grid tbody th {
  width: calc(var(--grid-cell) / 2);
}
.grid tbody th {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 12px;
}
.cell {
  position: relative;
  cursor: pointer;
}
.cell:focus {
  outline: none;
}
/* Firefox drops shared right/bottom cell borders if hover paints directly on the cell background under border-collapse, so the tint lives on ::after instead. */
.cell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
}
.cell:hover::after {
  background: rgba(0, 0, 0, 0.04);
}
.cell.filled:hover::after {
  background: transparent;
}
body.grid-locked .cell {
  cursor: default;
}
body.grid-locked .cell:hover::after {
  background: transparent;
}
.cell.filled {
  padding: 10px;
  cursor: zoom-in;
}
body.grid-locked .cell.filled {
  cursor: zoom-in;
}
.cell.filled:hover {
  background: transparent;
}
.cell.filled img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cell.revealed img {
  outline: 2px solid #c5302d;
  outline-offset: -2px;
  background: rgba(197, 48, 45, 0.2);
  animation: revealed-bounce 0.55s ease-in-out 3;
}
@keyframes revealed-bounce {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(-8px); }
  100% { transform: translateY(0); }
}
.cell.shake::before {
  content: '';
  position: absolute;
  inset: 10px;
  background: rgba(197, 48, 45, 0.20);
  box-shadow: inset 0 0 0 2px #c5302d;
  animation: cell-shake 0.4s ease-in-out;
  pointer-events: none;
}
@keyframes cell-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.picker[hidden] {
  display: none;
}
.picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
}
.picker-sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 480px;
  max-width: calc(100vw - 32px);
  z-index: 101;
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.22);
}
.picker-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.picker-cats {
  flex: 1;
  font-weight: 500;
  font-size: 14px;
  color: #1c1c1c;
}
.picker-close {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  color: var(--link-color);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.picker-close:hover {
  background: #f0f0f0;
}
.picker-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* iOS zooms the viewport on focus when this is < 16px. */
  border: 1px solid #999;
  border-radius: 6px;
  margin-bottom: 8px;
}
.picker-input:focus {
  outline: 2px solid var(--link-color);
  outline-offset: -2px;
}
.picker-suggestions {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.picker-suggestions li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  cursor: pointer;
  font-size: 15px;
  border-radius: 4px;
}
.picker-suggestions li.selected,
.picker-suggestions li:hover {
  background: rgba(102, 0, 51, 0.16);
}
.picker-suggestions span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.picker-open {
  overflow: hidden;
}

.archive-grid {
  width: 100%;
  max-width: 720px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 4px;
}
.archive-tile {
  aspect-ratio: 1;
  border: 1px solid #ddd;
  background: #fff;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  justify-items: center;
  text-decoration: none;
  color: #1c1c1c;
}
.archive-tile:hover {
  background: #f0f0f0;
}
.archive-tile-num {
  font-size: 20px;
  font-weight: 500;
  line-height: 1;
  color: var(--link-color);
  align-self: end;
}
.archive-tile-date {
  font-size: 11px;
  color: #888;
  line-height: 1;
  margin-top: 4px;
}
.archive-tile-score {
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  align-self: start;
  margin-top: 4px;
}
