/* =====================================================================
   かずをかぞえよう！さんすうクイズ  -  style.css
   - すべてのクラスに .kz- プレフィックス(親テーマ・CMSとの衝突回避)
   - --kz-u は JS がコンテナ幅から設定する基準長(文字・余白のスケール用)
   ===================================================================== */

.kz-page {
  margin: 0;
  padding: 0;
  background: #FFF4D6;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* 誤ジェスチャー防止(ダブルタップ拡大など) */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.kz-wrap {
  box-sizing: border-box;
  display: block;
  width: 100%;
  margin: 0 auto;
  padding: 12px;
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI",
               "Yu Gothic", "Meiryo", "Noto Sans JP", "Roboto", sans-serif;
  color: #5A4632;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.kz-wrap [class*="kz-"] {
  box-sizing: border-box;
}

.kz-wrap [hidden] {
  display: none !important;
}

/* ---------- Letterbox container (4:3 / portrait は 3:4) ---------- */
.kz-container {
  --kz-u: 8px;
  --kz-cell: 60px;
  position: relative;
  margin: 0 auto;
  width: min(100%, 960px, calc((100vh - 24px) * 4 / 3));
  aspect-ratio: 4 / 3;
  background: linear-gradient(180deg, #E8F6FF 0%, #FFF9E5 100%);
  border: 4px solid #FFD98A;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 8px 0 rgba(90, 70, 50, 0.14);
  touch-action: manipulation;
}

@supports (height: 100dvh) {
  .kz-container {
    width: min(100%, 960px, calc((100dvh - 24px) * 4 / 3));
  }
}

@media (orientation: portrait) {
  .kz-container {
    width: min(100%, 560px, calc((100vh - 24px) * 3 / 4));
    aspect-ratio: 3 / 4;
  }
  @supports (height: 100dvh) {
    .kz-container {
      width: min(100%, 560px, calc((100dvh - 24px) * 3 / 4));
    }
  }
}

.kz-screen {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--kz-u) * 1.6);
  gap: calc(var(--kz-u) * 1.2);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Back link (左上・小さめ。コンテナと同じ幅・左端に揃える) ---------- */
.kz-topbar {
  width: min(100%, 960px, calc((100vh - 24px) * 4 / 3));
  margin: 0 auto 4px;
  display: flex;
  justify-content: flex-start;
}

@supports (height: 100dvh) {
  .kz-topbar {
    width: min(100%, 960px, calc((100dvh - 24px) * 4 / 3));
  }
}

@media (orientation: portrait) {
  .kz-topbar {
    width: min(100%, 560px, calc((100vh - 24px) * 3 / 4));
  }
  @supports (height: 100dvh) {
    .kz-topbar {
      width: min(100%, 560px, calc((100dvh - 24px) * 3 / 4));
    }
  }
}

.kz-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 4px 12px 4px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid #E7DDC9;
  color: #8A7660;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.kz-back:active {
  background: #FFE27A;
}

.kz-back:focus-visible {
  outline: 4px solid #4D7CFF;
  outline-offset: 2px;
}

.kz-back-ico {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Buttons ---------- */
.kz-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  min-width: 52px;
  margin: 0;
  padding: 6px 14px;
  border: 4px solid #E7DDC9;
  border-radius: 20px;
  background: #FFFFFF;
  color: #5A4632;
  font-family: inherit;
  font-size: calc(var(--kz-u) * 3);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(90, 70, 50, 0.18);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.kz-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(90, 70, 50, 0.18);
}

.kz-btn:focus-visible {
  outline: 4px solid #4D7CFF;
  outline-offset: 2px;
}

.kz-btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

.kz-icon-btn {
  padding: 0;
  width: max(52px, calc(var(--kz-u) * 6.5));
  height: max(52px, calc(var(--kz-u) * 6.5));
  border-radius: 50%;
}

