:root {
  --bg1: #1b2a4a;
  --bg2: #102038;
  --card: #f6f3e9;
  --card-back: linear-gradient(135deg, #5b7cc4, #3a55a0);
  --accent: #ffcf5c;
  --good: #4fd18b;
  --ink: #20314f;
  --paper: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: #eef3ff;
  background: radial-gradient(120% 120% at 50% 0%, var(--bg1), var(--bg2));
  display: flex;
  justify-content: center;
}

.wrap {
  width: 100%;
  max-width: 560px;
  padding: 24px 16px 40px;
}

.head { text-align: center; margin-bottom: 18px; }
.head h1 { margin: 0; font-size: 1.9rem; letter-spacing: 0.04em; }
.head .sub { margin: 6px 0 0; color: #aebfe0; font-size: 0.92rem; }

.view { animation: fadeIn 0.35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.lead { text-align: center; color: #cdd9f5; line-height: 1.7; }

.levels { display: grid; gap: 12px; margin: 18px 0; }
.level-btn {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: var(--paper);
  color: #eef3ff;
  border-radius: 14px;
  padding: 16px 18px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease;
}
.level-btn:hover { transform: translateY(-2px); border-color: var(--accent); background: rgba(255, 255, 255, 0.1); }
.level-btn .lv-name { font-size: 1.15rem; font-weight: 700; }
.level-btn .lv-desc { display: block; margin-top: 4px; color: #aebfe0; font-size: 0.85rem; }
.level-btn .lv-best { display: block; margin-top: 6px; color: var(--accent); font-size: 0.82rem; }

.rules {
  margin-top: 10px;
  background: var(--paper);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.88rem;
  color: #cdd9f5;
}
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { margin: 8px 0 4px; padding-left: 1.2em; line-height: 1.7; }

.stats {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 16px;
}
.stat {
  flex: 1;
  background: var(--paper);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.stat-label { display: block; font-size: 0.72rem; color: #aebfe0; letter-spacing: 0.08em; }
.stat-val { display: block; font-size: 1.25rem; font-weight: 700; margin-top: 2px; }

.board {
  display: grid;
  gap: 10px;
  justify-content: center;
}

.cell { aspect-ratio: 3 / 4; perspective: 600px; }

.card {
  width: 100%;
  height: 100%;
  position: relative;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
  border-radius: 12px;
}
.card.flipped, .card.matched { transform: rotateY(180deg); }
.card:disabled { cursor: default; }

.face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: clamp(1.6rem, 9vw, 2.4rem);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}
.face.back {
  background: var(--card-back);
  color: rgba(255, 255, 255, 0.85);
}
.face.back::after { content: "?"; font-weight: 700; font-size: 1.4rem; opacity: 0.8; }
.face.front {
  background: var(--card);
  color: var(--ink);
  transform: rotateY(180deg);
}
.card.matched .face.front { background: #dff6e8; box-shadow: 0 0 0 2px var(--good), 0 4px 12px rgba(0, 0, 0, 0.2); }
.card.matched { animation: pop 0.4s ease; }
@keyframes pop { 0% { transform: rotateY(180deg) scale(1); } 50% { transform: rotateY(180deg) scale(1.08); } 100% { transform: rotateY(180deg) scale(1); } }

.actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--accent); color: #2a2207; }
.btn.ghost { background: var(--paper); color: #eef3ff; border: 1px solid rgba(255, 255, 255, 0.18); }

.clear-card {
  text-align: center;
  background: var(--paper);
  border-radius: 18px;
  padding: 30px 20px;
  margin-top: 10px;
}
.clear-emoji { font-size: 3rem; }
.clear-card h2 { margin: 6px 0 12px; }
.clear-summary { font-size: 1.05rem; line-height: 1.7; }
.clear-best { color: var(--accent); font-weight: 600; margin-top: 8px; min-height: 1.2em; }

.foot { text-align: center; color: #7e90b8; font-size: 0.78rem; margin-top: 30px; }

@media (prefers-reduced-motion: reduce) {
  .view, .card, .card.matched { animation: none; transition: none; }
}
