/* Fourfold tokens: dark mode only changes these values. Card colours follow the Okabe–Ito palette. */
:root {
  --g-fourfold: #2f8f83;
  --ff-0: #d55e00;
  --ff-1: #0072b2;
  --ff-2: #009e73;
  --ff-3: #a8509a;
  --ff-card: #ffffff;
  --ff-card-line: #dcdcd8;
  --ff-selected: #121212;
  --ff-guide: var(--hint-context);
  --ff-target: var(--hint-target);
  --ff-chip: #f1f1ee;
}
:root[data-theme='dark'] {
  --g-fourfold: #4fb8aa;
  --ff-0: #ff8f4d;
  --ff-1: #5cb3ec;
  --ff-2: #3fd0a4;
  --ff-3: #e08ad2;
  --ff-card: #1e1e1e;
  --ff-card-line: #333333;
  --ff-selected: #f2f2f2;
  --ff-chip: #2a2a2a;
}

.fourfold-shell {
  --game-accent: var(--g-sets); /* Manyfold: one game colour for both screens. */
}
.fourfold-shell .shell-stage {
  padding: var(--space-2) var(--space-4) 0;
}
.fourfold-shell .shell-board-area {
  width: 100%;
}
/* Width: the phone's width, or as wide as the rows allow in the height left after the bars, tray and status. */
.ff-board-wrap {
  --gap: 8px;
  --ratio: 1.25;
  display: grid;
  width: min(
    calc(150px * var(--cols)),
    calc(100vw - 32px),
    calc(
      (100dvh - 300px - (var(--rows) - 1) * var(--gap)) / var(--rows) * var(--ratio) * var(--cols) + (var(--cols) - 1) *
        var(--gap)
    )
  );
  /* A long tray of found quads scrolls instead of widening the cards. */
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  margin: 0 auto;
}
.ff-board {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap);
}
.ff-card {
  position: relative;
  display: grid;
  aspect-ratio: var(--ratio);
  place-items: center;
  padding: 4%;
  border: 1.5px solid var(--ff-card-line);
  border-radius: 12px;
  background: var(--ff-card);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.06);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 140ms ease-out,
    border-color 140ms ease-out,
    box-shadow 140ms ease-out;
}
.ff-card:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 2px;
}
.ff-card.selected {
  border-color: var(--ff-selected);
  box-shadow: 0 0 0 2px var(--ff-selected);
  transform: translateY(-3px);
}
.ff-card.guide {
  border-color: var(--ff-guide);
  box-shadow: 0 0 0 3px var(--ff-guide);
}
.ff-card.target {
  border-color: var(--ff-target);
  box-shadow: 0 0 0 3px var(--ff-target);
}
.ff-card.selected.guide {
  box-shadow:
    0 0 0 2px var(--ff-selected),
    0 0 0 5px var(--ff-guide);
}
.ff-card.found-flash {
  animation: ff-found 600ms ease-out;
}
@keyframes ff-found {
  30% {
    border-color: var(--ff-guide);
    box-shadow: 0 0 0 4px var(--ff-guide);
    transform: scale(1.04);
  }
}
.ff-card.shake {
  animation: ff-shake 320ms ease-out;
}
@keyframes ff-shake {
  25% {
    transform: translateX(-4px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}
.ff-board.dealing .ff-card {
  animation: ff-deal 320ms ease-out both;
  animation-delay: calc(var(--i) * 22ms);
}
@keyframes ff-deal {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
}
/* The art keeps its own aspect ratio; Safari cannot size an SVG from a percentage height inside a button. */
.ff-art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 100 / 80;
  overflow: visible;
}
.ff-color-0 {
  color: var(--ff-0);
}
.ff-color-1 {
  color: var(--ff-1);
}
.ff-color-2 {
  color: var(--ff-2);
}
.ff-color-3 {
  color: var(--ff-3);
}
.ff-used {
  position: absolute;
  top: 4px;
  right: 5px;
  display: grid;
  min-width: 16px;
  height: 16px;
  place-items: center;
  border-radius: 8px;
  background: var(--mark-bg);
  color: var(--mark-ink);
  font-size: 10px;
  font-weight: 700;
}
/* Tray of found quads: four mini cards per quad, scrolling sideways. */
.ff-tray {
  display: flex;
  min-width: 0;
  min-height: 40px;
  align-items: center;
  gap: var(--space-3);
}
.ff-tray-count {
  flex: none;
  color: var(--text-muted);
  font-size: 13px;
}
.ff-tray-count strong {
  color: var(--text);
  font-size: 16px;
}
.ff-found-list {
  display: flex;
  min-width: 0;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.ff-found-empty {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.ff-found {
  display: flex;
  flex: none;
  gap: 2px;
  padding: 3px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}
.ff-found.answer {
  outline: 1.5px dashed var(--text-muted);
  outline-offset: -1.5px;
  background: transparent;
}
.ff-mini {
  display: grid;
  width: 30px;
  height: 24px;
  place-items: center;
  padding: 1px;
  border-radius: 4px;
  background: var(--ff-card);
}
.ff-status {
  display: flex;
  min-height: 36px;
  margin: 0;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}
.ff-status .ff-next {
  min-height: 36px;
  padding: 0 18px;
}
/* Assist row: the selected values per attribute, and the fourth value once three cards are chosen. */
.ff-assist {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.ff-assist-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--ff-chip);
  color: var(--text);
  font-size: 13px;
}
.ff-assist-chip small {
  color: var(--text-muted);
  font-size: 11px;
}
.ff-assist-chip b {
  color: var(--ff-target);
}
/* Hint: the derived fourth card, one short line per attribute. */
.ff-derive {
  margin: 6px 0 0;
  padding-left: 1.1em;
  font-size: 13px;
  line-height: 1.45;
}
/* Picture rules: real cards in a row or a small table, with an optional tag above naming the pattern shown. */
.fourfold-shell .ff-demo {
  display: grid;
  width: 100%;
  justify-items: center;
  gap: 6px;
}
.ff-demo-tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--ff-chip);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}
.ff-demo-cards {
  --ratio: 1.25;
  position: relative;
  display: grid;
  width: 100%;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 6px;
}
.ff-demo-cards .ff-card {
  border-radius: 9px;
  cursor: default;
}
.ff-demo-cards .ff-demo-slot {
  border: 2px dashed var(--ff-target);
  background: transparent;
  color: var(--ff-target);
  font-size: 24px;
  font-weight: 800;
}
@media (prefers-reduced-motion: reduce) {
  .ff-card,
  .ff-board.dealing .ff-card {
    animation: none;
    transition: none;
  }
}
