/*
 * Connections. The shared shell (common.css) on a dusk-purple cloth with the puzzle's hardest
 * colour as the accent; this adds the word grid, the found groups and everyone else's grids.
 */

.cn {
  --bg-top: #2b2533;
  --bg-mid: #1c1822;
  --bg-edge: #110e15;
  --panel: rgba(14, 11, 18, 0.94);
  --accent: #ba81c5;
  --accent-hover: #c897d1;
  --accent-ink: #1a1020;

  /* The NYT's group colours, easiest first. */
  --level-0: #f9df6d;
  --level-1: #a0c35a;
  --level-2: #b0c4ef;
  --level-3: #ba81c5;

  --word: #efefe6;
  --word-ink: #121212;
  --word-selected: #5a594e;

  /* Sized off both axes: the activity frame is short on desktop and narrow on a phone. */
  --cell: clamp(46px, min(21vw, 11vh), 84px);
}

/* ------------------------------------------------------------------ stage */

.cn-stage {
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  padding: 10px 14px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 230px);
  gap: 16px;
  align-items: start;
}

/* Nobody else to show: the board gets the whole width. */
.cn-stage:has(.cn-side[hidden]) { grid-template-columns: minmax(0, 1fr); }

.cn-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.cn-groups,
.cn-grid {
  width: min(100%, 560px);
}

/* ------------------------------------------------------------------ groups */

.cn-groups {
  display: grid;
  gap: 8px;
}

.cn-groups:empty { display: none; }

.cn-group {
  min-height: var(--cell);
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--word-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  animation: cn-found 0.35s ease-out;
}

.cn-group.level-0 { background: var(--level-0); }
.cn-group.level-1 { background: var(--level-1); }
.cn-group.level-2 { background: var(--level-2); }
.cn-group.level-3 { background: var(--level-3); }

/* Shown when it's over, but not found. */
.cn-group.missed { opacity: 0.6; }

.cn-group-title {
  font-weight: 800;
  text-transform: uppercase;
  font-size: 14px;
}

.cn-group-words {
  text-transform: uppercase;
  font-size: 13px;
}

/* Unlimited: which NYT puzzle the group came from. */
.cn-group-source {
  font-size: 11px;
  opacity: 0.7;
}

@keyframes cn-found {
  from { transform: scale(0.94); }
  60% { transform: scale(1.02); }
  to { transform: none; }
}

/* ------------------------------------------------------------------ words */

.cn-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.cn-word {
  appearance: none;
  height: var(--cell);
  min-width: 0;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: var(--word);
  color: var(--word-ink);
  font: inherit;
  font-weight: 800;
  font-size: clamp(11px, 3.2vw, 16px);
  text-transform: uppercase;
  overflow-wrap: anywhere;
  line-height: 1.1;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.cn-word.long { font-size: clamp(9px, 2.6vw, 13px); }
.cn-word:active:not(:disabled) { transform: scale(0.96); }

.cn-word.selected {
  background: var(--word-selected);
  color: #fff;
}

.cn-word:disabled { cursor: default; }

/* The betting step: the words are shown, but can't be picked until a bet is chosen. */
.cn-grid.locked .cn-word {
  background: #6b6a63;
  color: rgba(255, 255, 255, 0.55);
}

/* A wrong guess. */
.cn-word.shake { animation: cn-shake 0.4s ease-in-out; }

@keyframes cn-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.cn-mistakes {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-dim);
}

.cn-mistakes:empty { display: none; }

.cn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--word-selected);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.cn-dot.spent {
  opacity: 0;
  transform: scale(0.4);
}

.cn-bet {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--ink-dim);
  max-width: 380px;
}

.cn-bet strong { color: var(--gold); }

/* How it went, once it's over. */
.cn-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: cn-rise 0.3s ease-out;
}

.cn-result-head { font-weight: 700; font-size: 15px; }
.cn-result.solved .cn-result-head { color: var(--win); }
.cn-result.failed .cn-result-head { color: var(--lose); }

/* Movement only, no fade: a card that can never be stuck invisible if its animation is paused. */
@keyframes cn-rise {
  from { transform: translateY(6px) scale(0.97); }
  to { transform: none; }
}

/* The share grid, as emoji squares. Emoji draw taller than their font size, so the rows need
 * more room than text does or they touch. */
.cn-squares {
  white-space: pre;
  line-height: 1.5;
  font-size: 16px;
  letter-spacing: 2px;
}

/* ------------------------------------------------------------------ side */

.cn-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

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

.cn-player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 8px;
  padding: 7px 9px;
}

.cn-player-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cn-player-state {
  grid-column: 2 / -1;
  font-size: 12px;
  color: var(--ink-dim);
}

.cn-player .cn-squares {
  grid-column: 2 / -1;
  font-size: 11px;
}

/* ------------------------------------------------------------------ small frames */

@media (max-width: 640px) {
  .cn-stage { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 460px) {
  .cn-stage { padding: 8px 10px 10px; }
  .cn-grid, .cn-groups { gap: 6px; }
  .cn-group-title { font-size: 12px; }
  .cn-group-words { font-size: 11px; }
}
