:root {
  --bg: #0f1724;
  --card-bg: #111827;
  --accent: #10b981;
  --muted: #dadada;
  --glass: rgba(255, 255, 255, 0.03);
  --tile-gap: 1vw;
  --cols: 4; /* JS будет менять */
  --tile-size: 12vw; /* JS будет менять (px) */
}

* {
  box-sizing: border-box;
  -webkit-user-select: none; /* Safari/Chrome/iOS */
  -moz-user-select: none; /* Firefox */
  -ms-user-select: none; /* IE/Edge */
  user-select: none; /* Современные браузеры */
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, "Helvetica Neue", Arial;
  background: linear-gradient(180deg, #630070 0%, #30024b 60%);
  color: #e6eef8;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.app {
  width: 100%;
  max-width: 100%;
  background: linear-gradient(
    180deg,
    rgba(255, 0, 0, 0.02),
    rgba(255, 255, 255, 0.01)
  );
  border-radius: 1vw;
  padding: 2vw;
  box-shadow: 0 1vw 2.5vw rgba(2, 6, 23, 0.6);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1vh;
}
.title {
  display: flex;
  align-items: center;
}
.logo {
  width: 5vw;
  height: 5vw;
  border-radius: 1vw;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
  box-shadow: 0 1vw 3vw rgba(16, 185, 129, 0.12) inset;
}
h1 {
  font-size: 1.5vw;
  margin: 0;
}

.controls {
  display: flex;
  align-items: center;
  color: #49005f;
}
button {
  background: var(--glass);
  border: 0.1vw solid rgba(255, 255, 255, 0.04);
  color: inherit;
  padding: 2vh 2vw;
  border-radius: 1vw;
  cursor: pointer;
}
button.primary {
  background: linear-gradient(90deg, rgb(0, 140, 255), #7c3aed);
  border: none;
  color: #ffffff;
  font-weight: bold;
}

.board-wrap {
  width: 100%;
}

.board {
  display: grid;
  gap: var(--tile-gap);
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  justify-content: center;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  aspect-ratio: 1 / 1;
  perspective: 800px;
  border-radius: 1vw;
}
.card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.2, 0.9, 0.3, 1);
  cursor: pointer;
  border-radius: 1vw;
}
.card.flip {
  transform: rotateY(180deg);
}
.face {
  position: absolute;
  inset: 0;
  border-radius: 1vw;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  box-shadow: 0 0vw .8vw rgba(143, 56, 143, 0.5);
}

.front {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02),
    rgba(255, 255, 255, 0.01)
  );
  border: 0.1vw solid rgba(255, 255, 255, 0.03);
}
.back {
  background: linear-gradient(180deg, #0b1220, #071024);
  transform: rotateY(180deg);
}

.info {
  display: flex;
  gap: 2vw;
  align-items: center;
  margin: 3vh 0 0 0;
  font-size: 2vw;
}
.muted {
  color: var(--muted);
  font-size: 1.5vw;
}

.timer-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 2vh;
}
.timer {
  width: 10vw;
  height: 10vw;
  display: grid;
  place-items: center;
  position: relative;
}
.timer svg {
  transform: rotate(-90deg);
}
.timer .label {
  position: absolute;
  font-size: 4vw;
  color: var(--muted);
  text-align: center;
}
.timer .time-left {
  font-weight: 700;
  color: #fff;
  font-size: 2vw;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.7), rgba(2, 6, 23, 0.6));
  border-radius: 2vw;
  padding: 2vw;
  z-index: 50;
}
.start-screen,
.win-screen,
.lose-screen {
  max-width: 60%;
  text-align: center;
}
.start-screen p {
  color: var(--muted);
}

.tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  border-radius: 1vw;
}

#overlayStart {
  padding: 2vh 2vw;
  font-size: 1.5vw;
}

.tile {
  -webkit-tap-highlight-color: transparent;
}
.card {
  min-height: 0;
}

.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 3rem;
  z-index: 9999;
}

.countdown {
  font-weight: bold;
  font-size: 10vh;
}

.loading-text {
  font-size: 1.5rem;
  margin-top: 10px;
  font-size: 5vh;
}

@keyframes flyFade {
  0% {
    opacity: 0;
    transform: translateY(1vh);
  }
  50% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-1vh);
  }
}

.animate {
  animation: flyFade 1s ease forwards;
}

#logo {
  width: 15vh;
  height: 15vh;
  margin-top: 5vh;
  border-radius: 2vh;
}
