/* =====================================================================
   えあわせパズル  -  style.css
   - すべてのクラスに .kc- プレフィックス（親テーマ・CMSとの衝突回避）
   - 色は var(--kl-*) を使う（カードの絵の色だけは index.html のSVGの中に閉じている）
   ===================================================================== */

.kc-page {
  margin: 0;
  padding: 0;
  background: var(--kl-bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.kc-app,
.kc-app *,
.kc-app *::before,
.kc-app *::after {
  box-sizing: border-box;
}

.kc-app {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 16px 16px;
  font-family: var(--kl-font);
  color: var(--kl-ink);
}

.kc-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.kc-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- ヘッダー ---------- */
.kc-topbar {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 4px;
}

.kc-header {
  margin: 4px 0 14px;
  text-align: center;
}

.kc-title {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  line-height: 1.25;
}

.kc-title::after {
  content: "";
  display: block;
  width: 84px;
  height: 6px;
  margin: 8px auto 0;
  border-radius: 3px;
  background: var(--kl-pink);
}

.kc-lead {
  margin: 8px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--kl-ink-muted);
}

/* ---------- 画面の切り替え ---------- */
.kc-screen {
  display: block;
}

.kc-screen[hidden],
.kc-dialog[hidden],
.kc-level-best[hidden],
.kc-result-new[hidden] {
  display: none;
}

/* ゲーム領域は、誤ジェスチャー（ダブルタップ拡大・長押しメニュー）を防ぐ */
.kc-main {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.kc-panel {
  position: relative;
  padding: 20px 16px 22px;
  background: var(--kl-card);
  border: var(--kl-border) solid var(--kl-line);
  border-radius: var(--kl-radius-lg);
  box-shadow: 0 6px 0 var(--kl-line-shadow);
  text-align: center;
}

/* ---------- ボタン ---------- */
.kc-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 56px;
  margin: 0;
  padding: 8px 18px;
  border: 4px solid var(--kl-line);
  border-radius: var(--kl-radius);
  background: var(--kl-card);
  color: var(--kl-ink);
  font-family: inherit;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--kl-line-shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
  touch-action: manipulation;
}

.kc-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--kl-line-shadow);
}

.kc-btn:focus-visible {
  outline: 4px solid var(--kl-focus);
  outline-offset: 2px;
}

.kc-icon-btn {
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
}

.kc-ico {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* おと ON / OFF（aria-pressed で切り替える） */
.kc-sound-btn[aria-pressed="true"] .kc-ico-off,
.kc-sound-btn[aria-pressed="false"] .kc-ico-on {
  display: none;
}

.kc-sound-btn[aria-pressed="false"] {
  background: var(--kl-purple-soft);
  color: var(--kl-ink-muted);
}

.kc-sound-corner {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* いちばんおしてほしいボタン */
.kc-primary-btn,
.kc-start-btn {
  background: var(--kl-yellow);
  border-color: var(--kl-yellow-dark);
  box-shadow: 0 5px 0 var(--kl-yellow-dark);
}

.kc-primary-btn:active,
.kc-start-btn:active {
  box-shadow: 0 1px 0 var(--kl-yellow-dark);
}

/* ---------- タイトル ---------- */
.kc-mascots {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 64px;
}

.kc-mascot {
  display: block;
  width: 52px;
  height: 52px;
  animation: kc-bob 1.8s ease-in-out infinite;
}

.kc-mascot:nth-child(2) { animation-delay: 0.2s; }
.kc-mascot:nth-child(3) { animation-delay: 0.4s; }
.kc-mascot:nth-child(4) { animation-delay: 0.6s; }

@keyframes kc-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.kc-howto {
  margin: 14px 0 18px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.6;
}

.kc-label {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 800;
  color: var(--kl-ink-muted);
}

.kc-levels {
  display: grid;
  gap: 12px;
  margin-bottom: 22px;
}

.kc-level-btn {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name sub"
    "best best";
  align-items: center;
  column-gap: 12px;
  width: 100%;
  min-height: 64px;
  text-align: left;
}

.kc-level-name {
  grid-area: name;
  font-size: 22px;
}

.kc-level-sub {
  grid-area: sub;
  font-size: 18px;
}

.kc-level-best {
  grid-area: best;
  margin-top: 2px;
  font-size: 14px;
  font-weight: 700;
  color: var(--kl-ink-muted);
}

.kc-level-btn.is-selected {
  background: var(--kl-green);
  border-color: var(--kl-green-dark);
  box-shadow: 0 5px 0 var(--kl-green-dark);
}

.kc-level-btn.is-selected .kc-level-best {
  color: var(--kl-ink);
}

.kc-start-btn {
  width: 100%;
  min-height: 68px;
  font-size: 26px;
  letter-spacing: 2px;
}

/* ---------- ゲーム ---------- */
.kc-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto 14px;
}

.kc-status {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.kc-status:focus {
  outline: none;
}

.kc-status-main {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.3;
}

.kc-status-sub {
  font-size: 15px;
  font-weight: 700;
  color: var(--kl-ink-muted);
}

.kc-board {
  --kc-cols: 3;
  display: grid;
  grid-template-columns: repeat(var(--kc-cols), minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  perspective: 900px;
  -webkit-perspective: 900px;
}

.kc-board[data-level="easy"] { max-width: 380px; }
.kc-board[data-level="hard"] { max-width: 520px; }

/* ---------- カード ---------- */
.kc-card {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--kl-radius);
  background: none;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* 正方形にする（aspect-ratio が使えない古い Safari でも動くように） */
.kc-card::before {
  content: "";
  display: block;
  padding-top: 100%;
}

.kc-card:focus-visible {
  outline: 4px solid var(--kl-focus);
  outline-offset: 3px;
}

.kc-card-inner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 0.35s ease;
}

.kc-card[data-state="up"] .kc-card-inner,
.kc-card[data-state="matched"] .kc-card-inner {
  transform: rotateY(180deg);
}

.kc-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--kl-border) solid;
  border-radius: var(--kl-radius);
  box-shadow: 0 4px 0 var(--kl-line-shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* 回転のちょうど半分（横向きになる瞬間）で表裏を入れ替える。
     WebKit では backface-visibility だけだと、うらのカードの絵が透けて見えてしまうため、visibility でも隠す */
  transition: visibility 0s linear 0.175s;
}

.kc-face-back {
  background: var(--kl-purple);
  border-color: var(--kl-purple-dark);
}

.kc-card[data-state="up"] .kc-face-back,
.kc-card[data-state="matched"] .kc-face-back {
  visibility: hidden;
}

.kc-face-back svg {
  width: 40%;
  height: 40%;
  fill: var(--kl-card);
}

.kc-face-front {
  background: var(--kl-yellow-soft);
  border-color: var(--kl-yellow-dark);
  transform: rotateY(180deg);
  visibility: hidden;
}

.kc-card[data-state="up"] .kc-face-front,
.kc-card[data-state="matched"] .kc-face-front {
  visibility: visible;
}

.kc-face-front svg {
  width: 78%;
  height: 78%;
}

.kc-card[data-state="matched"] .kc-face-front {
  background: var(--kl-green-soft);
  border-color: var(--kl-green-dark);
}

.kc-card[data-state="matched"] .kc-face-front svg {
  animation: kc-pop 0.5s ease 0.3s;
}

@keyframes kc-pop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* そろったカードのしるし（色だけに頼らないチェック） */
.kc-check {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--kl-green-dark);
  align-items: center;
  justify-content: center;
}

