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

.turn-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  color: #1c1c1c;
  margin: 24px 0 0;
}
.turn-line[hidden] {
  display: none;
}
.turn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  background: var(--x-color);
}
.turn-badge.o {
  background: var(--o-color);
}
.turn-badge.bounce {
  animation: turn-bounce 0.55s cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes turn-bounce {
  0%   { transform: translateY(0) scale(1); }
  30%  { transform: translateY(-10px) scale(1.2); }
  50%  { transform: translateY(0) scale(1); }
  70%  { transform: translateY(-5px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

:root {
  --x-color: #2d6a8c;
  --o-color: #dd6688;
}

.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;
}
.cell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
}
.cell:hover::after {
  background: rgba(0, 0, 0, 0.04);
}
.cell.owned:hover::after {
  background: transparent;
}
body.game-over .cell {
  cursor: default;
}
body.game-over .cell:hover::after {
  background: transparent;
}
.cell.owned {
  padding: 10px;
  cursor: default;
}
.cell.owned img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cell.owner-x { background: var(--x-color); }
.cell.owner-o { background: var(--o-color); }
.cell.winning {
  box-shadow: inset 0 0 0 3px #f4c842;
}

.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;
  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;
}
