/*
  しんけいすいじゃく だけの みため
  （いろなどの きほんは ../common/common.css に ある）
*/

:root {
  --color-miss: #ef3b55;        /* ちがった カードの わく（あか） */
  --color-card-back: #2fbcf5;   /* カードの うらの いろ */
  --color-card-back2: #1fa3dd;
}

/* ===== がめん1: せってい ===== */
.setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 20px 32px;
}

.rule-text {
  width: 100%;
  margin: 0;
  padding: 10px 16px;
  border-radius: var(--radius-medium);
  background: #f1effb;
  font-size: 1.05rem;
  text-align: center;
  word-break: keep-all; /* ことばの とちゅうで おりかえさない */
}

.setting {
  width: 100%;
}

.setting-title {
  margin: 0 0 12px;
  font-size: 1.15rem;
  text-align: center;
}

.setting-note {
  margin: 8px 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-text-sub);
  text-align: center;
  word-break: keep-all;
}

/* カードの まいすう */
.pairs-label {
  margin: 0;
  font-size: 1.2rem;
  text-align: center;
}

.pairs-value {
  margin-right: 2px;
  font-size: 2.2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

/* スライダー（スライドパズルと おなじ かたち） */
.pairs-slider {
  display: block;
  width: 100%;
  max-width: 360px;
  height: 40px;
  margin: 8px auto 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  touch-action: manipulation;
}

.pairs-slider::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 6px;
  background: var(--color-line);
}

.pairs-slider::-moz-range-track {
  height: 12px;
  border-radius: 6px;
  background: var(--color-line);
}

.pairs-slider::-webkit-slider-thumb {
  width: 34px;
  height: 34px;
  margin-top: -11px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--color-main);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  appearance: none;
  -webkit-appearance: none;
}

.pairs-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--color-main);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.pairs-slider:focus-visible {
  outline: 3px solid var(--color-yellow);
  outline-offset: 4px;
  border-radius: 8px;
}

.pairs-ticks {
  display: flex;
  justify-content: space-between;
  max-width: 360px;
  margin: 0 auto;
  padding: 0 4px;
  font-size: 0.85rem;
  color: var(--color-text-sub);
}

/* えらぶ ボタン（みせかた・ハート） */
.choice-list {
  display: grid;
  gap: 8px;
  max-width: 420px;
  margin: 0 auto;
}

.choice-list--show {
  grid-template-columns: repeat(3, 1fr);
}

.choice-list--heart {
  grid-template-columns: repeat(6, 1fr);
}

.choice {
  display: block;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ほんものの ラジオボタンは みえなく する（キーボードでは つかえる） */
.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 6px 2px;
  border: 3px solid var(--color-line);
  border-radius: var(--radius-medium);
  background: #faf9ff;
  font-size: 1rem;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}

.choice:hover .choice-inner {
  border-color: #c9c5ee;
}

.choice input:checked + .choice-inner {
  border-color: var(--color-main);
  background: var(--color-main);
  color: #fff;
}

.choice input:focus-visible + .choice-inner {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.setup-best {
  margin: 0;
  padding: 8px 18px;
  border-radius: 999px;
  background: #f1effb;
  font-size: 0.95rem;
  color: var(--color-text-sub);
  text-align: center;
}

.setup-best span {
  color: var(--color-text);
}

/* ===== がめん2: あそぶ ===== */
.play {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 960px;
  margin: 0 auto;
}

/* めくった かいすう・じかん・ハート */
.hud {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 560px;
}

.hud-item {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 4px 4px 6px;
  border-radius: var(--radius-medium);
  background: rgba(255, 255, 255, 0.1);
}

.hud-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
}

.hud-value {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 1.8rem;
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.hud-value--hearts {
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

.heart {
  color: var(--color-pink);
}

/* へった ハートは うすく のこす */
.heart--lost {
  color: rgba(255, 255, 255, 0.22);
}

/* ハート「なし」 */
.hud-value--none {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.6);
}

/* テーマ と ベスト */
.info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 14px;
  font-size: 0.9rem;
}