.kc-check svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--kl-card);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.kc-card[data-state="matched"] .kc-check {
  display: flex;
}

/* ---------- けっか ---------- */
.kc-medal {
  display: block;
  width: 112px;
  height: 112px;
  margin: 0 auto 8px;
}

.kc-result-title {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.3;
}

.kc-result-title:focus {
  outline: none;
}

.kc-result-line {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 800;
}

.kc-result-new {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--kl-yellow);
  color: var(--kl-ink);
}

.kc-result-best {
  margin: 0 0 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--kl-ink-muted);
}

.kc-result-actions {
  display: grid;
  gap: 12px;
}

.kc-result-actions .kc-btn {
  width: 100%;
  min-height: 64px;
}

/* ---------- やめる確認 ---------- */
.kc-dialog {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* うしろを暗くする（色の直書きを避けて、文字色トークンを透かす） */
.kc-dialog::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--kl-ink);
  opacity: 0.45;
}

.kc-dialog-card {
  position: relative;
  width: 100%;
  max-width: 340px;
  padding: 22px 18px 20px;
  background: var(--kl-card);
  border: var(--kl-border) solid var(--kl-line);
  border-radius: var(--kl-radius-lg);
  box-shadow: 0 6px 0 var(--kl-line-shadow);
  text-align: center;
}

.kc-dialog-title {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 800;
}

.kc-dialog-actions {
  display: grid;
  gap: 12px;
}

.kc-dialog-actions .kc-btn {
  width: 100%;
  min-height: 60px;
}

/* ---------- 紙ふぶき ---------- */
.kc-confetti {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: none;
}

.kc-confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: kc-fall 3s ease-in forwards;
}

.kc-cc0 { background: var(--kl-pink-dark); }
.kc-cc1 { background: var(--kl-blue-dark); }
.kc-cc2 { background: var(--kl-green-dark); }
.kc-cc3 { background: var(--kl-yellow-dark); }
.kc-cc4 { background: var(--kl-purple-dark); }

@keyframes kc-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(540deg); opacity: 0.9; }
}

/* ---------- 動きをへらす設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  .kc-card-inner,
  .kc-face,
  .kc-btn {
    transition: none;
  }

  .kc-mascot,
  .kc-card[data-state="matched"] .kc-face-front svg,
  .kc-confetti-piece {
    animation: none;
  }
}

/* ---------- せまい画面 ---------- */
@media (max-width: 360px) {
  .kc-app {
    padding-right: 12px;
    padding-left: 12px;
  }

  .kc-board {
    gap: 8px;
  }
}
