:root {
  --ink: #351146;
  --muted: #6c5580;
  --paper: #fbf7fc;
  --surface: #ffffff;
  --primary: #661d88;
  --primary-dark: #4b1066;
  --accent: #e536a4;
  --success: #783f9a;
  --line: #e5cfe9;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
}

button {
  font: inherit;
}

.site-header,
.game-nav,
main,
footer {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding: 3.5rem 0 2rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.3rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0.35rem;
  font-size: clamp(1.7rem, 4vw, 2.4rem);
}

.eyebrow,
.clue-label {
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.eyebrow {
  margin-bottom: 0.5rem;
}

.intro {
  max-width: 27rem;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.fullscreen-button {
  margin-top: 1rem;
}

.fullscreen-status {
  min-height: 1.25rem;
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.game-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.game-nav[hidden] {
  display: none;
}

.team-settings {
  margin-left: auto;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  color: var(--primary);
  background: white;
  font-weight: 700;
  cursor: pointer;
}

.team-settings:hover,
.team-settings:focus-visible {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
}

.game-tab {
  padding: 0.8rem 1.1rem;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.game-tab:hover,
.game-tab:focus-visible {
  color: var(--primary);
}

.game-tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--primary-dark);
}

main {
  padding: 2rem 0 3rem;
}

.game-panel {
  padding: clamp(1.2rem, 3vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  background: var(--surface);
  box-shadow: 0 15px 40px rgb(34 65 47 / 8%);
}

.team-setup {
  max-width: 44rem;
  margin-inline: auto;
}

.team-setup > p {
  color: var(--muted);
  line-height: 1.5;
}

.team-count-label,
.team-name-fields label {
  display: block;
  color: var(--primary-dark);
  font-weight: 800;
}

#team-count,
.team-name-fields input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  color: var(--ink);
  background: white;
}

#team-count {
  width: 8rem;
}

.team-name-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.setup-error {
  min-height: 1.5rem;
  color: #a11b67 !important;
  font-weight: 700;
}

.team-scoreboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: #f9f1fb;
}

.team-turn {
  flex: 0 0 auto;
  margin: 0;
  color: var(--primary-dark);
}

.team-scores {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.team-score {
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: white;
  font-size: 0.85rem;
}

.team-score strong {
  margin-left: 0.2rem;
  color: var(--primary-dark);
}

.team-score.is-current {
  border-color: var(--primary);
  color: white;
  background: var(--primary);
}

.team-score.is-current strong {
  color: white;
}

.game-heading {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: start;
}

.game-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
}

