/* 翻牌寻宝 · 记忆配对 — 香槟金主题（视觉增强版） */

:root {
  --bg: #09090b;
  --bg-elev: #111114;
  --card: rgba(22, 22, 26, 0.7);
  --card2: rgba(28, 28, 34, 0.8);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #c9a227;
  --accent-2: #e8d48b;
  --accent-dim: rgba(201, 162, 39, .14);
  --on-accent: #1a1408;
  --line: rgba(201, 162, 39, .2);
  --line-soft: rgba(255, 255, 255, .08);
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-pill: 999px;
}

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

html, body { height: 100%; }

body {
  background: url('../img/bg.jpg') center/cover no-repeat;
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
}

/* Dynamic Ambient Glow */
body::before, body::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  z-index: 0;
  opacity: 0.1;
  animation: float-glow 15s ease-in-out infinite alternate;
  pointer-events: none;
}
body::before {
  width: 50vw; height: 50vw;
  background: var(--accent);
  top: 10%; left: -20vw;
}
body::after {
  width: 40vw; height: 40vw;
  background: var(--accent-2);
  bottom: -10vw; right: -10vw;
  animation-delay: -5s;
}

@keyframes float-glow {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(5vw, 10vh) scale(1.1); }
}

.game-shell { display:flex; flex-direction:column; height:100dvh; max-width:560px; margin:0 auto; position:relative; z-index:1; background: rgba(0,0,0,0.65); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

/* ---- HUD ---- */
.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(17, 17, 20, 0.4);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
}

.hud-back {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-pill);
  text-decoration: none;
  background: rgba(255,255,255,0.03);
  transition: all 0.2s ease;
}
.hud-back svg { width: 18px; height: 18px; }
.hud-back:active { transform: scale(.92); }
.hud-back:hover { background: rgba(255,255,255,0.1); color: var(--text); border-color: rgba(255,255,255,0.15); }

.hud-mid { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.hud-kicker { font-size: 10px; letter-spacing: .22em; color: var(--accent); font-weight: 700; text-shadow: 0 0 8px var(--accent-dim); }
.hud-title { font-size: 17px; font-weight: 700; letter-spacing: 0.02em; }

.hud-stats { display: flex; gap: 8px; }
.hud-pill {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px 10px;
  background: rgba(201, 162, 39, 0.05);
  box-shadow: 0 0 10px inset rgba(201, 162, 39, 0.05);
}

/* ---- Board ---- */
.stage-wrap { position: relative; flex: 1; min-height: 0; display: flex; }

.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 12px;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  align-content: center;
  max-height: 100%;
}

.tile {
  position: relative;
  perspective: 1000px;
  min-height: 96px;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  border-radius: var(--r-md);
}
.tile:focus-visible .tile-inner { box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.5); }
.tile:hover { transform: translateY(-2px); }

.tile-inner {
  position: absolute;
  inset: 0;
  border-radius: var(--r-md);
  transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.34, 1.56, .64, 1); /* Enhanced bouncy flip */
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.tile.is-open .tile-inner, .tile.is-done .tile-inner { transform: rotateY(180deg); }

.tile-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.tile-front {
  background: rgba(28, 28, 34, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .15) inset, 0 8px 32px rgba(0,0,0,0.3);
}
.tile-front::after {
  content: "";
  width: 38%;
  height: 38%;
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  background: radial-gradient(circle at 35% 30%, rgba(201, 162, 39, 0.25), transparent 70%);
  box-shadow: 0 0 15px rgba(201, 162, 39, 0.1);
  transition: all 0.3s ease;
}
.tile:hover .tile-front::after {
  border-color: rgba(201, 162, 39, 0.4);
  box-shadow: 0 0 20px rgba(201, 162, 39, 0.2);
}

.tile-back {
  background: rgba(201, 162, 39, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(201, 162, 39, 0.4);
  color: var(--accent-2);
  transform: rotateY(180deg);
  box-shadow: 0 8px 32px rgba(201, 162, 39, 0.2) inset;
}
.tile-back .emoji {
  font-size: 42px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.8));
  transition: all 0.3s ease;
}

