:root {
  --navy: #01102b;
  --navy-soft: #0b1933;
  --white: #ffffff;
  --cyan: #5fb6c6;
  --magenta: #cb4e85;
  --yellow: #f3d15d;
  --green: #8ebc66;
  --brand-green: #83df4a;
  --panel: rgba(11, 25, 51, 0.92);
  --panel-strong: rgba(1, 16, 43, 0.96);
  --line: rgba(255, 255, 255, 0.14);
  --shadow: 0 26px 70px rgba(1, 16, 43, 0.34);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Roboto Flex", sans-serif;
  color: var(--white);
  background:
    radial-gradient(circle at top right, rgba(95, 182, 198, 0.16), transparent 22%),
    radial-gradient(circle at bottom left, rgba(203, 78, 133, 0.18), transparent 28%),
    linear-gradient(180deg, var(--navy), var(--navy-soft));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  filter: blur(24px);
  pointer-events: none;
}

body::before {
  top: -60px;
  right: -60px;
  background: rgba(95, 182, 198, 0.16);
}

body::after {
  bottom: 8%;
  left: -90px;
  background: rgba(243, 209, 93, 0.12);
}

.app-shell {
  width: 100vw;
  height: 100dvh;
}

.game-card {
  position: relative;
  overflow: hidden;
  width: 100vw;
  height: 100dvh;
  background: var(--panel);
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.primary-button,
.ghost-button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 14px 16px;
  font: inherit;
}

.primary-button {
  background: var(--brand-green);
  color: var(--navy);
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 14px 26px rgba(131, 223, 74, 0.24);
}

.game-card {
  --stage-pad: 28px;
  --hud-height: 92px;
  --board-gap: 14px;
  --board-height-fit: calc((100dvh - (var(--stage-pad) * 2) - var(--hud-height) - 22px - var(--board-gap)) / 2);
  --board-width-fit: calc(((100vw - (var(--stage-pad) * 2)) - (var(--board-gap) * 5)) * 7 / 30);
  --card-height: min(var(--board-height-fit), var(--board-width-fit), 42dvh);
  --card-width: calc(var(--card-height) * 5 / 7);
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(11, 25, 51, 0.98), rgba(1, 16, 43, 0.98));
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(1, 16, 43, 0.46);
  backdrop-filter: blur(3px);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.game-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-panel {
  width: min(100%, 520px);
  position: relative;
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 32px 30px 30px;
  background: rgba(8, 22, 48, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 28px;
  box-shadow: 0 14px 32px rgba(1, 16, 43, 0.14);
  backdrop-filter: blur(18px);
}

.overlay-logo {
  width: min(100%, 320px);
  height: auto;
  display: block;
  object-fit: contain;
}

.overlay-message {
  margin: 0;
  color: var(--white);
  text-align: center;
  font-size: clamp(1.6rem, 3.2vw, 2.7rem);
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.overlay-instructions {
  width: min(100%, 620px);
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  line-height: 1.45;
  font-weight: 500;
  text-wrap: balance;
}

.game-overlay .primary-button {
  min-width: min(100%, 420px);
  min-height: 96px;
  padding: 24px 40px;
  font-size: clamp(1.6rem, 2.8vw, 2.25rem);
  font-weight: 700;
  border-radius: 999px;
}

.game-overlay:not(.hidden) .overlay-panel {
  animation: overlay-panel-in 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.game-overlay:not(.hidden) .overlay-logo {
  animation: overlay-item-in 520ms 80ms both;
}

.game-overlay:not(.hidden) .overlay-instructions {
  animation: overlay-item-in 520ms 160ms both;
}

.game-overlay:not(.hidden) .overlay-message:not([hidden]) {
  animation: overlay-item-in 520ms 120ms both;
}

.game-overlay:not(.hidden) .primary-button {
  animation:
    overlay-item-in 520ms 240ms both,
    overlay-button-breathe 2.6s ease-in-out 900ms infinite;
}

@keyframes overlay-panel-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }

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

@keyframes overlay-item-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes overlay-button-breathe {
  0%,
  100% {
    transform: translateY(0);
    box-shadow:
      0 14px 26px rgba(131, 223, 74, 0.28),
      0 0 20px rgba(131, 223, 74, 0.26);
  }

  50% {
    transform: translateY(0);
    box-shadow:
      0 18px 34px rgba(131, 223, 74, 0.36),
      0 0 48px rgba(131, 223, 74, 0.52),
      0 0 76px rgba(131, 223, 74, 0.24);
  }
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.playfield {
  width: calc((var(--card-width) * 6) + (var(--board-gap) * 5));
  max-width: 100%;
  display: grid;
  gap: 22px;
  align-content: center;
}

.hud h2 {
  margin: 0;
  flex: 0 1 auto;
  min-width: calc((var(--card-width) * 4) + (var(--board-gap) * 3));
  max-width: calc(100% - 140px);
  font-size: clamp(1.55rem, 2.8vw, 3.25rem);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.timer-ring {
  --timer-progress: 100%;
  min-width: 112px;
  padding: 16px;
  position: relative;
  display: grid;
  justify-items: center;
  align-items: center;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(131, 223, 74, 0.18);
  border: 1px solid var(--line);
}

.timer-ring::before {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--timer-progress);
  background: var(--brand-green);
  border-radius: 24px 0 0 24px;
  transition: width 900ms linear;
}

.timer-ring::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: var(--navy-soft);
}

.timer-ring strong {
  position: relative;
  z-index: 1;
  font-size: 2.4rem;
  line-height: 1;
  color: var(--white);
}

.game-board {
  display: grid;
  grid-template-columns: repeat(6, var(--card-width));
  grid-template-rows: repeat(2, var(--card-height));
  gap: var(--board-gap);
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  perspective: 1200px;
  -webkit-perspective: 1200px;
}

.memory-card {
  position: relative;
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 20px;
  border: none;
  padding: 0;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 220ms ease;
  background: transparent;
  overflow: hidden;
  will-change: transform;
}

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

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 320ms ease, filter 220ms ease;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.88),
    0 8px 18px rgba(33, 44, 36, 0.12);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
  background-color: rgba(8, 22, 48, 0.01);
}

