/* ===== 色やサイズの「変数」（ポートフォリオとおそろい） ===== */
:root {
  --ink: #2b2a26;
  --muted: #6b675c;
  --bg: #f7f2e6;
  --card: #fffdf7;
  --green: #cfe0a8;
  --yellow: #f6efc4;
  --accent: #4a6b22;
  --red: #d9534f;
  --radius: 20px;
  --ease: cubic-bezier(0.4, 0.4, 0, 1);
}

/* ===== 全体の設定 ===== */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Zen Maru Gothic", "Yu Gothic UI", "Meiryo", sans-serif;
  font-weight: 500;
  line-height: 1.7;
}

button {
  font-family: inherit;
  color: inherit;
}

kbd {
  display: inline-block;
  padding: 0 6px;
  font-family: inherit;
  font-size: 12px;
  border: 1.5px solid currentColor;
  border-radius: 6px;
}

.button {
  display: inline-block;
  padding: 12px 28px;
  font-size: 16px;
  color: var(--bg);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.2s, color 0.2s;
}

.button:hover {
  color: var(--ink);
  background: transparent;
  transform: translateY(-2px);
}

.button.is-outline {
  color: var(--ink);
  background: transparent;
}

.button.is-outline:hover {
  color: var(--bg);
  background: var(--ink);
}

/* ===== ヘッダー ===== */
.app-header {
  padding: 16px 24px;
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: inherit;
}

/* ===== 画面の共通 ===== */
.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 8px 24px 64px;
}

.screen {
  text-align: center;
  animation: fade-up 0.5s var(--ease);
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

/* ===== タイトル画面 ===== */
.title-egg {
  width: 150px;
  margin: 8px auto 0;
}

.title-egg svg {
  display: block;
  width: 100%;
  animation: wobble 2.4s ease-in-out infinite;
  transform-origin: 50% 90%;
}

/* たまごがゆらゆら */
@keyframes wobble {
  0%, 60%, 100% { transform: rotate(0); }
  70% { transform: rotate(-6deg); }
  80% { transform: rotate(5deg); }
  90% { transform: rotate(-3deg); }
}

h1 {
  margin: 8px 0 12px;
  font-size: clamp(28px, 5vw, 40px);
  line-height: 1.35;
}

.lead {
  margin: 0 0 32px;
  color: var(--muted);
}

.level-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 560px;
  margin: 0 auto 24px;
}

.level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 24px 16px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.2s;
}

.level-card:hover {
  background: var(--yellow);
  transform: translateY(-4px);
}

.level-num {
  padding: 0 12px;
  font-size: 13px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
}

.level-card strong {
  margin-top: 8px;
  font-size: 22px;
}

.level-desc {
  font-size: 14px;
  color: var(--muted);
}

.best {
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent);
}

.note {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* スマホ（指で操作する端末）のときだけ出す注意書き */
.mobile-note {
  display: none;
  margin-top: 8px;
  color: var(--red);
}

@media (pointer: coarse) {
  .mobile-note {
    display: block;
  }
}

/* ===== カウントダウン ===== */
.countdown {
  margin: 120px 0;
  font-size: 120px;
  font-weight: 700;
  line-height: 1;
}

.countdown.tick {
  animation: tick 0.8s var(--ease);
}

@keyframes tick {
  from {
    opacity: 0;
    transform: scale(1.6);
  }
}

/* ===== プレイ画面 ===== */
.play-status {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums; /* 数字の幅をそろえて、タイマーがガタつかないように */
}

.play-main {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: stretch;
}

.nest {
  padding: 16px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
}

.kakapo-stage svg {
  display: block;
  width: 100%;
}

/* 成長したときに、ぴょこんと弾む */
.kakapo-stage.grow svg {
  animation: grow 0.7s var(--ease);
}

@keyframes grow {
  0% { transform: scale(1); }
  30% { transform: scale(1.18) rotate(-4deg); }
  60% { transform: scale(0.95) rotate(3deg); }
  100% { transform: scale(1); }
}

/* 正解したときに、小さくうなずく */
.kakapo-stage.nod svg {
  animation: nod 0.35s var(--ease);
}

@keyframes nod {
  50% { transform: translateY(-6px); }
}

/* ===== 小石・リムの実・♥ の演出 ===== */
.stage-wrap {
  position: relative; /* 演出（effects）をカカポの上に重ねる基準 */
}

.kakapo-stage svg {
  transform-origin: 50% 90%; /* 足もとを中心に動かす */
}

.effects {
  position: absolute;
  inset: 0; /* 上下左右0＝カカポとぴったり同じ大きさ */
  pointer-events: none;
}

.fx {
  position: absolute;
  left: 50%;
  top: 42%;
}

/* 小石：右上から飛んできて、当たって落ちる */
.fx-stone {
  width: 18px;
  margin-left: -9px;
  animation: stone-hit 0.5s var(--ease) forwards;
}

@keyframes stone-hit {
  0% { transform: translate(90px, -60px) rotate(0); opacity: 1; }
  45% { transform: translate(8px, 0) rotate(-180deg); opacity: 1; }
  100% { transform: translate(40px, 70px) rotate(-320deg); opacity: 0; }
}

/* 「いてっ」 */
.fx-ouch {
  top: 8%;
  left: 62%;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  animation: float-up 0.7s var(--ease) forwards;
}

/* リムの実：上から落ちてきて、くちばしのところで消える */
.fx-berry {
  width: 18px;
  margin-left: -9px;
  animation: berry-drop 0.55s var(--ease) forwards;
}

@keyframes berry-drop {
  0% { transform: translateY(-90px); opacity: 0; }
  20% { opacity: 1; }
  70% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(6px) scale(0.2); opacity: 0; }
}