.genre {
  padding: 2px 14px;
  border-radius: 999px;
  background: var(--color-yellow);
  color: var(--color-text);
}

.play-best {
  color: rgba(255, 255, 255, 0.8);
}

.play-best span {
  color: var(--color-yellow);
}

/* ===== ばんめん ===== */
/* ばんめんの おきば（のこりの たかさを ぜんぶ もらう） */
.board-area {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 160px;
}

.board {
  --cols: 4;           /* れつの かず（main.js で かえる） */
  --card-size: 80px;   /* カードの おおきさ（main.js で かえる） */
  --gap: 6px;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--card-size));
  gap: var(--gap);
  justify-content: center;
}

/* カード（ボタン） */
.card {
  width: var(--card-size);
  height: var(--card-size);
  padding: 0;
  border: none;
  background: none;
  font-family: inherit;
  cursor: pointer;
  perspective: 600px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.card:focus-visible {
  outline: 3px solid var(--color-yellow);
  outline-offset: 2px;
  border-radius: 12px;
}

/* みせている あいだ・そろった カードは おせない みため */
.board--locked .card,
.card.is-matched {
  cursor: default;
}

/* うら と おもてを かさねて、まわして めくる */
.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.35s;
}

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

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* カードの うら */
.card-back {
  border: 3px solid #fff;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.28) 0 22%, transparent 23%),
    repeating-linear-gradient(45deg, var(--color-card-back) 0 8px, var(--color-card-back2) 8px 16px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.card-back::after {
  content: "?";
  color: #fff;
  font-size: calc(var(--card-size) * 0.34);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.card:hover .card-back {
  filter: brightness(1.08);
}

/* カードの おもて */
.card-front {
  padding: 5% 2% 4%;
  border: 3px solid #d9d6ef;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  transform: rotateY(180deg);
}

.card-front svg {
  flex: 1;
  width: 100%;
  min-height: 0;
}

/* なまえ（もじの かずに あわせて おおきさを かえる。--len は main.js で いれる） */
.card-name {
  max-width: 100%;
  font-size: min(14px, calc(var(--card-size) * 0.16), calc(var(--card-size) * 0.88 / var(--len)));
  line-height: 1.25;
  letter-spacing: -0.03em;
  color: var(--color-text);
  white-space: nowrap;
}

/* 2ぎょうに わけた なまえ（ぎょうの あいだを つめる） */
.card-name--2lines {
  line-height: 1.05;
}

/* そろった カードは みどりの わく */
.card.is-matched .card-front {
  border-color: var(--color-green);
  background: #eafbf2;
}

/* ちがった カードは あかい わく */
.card.is-wrong .card-front {
  border-color: var(--color-miss);
  background: #fff0f2;
}

/* クリアしたとき カードが はねる */
.board--clear .card-front {
  animation: card-pop 0.5s ease-out;
}

@keyframes card-pop {
  50% { scale: 1.08; }
}

/* ===== メッセージ ===== */
.message {
  min-height: 1.6em;
  margin: 0;
  font-size: 1.05rem;
  text-align: center;
}

.message--hit {
  color: var(--color-green);
}

.message--miss {
  color: var(--color-pink);
}

/* ===== ハートが なくなったとき ===== */
.over-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 420px;
  padding: 18px 16px 20px;
  text-align: center;
}

.over-title {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1.2;
  color: var(--color-accent-dark);
}

.over-text {
  margin: 0 0 6px;
}

.play-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

/* ===== クリアの がめん（スライドパズルと おなじ かたち） ===== */
.clear-dialog {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 10, 40, 0.6);
  animation: fade-in 0.25s;
}

.clear-dialog[hidden] {
  display: none;
}

.clear-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 20px 24px;
  text-align: center;
  animation: pop-in 0.4s cubic-bezier(0.3, 1.5, 0.6, 1);
}

.clear-title {
  margin: 0;
  font-size: 2.6rem;
  font-weight: 900;
  line-height: 1.1;
  color: var(--color-main);
  letter-spacing: 0.08em;
}

