/*
 * Wordle. The shared shell (common.css) on a slate cloth with Wordle's own green as the accent; this
 * adds the board, the keyboard, the bot's game and the round's players.
 */

.wd {
  --bg-top: #262b36;
  --bg-mid: #181b23;
  --bg-edge: #0e1015;
  --panel: rgba(10, 12, 17, 0.94);
  --accent: #538d4e;
  --accent-hover: #62a05c;
  --accent-ink: #fff;

  --correct: #538d4e;
  --misplaced: #b59f3b;
  --wrong: #3a3a3c;
  --tile-border: rgba(255, 255, 255, 0.16);
  --tile-typed: rgba(255, 255, 255, 0.45);

  /* Sized off both axes: the activity frame is short on desktop and narrow on a phone. */
  --tile: clamp(34px, min(11vw, 6.6vh), 54px);
}

/* The keyboard fills the bottom, so the toast goes under the topbar instead. */
body:has(#wordle:not([hidden])) .toast {
  top: calc(56px + var(--sait));
  bottom: auto;
}

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

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

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

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

/* ------------------------------------------------------------------ board */

.wd-board {
  display: grid;
  gap: 5px;
  perspective: 600px;
}

.wd-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--tile);
  gap: 5px;
}

.wd-tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  border: 2px solid var(--tile-border);
  border-radius: 4px;
  font-size: calc(var(--tile) * 0.52);
  font-weight: 800;
  text-transform: uppercase;
  line-height: 1;
  user-select: none;
}

.wd-tile.typed { border-color: var(--tile-typed); }

/* Unlimited's betting step: the board can't be played until a bet is placed or skipped. */
.wd-board.locked .wd-tile {
  background: #6b6a63;
  border-color: transparent;
}

.wd-tile.correct,
.wd-tile.misplaced,
.wd-tile.wrong {
  border-color: transparent;
  color: #fff;
}

.wd-tile.correct { background: var(--correct); }
.wd-tile.misplaced { background: var(--misplaced); }
.wd-tile.wrong { background: var(--wrong); }

/* A letter going in. */
.wd-tile.pop { animation: wd-pop 0.1s ease-out; }

@keyframes wd-pop {
  from { transform: scale(0.86); }
  50% { transform: scale(1.1); }
  to { transform: none; }
}

/* A guess being scored: each tile turns over, left to right, and shows its colour on the way back. */
.wd-tile.flip {
  animation: wd-flip 0.5s ease-in-out both;
  animation-delay: var(--delay, 0s);
}

@keyframes wd-flip {
  0% {
    transform: rotateX(0);
    background: transparent;
    border-color: var(--tile-typed);
    color: var(--ink);
  }
  50% {
    transform: rotateX(90deg);
    background: transparent;
    border-color: var(--tile-typed);
    color: var(--ink);
  }
  100% { transform: rotateX(0); }
}

/* A word that wasn't taken. */
.wd-row.shake { animation: wd-shake 0.4s ease-in-out; }

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

/* Solved just now: the winning row hops, left to right, once it has turned over. */
.wd-row.won .wd-tile.flip {
  animation: wd-flip 0.5s ease-in-out both, wd-hop 0.5s ease-out both;
  animation-delay: var(--delay, 0s), calc(1.1s + var(--delay, 0s) * 0.8);
}

@keyframes wd-hop {
  0%, 100% { transform: none; }
  40% { transform: translateY(-12px); }
  70% { transform: translateY(2px); }
}

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

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

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

.wd-result-head { font-weight: 700; font-size: 15px; }
.wd-result-answer { letter-spacing: 0.14em; font-weight: 800; }
.wd-result.win .wd-result-verdict { color: var(--win); }
.wd-result.tie .wd-result-verdict { color: var(--push); }
.wd-result.lose .wd-result-verdict { color: var(--lose); }

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

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

.wd-bot {
  padding: 9px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.wd-bot-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.wd-bot-score {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* The bot's game, and other players' colours: the board in miniature. */
.wd-mini {
  display: grid;
  gap: 2px;
}

.wd-mini-row {
  display: flex;
  gap: 2px;
}

.wd-mini-tile {
  width: 18px;
  height: 18px;
  border-radius: 2px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  text-transform: uppercase;
  background: var(--wrong);
}

.wd-mini-tile.correct { background: var(--correct); }
.wd-mini-tile.misplaced { background: var(--misplaced); }

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

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

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

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

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

.wd-player .wd-mini { grid-column: 2 / -1; }

/* ------------------------------------------------------------------ keyboard */

.wd-play-extras:not(:has(.button:not([hidden]))) { display: none; }

.wd-keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.wd-key-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.wd-key {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  max-width: 44px;
  height: 46px;
  border: 0;
  border-radius: 5px;
  background: #818384;
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.2s ease;
}

.wd-key.wide {
  flex-grow: 1.6;
  max-width: 70px;
  font-size: 11px;
}

.wd-key:active { filter: brightness(1.15); }
.wd-key.correct { background: var(--correct); }
.wd-key.misplaced { background: var(--misplaced); }
.wd-key.wrong { background: var(--wrong); }

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

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

@media (max-width: 460px) {
  .wd-key { height: 42px; }
}