/* ♥（もぐもぐ・ぬくぬく） */
.fx-heart {
  top: 6%;
  left: 30%;
  font-size: 18px;
  color: #d9837a;
  animation: float-up 0.9s var(--ease) forwards;
}

.fx-heart.right {
  left: 66%;
  animation-delay: 0.1s;
  opacity: 0;
}

@keyframes float-up {
  0% { transform: translateY(8px); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translateY(-24px); opacity: 0; }
}

/* 小石が当たったとき：よろける */
.kakapo-stage.hit svg {
  animation: hit 0.4s var(--ease);
}

@keyframes hit {
  25% { transform: translateX(-7px) rotate(-8deg) scale(0.95); }
  60% { transform: translateX(4px) rotate(4deg); }
}

/* リムの実を食べたとき：もぐもぐ */
.kakapo-stage.munch svg {
  animation: munch 0.5s var(--ease);
}

@keyframes munch {
  30% { transform: scale(1.05, 0.94); }
  55% { transform: scale(0.97, 1.04); }
  80% { transform: scale(1.02, 0.98); }
}

.stage-name {
  margin: 4px 0 8px;
  font-weight: 700;
}

.growth-bar {
  height: 10px;
  overflow: hidden;
  background: #ece6d6;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
}

#growthFill {
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width 0.4s var(--ease);
}

.question-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 300px;
  padding: 24px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
}

/* ミスタイプしたときに、ぷるっと震える */
.question-card.miss {
  animation: shake 0.25s;
}

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

.pref {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.furigana {
  min-height: 1.5em;
  margin: 8px 0 0;
  font-size: 18px;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.kanji {
  margin: 0;
  font-size: clamp(44px, 8vw, 72px);
  font-weight: 700;
  line-height: 1.2;
}

/* レベル2：打てたところまで読みを表示 */
.reading {
  min-height: 1.6em;
  margin: 8px 0 0;
  font-size: 22px;
  letter-spacing: 0.15em;
}

.reading .hint {
  color: #b3ad9c;
}

.reading .blank {
  color: #d6d0c0;
}

.romaji {
  min-height: 1.6em;
  margin: 16px 0 0;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 24px;
  letter-spacing: 0.08em;
}

.romaji .typed {
  color: var(--accent);
}

.romaji .rest {
  color: #b3ad9c;
}

.message {
  min-height: 1.7em;
  margin: 12px 0 0;
  font-weight: 700;
}

.message.is-good {
  color: var(--accent);
}

.message.is-skip {
  color: var(--red);
}

.play-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.play-actions button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  font-size: 14px;
  background: transparent;
  border: 2px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
}

.play-actions button:hover {
  background: var(--yellow);
}

/* 「やめる」は目立たせない */
.play-actions .quit {
  color: var(--muted);
  border-color: #c9c2b0;
}

.ime-warning {
  display: inline-block;
  margin: 16px 0 0;
  padding: 6px 16px;
  color: #fff;
  background: var(--red);
  border-radius: 999px;
}

/* ===== 結果画面 ===== */
.result-kakapo {
  width: 200px;
  margin: 0 auto;
}

.result-kakapo svg {
  display: block;
  width: 100%;
  animation: grow 0.9s var(--ease);
}

.result-stage {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
}

.result-message {
  margin: 4px 0 0;
  color: var(--muted);
}

.new-record {
  display: inline-block;
  margin: 12px 0 0;
  padding: 2px 16px;
  font-weight: 700;
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 999px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 600px;
  margin: 24px auto;
}

.result-stats div {
  padding: 12px 8px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 14px;
}

.result-stats dt {
  font-size: 13px;
  color: var(--muted);
}

.result-stats dd {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

/* ===== シェア ===== */
.share {
  margin: 0 auto 24px;
}

.share-title {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.share-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.share-button {
  display: inline-block;
  padding: 6px 18px;
  font-size: 14px;
  color: var(--ink);
  text-decoration: none;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
}

.share-button:hover {
  background: var(--yellow);
}

.copy-message {
  min-height: 1.5em;
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--accent);
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.answer-list {
  max-width: 600px;
  margin: 32px auto 0;
  text-align: left;
}

.answer-list summary {
  cursor: pointer;
  font-weight: 700;
}

.answer-list ol {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 24px;
  padding-left: 1.5em;
}

.answer-list li.is-skip {
  color: var(--red);
}

.answer-list small {
  color: var(--muted);
}

/* ===== スマホ・狭い画面 ===== */
@media (max-width: 640px) {
  .level-select,
  .play-main {
    grid-template-columns: 1fr;
  }

  /* 巣は横長にして、左にカカポ・右に名前とバー */
  .nest {
    display: grid;
    grid-template-columns: 90px 1fr;
    align-items: center;
    gap: 4px 12px;
    text-align: left;
  }

  .nest .stage-wrap {
    grid-row: span 2;
  }

  .result-stats {
    grid-template-columns: 1fr 1fr;
  }

  .answer-list ol {
    grid-template-columns: 1fr;
  }
}

/* 動きを減らす設定の人には、アニメーションを止める */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