.tile.is-done .tile-back {
  border-color: rgba(201, 162, 39, .8);
  background: rgba(201, 162, 39, .35);
  box-shadow: 0 0 30px rgba(201, 162, 39, .5), 0 0 0 1px rgba(201, 162, 39, .6) inset;
}
.tile.is-done .tile-back .emoji { filter: drop-shadow(0 0 20px rgba(255, 255, 255, 1)) scale(1.15); }
.tile.is-done { cursor: default; transform: none; }

.tile.is-miss .tile-inner { animation: miss-shake .4s cubic-bezier(.36,.07,.19,.97) both; }

@keyframes miss-shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20%, 60% { transform: rotateY(180deg) translateX(-6px); }
  40%, 80% { transform: rotateY(180deg) translateX(6px); }
}

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 9, 11, .3);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 2;
}
.overlay.is-open { opacity: 1; pointer-events: auto; }

.overlay-card {
  width: 100%;
  max-width: 340px;
  background: rgba(22, 22, 26, 0.35);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .15) inset, 0 30px 60px rgba(0, 0, 0, .7), 0 0 50px rgba(201, 162, 39, 0.2);
  padding: 32px 24px 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.overlay-card::before {
  content: '';
  position: absolute;
  top: -50px; left: -50px; right: -50px; height: 150px;
  background: radial-gradient(ellipse at top, rgba(201, 162, 39, 0.15), transparent 70%);
  pointer-events: none;
}
.overlay.is-open .overlay-card { animation: card-in .4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: none; }
}

.overlay-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: linear-gradient(135deg, var(--accent-dim), transparent);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  box-shadow: 0 8px 20px rgba(201, 162, 39, 0.15);
  position: relative;
}
.overlay-icon::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  z-index: -1;
  background: var(--accent);
  opacity: 0.15;
  filter: blur(8px);
}
.overlay-icon svg { width: 32px; height: 32px; }

.overlay-kicker { font-size: 11px; letter-spacing: .2em; color: var(--accent); font-weight: 700; text-shadow: 0 0 10px var(--accent-dim); }

.overlay-card h1, .overlay-card h2 { 
  font-size: 1.7rem; 
  font-weight: 800; 
  letter-spacing: .02em; 
  margin: 8px 0 12px; 
  background: linear-gradient(to right, #fff, var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.overlay-card p { font-size: 14px; color: var(--muted); line-height: 1.7; margin-bottom: 24px; }

.stars { display: flex; justify-content: center; gap: 10px; margin: 12px 0 16px; }
.star { 
  width: 38px; height: 38px; 
  fill: rgba(28, 28, 34, 0.8); 
  stroke: rgba(255,255,255,0.1); 
  stroke-width: 1.5; 
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: scale(0.8);
}
.star.is-lit { 
  fill: var(--accent); 
  stroke: #fff; 
  filter: drop-shadow(0 0 15px rgba(232, 212, 139, 0.6)); 
  transform: scale(1.1);
}

.end-meta { font-size: 14px; color: rgba(161, 170, 184, 0.9); margin-bottom: 6px !important; font-weight: 500; }

.end-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border: none;
  border-radius: var(--r-pill);
  box-shadow: 0 8px 24px rgba(201, 162, 39, .3);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}
.btn-primary::after {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 50%; height: 100%;
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.4), transparent);
  transform: skewX(-20deg);
  animation: shine 3s infinite;
}
.btn-primary:active { transform: scale(.96); box-shadow: 0 4px 12px rgba(201, 162, 39, .2); }
.btn-primary:hover { box-shadow: 0 12px 30px rgba(201, 162, 39, .4); }
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.5); }

.btn-ghost {
  display: block;
  width: 100%;
  padding: 13px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-ghost:active { transform: scale(.96); }
.btn-ghost:hover { background: rgba(255,255,255,0.08); border-color: rgba(201, 162, 39, 0.4); color: #fff; }
.btn-ghost:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.3); }

.is-hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .overlay { transition: none; }
  .overlay.is-open .overlay-card { animation: none; }
  .tile-inner { transition: none; }
  .tile.is-miss .tile-inner { animation: none; }
  body::before, body::after, .btn-primary::after { animation: none; }
  .star { transition: none; transform: none; }
  .star.is-lit { transform: none; }
}

