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

body {
  font-family: 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #fff;
  min-height: 100vh;
  user-select: none;
  overflow-x: hidden;
}

/* ── HEADER ── */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, #16213e 0%, #0f3460 100%);
  border-bottom: 3px solid #e94560;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

#game-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f0c040;
  white-space: nowrap;
}

/* Pure-CSS Poké Ball (matching pokemon game) */
.pokeball {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(to bottom, #e63946 50%, #fff 50%);
  border: 3px solid #222;
  position: relative;
  flex-shrink: 0;
  animation: spin 4s linear infinite;
}
.pokeball::before {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%,-50%);
  width: 100%; height: 3px;
  background: #222;
}
.pokeball::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%,-50%);
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #222;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stat-group {
  display: flex;
  gap: 16px;
  margin-left: auto;
  align-items: center;
  flex-wrap: wrap;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.08);
  padding: 6px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
}
.stat-label { font-size: 0.65rem; color: #aaa; text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-size: 1.1rem; font-weight: 700; color: #f0c040; }

/* ── BOARD ── */
#board-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: calc(100vh - 83px);
}

#board {
  --gap: 8px;
  --avail-h: calc(100vh - 140px);
  --card-h: calc((var(--avail-h) - (var(--rows, 3) - 1) * var(--gap)) / var(--rows, 3));
  --w-from-h: calc(var(--cols, 4) * var(--card-h) * 5 / 7 + (var(--cols, 4) - 1) * var(--gap));

  display: grid;
  grid-template-columns: repeat(var(--cols, 4), 1fr);
  gap: var(--gap);
  width: min(95vw, var(--w-from-h));
}

/* ── CARD ── */
.card {
  aspect-ratio: 5 / 7;
  perspective: 700px;
  cursor: pointer;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.48s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 8px;
}

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

.card-back,
.card-front {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* ── CARD BACK — TCG-style blue/gold ── */
.card-back {
  background: linear-gradient(160deg, #0d1b4e 0%, #1e2f8a 50%, #0d1b4e 100%);
  border: 3px solid #c8a020;
  box-shadow: inset 0 0 0 2px rgba(200,160,32,0.18), inset 0 0 24px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Watermark pokeball */
.cb-ball {
  width: 52%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.22);
  background: linear-gradient(to bottom, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 50%);
  position: relative;
  pointer-events: none;
}
.cb-ball::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 100%; height: 1.5px;
  background: rgba(255,255,255,0.22);
}
.cb-ball::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 26%; height: 26%;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 1.5px solid rgba(255,255,255,0.28);
}

/* ── CARD FRONT — TCG-style ── */
.card-front {
  transform: rotateY(180deg);
  background: #eee;
  border: 3px solid #c8a020;
  box-shadow: inset 0 0 0 2px rgba(200,160,32,0.2);
  display: flex;
  flex-direction: column;
}

/* Colored top stripe (type colour via --tc) */
.cf-stripe {
  flex: 0 0 22%;
  background: var(--tc, #e63946);
  display: flex;
  align-items: center;
  padding: 0 8%;
  gap: 6px;
}
.cf-stripe-ball {
  width: 16%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(to bottom, rgba(255,255,255,0.7) 50%, rgba(255,255,255,0.3) 50%);
  border: 1.5px solid rgba(0,0,0,0.25);
  flex-shrink: 0;
  position: relative;
}
.cf-stripe-ball::before {
  content: '';
  position: absolute;
  left: 0; top: 50%; transform: translateY(-50%);
  width: 100%; height: 1.5px;
  background: rgba(0,0,0,0.25);
}
.cf-stripe-ball::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 30%; height: 30%;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(0,0,0,0.2);
}
.cf-dex {
  font-size: 0.6em;
  font-weight: 800;
  color: rgba(255,255,255,0.9);
  letter-spacing: 0.04em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  white-space: nowrap;
  overflow: hidden;
}

/* Art area */
.cf-art {
  flex: 1;
  background: radial-gradient(ellipse at 50% 40%, #f5f5f5 0%, #dde4f0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cf-art img {
  height: 100%;
  max-width: 100%;
  width: auto;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.35));
}