.kz-svg-ico {
  width: 60%;
  height: 60%;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.kz-sound-ico {
  font-size: calc(var(--kz-u) * 3.6);
  line-height: 1;
}

.kz-sound-btn[aria-pressed="false"] {
  background: #EFEAE0;
  color: #A89B86;
  text-decoration: line-through;
}

/* ---------- Title ---------- */
.kz-title-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.kz-title-screen .kz-sound-btn {
  position: absolute;
  top: calc(var(--kz-u) * 1.4);
  right: calc(var(--kz-u) * 1.4);
}

.kz-title {
  margin: 0;
  padding: 0;
  display: block;
  font-family: inherit;
  font-weight: 800;
  line-height: 1.2;
  border: 0;
}

.kz-title-line1 {
  display: block;
  font-size: calc(var(--kz-u) * 5.6);
  color: #FF6B81;
  text-shadow: 0 3px 0 #fff;
}

.kz-title-line2 {
  display: block;
  font-size: calc(var(--kz-u) * 4.6);
  color: #3A86D8;
  text-shadow: 0 3px 0 #fff;
}

.kz-mascots {
  display: flex;
  justify-content: center;
  gap: calc(var(--kz-u) * 1.2);
}

.kz-mascot {
  display: block;
  width: calc(var(--kz-u) * 6.4);
  height: calc(var(--kz-u) * 6.4);
  animation: kz-bob 1.6s ease-in-out infinite;
}

.kz-mascot svg {
  display: block;
  width: 100%;
  height: 100%;
}

.kz-setting {
  width: 100%;
}

.kz-setting-row {
  display: flex;
  gap: calc(var(--kz-u) * 1.4);
  width: 100%;
}

.kz-setting-row .kz-setting {
  flex: 1 1 0;
  min-width: 0;
}

.kz-setting-label {
  margin: 0 0 calc(var(--kz-u) * 0.6);
  font-size: calc(var(--kz-u) * 2.5);
  font-weight: 800;
  color: #8A7660;
}

.kz-seg {
  display: grid;
  gap: calc(var(--kz-u) * 1);
}

.kz-seg-3 { grid-template-columns: repeat(3, 1fr); }
.kz-seg-2 { grid-template-columns: repeat(2, 1fr); }

.kz-seg-btn {
  min-width: 0;
  padding: 6px 4px;
  font-size: calc(var(--kz-u) * 2.8);
}

.kz-seg-btn.is-selected {
  background: #FFE27A;
  border-color: #F2B705;
  transform: translateY(-2px);
}

.kz-start-btn {
  width: 100%;
  min-height: max(64px, calc(var(--kz-u) * 9));
  font-size: calc(var(--kz-u) * 4.6);
  letter-spacing: 2px;
  color: #fff;
  background: linear-gradient(180deg, #FF9BB8 0%, #F0759A 100%);
  border-color: #D9507A;
  box-shadow: 0 6px 0 #C2406A;
}

.kz-start-btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #C2406A;
}

/* ---------- Game: header / timer ---------- */
.kz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--kz-u) * 1.2);
  flex: 0 0 auto;
}

.kz-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: calc(var(--kz-u) * 0.8);
  flex: 1 1 auto;
  min-width: 0;
}

.kz-progress-text {
  margin-right: calc(var(--kz-u) * 0.6);
  font-size: calc(var(--kz-u) * 2.8);
  font-weight: 800;
}

.kz-dot {
  display: block;
  width: calc(var(--kz-u) * 2.4);
  height: calc(var(--kz-u) * 2.4);
  border-radius: 50%;
  background: #E7DDC9;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #E0D3BC;
}

