@import url("../theme.css");
@import url("../chrome.css");

:root {
  --topbar: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- Top bar (header chrome is shared in ../chrome.css) ---------- */
.score {
  font-weight: bold;
  color: var(--ink-soft);
  font-size: clamp(13px, 3vw, 18px);
  white-space: nowrap;
}
.btn:focus-visible,
.choice:focus-visible,
.card:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* ---------- Play area ---------- */
.stage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

/* Card grid. --cols / --rows are set by render.js (3x4 portrait, 4x3 landscape);
   its pixel width/height are computed in JS (fitBoard) so every cell is an equal
   square that fits inside the stage and the board never overflows (no scrolling). */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), 1fr);
  grid-template-rows: repeat(var(--rows, 3), 1fr);
  gap: clamp(6px, 1.6vw, 14px);
  margin: auto;
}

/* ---------- Flip cards ---------- */
.card {
  position: relative;
  width: 100%;
  height: 100%;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  perspective: 600px;
  font-family: inherit;
}
.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .3s ease;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: clamp(10px, 2.4vw, 18px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 4px 0 var(--shadow);
}
/* Back = PeekaFox logo on an accent tile ("peek a fox!"). */
.card-back {
  background: var(--accent);
}
.card-back img {
  width: 56%;
  height: 56%;
  object-fit: contain;
  opacity: .92;
  filter: drop-shadow(0 1px 2px #0003);
}
/* Front = the matchable face; rotated so it shows when flipped. */
.card-front {
  background: var(--card);
  transform: rotateY(180deg);
}

.card.matched .card-inner { transform: rotateY(180deg); }
.card.matched .card-front {
  background: #eafbef;
  box-shadow: 0 0 0 3px #57c46b inset, 0 4px 0 var(--shadow);
  animation: matchPop .4s ease;
}
@keyframes matchPop {
  0% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}

/* Faces (sized off the real cell size set by fitBoard). */
.face-emoji { font-size: calc(var(--cell-size, 64px) * 0.6); line-height: 1; }
.face-color { width: 64%; height: 64%; border-radius: 50%; box-shadow: inset 0 -4px 8px #0002; }
.face-shape { width: 70%; height: 70%; }

/* ---------- Overlay screens (start / win) ---------- */
.screen {
  position: fixed;
  inset: 0;
  background: #0008;
  display: none;
  padding: 16px;
  z-index: 10;
  overflow: auto;
}
.screen.show { display: flex; }
.screen-card {
  position: relative;
  margin: auto;
  background: #fff;
  border-radius: 28px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 10px 0 #0004;
  max-width: 560px;
  width: 100%;
  animation: pop .3s ease;
}
.start-card {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.screen-close {
  position: absolute;
  top: 8px;
  right: 12px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: bold;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 50%;
}
.screen-close:active { background: rgba(0,0,0,.08); }
.deck-choices.scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  padding: 4px;
}
.start-card .play { flex: 0 0 auto; }

.screen-title { color: var(--primary); margin: 0 0 8px; font-size: clamp(28px, 7vw, 46px); }
.screen-card h2 { color: var(--primary); margin: 8px 0 8px; font-size: clamp(24px, 6vw, 40px); }
.screen-label { color: var(--ink-soft); margin: 14px 0 8px; font-weight: bold; }
.big-emoji { font-size: clamp(60px, 16vw, 120px); }
.actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
@keyframes pop {
  from { transform: scale(.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Deck picker: compact grid so many fit without a tall modal. */
.deck-choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}
.choice {
  font-family: inherit;
  cursor: pointer;
  border: 3px solid transparent;
  border-radius: 18px;
  background: #FBEFE2;
  color: var(--ink);
  padding: 12px 8px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.choice.selected {
  border-color: var(--accent);
  background: #E6F5F3;
  box-shadow: 0 4px 0 var(--shadow);
}
.choice .choice-icons { font-size: 34px; line-height: 1; }
.choice .choice-sub { font-size: 13px; color: var(--ink-soft); }
.play { margin-top: 22px; }
