/* くるまでペア！ スタイル（絵本風・子ども向け） */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --outline: #4a3b32;
  --cream: #fff8ec;
  --sky: #cdeafc;
  --red: #e94f43;
  --yellow: #ffd23e;
  --green: #62bd5c;
  --blue: #4a90d9;
  --orange: #ff8c42;
}

html,
body {
  height: 100%;
}

body {
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'ヒラギノ丸ゴ ProN', sans-serif;
  color: var(--outline);
  background: linear-gradient(180deg, #bde3fa 0%, #dff1fd 45%, #fff8ec 100%);
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}

.screen.active {
  display: flex;
}

/* ---------- タイトル画面 ---------- */
#screen-title {
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.title-sun {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 46px;
  height: 46px;
  z-index: -1;
  border-radius: 50%;
  background: var(--yellow);
  border: 5px solid var(--outline);
  box-shadow: 0 0 0 10px rgba(255, 210, 62, 0.35);
}

.title-logo {
  font-size: clamp(2.2rem, 9vw, 3.6rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow:
    3px 3px 0 #fff,
    -3px 3px 0 #fff,
    3px -3px 0 #fff,
    -3px -3px 0 #fff;
}

.title-logo .accent {
  color: var(--red);
}

.title-sub {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
}

/* マイケルくんガイド */
.guide {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0;
}

.michael {
  width: 96px;
  height: auto;
  filter: drop-shadow(0 4px 0 rgba(74, 59, 50, 0.15));
}

.guide-clear .michael {
  width: 112px;
}

.bubble {
  position: relative;
  background: #fff;
  border: 4px solid var(--outline);
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 1.05rem;
  font-weight: 800;
  box-shadow: 0 3px 0 var(--outline);
  text-align: left;
  color: var(--outline);
}

.bubble::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
  border: 8px solid transparent;
  border-right: 10px solid var(--outline);
}

.bubble::after {
  content: '';
  position: absolute;
  left: -9px;
  top: 50%;
  transform: translateY(-50%);
  border: 7px solid transparent;
  border-right: 8px solid #fff;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.level-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(80vw, 300px);
  margin-top: 10px;
}

.btn {
  font-family: inherit;
  font-weight: 800;
  color: var(--outline);
  border: 4px solid var(--outline);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.btn:active {
  transform: scale(0.95);
}

.btn-level {
  font-size: 1.5rem;
  padding: 16px 20px;
  box-shadow: 0 5px 0 var(--outline);
}

.btn-level:active {
  box-shadow: 0 2px 0 var(--outline);
  transform: translateY(3px);
}

.btn-level[data-level='easy'] {
  background: var(--green);
  color: #fff;
}

.btn-level[data-level='normal'] {
  background: var(--yellow);
}

.btn-level[data-level='hard'] {
  background: var(--red);
  color: #fff;
}

.btn-level small {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.9;
}

/* ---------- ゲーム画面 ---------- */
#screen-game {
  gap: 10px;
  height: 100dvh;
  overflow: hidden;
  padding: 12px;
}

.game-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  row-gap: 8px;
  width: min(100%, 560px);
}

.btn-small {
  font-size: 0.85rem;
  padding: 7px 10px;
  background: #fff;
  box-shadow: 0 3px 0 var(--outline);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-mute,
.btn-bgm {
  padding: 7px 10px;
  background: #fff;
  box-shadow: 0 3px 0 var(--outline);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--outline);
}

.btn-mute.sound-off,
.btn-bgm.sound-off {
  background: #e7e2d8;
  color: #a2988a;
}

.sound-buttons {
  display: flex;
  gap: 12px;
}

.btn-peek {
  background: var(--yellow);
}

#preview-banner {
  background: var(--yellow);
  border: 4px solid var(--outline);
  border-radius: 999px;
  padding: 8px 22px;
  font-size: 1.15rem;
  font-weight: 900;
  box-shadow: 0 4px 0 var(--outline);
}

.game-stats {
  display: flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
}

.stat {
  background: #fff;
  border: 3px solid var(--outline);
  border-radius: 14px;
  padding: 3px 9px;
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
  min-width: 52px;
  white-space: nowrap;
}

.stat .stat-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  opacity: 0.75;
}

#level-name {
  font-weight: 800;
  font-size: 0.75rem;
  background: var(--sky);
  border: 3px solid var(--outline);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}

/* カードグリッド（スクロールなしで全カードが見えるよう画面高さにフィット） */
#grid {
  display: grid;
  gap: 10px;
  width: min(100%, 560px);
  flex: 1 1 auto;
  min-height: 0;
  justify-content: center;
}

