:root {
  color-scheme: dark;
  font-family: 'Fira Sans', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #111;
  color: #eee;
  min-height: 100vh;
  display: grid;
  place-items: center;
}

#app {
  width: min(92vw, 70rem);
  min-height: 80vh;
  display: grid;
  grid-template-rows: auto 1fr;
  justify-items: center;
  align-items: stretch;
}

#app .hud {
  display: none;
}

#board-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(2rem, 4vw, 3rem);
}

.board-slot {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.thumbnail-row {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  justify-content: space-between;
  gap: clamp(0.5rem, 2vw, 1.5rem);
}

.thumbnail-row .board-wrapper {
  flex: 1 1 30%;
  max-width: 30%;
}

.board-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  border-radius: 0.75rem;
  border: none;
  background: none;
  transition: opacity 180ms ease-in-out;
  will-change: opacity;
}

.board-wrapper--fading {
  opacity: 0;
  pointer-events: none;
}

.board-wrapper--animating {
  pointer-events: none;
}

.board-wrapper--primary {
  width: min(100%, 52rem);
  padding: 1rem;
  background: none;
  box-shadow: none;
}

.board-wrapper--thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  opacity: 0.75;
  cursor: pointer;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  flex: 1 1 auto;
}

.board-wrapper--thumb:hover {
  opacity: 1;
}

.board-wrapper--primary .board-grid {
  max-width: 100%;
  margin: 0 auto;
}

.board-wrapper--thumb .board-grid {
  transform: scale(0.28);
  transform-origin: top center;
  width: 100%;
  height: 100%;
}

@media (max-width: 640px) {
  .board-wrapper--thumb .board-grid {
    transform: scale(0.25);
  }
}

@media (max-width: 480px) {
  .board-wrapper--thumb .board-grid {
    transform: scale(0.22);
  }
}

.board-grid {
  outline: none;
  display: grid;
  gap: clamp(0.25rem, 1.8vw, 0.45rem);
  justify-content: center;
  align-content: center;
}

.board-grid:focus-visible {
  outline: none;
}

.board-grid[data-mode="ordered"] .cell.cursor,
.board-grid[data-mode="words"] .cell.cursor {
  outline: 2px solid #888;
  outline-offset: -2px;
}

.cell {
  width: clamp(1.9rem, 7vw, 2.7rem);
  height: clamp(1.9rem, 7vw, 2.7rem);
  display: grid;
  place-items: center;
  font-size: clamp(1.1rem, 4vw, 1.7rem);
  color: #d6d7dc;
  border-radius: 0.2rem;
  border: 1px solid #222;
  background: #1a1a1a;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.cell.revealed {
  color: #0a0a0c;
  border-color: #f0d98c;
  background: #f9f2c5;
}

.cell--ordered-cleared {
  color: #0a0a0c;
}

.cell__letter {
  position: relative;
  display: inline-block;
  transition: opacity 180ms ease, transform 180ms ease;
  will-change: opacity, transform;
  z-index: 1;
}

.cell__letter--hidden {
  opacity: 0;
  transform: translateY(6px) scale(0.9);
}

.cell--ghost {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  pointer-events: none;
  transform: translate(0, 0) rotate(0deg);
  opacity: 1;
  transition: transform 200ms cubic-bezier(0.19, 0.78, 0.32, 1.08), opacity 180ms ease;
  z-index: 2;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.cell.revealed .cell--ghost {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.25);
}

.cell--ghost--flying {
  transform: translate(var(--ghost-tx, 0px), var(--ghost-ty, 0px)) rotate(var(--ghost-rot, 0deg));
  opacity: 0;
}

.cell.cursor {
  outline: none;
}

.cell.target {
  cursor: pointer;
  border-color: #f0d98c;
  background: #f9f2c5;
  box-shadow: none;
}

.cell.target-red {
  border-color: #ff3048;
  background: linear-gradient(160deg, #ff5a63 0%, #c8001d 85%);
  box-shadow: 0 0 20px rgba(255, 48, 72, 0.6);
}

.cell.target-green {
  border-color: #1fbd66;
  background: linear-gradient(160deg, #6ef7a5 0%, #0a7f46 85%);
  box-shadow: 0 0 20px rgba(31, 189, 102, 0.55);
}

.cell.target-blue {
  border-color: #2f78ff;
  background: linear-gradient(160deg, #75c2ff 0%, #1f4ed8 85%);
  box-shadow: 0 0 20px rgba(47, 120, 255, 0.55);
}

.cell.word-complete {
  color: #fff;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.35);
}

.cell.word-complete.target {
  color: #fff9d6;
}

#primary-slot {
  margin-bottom: clamp(1rem, 3vw, 2.5rem);
}

@media (prefers-reduced-motion: reduce) {
  .cell__letter {
    transition-duration: 0ms;
  }
  .cell--ghost,
  .cell--ghost--flying {
    transition-duration: 0ms;
  }
}

.virtual-keyboard {
  display: none;
  width: min(100%, 26rem);
  margin-inline: auto;
  margin-top: clamp(1.25rem, 4vw, 2.5rem);
  gap: 0.6rem;
}

.virtual-keyboard--visible {
  display: grid;
}

.virtual-keyboard__row {
  display: flex;
  justify-content: center;
  gap: clamp(0.3rem, 2.5vw, 0.5rem);
  flex-wrap: nowrap;
}

.virtual-keyboard__key {
  flex: 0 1 clamp(2.2rem, 8vw, 2.8rem);
  padding: clamp(0.65rem, 3vw, 0.8rem) clamp(0.35rem, 2vw, 0.55rem);
  border-radius: 0.45rem;
  border: 1px solid #2a2a2a;
  background: #1f1f1f;
  color: #f3f3f3;
  font-size: clamp(0.95rem, 3.4vw, 1.05rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease, transform 100ms ease;
}

.virtual-keyboard__key:focus-visible {
  outline: 2px solid #ff5a63;
  outline-offset: 2px;
}

.virtual-keyboard__key:active {
  transform: translateY(1px);
  background: #2a2a2a;
}

@media (max-width: 480px) {
  .virtual-keyboard {
    gap: 0.45rem;
  }
  .virtual-keyboard__row {
    gap: 0.3rem;
  }
  .virtual-keyboard__key {
    flex-basis: clamp(2rem, 9vw, 2.4rem);
    padding: 0.6rem 0.3rem;
    font-size: 0.95rem;
  }
}