.kz-dot.is-current { background: #FFD54A; box-shadow: 0 0 0 3px #F2B705; transform: scale(1.2); }
.kz-dot.is-perfect { background: #FF8FA3; box-shadow: 0 0 0 2px #E5486A; }
.kz-dot.is-retry   { background: #8AC8FF; box-shadow: 0 0 0 2px #3A86D8; }
.kz-dot.is-timeout { background: #C9C2D6; box-shadow: 0 0 0 2px #8E80A0; }

.kz-timer {
  display: flex;
  align-items: center;
  gap: calc(var(--kz-u) * 1);
  flex: 0 0 auto;
}

.kz-timer-icon {
  display: block;
  width: calc(var(--kz-u) * 3.6);
  height: calc(var(--kz-u) * 3.6);
  min-width: 24px;
  min-height: 24px;
}

.kz-timer-icon svg { display: block; width: 100%; height: 100%; }

.kz-timer.is-low .kz-timer-icon { animation: kz-wiggle 0.5s ease-in-out infinite; }

.kz-timer-track {
  flex: 1 1 auto;
  height: calc(var(--kz-u) * 2.4);
  min-height: 14px;
  border-radius: 999px;
  background: #fff;
  border: 3px solid #E0D3BC;
  overflow: hidden;
}

.kz-timer-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #5BC15B;
  transition: width 0.1s linear, background-color 0.3s ease;
}

.kz-timer.is-mid .kz-timer-fill { background: #FFC857; }
.kz-timer.is-low .kz-timer-fill { background: #FF6B6B; }

.kz-timer-sec {
  min-width: 2.2em;
  text-align: right;
  font-size: calc(var(--kz-u) * 2.8);
  font-weight: 800;
}

/* ---------- Game: question ---------- */
.kz-question {
  flex: 0 0 auto;
  padding: calc(var(--kz-u) * 1) calc(var(--kz-u) * 1.6);
  background: #fff;
  border: 4px solid #FFD98A;
  border-radius: 22px;
  text-align: center;
}

.kz-question-text {
  margin: 0;
  font-size: calc(var(--kz-u) * 3.5);
  font-weight: 800;
  line-height: 1.35;
}

.kz-hint {
  margin: calc(var(--kz-u) * 0.4) 0 0;
  min-height: 1.3em;
  font-size: calc(var(--kz-u) * 2.5);
  font-weight: 800;
  line-height: 1.3;
  color: #3A86D8;
}

.kz-hint.is-warn { color: #E5486A; }

/* ---------- Game: stage ---------- */
.kz-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  border-radius: 24px;
  background:
    radial-gradient(circle at 20% 25%, rgba(255, 255, 255, 0.9) 0 6%, transparent 7%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.9) 0 5%, transparent 6%),
    #CFEFD3;
  border: 4px solid #A8DDB0;
  overflow: hidden;
}

.kz-frame {
  position: absolute;
  top: 2%;
  height: 96%;
  border: 4px dashed #4D9BEA;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.45);
  transition: left 0.9s ease, width 0.9s ease, opacity 0.6s ease, border-color 0.9s ease, background-color 0.9s ease;
  pointer-events: none;
}

.kz-frame-a { left: 1%; width: 98%; }
.kz-frame-b { left: 50.5%; width: 0; opacity: 0; border-color: #F39A3D; }

.kz-stage.is-addition .kz-frame-a { width: 48.5%; }
.kz-stage.is-addition .kz-frame-b { width: 48.5%; opacity: 1; }

.kz-stage.is-addition.is-merged .kz-frame-a { width: 98%; border-color: #3DB46D; background: rgba(255, 255, 255, 0.55); }
.kz-stage.is-addition.is-merged .kz-frame-b { left: 50%; width: 0; opacity: 0; }

.kz-plus {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--kz-u) * 6);
  font-weight: 800;
  color: #F0759A;
  text-shadow: 0 2px 0 #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.kz-stage.is-addition:not(.is-merged) .kz-plus { opacity: 1; }

.kz-items {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.kz-item {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
  transition: left 0.9s ease, top 0.9s ease;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.kz-item:focus-visible {
  outline: 4px solid #4D7CFF;
  border-radius: 50%;
}

.kz-item-art {
  display: block;
  width: 100%;
  height: 100%;
  transition: transform 0.45s ease, opacity 0.45s ease, filter 0.2s ease;
}

.kz-item-art svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.kz-item.is-counted .kz-item-art {
  filter: drop-shadow(0 0 5px #4D7CFF);
}

.kz-item.is-bounce .kz-item-art {
  animation: kz-bounce 0.35s ease-out;
}

.kz-item.is-removed {
  pointer-events: none;
}

.kz-item.is-removed .kz-item-art {
  transform: scale(0);
  opacity: 0.3;
}

.kz-badge {
  position: absolute;
  right: -8%;
  bottom: -8%;
  display: none;
  align-items: center;
  justify-content: center;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: #4D7CFF;
  border: 2px solid #fff;
  color: #fff;
  font-size: calc(var(--kz-cell) * 0.3);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

.kz-item.is-counted .kz-badge {
  display: flex;
  animation: kz-pop 0.3s ease-out;
}

/* ---------- Game: action / answers ---------- */
.kz-action-row {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
}

.kz-merge-btn {
  min-width: 50%;
  min-height: max(52px, calc(var(--kz-u) * 6));
  background: #FFB347;
  border-color: #E8892B;
  color: #fff;
  box-shadow: 0 5px 0 #C46F1B;
}

.kz-answer-pad {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--kz-choices, 4), 1fr);
  gap: calc(var(--kz-u) * 1.4);
}

.kz-choice {
  min-height: max(60px, calc(var(--kz-u) * 9));
  min-width: 60px;
  padding: 0;
  font-size: calc(var(--kz-u) * 5.4);
  background: #FFFFFF;
  border-color: #4DA3FF;
  color: #2F6FB8;
  box-shadow: 0 6px 0 #3A86D8;
}

.kz-choice:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #3A86D8;
}

.kz-choice.is-wrong {
  background: #EFEAE0;
  border-color: #D5CAB6;
  color: #B3A68F;
  box-shadow: 0 6px 0 #C9BDA6;
}

.kz-choice.is-correct {
  background: #FFE27A;
  border-color: #F2B705;
  color: #5A4632;
  box-shadow: 0 6px 0 #D69E00;
}

.kz-shake {
  animation: kz-shake 0.45s ease-in-out;
}

/* ---------- Feedback overlay ---------- */
.kz-feedback {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.6);
}

.kz-fb-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--kz-u) * 1);
  text-align: center;
}

.kz-fb-art {
  display: block;
  width: calc(var(--kz-u) * 30);
  height: calc(var(--kz-u) * 30);
  max-height: 55%;
  animation: kz-stamp 1.1s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.kz-fb-art svg {
  display: block;
  width: 100%;
  height: 100%;
}

.kz-fb-text {
  margin: 0;
  font-size: calc(var(--kz-u) * 6);
  font-weight: 800;
  color: #F0759A;
  text-shadow: 0 3px 0 #fff;
  animation: kz-fade-up 0.5s ease-out 0.2s both;
}

.kz-fb-sub {
  margin: 0;
  font-size: calc(var(--kz-u) * 3.4);
  font-weight: 800;
  color: #5A4632;
  animation: kz-fade-up 0.5s ease-out 0.35s both;
}

/* ---------- Dialog ---------- */
.kz-dialog {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--kz-u) * 2);
  background: rgba(90, 70, 50, 0.5);
}

.kz-dialog-card {
  width: min(100%, 520px);
  padding: calc(var(--kz-u) * 2.4);
  background: #fff;
  border: 4px solid #FFD98A;
  border-radius: 26px;
  text-align: center;
}

.kz-dialog-title {
  margin: 0 0 calc(var(--kz-u) * 2);
  font-size: calc(var(--kz-u) * 4);
  font-weight: 800;
}

.kz-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(var(--kz-u) * 1.4);
}

