* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% 0%, rgba(30, 91, 159, 0.95) 0%, rgba(5, 42, 95, 0.9) 36%, rgba(0, 19, 61, 1) 100%),
    #00133d;
  color: #ffffff;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
}

.canvas {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 10%, rgba(45, 103, 174, 0.9) 0%, rgba(3, 47, 113, 0.88) 38%, rgba(0, 19, 61, 1) 100%),
    #00133d;
  touch-action: manipulation;
}

#app {
  width: 100vw;
  height: 100vh;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: max(56px, env(safe-area-inset-top)) max(56px, env(safe-area-inset-right)) max(64px, env(safe-area-inset-bottom)) max(56px, env(safe-area-inset-left));
}

.screen.active {
  display: flex;
}

.logo {
  width: 280px;
  max-width: 54%;
  height: auto;
  margin-top: 22px;
}

.logo-game-name {
  margin-top: 18px;
  color: #ffffff;
  font-size: clamp(36px, 4.4vh, 60px);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.title {
  width: 100%;
  text-align: center;
  font-size: clamp(34px, 4.2vh, 62px);
  line-height: 1.12;
  font-weight: 700;
  margin: 145px 0 56px;
}

#screen-start {
  justify-content: center;
  gap: 0;
}

#screen-prepare {
  justify-content: center;
}

#screen-start .logo {
  margin-top: 0;
  margin-bottom: 0;
}

#screen-start .logo-game-name {
  margin-bottom: 100px;
}

#screen-prepare .logo {
  margin-top: 0;
  margin-bottom: 0;
}

#screen-start .title {
  margin: 56px 0 44px;
}

.prepare-panel {
  width: 100%;
  max-width: 690px;
  margin-top: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  padding: 56px 36px;
  border-radius: 20px;
  background: rgba(0, 13, 48, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.24);
  text-align: center;
}

.prepare-copy {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: clamp(32px, 4vh, 56px);
  line-height: 1.15;
  font-weight: 700;
}

.prep-countdown {
  min-width: 280px;
  padding: 30px 48px;
  border-radius: 18px;
  background: #d71920;
  color: #ffffff;
  font-size: clamp(86px, 11vh, 150px);
  line-height: 1;
  font-weight: 800;
  text-transform: uppercase;
  box-shadow: 0 18px 32px rgba(123, 6, 11, 0.4);
}

.start-form {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

#screen-start .start-form {
  gap: 0;
}

.start-form.is-loading {
  pointer-events: none;
}

.start-form.is-loading .btn {
  opacity: 0.72;
}

#screen-start .start-form .btn {
  margin-top: 100px;
}

.start-cta {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 38px 30px;
  border: 2px dashed rgba(255, 255, 255, 0.54);
  border-radius: 8px;
  background: rgba(0, 13, 48, 0.28);
  text-align: center;
}

.start-cta-title {
  font-size: 42px;
  line-height: 1.12;
  font-weight: 700;
}

.start-cta-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 30px;
  line-height: 1.35;
  font-weight: 500;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 26px 52px;
  font-size: 38px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
  min-width: 330px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
  touch-action: manipulation;
}

.btn.primary {
  background: #d71920;
  color: #ffffff;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.34);
}

.btn.primary:active {
  transform: translateY(2px);
  box-shadow: 0 7px 16px rgba(0, 0, 0, 0.42);
}

.game-area {
  width: 100%;
  max-width: min(88vw, 790px, calc((100dvh - 170px) / 1.25));
  margin-top: 24px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  width: 100%;
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.25;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: transparent;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  transform-style: preserve-3d;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.card-inner {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  transition: transform 0.28s ease;
}

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

.card-face {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  border-radius: 8px;
  backface-visibility: hidden;
}

.card-face.back {
  background:
    url("images/lot-crane.svg") center / 46% auto no-repeat,
    linear-gradient(145deg, #063783 0%, #001a54 58%, #000f38 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.card-face.front {
  transform: rotateY(180deg);
  background: #ffffff;
}

.card-face img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.card.variant-1 .card-face.front img {
  filter: saturate(1.16) contrast(1.08) brightness(0.92);
}

.card.variant-1 .card-face.front::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(215, 25, 32, 0.28), rgba(255, 255, 255, 0) 45%);
  pointer-events: none;
}

