:root {
  --bg: #3a0720;
  --ink: #111111;
  --muted: rgba(255, 244, 220, 0.86);
  --card: #e7d4ae;
  --card-edge: #cbb58a;
  --word-ink: #161412;
  --red: #d32f2f;
  --blue: #1565c0;
  --line: rgba(255, 255, 255, 0.55);
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.18), 0 10px 22px rgba(40, 0, 20, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --type: "Arial Black", "Arial Bold", Arial, Helvetica, sans-serif;
  --rings: repeating-radial-gradient(
    circle at 50% 46%,
    rgba(255, 255, 255, 0.11) 0 1.5px,
    transparent 1.5px 52px
  );
  --glow: radial-gradient(
    circle at 50% 46%,
    #fffbe0 0%,
    #ffe45c 14%,
    #ffb12a 26%,
    #ff6e1c 40%,
    #e32636 54%,
    #c2185b 68%,
    #7a123f 82%,
    #2e0616 100%
  );
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

@font-face {
  font-family: "DIN";
  src:
    local("DIN Alternate Bold"),
    local("DIN Alternate"),
    url("./fonts/D-DIN-Bold.woff2") format("woff2");
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background-color: var(--bg);
  background-image: var(--rings), var(--glow);
  color: #fff8e8;
  font-family: "Segoe UI", "Avenir Next", "Helvetica Neue", sans-serif;
}

body {
  min-height: 100dvh;
}

.app {
  width: min(880px, calc(100% - 1.2rem));
  margin: 0 auto;
  padding: calc(1.1rem + var(--safe-top)) 0 calc(1.2rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 100dvh;
  position: relative;
  z-index: 1;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}

.brand h1 {
  margin: 0;
  color: #fff;
  font-family: var(--type);
  font-size: clamp(1.45rem, 4.4vw, 2.15rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  line-height: 0.95;
  text-transform: uppercase;
  filter: url(#stamp);
  text-shadow: 0 2px 0 rgba(60, 0, 30, 0.35);
}

.scores {
  display: flex;
  gap: 0.5rem;
}

.score {
  min-width: 4.3rem;
  padding: 0.4rem 0.65rem 0.45rem;
  border-radius: 12px;
  text-align: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(40, 0, 20, 0.28);
}

.score .score-label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.85;
}

.score .score-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.15;
}

.score.red {
  background: var(--red);
}

.score.blue {
  background: var(--blue);
}

.score.lead {
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.72),
    0 4px 12px rgba(40, 0, 20, 0.28);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  perspective: 1100px;
  -webkit-perspective: 1100px;
}

.card {
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1.28 / 1;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 1100px;
  -webkit-perspective: 1100px;
}

.card:focus-visible {
  outline: 2px solid #fff8e8;
  outline-offset: 3px;
  border-radius: 10px;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  transition: transform 0.55s cubic-bezier(0.2, 0.75, 0.2, 1);
  -webkit-transition: transform 0.55s cubic-bezier(0.2, 0.75, 0.2, 1);
}

.board.key-animating .card-inner {
  transition-delay: calc(var(--i, 0) * 18ms);
  -webkit-transition-delay: calc(var(--i, 0) * 18ms);
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
}

.card[aria-disabled="true"] {
  cursor: default;
}

.board.show-key .card.revealed {
  opacity: 0.5;
}

.face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow: var(--shadow);
}

.front {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.28rem 0.32rem 0.3rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 42%),
    var(--card);
  color: var(--word-ink);
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
}

.front::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(92, 68, 32, 0.18);
  border-radius: 7px;
  pointer-events: none;
}

.punch {
  width: 1rem;
  height: 1rem;
  margin-top: 0.5rem;
  border-radius: 50%;
  background: #d7c39a;
  box-shadow:
    inset 0 0 0 1px #b89a6c,
    0 0 0 1px #efe0c4;
  z-index: 1;
  flex: none;
  opacity: 0.5;
}