.kz-dialog-btn { min-height: 60px; }
.kz-dialog-continue { background: #FFE27A; border-color: #F2B705; }
.kz-dialog-quit { background: #FFD6DE; border-color: #F0759A; }

/* ---------- Result ---------- */
.kz-result-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.kz-result-medal {
  flex: 0 1 auto;
  width: calc(var(--kz-u) * 17);
  max-width: 40%;
}

.kz-result-medal svg {
  display: block;
  width: 100%;
  height: auto;
  animation: kz-medal 0.9s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.kz-result-title {
  margin: 0;
  font-family: inherit;
  font-size: calc(var(--kz-u) * 5.2);
  font-weight: 800;
  color: #F0759A;
  text-shadow: 0 3px 0 #fff;
  border: 0;
  padding: 0;
}

.kz-result-sub {
  margin: 0;
  font-size: calc(var(--kz-u) * 3.2);
  font-weight: 800;
}

.kz-stamps {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: calc(var(--kz-u) * 0.8);
  max-width: 92%;
}

.kz-stamp {
  display: block;
  width: calc(var(--kz-u) * 6);
  height: calc(var(--kz-u) * 6);
  min-width: 34px;
  min-height: 34px;
  animation: kz-pop 0.4s ease-out both;
}

.kz-stamp svg { display: block; width: 100%; height: 100%; }

.kz-stamp-timeout {
  opacity: 0.8;
}

.kz-result-time {
  margin: 0;
  min-height: 1.2em;
  font-size: calc(var(--kz-u) * 2.6);
  font-weight: 800;
  color: #8A7660;
}

.kz-result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(var(--kz-u) * 1.4);
  width: min(100%, 640px);
}

.kz-result-btn { min-height: max(60px, calc(var(--kz-u) * 8)); }
.kz-result-retry { background: #FF9BB8; border-color: #D9507A; color: #fff; box-shadow: 0 5px 0 #C2406A; }
.kz-result-home { background: #BFE0FF; border-color: #4D9BEA; }

/* ---------- Confetti canvas ---------- */
.kz-confetti {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 30;
  pointer-events: none;
}

/* ---------- Ad ---------- */
.kz-ad {
  display: block;
  max-width: 960px;
  margin: 28px auto 0;
  padding: 10px 0 0;
  border-top: 2px dashed #E0D3BC;
  text-align: center;
  overflow: hidden;
  -webkit-user-select: auto;
  user-select: auto;
}

.kz-ad-label {
  margin: 0 0 4px;
  font-size: 11px;
  color: #8A7660;
}

.kz-ad-slot {
  display: block;
  max-width: 100%;
  overflow: hidden;
}

/* ---------- Keyframes ---------- */
@keyframes kz-bounce {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

@keyframes kz-pop {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes kz-shake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-8px); }
  40%  { transform: translateX(8px); }
  60%  { transform: translateX(-8px); }
  80%  { transform: translateX(8px); }
  100% { transform: translateX(0); }
}

@keyframes kz-stamp {
  0%   { opacity: 0; transform: scale(2.4) rotate(-25deg); }
  60%  { opacity: 1; transform: scale(0.92) rotate(6deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes kz-fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes kz-medal {
  0%   { opacity: 0; transform: scale(0.2) rotate(-30deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

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

@keyframes kz-wiggle {
  0%, 100% { transform: rotate(-12deg); }
  50%      { transform: rotate(12deg); }
}

/* ---------- Portrait tweaks ---------- */
@media (orientation: portrait) {
  .kz-setting-row {
    flex-direction: column;
  }
  .kz-title-line1 { font-size: calc(var(--kz-u) * 5.2); }
  .kz-title-line2 { font-size: calc(var(--kz-u) * 4.4); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .kz-wrap [class*="kz-"] {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
  }
}
