body {
  background: linear-gradient(160deg, #8ecae6, #118ab2);
  color: #14213d;
}

#board {
  position: fixed;
  inset: max(76px, calc(env(safe-area-inset-top) + 68px)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), var(--size, 20vmin));
  grid-auto-rows: var(--size, 20vmin);
  gap: calc(var(--size, 20vmin) * 0.1);
  place-content: center;
}

.card {
  position: relative;
  border: none;
  background: none;
  padding: 0;
  perspective: 800px;
}

.card .back,
.card .face {
  position: absolute;
  inset: 0;
  border-radius: 14%;
  border: max(4px, 0.8vmin) solid #fff;
  box-shadow: 0 0.8vmin 0 rgba(0, 0, 0, 0.18);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 0.35s;
}

.card .back {
  background: var(--back, #ef476f);
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.35) 18%, transparent 19%);
  background-size: 33% 33%;
}

.card .face {
  background: #fff center / cover no-repeat;
  display: grid;
  place-items: center;
  font-size: calc(var(--size, 20vmin) * 0.6);
  line-height: 1;
  transform: rotateY(180deg);
}

.card.up .back { transform: rotateY(180deg); }
.card.up .face { transform: rotateY(360deg); }

.card.done {
  animation: happy 0.6s;
}

.card.done .face {
  border-color: #ffd166;
  box-shadow: 0 0 0 max(3px, 0.6vmin) #06d6a0, 0 0.8vmin 0 rgba(0, 0, 0, 0.18);
}

@keyframes happy {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.12) rotate(-4deg); }
  70% { transform: scale(0.96) rotate(3deg); }
}

#bravo {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  color: #fff;
  font-size: 16vmin;
  font-weight: 900;
  pointer-events: none;
  z-index: 40;
  text-shadow: 1vmin 1vmin 0 #ef476f, -1vmin -1vmin 0 #ffd166, 2vmin 1vmin 0 #7b2cbf;
}

#bravo.show {
  display: grid;
  animation: pulse 0.8s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.confetti {
  position: fixed;
  top: -5vh;
  width: 3vmin;
  height: 3vmin;
  border-radius: 50%;
  z-index: 30;
  pointer-events: none;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translateY(115vh) rotate(540deg); }
}

/* settings: small, top-right, opened by holding */
.gear {
  position: fixed;
  z-index: 50;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: rgba(255, 255, 255, 0.85) conic-gradient(#06d6a0 var(--p, 0%), transparent 0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  font-size: 26px;
}

.gear.holding {
  animation: hold 0.8s linear forwards;
}

@property --p {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}

@keyframes hold {
  to { --p: 100%; }
}

dialog {
  margin: auto;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  border: none;
  border-radius: 24px;
  padding: 24px;
  background: #fff;
  color: #14213d;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  touch-action: pan-y;
}

dialog::backdrop {
  background: rgba(20, 33, 61, 0.5);
}

dialog h2 {
  font-size: 28px;
  margin-bottom: 12px;
}

dialog h3 {
  font-size: 18px;
  margin: 16px 0 8px;
}

#thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

#thumbs img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
}

.hint {
  font-size: 15px;
  color: #5c677d;
  margin: 8px 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  border: 2px solid #d9dee8;
  background: #f4f6fa;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  background: #118ab2;
  border-color: #118ab2;
  color: #fff;
}

.btn.pair {
  min-width: 56px;
  font-size: 20px;
}

.btn.pair.on {
  background: #06d6a0;
  border-color: #06d6a0;
  color: #fff;
}

.btn.big {
  width: 100%;
  margin-top: 24px;
  min-height: 60px;
  font-size: 22px;
}

[hidden] {
  display: none !important;
}
