:root {
  --ink: #191919;
  --paper: #f8f4ee;
  --coral: #ff4d5f;
  --yellow: #ffd84d;
}

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

html,
body {
  min-height: 100%;
}

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 8%, rgb(255 216 77 / 24%), transparent 24rem),
    radial-gradient(circle at 90% 88%, rgb(255 77 95 / 13%), transparent 23rem),
    var(--paper);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Arial Rounded MT Bold", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.game-shell {
  min-height: 100vh;
  min-height: 100svh;
  padding:
    max(20px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px)))
    16px
    max(20px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  display: grid;
  place-items: start center;
  overflow: hidden;
}

.game {
  width: min(100%, 500px);
  margin-top: clamp(8px, 7svh, 56px);
}

.game-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.eyebrow {
  width: fit-content;
  margin: 0 0 9px;
  padding: 4px 8px 3px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 8vw, 43px);
  font-weight: 950;
  letter-spacing: -0.06em;
  line-height: 1;
}

.counter {
  min-width: 62px;
  padding: 8px 10px 7px;
  border: 2px solid var(--ink);
  border-radius: 15px;
  background: #fff;
  box-shadow: 3px 3px 0 var(--ink);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 3px;
}

.counter strong {
  font-size: 20px;
  line-height: 1;
}

.counter span {
  font-size: 11px;
  font-weight: 800;
}

.play-area {
  width: 100%;
  height: min(calc(100vw - 32px), 500px);
}

.play-area > * {
  width: 100%;
  height: 100%;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(7px, 2.4vw, 12px);
}

.card {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: clamp(13px, 4vw, 20px);
  background: #fff;
  box-shadow: 3px 4px 0 var(--ink);
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 180ms ease,
    opacity 180ms ease,
    filter 180ms ease,
    box-shadow 120ms ease;
  touch-action: manipulation;
}

.card img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.card:not(:disabled):active {
  transform: translate(2px, 3px) scale(0.96);
  box-shadow: 1px 1px 0 var(--ink);
}

.card:focus-visible,
.play-again:focus-visible {
  outline: 4px solid #2d72ff;
  outline-offset: 3px;
}

.card-cleared {
  opacity: 0;
  filter: blur(4px);
  transform: scale(0.66) rotate(7deg);
  box-shadow: none;
  pointer-events: none;
}

.bomb-reveal {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  animation: result-in 360ms cubic-bezier(0.18, 0.86, 0.32, 1.22) both;
}

.bomb-visual {
  position: relative;
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bomb-face {
  width: min(90vw, 430px);
  height: auto;
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
  user-select: none;
}

.bomb-visual-double {
  padding: 0;
}

.bomb-visual-double .bomb-face {
  position: absolute;
  bottom: 0;
  left: -7%;
  width: min(78%, 390px);
  max-width: none;
  transform: rotate(-5deg);
  transform-origin: center bottom;
}

.bomb-visual-double .bomb-face-second {
  right: -7%;
  left: auto;
  margin-left: 0;
  transform: translateY(2%) rotate(6deg);
}

.double-badge {
  position: absolute;
  z-index: 2;
  top: -2%;
  right: 0;
  min-width: 98px;
  padding: 14px 18px 12px;
  border: 5px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  box-shadow: 7px 8px 0 var(--ink);
  font-size: 44px;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  transform: rotate(7deg);
}

.play-again {
  width: min(100%, 360px);
  min-height: 54px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--coral);
  color: white;
  box-shadow: 4px 5px 0 var(--ink);
  font-size: 19px;
  font-weight: 950;
  cursor: pointer;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease;
  touch-action: manipulation;
}

.play-again:active {
  transform: translate(3px, 4px);
  box-shadow: 1px 1px 0 var(--ink);
}

.game-rules {
  margin-top: 24px;
  padding: 14px 16px 15px;
  border: 2px dashed #8d837a;
  border-radius: 16px;
  background: rgb(255 255 255 / 48%);
  color: #514b46;
  font-size: 12px;
  line-height: 1.55;
}

.game-rules h2 {
  margin: 0 0 7px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 950;
  letter-spacing: 0.04em;
}

.game-rules p {
  margin: 0;
}

.game-rules .rules-label {
  margin-top: 9px;
  color: var(--ink);
  font-weight: 900;
}

.game-rules ul {
  margin: 5px 0 0;
  padding-left: 0;
  list-style: none;
}

.game-rules li {
  position: relative;
  padding-left: 1em;
}

.game-rules li::before {
  position: absolute;
  left: 0;
  content: "·";
  font-weight: 950;
}

.game-rules li + li {
  margin-top: 4px;
}

@keyframes result-in {
  from {
    opacity: 0;
    transform: scale(0.72) rotate(-4deg);
  }

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

@media (max-height: 650px) {
  .game-shell {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .eyebrow {
    display: none;
  }

  .game {
    margin-top: 0;
  }

  .game-header {
    margin-bottom: 14px;
  }

  h1 {
    font-size: 27px;
  }

  .counter {
    padding-block: 6px;
  }

  .card-grid {
    gap: 7px;
  }

  .bomb-reveal {
    min-height: 0;
    gap: 14px;
  }

  .bomb-face {
    width: min(78vw, 330px);
    max-height: 100%;
  }

  .bomb-visual-double .bomb-face {
    bottom: -2%;
    left: -9%;
    width: min(80%, 300px);
  }

  .bomb-visual-double .bomb-face-second {
    right: -9%;
    left: auto;
  }

  .double-badge {
    top: -2%;
    right: 0;
    min-width: 82px;
    padding: 11px 15px 9px;
    border-width: 4px;
    font-size: 36px;
  }

  .game-rules {
    margin-top: 16px;
    padding: 11px 13px 12px;
    font-size: 11px;
  }
}

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