/* Карты — SVG из art.js. CSS раскладывает и поворачивает их и рисует фон-поляну. */
:root {
  --cols: 4;
  --rows: 4;
  --gap: clamp(6px, 1.6vmin, 14px);
  --ratio: 0.75;
  --hud-h: 86px;
}

html, body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  display: flex; flex-direction: column; align-items: center;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 240, 180, .25), transparent 60%),
    repeating-linear-gradient(115deg, rgba(0, 0, 0, .05) 0 3px, transparent 3px 11px),
    radial-gradient(ellipse at 50% 40%, #5e8f45, #2c4a24 75%);
  background-attachment: fixed;
  font-family: "Trebuchet MS", sans-serif; color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, .8);
  user-select: none;
}

header {
  box-sizing: border-box;
  text-align: center;
  padding: 8px 16px 4px;
}

h1 {
  margin: 0;
  font-size: clamp(20px, 4.5vmin, 36px);
}

.stats {
  display: flex; gap: clamp(10px, 2.5vw, 22px);
  justify-content: center; align-items: center;
  font-size: clamp(14px, 2.8vmin, 20px);
  margin-top: 4px;
}

.hub-link {
  color: #fbf1d6; text-decoration: none;
  padding: 2px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, .28);
}
.hub-link:hover, .hub-link:focus-visible {
  background: rgba(0, 0, 0, .45);
  outline: 2px solid #f4b860; outline-offset: 2px;
}

.lives {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.firefly {
  width: clamp(20px, 3.6vmin, 28px);
  height: clamp(20px, 3.6vmin, 28px);
  object-fit: contain;
  vertical-align: middle;
  transition: opacity .3s, filter .3s;
}

.firefly.off {
  opacity: .25;
  filter: grayscale(1);
}

#board {
  --card-w: min(
    calc((100vw - 24px) / var(--cols) - var(--gap)),
    calc(((100vh - var(--hud-h) - 24px) / var(--rows) - var(--gap)) * var(--ratio))
  );
  width: calc(var(--card-w) * var(--cols) + var(--gap) * (var(--cols) - 1));
  max-width: calc(100vw - 24px);
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: var(--gap);
  margin: auto 0;
  padding-bottom: 8px;
  box-sizing: border-box;
}

.card {
  aspect-ratio: var(--ratio);
  perspective: 800px;
  cursor: pointer;
}

.card .inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .45s ease; transform-style: preserve-3d;
}

.card.open .inner,
.card.matched .inner,
.card.peek .inner {
  transform: rotateY(180deg);
}

.card img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  pointer-events: none; -webkit-user-drag: none;
}

.card .front { transform: rotateY(180deg); }
.card:not(.open):not(.matched):not(.peek):hover .inner { transform: translateY(-4px); }
.card.matched { cursor: default; animation: pop .5s ease .45s; }
@keyframes pop { 50% { transform: scale(1.08); } }

#banner {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .45); color: #fbf1d6;
  font-size: clamp(32px, 8vmin, 64px); font-weight: bold;
  text-shadow: 0 4px 16px rgba(0, 0, 0, .9);
  pointer-events: none; z-index: 50;
}
#banner[hidden] { display: none; }

#win {
  position: fixed; inset: 0; display: flex;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .6);
  z-index: 100;
}
#win[hidden], #error[hidden] { display: none; }

.modal {
  background: #fbf1d6;
  color: #3a2614;
  text-shadow: none;
  border: 4px solid #4a3420;
  border-radius: 20px;
  padding: clamp(16px, 4vmin, 28px) clamp(20px, 5vmin, 36px);
  width: min(90vw, 380px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .7), 0 0 0 2px #dcc79c;
  text-align: center;
  box-sizing: border-box;
}

.modal h2 {
  margin: 0 0 12px;
  font-size: clamp(24px, 5vmin, 32px);
  color: #3a2614;
}

.summary {
  margin: 12px 0 20px;
  text-align: left;
  display: inline-block;
  width: 100%;
}

.summary p {
  margin: 6px 0;
  font-size: clamp(15px, 3.2vmin, 18px);
  font-weight: 600;
}

.actions {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: inherit; font-size: clamp(15px, 3vmin, 18px); font-weight: bold;
  padding: 10px 20px; border-radius: 999px;
  text-decoration: none; cursor: pointer;
  border: 2px solid #4a3420;
  background: #dcc79c; color: #3a2614;
  transition: background .15s, transform .1s;
  user-select: none;
}
.btn:hover, .btn:focus-visible {
  background: #cfb786; outline: none;
}
.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #e06c22; color: #fff; border-color: #3a2614;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
.btn-primary:hover, .btn-primary:focus-visible {
  background: #d45e15;
}

#error { font-size: 20px; margin: auto; }
