:root {
  --bg: #f4fbfc;
  --text: #234;
  --blue: #4fc3d9;
  --blue-dark: #2fa9c0;

  --lvl1: #2f9d8f;
  --lvl2: #3d8fc4;
  --lvl3: #c98a2e;
  --lvl4: #c0603f;
  --lvl5: #7c5aa8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.top {
  text-align: center;
  padding: 20px 16px 6px;
}
.top h1 { margin: 0; font-size: 1.6rem; cursor: pointer; }
.top h1:active { opacity: 0.6; }
.top .sub { margin: 2px 0 0; color: #567; }

.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  flex-wrap: wrap;
}
.tabs.hidden { display: none; }

.tab-btn {
  border: none;
  background: #e0eef1;
  color: #345;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
}
.tab-btn:active { transform: scale(0.95); }

/* Level buttons: each level keeps its own color everywhere in the app
   (button, card background, game tiles) so it's always clear which
   level you're practicing. */
.lvl-1 { background: color-mix(in srgb, var(--lvl1) 18%, white); }
.lvl-1.active { background: var(--lvl1); color: white; }
.lvl-2 { background: color-mix(in srgb, var(--lvl2) 18%, white); }
.lvl-2.active { background: var(--lvl2); color: white; }
.lvl-3 { background: color-mix(in srgb, var(--lvl3) 18%, white); }
.lvl-3.active { background: var(--lvl3); color: white; }
.lvl-4 { background: color-mix(in srgb, var(--lvl4) 18%, white); }
.lvl-4.active { background: var(--lvl4); color: white; }
.lvl-5 { background: color-mix(in srgb, var(--lvl5) 18%, white); }
.lvl-5.active { background: var(--lvl5); color: white; }

.section-btn.active { background: var(--blue-dark); color: white; }

main { max-width: 480px; margin: 0 auto; padding: 0 16px 40px; }

.panel { display: none; }
.panel.active { display: block; }

/* --- Home / logo screen shown before any level is tapped --- */
.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 60px 20px;
}
.home-logo {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.home-hint {
  margin: 0;
  color: var(--blue-dark);
  font-weight: bold;
  font-size: 1.05rem;
  text-align: center;
}

/* --- 1枚ずつ表示するカードビューア --- */
.viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.progress {
  font-weight: bold;
  color: var(--blue-dark);
  font-size: 1rem;
}

/* Shadow lives on this outer wrapper, never on the clipped box itself —
   iOS Safari has a known bug where border-radius + overflow:hidden +
   box-shadow on the SAME element can leave a small square sliver of the
   page background peeking out at a rounded corner. Splitting the shadow
   onto a non-clipping wrapper avoids it. */
.stage-wrap {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 3 / 4;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 7.2rem;
  line-height: 1.3;
  font-weight: bold;
  color: white;
  text-align: center;
  padding: 20px;
}

.caption {
  min-height: 1.4em;
  color: var(--blue-dark);
  font-weight: bold;
  font-size: 0.95rem;
  text-align: center;
}

.nav-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.nav-btn {
  border: none;
  background: white;
  border: 2px solid var(--blue);
  color: var(--blue-dark);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
}
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn:active:not(:disabled) { transform: scale(0.92); }

.replay-btn {
  border: none;
  background: var(--blue);
  color: white;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
}
.replay-btn:active { transform: scale(0.96); }

/* --- Memory matching game --- */
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.shuffle-btn {
  border: none;
  background: var(--blue);
  color: white;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
}
.shuffle-btn:active { transform: scale(0.96); }

.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 360px;
}

.game-tile {
  border: none;
  background: none;
  padding: 0;
  aspect-ratio: 3 / 4;
  perspective: 800px;
  cursor: pointer;
}

.game-tile-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s;
  transform-style: preserve-3d;
}
.game-tile.flipped .game-tile-inner,
.game-tile.matched .game-tile-inner {
  transform: rotateY(180deg);
}

.game-tile-back,
.game-tile-front {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.game-tile-back {
  background: var(--blue);
}
.game-tile-back img {
  width: 68%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  object-fit: cover;
}
.game-tile-front {
  color: white;
  font-weight: bold;
  font-size: 1.15rem;
  text-align: center;
  padding: 6px;
  transform: rotateY(180deg);
}

.game-tile.matched {
  opacity: 0.5;
}