.card-front {
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.card-back {
  transform: rotateY(-180deg);
  -webkit-transform: rotateY(-180deg);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

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

.memory-card.flipped .card-back {
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
}

.memory-card.matched .card-back {
  border-color: rgba(131, 223, 74, 0.9);
  box-shadow:
    inset 0 0 0 2px rgba(131, 223, 74, 0.95),
    0 8px 18px rgba(33, 44, 36, 0.12);
}

.memory-card.celebrate {
  animation: matched-card-celebrate 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

  45% {
    transform: scale(1.07);
  }

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

@media (max-width: 900px) {
  .app-shell {
    width: 100%;
    height: 100dvh;
  }

  .game-card {
    --stage-pad: 18px;
    --hud-height: 74px;
    --board-gap: 10px;
    --card-height: min(var(--board-height-fit), var(--board-width-fit), 36dvh);
    width: 100%;
    height: 100dvh;
    aspect-ratio: auto;
    padding: 18px;
  }

  .playfield {
    gap: 16px;
  }

  .hud {
    gap: 10px;
  }

  .hud h2 {
    min-width: calc((var(--card-width) * 4.2) + (var(--board-gap) * 3.2));
    max-width: calc(100% - 96px);
    font-size: clamp(2rem, 4.6vw, 3.4rem);
    line-height: 0.98;
  }

  .overlay-panel {
    width: 100%;
    padding: 26px 24px 22px;
  }
}

@media (max-width: 420px) {
  .game-card {
    padding: 16px;
  }

  .overlay-panel {
    padding: 22px 18px 18px;
  }

  .hud h2 {
    min-width: calc((var(--card-width) * 4.1) + (var(--board-gap) * 3));
    max-width: calc(100% - 88px);
    font-size: clamp(1.9rem, 5.2vw, 2.6rem);
  }

  .timer-ring {
    min-width: 82px;
    padding: 12px;
  }

  .timer-ring::after {
    width: 50px;
    height: 50px;
  }

  .timer-ring strong {
    font-size: 1.9rem;
  }
}

@media (orientation: portrait) {
  .game-card {
    --stage-pad: 20px;
    --board-gap: 14px;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: var(--stage-pad);
  }

  .playfield {
    gap: 28px;
  }

  .hud {
    flex-direction: row;
    gap: 16px;
  }

  .hud h2 {
    font-size: clamp(2rem, 5.5vw, 4rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    line-height: 1.1;
  }

  .timer-ring {
    min-width: 120px;
    flex-shrink: 0;
    padding: 14px 16px;
  }

  .overlay-panel {
    width: min(100%, 680px);
    gap: 28px;
    padding: 40px 36px 36px;
  }

  .overlay-logo {
    width: min(100%, 440px);
  }

  .overlay-message {
    font-size: clamp(2rem, 5.5vw, 4rem);
  }

  .overlay-instructions {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
  }

  .game-overlay .primary-button {
    min-height: 110px;
    font-size: clamp(2rem, 5vw, 3rem);
  }
}

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