#grid[data-level='easy'] {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(4, 1fr);
  width: min(100%, 380px);
}

#grid[data-level='normal'] {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  width: min(100%, 470px);
}

#grid[data-level='hard'] {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

@media (min-width: 640px) {
  #grid[data-level='easy'] {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    width: min(100%, 700px);
  }

  #grid[data-level='normal'] {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: min(100%, 620px);
  }
}

.card {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  perspective: 700px;
  padding: 0;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.85s cubic-bezier(0.35, 1.15, 0.45, 1);
}

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

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 4px solid var(--outline);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card-back {
  background: #bde3fa url('../img/card-back.png') center / cover no-repeat;
  box-shadow: 0 4px 0 var(--outline);
}

.card-front {
  background: #fff;
  transform: rotateY(180deg);
  gap: 2px;
  padding: 6px 4px;
}

.car-art {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.car-art img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  pointer-events: none;
}

.car-name {
  font-size: clamp(0.55rem, 2.4vw, 0.85rem);
  font-weight: 800;
  white-space: nowrap;
  max-width: 100%;
}

.car-name.long {
  font-size: clamp(0.48rem, 1.9vw, 0.75rem);
  letter-spacing: -0.02em;
}

.card.matched .card-inner {
  animation: pop 0.5s ease;
}

.card.matched .card-face.card-front {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 140, 66, 0.4);
}

@keyframes pop {
  0% {
    transform: rotateY(180deg) scale(1);
  }
  40% {
    transform: rotateY(180deg) scale(1.12);
  }
  100% {
    transform: rotateY(180deg) scale(1);
  }
}

/* ---------- クリア画面 ---------- */
#screen-clear {
  justify-content: center;
  gap: 16px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.clear-title {
  font-size: clamp(2.4rem, 10vw, 3.8rem);
  font-weight: 900;
  color: var(--red);
  text-shadow:
    3px 3px 0 #fff,
    -3px 3px 0 #fff,
    3px -3px 0 #fff,
    -3px -3px 0 #fff;
  animation: bounce 1.6s ease-in-out infinite;
}

.clear-stats {
  display: flex;
  gap: 14px;
}

.clear-stat {
  background: #fff;
  border: 4px solid var(--outline);
  border-radius: 18px;
  padding: 12px 22px;
  font-size: 1.6rem;
  font-weight: 900;
}

.clear-stat .stat-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.75;
}

.clear-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(80vw, 300px);
  z-index: 1;
}

.btn-clear-action {
  font-size: 1.3rem;
  padding: 14px 20px;
  box-shadow: 0 5px 0 var(--outline);
}

#btn-retry {
  background: var(--orange);
  color: #fff;
}

#btn-change-level {
  background: #fff;
}

/* ---------- 設定画面 ---------- */
#screen-settings {
  justify-content: center;
  gap: 16px;
}

.settings-title {
  font-size: 1.8rem;
  font-weight: 900;
}

.settings-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(88vw, 340px);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 4px solid var(--outline);
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: 0 3px 0 var(--outline);
}

.settings-label {
  font-weight: 800;
  color: var(--outline);
}

.theme-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.settings-row-wrap {
  flex-wrap: wrap;
  row-gap: 8px;
}

.theme-buttons .btn-small.active {
  background: var(--yellow);
}

.michael-intro {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 4px solid var(--outline);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 3px 0 var(--outline);
  width: min(88vw, 340px);
}

.michael-intro img {
  width: 60px;
  flex-shrink: 0;
}

.michael-intro p {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: left;
  line-height: 1.6;
  color: var(--outline);
}

.michael-intro a {
  color: var(--blue);
}

.btn-settings-back {
  background: #fff;
  width: min(88vw, 340px);
}

/* ---------- ダークモード ---------- */
body {
  transition: background 0.3s ease;
}

body.dark {
  background: linear-gradient(180deg, #1b2440 0%, #273455 55%, #3b3350 100%);
}

body.dark .title-logo,
body.dark .title-sub,
body.dark .settings-title {
  color: #fff6e6;
  text-shadow:
    3px 3px 0 #1b2440,
    -3px 3px 0 #1b2440,
    3px -3px 0 #1b2440,
    -3px -3px 0 #1b2440;
}

body.dark .title-logo .accent {
  color: #ff8d84;
}

body.dark .title-sun {
  opacity: 0.35;
}

body.dark .clear-title {
  text-shadow:
    3px 3px 0 #1b2440,
    -3px 3px 0 #1b2440,
    3px -3px 0 #1b2440,
    -3px -3px 0 #1b2440;
}

#confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  animation: fall linear infinite;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(720deg);
  }
}