.word-box {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin-top: auto;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 0 0 8px 8px;
  height: 36%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.word {
  display: block;
  font-family: "DIN", "DIN Alternate", sans-serif;
  font-size: clamp(calc(0.82rem + 2px), calc(3.1vw + 2px), calc(1.32rem + 2px));
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
}

@media (min-width: 521px) and (max-width: 900px) {
  .app {
    width: min(640px, calc(100% - 1.2rem));
  }

  .card.long-md .word {
    font-size: clamp(
      calc(0.68rem + 2px),
      calc(2.55vw + 2px),
      calc(1.08rem + 2px)
    );
    letter-spacing: 0;
  }
}

@media (max-height: 900px) and (min-width: 521px) {
  .app {
    width: min(680px, calc(100% - 1.2rem));
    gap: 0.7rem;
    padding: calc(0.7rem + var(--safe-top)) 0 calc(0.7rem + var(--safe-bottom));
  }

  .board {
    gap: 0.32rem;
  }

  .btn {
    padding: 0.7rem 1rem;
  }
}

@media (min-width: 901px) {
  .card.long-lg .word {
    font-size: clamp(
      calc(0.68rem + 2px),
      calc(2.55vw + 2px),
      calc(1.08rem + 2px)
    );
    letter-spacing: 0;
  }
}

.back {
  background: #1a1410;
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
  overflow: hidden;
}

.portrait {
  position: absolute;
  inset: -3px;
  width: calc(100% + 6px);
  height: calc(100% + 6px);
  object-fit: cover;
  display: block;
  border-radius: 10px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.back .word-box {
  transform: translateZ(1px);
  -webkit-transform: translateZ(1px);
}

.back .word {
  color: var(--word-ink);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.card[data-type="red"] .back .word-box {
  background: var(--red);
}

.card[data-type="red"] .back .word {
  color: rgba(255, 255, 255, 0.94);
  -webkit-text-fill-color: rgba(255, 255, 255, 0.94);
}

.card[data-type="blue"] .back .word-box {
  background: var(--blue);
}

.card[data-type="blue"] .back .word {
  color: rgba(255, 255, 255, 0.94);
  -webkit-text-fill-color: rgba(255, 255, 255, 0.94);
}

.card[data-type="civilian"] .back .word-box {
  background: #caae7c;
}

.card[data-type="civilian"] .back .word {
  color: rgba(255, 255, 255, 0.94);
  -webkit-text-fill-color: rgba(255, 255, 255, 0.94);
}

.card[data-type="assassin"] .back .word-box {
  background: #111;
}

.card[data-type="assassin"] .back .word {
  color: rgba(255, 255, 255, 0.94);
  -webkit-text-fill-color: rgba(255, 255, 255, 0.94);
}

.status {
  min-height: 0;
  margin: 0;
  text-align: center;
  font-size: 1rem;
  color: var(--muted);
}

.status:empty {
  display: none;
}

.status.win-red {
  color: var(--red);
}

.status.win-blue {
  color: var(--blue);
}

.status.win-assassin {
  color: #2b2722;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: transparent;
  pointer-events: none;
  visibility: hidden;
  overflow: hidden;
  transition: visibility 0s linear 0.45s;
}

.overlay.open {
  visibility: visible;
  pointer-events: auto;
  transition: visibility 0s linear 0s;
}

.overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--rings), var(--glow);
  opacity: 0;
  filter: saturate(1.05) brightness(0.42);
  transition: opacity 0.45s ease;
}

.overlay.open::before {
  opacity: 1;
}

.overlay-spies {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  opacity: 0;
  pointer-events: none;
  transform-origin: 50% 58%;
}

.overlay-spies-inner {
  width: min(72rem, 100%);
  height: 94%;
  max-height: 94%;
  min-height: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.overlay-spy {
  height: 100%;
  max-height: 100%;
  width: auto;
  max-width: 42%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 18px 24px rgba(20, 0, 10, 0.55));
}

.overlay.open .overlay-spies {
  animation: spies-in 0.85s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes spies-in {
  from {
    opacity: 0;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.overlay-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.45rem;
}

.overlay.open .overlay-kicker,
.overlay.open .overlay-title,
.overlay.open .overlay-btn {
  animation: from-center 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.overlay.open .overlay-title {
  animation-delay: 0.08s;
}

.overlay.open .overlay-actions .overlay-btn:nth-child(1) {
  animation-delay: 0.18s;
}

.overlay.open .overlay-actions .overlay-btn:nth-child(2) {
  animation-delay: 0.26s;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin-top: 0.35rem;
}

.overlay-kicker {
  margin: 0 0 0.15rem;
  min-height: 0;
  padding: 0.32rem 0.9rem;
  border-radius: 999px;
  background: #fff;
  color: #d32f2f;
  font-family: var(--type);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.overlay-kicker:empty {
  display: none;
}

.overlay-title {
  margin: 0 0 1.15rem;
  font-family: var(--type);
  font-size: clamp(2.2rem, 8vw, 4.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 0.95;
  text-transform: uppercase;
  color: #fff;
  filter: url(#stamp);
  text-shadow: 0 3px 0 rgba(40, 0, 20, 0.35);
}

.overlay.win-red .overlay-title {
  color: #fff;
}

.overlay.win-blue .overlay-title {
  color: #fff;
}

.overlay.win-assassin .overlay-title {
  color: #fff;
}

@keyframes from-center {
  from {
    opacity: 0;
    transform: scale(0.28);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.credit {
  font-family: "DIN";
  margin: 0;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: rgba(255, 244, 220, 0.38);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1rem;
  background: #111;
  color: #fff8e8;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.btn.ghost {
  background: transparent;
  color: #fff8e8;
  box-shadow: inset 0 0 0 1.5px var(--line);
}

.btn.ghost[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.14);
}

.btn:focus-visible {
  outline: 2px solid #fff8e8;
  outline-offset: 3px;
}

.btn.overlay-btn {
  min-width: 8.5rem;
  background: #fff;
  color: #111;
}

.btn.ghost.overlay-btn {
  background: transparent;
  color: #fff8e8;
  box-shadow: inset 0 0 0 1.5px var(--line);
}

@media (max-width: 520px) {
  .app {
    width: min(100% - 0.7rem, 880px);
    gap: 0.75rem;
  }

  .board {
    gap: 0.28rem;
  }

  .card {
    aspect-ratio: 1.08 / 1;
    border-radius: 8px;
  }

  .front {
    padding: 0.18rem 0.16rem 0.16rem;
  }

  .front::before {
    inset: 3px;
  }

  .punch {
    width: 0.45rem;
    height: 0.45rem;
    margin-top: 0.2rem;
  }

  .word {
    font-size: clamp(calc(0.64rem + 2px), calc(4vw + 2px), calc(1.02rem + 2px));
  }

  .card.long-sm .word {
    font-size: clamp(
      calc(0.54rem + 2px),
      calc(3.3vw + 2px),
      calc(0.86rem + 2px)
    );
    letter-spacing: 0;
  }

  .overlay-spies-inner {
    height: 84%;
  }

  .overlay-spy {
    max-width: 48%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner,
  .overlay,
  .overlay::before,
  .overlay.open .overlay-kicker,
  .overlay.open .overlay-title,
  .overlay.open .overlay-btn,
  .overlay.open .overlay-spies {
    transition: none;
    -webkit-transition: none;
    animation: none;
  }

  .overlay.open .overlay-spies {
    opacity: 1;
    transform: none;
  }
}
