/* メインイメージ線画アニメーション */

/* クリティカルCSS - アニメーション即座開始用 */
html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
}

.mainimage-svg-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 100vh;
  min-height: 800px;
  overflow: hidden;
  background-color: transparent;
  display: block !important;
  visibility: visible !important;
  pointer-events: none;
}

.mainimage-svg-container svg {
  width: 100%;
  max-width: 100%;
  height: 100%;
  display: block !important;
  position: absolute;
  top: 0;
  left: 0;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 1;
  transform: translateY(15px);
}

.mainimage {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  display: block !important;
  visibility: visible !important;
  pointer-events: none;
  overflow: hidden;
}

.st2 {
  fill: none;
  stroke: #001400;
  stroke-miterlimit: 10;
  stroke-width: 8px;
}

.st3 {
  fill: #d2d2d2;
}

.st1 {
  fill: #fff;
  stroke: #001400;
  stroke-miterlimit: 10;
  fill-rule: evenodd;
  stroke-width: 3px;
}

.st0 {
  fill: #001400;
  fill-rule: evenodd;
}

/*
  アニメーションの長さ・タイミングの設定方法
  ------------------------------------------------
  animation: name duration timing-function delay fill-mode;

  - name: キーフレーム名（drawFirstLine, fadeOut, fadeIn など）
  - duration: 再生時間（例: 2s, 18s）
  - timing-function:  easing（linear, ease-in-out など）
  - delay: 開始までの待機時間（例: 5s, 19.5s）
  - fill-mode: 終了後の状態（forwards = 最後のフレームを維持）

  タイミング変更時は各要素の delay / duration の整合性に注意
*/

#first-line {
  opacity: 1;
  animation: fadeOut 1s ease-out 13.5s forwards !important;
  animation-play-state: running !important;
}

#first-line .st2 {
  stroke-dasharray: 5500;
  stroke-dashoffset: 5500;
  animation: drawFirstLine 12.5s linear 0s forwards !important;
  animation-play-state: running !important;
  will-change: stroke-dashoffset;
}

/* #tree は #first-line に統合されたため無効化 */
/*
#tree {
  opacity: 1;
  animation: fadeOut 1s ease-in-out 9.5s forwards;
}

#tree .st2 {
  stroke-dasharray: 2000;
  stroke-dashoffset: 2000;
  animation: drawTree 4s linear 1.8s forwards;
}
*/

#second-line {
  opacity: 1;
  animation: fadeOut 1s ease-out 13.5s forwards;
}

#second-line .st2 {
  stroke-dasharray: 350;
  stroke-dashoffset: 350;
  animation: drawSecondLine 0.7s linear 9.8s forwards;
}

.final-state {
  opacity: 0;
  animation: fadeIn 1.5s ease-in-out 15.5s forwards;
}

/* 完成図表示後のみ：3回点滅→3秒待機をリピート */
#nock {
  opacity: 0;
  animation: knockRepeat 6s step-end 17s infinite;
}

.mainimage-character {
  position: absolute;
  bottom: 20%;
  left: 30%;
  transform: translateX(-30%);
  width: 200px;
  height: auto;
  opacity: 0;
  animation: fadeIn 1.5s ease-in-out 15.5s forwards;
  cursor: pointer;
  z-index: 100;
  transition: transform 0.3s ease;
  pointer-events: none;
}

.mainimage-character:hover {
  transform: translateX(-30%) scale(1.05);
}

.mainimage-moon {
  position: absolute;
  top: 60px;
  left: 95px;
  width: 120px;
  height: auto;
  opacity: 0;
  animation: fadeIn 1.5s ease-in-out 15.5s forwards;
  z-index: 10;
  pointer-events: none;
}

#door {
  transform: translateY(-4px);
}

#door-link {
  cursor: pointer;
}

@keyframes drawFirstLine {
  0% {
    stroke-dashoffset: 5500;
  }

  100% {
    stroke-dashoffset: 0;
  }
}

@keyframes drawTree {
  0% {
    stroke-dashoffset: 2000;
  }

  100% {
    stroke-dashoffset: 0;
  }
}

@keyframes drawSecondLine {
  0% {
    stroke-dashoffset: 350;
  }

  100% {
    stroke-dashoffset: 0;
  }
}

@keyframes fadeOut {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes knock3Times {

  0%,
  10% {
    opacity: 0;
  }

  15%,
  25% {
    opacity: 1;
  }

  30%,
  40% {
    opacity: 0;
  }

  45%,
  55% {
    opacity: 1;
  }

  60%,
  70% {
    opacity: 0;
  }

  75%,
  100% {
    opacity: 1;
  }
}

/* 3回点滅 → 3秒待機 をリピート（1サイクル＝約2秒の点滅＋3秒待機＝6秒） */
@keyframes knockRepeat {
  0% {
    opacity: 1;
  }

  8.33% {
    opacity: 0;
  }

  16.67% {
    opacity: 1;
  }

  25% {
    opacity: 0;
  }

  33.33% {
    opacity: 1;
  }

  41.67% {
    opacity: 0;
  }

  100% {
    opacity: 0;
  }
}

/* 別ページから戻ったとき：アニメーション終了状態で表示 */
body.top-anime-done #first-line,
body.top-anime-done #tree,
body.top-anime-done #second-line {
  opacity: 0 !important;
  animation: none !important;
}

body.top-anime-done #first-line .st2,
body.top-anime-done #tree .st2,
body.top-anime-done #second-line .st2 {
  animation: none !important;
  stroke-dashoffset: 0;
}

body.top-anime-done .final-state,
body.top-anime-done .mainimage-character,
body.top-anime-done .mainimage-moon {
  opacity: 1 !important;
  animation: none !important;
}

/* 別ページから戻ったときもノックは点滅を続ける */
body.top-anime-done #nock {
  animation: knockRepeat 6s step-end 0s infinite !important;
}

body.top-anime-done .mainimage-character {
  pointer-events: auto;
}

body.top-anime-done #door-link {
  pointer-events: auto;
}

/* 経過秒数表示（アニメーション確認用） */
.animation-timer {
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-family: monospace;
  font-size: 18px;
  font-weight: bold;
  border-radius: 6px;
  z-index: 9999;
  pointer-events: none;
}

@media (max-width: 768px) {
  .mainimage {
    max-width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
  }

  .mainimage-svg-container {
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mainimage-svg-container svg {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    position: relative;
    object-fit: contain;
  }

  /* スマホ時：左から出る線（second-line）は非表示 */
  #second-line,
  #second-line-final {
    display: none !important;
  }

  .mainimage-character {
    width: 180px;
    bottom: 38%;
  }

  .mainimage-moon {
    width: 80px;
    top: 12%;
    left: 3%;
  }

  .st2 {
    stroke-width: 10px;
  }

  .st1 {
    stroke-width: 4px;
  }

  .animation-timer {
    top: 8px;
    right: 8px;
    font-size: 14px;
    padding: 6px 10px;
  }
}

@media only screen and (max-width: 599px) {
  .mainimage-svg-container {
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    min-height: 100vh;
    overflow-x: hidden;
  }

  .mainimage-character {
    width: 70px;
    bottom: 39%;
    left: 20%;
    transform: translateX(-20%);
  }

  .mainimage-moon {
    width: 50px;
    top: 30%;
  }
}