.card.matched {
  cursor: default;
}

.game-timer {
  min-width: 220px;
  margin-top: 0;
  padding: 14px 24px;
  border-radius: 12px;
  background: rgba(0, 19, 61, 0.86);
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.28);
  text-align: center;
  font-size: 54px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.game-timer.is-danger {
  background: rgba(215, 25, 32, 0.96);
  border-color: rgba(255, 255, 255, 0.38);
  box-shadow: 0 16px 34px rgba(123, 6, 11, 0.4);
}

#screen-game {
  justify-content: center;
  padding-top: max(34px, env(safe-area-inset-top));
  padding-bottom: max(34px, env(safe-area-inset-bottom));
}

#screen-result {
  justify-content: center;
}

.result-cta {
  width: 100%;
  max-width: 700px;
  margin-top: 92px;
  margin-bottom: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  text-align: center;
  animation: resultCtaEnter 0.75s ease-out both;
}

.result-cta-lead {
  font-size: clamp(36px, 4.2vh, 58px);
  line-height: 1.1;
  font-weight: 700;
  animation: resultLeadPulse 1.6s ease-in-out 0.75s infinite;
}

.result-cta-title {
  font-size: clamp(42px, 5vh, 74px);
  line-height: 1.08;
  font-weight: 800;
}

.reward-copy {
  padding: 18px 30px;
  border-radius: 8px;
  font-size: clamp(36px, 4.2vh, 58px);
  line-height: 1.2;
  font-weight: 800;
}

.result-time-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 330px;
  padding: 20px 30px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  background: rgba(0, 19, 61, 0.72);
}

.result-time-label {
  font-size: 24px;
  line-height: 1.1;
  font-weight: 600;
}

.result-time {
  font-size: clamp(54px, 6vh, 82px);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.reward-copy.is-success {
  background: #168246;
  color: #ffffff;
}

.reward-copy[hidden] {
  display: none;
}

.btn-home {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  min-width: 44px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.58);
  box-shadow: none;
  font-size: 28px;
  line-height: 1;
}

.btn-home:active {
  transform: translateY(1px);
}

.btn-home span {
  transform: translateY(-2px);
}

@keyframes resultCtaEnter {
  0% {
    opacity: 0;
    transform: translateY(28px) scale(0.96);
  }

  70% {
    opacity: 1;
    transform: translateY(-6px) scale(1.02);
  }

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

@keyframes resultLeadPulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.08);
  }
}

@media (max-width: 480px) {
  .screen {
    padding: 40px 28px 54px;
  }

  .logo {
    width: 180px;
    max-width: 70%;
  }

  .title {
    font-size: 32px;
    margin: 92px 0 36px;
  }

  .btn {
    min-width: 220px;
    padding: 19px 30px;
    font-size: 26px;
  }

  .game-area {
    margin-top: 48px;
  }

  .result-cta {
    margin-top: 36px;
    margin-bottom: 36px;
    gap: 16px;
  }

  .result-time-panel {
    min-width: 260px;
    padding: 16px 22px;
  }

  .result-time-label {
    font-size: 20px;
  }

  .reward-copy {
    padding: 14px 22px;
    font-size: 30px;
  }
}

@media (min-width: 768px) and (max-width: 1194px) {
  .screen {
    padding-left: 44px;
    padding-right: 44px;
  }

  .logo {
    width: 260px;
  }

  .logo-game-name {
    font-size: 44px;
  }

  .title {
    font-size: 46px;
  }

  .game-timer {
    font-size: 49px;
    padding: 12px 22px;
  }

  .game-area {
    max-width: min(92vw, 760px, calc((100dvh - 155px) / 1.25));
    margin-top: 20px;
  }

  .game-grid {
    gap: 12px;
  }
}

@media (orientation: landscape) and (min-width: 768px) {
  #screen-game {
    display: none;
    grid-template-columns: minmax(170px, 230px) minmax(620px, 840px);
    justify-content: center;
    align-content: center;
    column-gap: 38px;
    padding: 32px 44px;
  }

  #screen-game.active {
    display: grid;
  }

  .game-timer {
    grid-column: 1;
    align-self: center;
    justify-self: center;
  }

  .game-area {
    grid-column: 2;
    align-self: center;
    max-width: min(72vh, 840px);
    margin-top: 0;
  }
}