/* Footer name bar */
.cf-footer {
  flex: 0 0 18%;
  background: var(--tc, #e63946);
  border-top: 2px solid rgba(200,160,32,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6%;
}
.cf-footer span {
  font-size: 0.58em;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  text-transform: capitalize;
  letter-spacing: 0.05em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── MATCHED ── */
.card.matched .card-front {
  border-color: #2ecc71;
  box-shadow: 0 0 18px rgba(46,204,113,0.7), inset 0 0 0 2px rgba(46,204,113,0.3);
  animation: match-glow 0.55s ease;
}
@keyframes match-glow {
  0%   { box-shadow: 0 0 0px rgba(46,204,113,0); }
  50%  { box-shadow: 0 0 32px rgba(46,204,113,1); }
  100% { box-shadow: 0 0 18px rgba(46,204,113,0.7); }
}

/* ── WRONG PAIR ── */
.card.wrong .card-inner {
  animation: card-shake 0.38s ease;
}
@keyframes card-shake {
  0%,100% { transform: rotateY(180deg) translateX(0); }
  20%      { transform: rotateY(180deg) translateX(-6px); }
  40%      { transform: rotateY(180deg) translateX(6px); }
  60%      { transform: rotateY(180deg) translateX(-5px); }
  80%      { transform: rotateY(180deg) translateX(4px); }
}
.card.wrong .card-front {
  border-color: #e63946;
  box-shadow: 0 0 16px rgba(230,57,70,0.65);
}

/* ── CONFETTI ── */
.confetti-dot {
  position: fixed;
  width: 10px; height: 10px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 300;
  animation: confetti-fall 1.2s ease-in forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(400px) rotate(720deg); opacity: 0; }
}

/* ── START SCREEN ── */
#start-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
#start-screen h1 { font-size: 2.8rem; color: #f0c040; text-shadow: 0 0 20px rgba(240,192,64,0.5); }
#start-screen p  { color: #aaa; font-size: 1rem; max-width: 380px; text-align: center; line-height: 1.6; }

.big-pokeball {
  width: 100px; height: 100px;
  border-radius: 50%;
  background: linear-gradient(to bottom, #e63946 50%, #fff 50%);
  border: 6px solid #222;
  position: relative;
  animation: spin 3s linear infinite;
}
.big-pokeball::before {
  content: ''; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%,-50%); width: 100%; height: 6px; background: #222;
}
.big-pokeball::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%,-50%); width: 28px; height: 28px;
  border-radius: 50%; background: #fff; border: 6px solid #222;
}

/* ── OVERLAYS ── */
#ready-overlay,
#win-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.80);
  z-index: 450;
  align-items: center;
  justify-content: center;
}
#ready-overlay.show,
#win-overlay.show { display: flex; }

.overlay-box {
  background: linear-gradient(135deg, #16213e, #0f3460);
  border: 3px solid #e94560;
  border-radius: 20px;
  padding: 40px 50px;
  text-align: center;
  box-shadow: 0 0 60px rgba(233,69,96,0.4);
  animation: pop-in 0.4s cubic-bezier(0.175,0.885,0.32,1.275);
  max-width: 90vw;
}
@keyframes pop-in {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.overlay-box h2 { font-size: 2rem; color: #f0c040; margin-bottom: 8px; }

.action-btn {
  margin-top: 20px;
  padding: 14px 36px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  transition: transform 0.15s;
}
.green-btn { background: #2ecc71; box-shadow: 0 4px 15px rgba(46,204,113,0.5); }
.green-btn:hover { background: #27ae60; transform: scale(1.05); }
.red-btn   { background: #e63946; box-shadow: 0 4px 15px rgba(230,57,70,0.5); }
.red-btn:hover { transform: scale(1.05); }

#start-btn {
  padding: 16px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  background: #e63946;
  color: #fff;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(230,57,70,0.5);
  transition: transform 0.15s;
}
#start-btn:hover { transform: scale(1.06); }