.game-heading > div > p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.button {
  padding: 0.7rem 1rem;
  border: 1px solid var(--primary);
  border-radius: 0.5rem;
  color: white;
  background: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

.button:hover,
.button:focus-visible {
  background: var(--primary-dark);
}

.button-secondary {
  flex: 0 0 auto;
  color: var(--primary);
  background: white;
}

.button-secondary:hover,
.button-secondary:focus-visible {
  color: white;
}

.scoreboard {
  display: flex;
  gap: 1.25rem;
  margin-top: 1.5rem;
  color: var(--muted);
}

.scoreboard strong,
.attempts strong {
  color: var(--primary-dark);
}

.live-message {
  min-height: 1.5rem;
  margin: 1rem 0;
  color: var(--primary-dark);
  font-weight: 700;
}

.remaining-content {
  margin: -0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.competition-result {
  margin: 0 0 1rem;
  color: var(--primary-dark);
  font-weight: 800;
}

.countdown-slot {
  min-height: 2rem;
}

.countdown {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-weight: 800;
}

.countdown strong {
  display: inline-flex;
  width: 1.6rem;
  height: 1.6rem;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: white;
  background: var(--accent);
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.5rem;
  perspective: 1000px;
}

.memory-card {
  position: relative;
  min-height: 150px;
  padding: 0;
  border: 1px solid var(--primary);
  border-radius: 0.8rem;
  background: var(--primary);
  color: white;
  cursor: pointer;
  overflow: hidden;
  transform-style: preserve-3d;
  will-change: transform;
}

.memory-card:hover:not(:disabled),
.memory-card:focus-visible:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

.memory-card:disabled {
  cursor: default;
}

.card-back,
.card-front {
  display: flex;
  width: 100%;
  height: 100%;
  padding: 1rem;
  align-items: center;
  justify-content: center;
}

.card-back {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

.card-back img {
  width: min(86%, 175px);
  max-height: 76px;
  object-fit: contain;
}

.card-front {
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
  justify-content: flex-start;
  color: var(--ink);
  background: #fdfcf8;
  text-align: left;
}

.memory-card:not(.is-revealed) .card-front,
.memory-card.is-revealed .card-back {
  display: none;
}

.memory-card.is-revealed {
  border-color: var(--accent);
  background: #fdfcf8;
}

.memory-card.is-flipping {
  animation: card-flip 380ms ease-in-out both;
}

.memory-card.is-matched {
  border-color: var(--success);
  background: #f4eafa;
  animation: card-match 500ms ease-out both;
}

.card-front strong {
  line-height: 1.15;
}

.card-description {
  font-size: 0.88rem;
  line-height: 1.3;
}

.card-front small,
.source {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.hangman-layout {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(0, 1.2fr);
  gap: 2rem;
  align-items: center;
  margin-top: 1.5rem;
}

.hangman-figure {
  margin: 0;
  padding: 1.25rem;
  border-radius: 0.8rem;
  color: var(--primary-dark);
  background: #f4eafa;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  line-height: 1.1;
  animation: figure-enter 280ms ease-out both;
}

.hangman-figure.is-mistake {
  color: #a11b67;
  background: #fff0f8;
  animation: mistake-shake 360ms ease-in-out both;
}

.clue-label {
  margin-bottom: 0.3rem;
}

.clue {
  margin-bottom: 0.45rem;
  font-size: 1.1rem;
  line-height: 1.45;
}

.word {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 1.4rem 0 1rem;
}

.word-letter {
  display: inline-flex;
  width: 1.7rem;
  height: 2.2rem;
  align-items: end;
  justify-content: center;
  border-bottom: 3px solid var(--primary);
  font-size: 1.5rem;
  font-weight: 800;
}

.keyboard {
  display: flex;
  max-width: 42rem;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 1.5rem 0;
}

.key {
  width: 2.45rem;
  height: 2.45rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  color: var(--primary-dark);
  background: white;
  font-weight: 800;
  cursor: pointer;
}

.key:hover:not(:disabled),
.key:focus-visible:not(:disabled) {
  border-color: var(--primary);
  color: white;
  background: var(--primary);
}

.key:disabled {
  color: #9c83a5;
  background: #f2eaf4;
  cursor: default;
}

.key.is-used {
  animation: key-press 220ms ease-out both;
}

footer {
  padding-bottom: 2rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

@keyframes card-flip {
  0% {
    transform: rotateY(0);
  }

  45% {
    transform: rotateY(88deg) scale(0.98);
  }

  55% {
    transform: rotateY(92deg) scale(0.98);
  }

  100% {
    transform: rotateY(0);
  }
}

@keyframes card-match {
  0% {
    transform: scale(1);
  }

  55% {
    transform: scale(1.04);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes figure-enter {
  from {
    opacity: 0;
    transform: scale(0.96);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes mistake-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25%,
  75% {
    transform: translateX(-8px);
  }

  50% {
    transform: translateX(8px);
  }
}

@keyframes key-press {
  from {
    transform: scale(1.12);
  }

  to {
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (max-width: 760px) {
  .site-header,
  .game-heading {
    display: block;
  }

  .site-header {
    padding-top: 2.25rem;
  }

  .intro {
    margin-top: 1rem;
  }

  .game-heading .button {
    margin-top: 1rem;
  }

  .memory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .team-scoreboard {
    display: block;
  }

  .team-scores {
    justify-content: flex-start;
    margin-top: 0.65rem;
  }

  .hangman-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

@media (max-width: 430px) {
  .site-header,
  .game-nav,
  main,
  footer {
    width: min(100% - 1rem, 1120px);
  }

  .game-panel {
    padding: 1rem;
    border-radius: 0.8rem;
  }

  .memory-card {
    min-height: 135px;
  }

  .team-name-fields {
    grid-template-columns: 1fr;
  }

  .game-nav {
    align-items: center;
  }

  .team-settings {
    margin-left: 0;
  }

  .scoreboard {
    display: block;
  }

  .scoreboard span {
    display: block;
    margin-bottom: 0.25rem;
  }
}