/* 「クリア！」の まわりの ほし */
.clear-title::before,
.clear-title::after {
  content: "★";
  display: inline-block;
  margin: 0 8px;
  font-size: 0.55em;
  color: var(--color-yellow);
  vertical-align: middle;
  animation: twinkle 1.2s ease-in-out infinite;
}

.clear-title::after {
  animation-delay: 0.6s;
}

.new-record {
  margin: -6px 0 0;
  padding: 4px 16px;
  border-radius: 999px;
  background: var(--color-pink);
  color: #fff;
  animation: pop-in 0.5s 0.2s both;
}

.result-text {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-medium);
  background: #f1effb;
  font-size: 1.05rem;
  line-height: 1.7;
  word-break: keep-all;
}

.result-number {
  font-size: 1.5em;
  font-weight: 900;
  color: var(--color-main-dark);
  font-variant-numeric: tabular-nums;
}

.clear-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

/* きょうしつへの ボタン（こどもが おしたく なる みため） */
.studio-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  margin-top: 4px;
  padding: 14px 16px;
  border: 3px dashed #c9c5ee;
  border-radius: var(--radius-medium);
  background: #faf9ff;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.studio-button:hover {
  border-color: var(--color-accent);
  background: #eef9ff;
}

.studio-button-main {
  font-size: 1.05rem;
  color: var(--color-text);
}

.studio-button-sub {
  font-size: 0.85rem;
  color: var(--color-accent-dark);
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.7); }
}

@keyframes twinkle {
  50% { transform: scale(1.4) rotate(20deg); }
}

/* ===== ちいさい がめん（スマホ）===== */
@media (max-width: 600px) {
  .rule-text {
    padding: calc(6px + var(--spare) * 4 / 190) 10px;
    font-size: calc(0.9rem + var(--spare) * 1.6 / 190);
    letter-spacing: -0.02em;
  }

  .pairs-label {
    font-size: calc(1rem + var(--spare) * 1.6 / 190);
    line-height: 1.3;
  }

  .pairs-value {
    font-size: calc(1.6rem + var(--spare) * 6.4 / 190);
  }

  .pairs-slider {
    height: 36px;
    margin-top: calc(2px + var(--spare) * 4 / 190);
  }

  .pairs-ticks {
    margin-top: -4px;
    font-size: calc(0.75rem + var(--spare) * 1.6 / 190);
  }

  .choice-inner {
    min-height: calc(44px + var(--spare) * 8 / 190);
    font-size: calc(0.95rem + var(--spare) * 0.8 / 190);
  }

  .play {
    gap: calc(6px + var(--spare) * 8 / 190);
  }

  .hud-item {
    padding: calc(2px + var(--spare) * 4 / 190) 4px calc(3px + var(--spare) * 4 / 190);
  }

  .hud-label {
    font-size: calc(0.72rem + var(--spare) * 1.28 / 190);
  }

  .hud-value {
    height: calc(1.5rem + var(--spare) * 6.4 / 190);
    font-size: calc(1.2rem + var(--spare) * 4.0 / 190);
  }

  .info {
    font-size: calc(0.8rem + var(--spare) * 1.6 / 190);
  }

  .message {
    min-height: 1.5em;
    font-size: calc(0.95rem + var(--spare) * 1.6 / 190);
    line-height: 1.5;
  }

  .over-box {
    padding: calc(10px + var(--spare) * 8 / 190) 12px calc(12px + var(--spare) * 8 / 190);
    gap: calc(4px + var(--spare) * 6 / 190);
  }

  .play-buttons {
    gap: 8px;
  }

  .play-buttons .btn {
    padding: 6px 16px;
    font-size: calc(0.9rem + var(--spare) * 1.6 / 190);
  }
}

/* うごきを へらす せっていの ひとには、カードが まわる うごきを なくす */
@media (prefers-reduced-motion: reduce) {
  .card-inner {
    transition: none;
  }

  .board--clear .card-front {
    animation: none;
  }
}

/* たかさが みじかい スマホでは、もっと つめる */
@media (max-width: 600px) and (max-height: 620px) {
  .page--game .setup {
    gap: 8px;
    padding-top: 10px;
  }

  .pairs-slider {
    height: 32px;
  }
}
