/*
  スライドパズル だけの みため
  （いろなどの きほんは ../common/common.css に ある）
*/

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

.setting {
  width: 100%;
}

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

/* マスの かずの みほん */
.size-view {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.size-icon {
  display: grid;
  gap: 3px;
  width: 64px;
  height: 64px;
  padding: 4px;
  border-radius: 10px;
  background: var(--color-bg);
}

.size-icon span {
  border-radius: 3px;
  background: var(--color-accent);
}

/* さいごの 1つは あいている マス */
.size-icon span:last-child {
  background: transparent;
}

.size-label {
  margin: 0;
  font-size: 2.2rem;
  font-weight: 900;
}

/* スライダー（ゆびで うごかしやすいように おおきく する） */
.size-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;
}

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

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

.size-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;
}

.size-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);
}

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

.size-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);
}

/* むずかしさの えらぶ ボタン */
.mode-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

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

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

.mode-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  padding: 12px 14px;
  border: 3px solid var(--color-line);
  border-radius: var(--radius-medium);
  background: #faf9ff;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

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

.mode-card input:checked + .mode-inner {
  border-color: var(--color-main);
  background: #fff4ee;
  transform: scale(1.02);
}

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

.mode-stars {
  color: var(--color-yellow);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  -webkit-text-stroke: 1px #e0a800;
}

.star-off {
  color: #e6e4f2;
  -webkit-text-stroke: 0;
}

.mode-name {
  font-size: 1.1rem;
}

.mode-desc {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--color-text-sub);
}

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

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

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

/* てかず・じかん・ベスト */
.hud {
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 560px;
}

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

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

/* 3つの わくの すうじの ところは、おなじ たかさに して まんなかに そろえる */
.hud-value {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* ベストは もじを ちいさく して、とちゅうで おりかえさない */
.hud-value--small {
  font-size: 1rem;
  white-space: nowrap;
}

/* スマホでは ベストを「てかず」と「じかん」の 2だんに わける */
@media (max-width: 600px) {
  .hud-value--small {
    flex-direction: column;
    font-size: 0.85rem;
    line-height: 1.15;
  }

  .best-separator {
    display: none;
  }
}

.hud-item--best .hud-label {
  color: var(--color-yellow);
}

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

.board {
  --n: 3;            /* マスの かず（main.js で かえる） */
  --gap: 8px;        /* ばんめんの ふち */
  position: relative;
  /* おきばの はば と たかさの どちらにも おさまる おおきさに する */
  width: min(100cqw, 100cqh, 560px);
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  background: #2b2d72;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.45), var(--shadow);
  container-type: inline-size;
  transition: box-shadow 0.4s;
}

.tiles {
  position: absolute;
  inset: var(--gap);
}

/* ピース（ばしょは transform で きめる） */
.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--n));
  height: calc(100% / var(--n));
  padding: max(2px, calc(1.2cqw / var(--n) * 3));
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.13s ease-out;
}

/* まぜている あいだは ゆっくり うごかす */
.board--shuffling .tile {
  transition: transform 0.6s cubic-bezier(0.5, 0, 0.3, 1);
}

.tile-face {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: max(6px, calc(4cqw / var(--n)));
  background-color: #fff;
  background-repeat: no-repeat;
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.18),
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    0 3px 6px rgba(0, 0, 0, 0.25);
}

.tile:hover .tile-face {
  filter: brightness(1.06);
}

/* うごかせない ピースを おしたときに ぷるっと する */
.tile--no .tile-face {
  animation: shake 0.25s;
}

@keyframes shake {
  25% { transform: translateX(-4%); }
  75% { transform: translateX(4%); }
}

/* すうじ モードの おおきい すうじ */
.tile-number {
  font-size: calc(46cqw / var(--n));
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.22);
  font-variant-numeric: tabular-nums;
}

/* え ＋ ばんごう モードの ちいさい ばんごう */
.tile-number--small {
  position: absolute;
  top: 6%;
  left: 6%;
  min-width: 1.6em;
  padding: 0 0.3em;
  border-radius: 999px;
  background: rgba(20, 20, 60, 0.6);
  font-size: max(10px, calc(12cqw / var(--n)));
  line-height: 1.6;
  text-align: center;
  text-shadow: none;
}

/* おてほん（かんせいした え） */
.sample-overlay {
  position: absolute;
  inset: var(--gap);
  border-radius: 14px;
  background-size: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.sample-overlay.is-visible {
  opacity: 1;
}

/* ばんめんの うえの メッセージ */
.board-message {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 60%;
  padding: 14px 24px;
  border-radius: var(--radius-medium);
  background: rgba(18, 19, 56, 0.82);
  font-size: clamp(1.1rem, 5cqw, 1.6rem);
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.board-message-number {
  display: block;
  font-size: 2.4em;
  color: var(--color-yellow);
}

/* クリアしたとき ばんめんが ひかる */
.board--clear {
  box-shadow: 0 0 0 5px var(--color-yellow), 0 0 50px rgba(255, 210, 63, 0.6);
}

.board--clear .tile-face {
  animation: tile-pop 0.5s ease-out;
}

@keyframes tile-pop {
  50% { transform: scale(1.08); }
}

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

/* おてほんボタンを ながおし しても メニューが でないように する */
#sample-button {
  -webkit-touch-callout: none;
}

.play-hint {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
}

/* ===== クリアの がめん ===== */
.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 {
  display: flex;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.result-item {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 8px;
  border-radius: var(--radius-medium);
  background: #f1effb;
}

.result-label {
  font-size: 0.85rem;
  color: var(--color-text-sub);
}

.result-value {
  font-size: 1.8rem;
  font-weight: 900;
  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) {
  /* マスの かずは、みほん・スライダーを 1ぎょうに ならべる */
  .size-row {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .size-view {
    flex: none;
    justify-content: flex-start;
    gap: 8px;
    width: 128px;
  }

  .size-icon {
    width: calc(44px + var(--spare) * 12 / 190);
    height: calc(44px + var(--spare) * 12 / 190);
    padding: 3px;
    gap: 2px;
  }

  .size-label {
    font-size: calc(1.5rem + var(--spare) * 4.8 / 190);
    white-space: nowrap;
  }

  .size-row .size-slider {
    flex: 1;
    min-width: 0;
    margin: 0;
  }

  .size-ticks {
    max-width: none;
    margin: -8px 0 0 138px; /* スライダーの したに そろえる */
    font-size: 0.75rem;
  }

  .mode-list {
    gap: calc(8px + var(--spare) * 4 / 190);
  }

  .mode-inner {
    padding: calc(6px + var(--spare) * 6 / 190) 10px;
    gap: 0;
  }

  .mode-stars {
    font-size: calc(0.95rem + var(--spare) * 1.6 / 190);
    line-height: 1.3;
  }

  .mode-name {
    font-size: calc(0.95rem + var(--spare) * 1.6 / 190);
    line-height: 1.4;
  }

  .mode-desc {
    font-size: calc(0.72rem + var(--spare) * 1.28 / 190);
    line-height: 1.35;
    word-break: keep-all; /* ことばの とちゅうで おりかえさない */
  }

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

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

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

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

  .play-buttons {
    gap: 8px;
  }

  .play-buttons .btn {
    min-height: 44px;
    padding: 6px 12px;
    font-size: calc(0.85rem + var(--spare) * 1.6 / 190);
  }

  .play-hint {
    font-size: calc(0.75rem + var(--spare) * 1.6 / 190);
    line-height: 1.4;
  }
}
