/* ==========================================================================
   ドット絵コード — 動き
   入場の動きは animation-fill-mode: backwards（終わったら元の指定に戻す。hover や選択の transform を消さない）。
   prefers-reduced-motion: reduce では、動きを止めるか最小にする（末尾）。
   ========================================================================== */

/* ヘッダー: ロゴがふわふわ、飾りのドットがまたたく */
.brand-mark {
  animation: bob 3.8s ease-in-out infinite;
}

.brand-title {
  animation: rise-in 0.7s var(--ease-out) backwards;
}

.brand-lead {
  animation: rise-in 0.7s 0.08s var(--ease-out) backwards;
}

.brand-badge {
  animation: badge-wiggle 4.8s 1.2s ease-in-out infinite;
}

.header-dots i {
  animation: twinkle 2.8s ease-in-out infinite;
}

.header-dots i:nth-child(2) { animation-delay: -0.6s; animation-duration: 3.4s; }
.header-dots i:nth-child(3) { animation-delay: -1.4s; animation-duration: 2.4s; }
.header-dots i:nth-child(4) { animation-delay: -2.1s; animation-duration: 3.1s; }
.header-dots i:nth-child(5) { animation-delay: -0.9s; animation-duration: 2.6s; }
.header-dots i:nth-child(6) { animation-delay: -1.8s; animation-duration: 3.6s; }
.header-dots i:nth-child(7) { animation-delay: -0.3s; animation-duration: 2.9s; }

/* タブ: 下線（と下地）がばねで滑る */
.tabs {
  animation: rise-in 0.6s 0.12s var(--ease-out) backwards;
}

.tab-indicator {
  transition: transform 0.5s var(--spring), width 0.45s var(--ease-out);
}

.tab-indicator.no-anim {
  transition: none;
}

.tab .icon {
  transition: transform 0.45s var(--spring);
}

.tab[aria-selected="true"] .icon {
  transform: rotate(-8deg) scale(1.12);
}

.tab {
  transition: color 0.3s ease, transform 0.35s var(--spring);
}

.tab:active {
  transform: scale(0.96);
  transition-duration: 0.06s;
}

/* パネルの切り替え（右のタブへは右から、左へは左から） */
.panel.is-entering {
  animation: panel-in-right 0.5s var(--ease-out) backwards;
}

.panel.is-entering[data-from="left"] {
  animation-name: panel-in-left;
}

/* カードが順に現れる・選ぶと弾んで光る */
.animal-card {
  animation: card-in 0.55s var(--spring) backwards;
  animation-delay: calc(var(--i, 0) * 45ms + 60ms);
}

/* card-in を先頭に残す（外したときに入場の動きがやり直されないように） */
.animal-card.just-picked {
  animation: card-in 0.55s var(--spring) backwards, pick-pop 0.55s var(--spring), glow 1.3s 0.15s ease-in-out 2;
  animation-delay: calc(var(--i, 0) * 45ms + 60ms), 0s, 0.15s;
}

.animal-card.just-picked .animal-check {
  animation: check-pop 0.5s var(--spring) backwards;
}

.animal-card.just-picked .animal-art canvas {
  animation: art-hop 0.6s var(--spring);
}

.animal-card.just-picked .spark {
  animation: spark-fly 0.75s var(--ease-out) var(--d, 0s);
}

.animal-card.is-skeleton .animal-art,
.skel-line {
  animation: skeleton 1.3s ease-in-out infinite;
}

.empty-state {
  animation: rise-in 0.5s var(--ease-out) backwards;
}

.empty-art i {
  animation: twinkle 2.2s ease-in-out infinite;
}

.empty-art i:nth-child(3n) { animation-delay: -0.7s; }
.empty-art i:nth-child(4n) { animation-delay: -1.3s; }

/* 作業台 */
.bench {
  animation: rise-in 0.6s 0.2s var(--ease-out) backwards;
}

.stage.is-picked .stage-canvas {
  animation: stage-pop 0.6s var(--spring);
}

.stage.is-done .stage-canvas {
  animation: done-bounce 0.8s var(--spring);
}

.stage.is-done .stage-shine::before {
  animation: shine 1.1s 0.1s var(--ease-out);
}

.stage-hint {
  animation: hint-float 2.6s ease-in-out infinite;
}

.stage-caption > * {
  animation: rise-in 0.5s var(--ease-out) backwards;
}

.stage-caption > *:nth-child(2) {
  animation-delay: 0.08s;
}

.result-actions > * {
  animation: rise-in 0.5s var(--spring) backwards;
  animation-delay: calc(var(--i, 0) * 80ms + 120ms);
}

.btn.is-shake,
.url-input.is-shake {
  animation: shake 0.45s ease-in-out;
}

#generate-btn.is-ready {
  animation: ready-pulse 2.4s 0.4s ease-in-out infinite;
}

#generate-btn.is-busy .btn-label::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1s steps(4, end) infinite;
}

#save-btn.is-done .icon-done {
  animation: check-draw 0.45s 0.05s var(--ease-out) backwards;
}

#save-btn.is-done {
  animation: pick-pop 0.5s var(--spring);
}

.input-clear:not([hidden]) {
  animation: pop-in 0.3s var(--spring);
}

/* 読み取り: 枠が息をして、走査線が上下する */
.viewer[data-state="live"] .scan-box {
  animation: breathe 2.6s ease-in-out infinite;
}

.viewer[data-state="live"] .scan-line::before {
  animation: scan-y 2.3s ease-in-out infinite alternate;
}

.viewer[data-state="starting"] .corner {
  animation: blink 1s ease-in-out infinite;
}

.viewer.is-found .scan-line {
  opacity: 0.35;
}

.viewer.is-near .quad {
  animation: march 0.7s linear infinite;
}

.viewer.is-locked .quad {
  animation: quad-lock 0.9s var(--spring) backwards;
}

.viewer.is-locked .quad-dot {
  animation: dot-pop 0.5s var(--spring) backwards;
}

.viewer.is-busy .busy-sweep::before {
  animation: sweep-y 1.1s ease-in-out infinite alternate;
}

.viewer-idle .idle-art i {
  animation: idle-dot 2.4s ease-in-out infinite;
}

.viewer-idle .idle-art i:nth-child(2) { animation-delay: 0.15s; }
.viewer-idle .idle-art i:nth-child(3) { animation-delay: 0.3s; }
.viewer-idle .idle-art i:nth-child(4) { animation-delay: 0.45s; }
.viewer-idle .idle-art i:nth-child(5) { animation-delay: 0.6s; }
.viewer-idle .idle-art i:nth-child(6) { animation-delay: 0.75s; }
.viewer-idle .idle-art i:nth-child(7) { animation-delay: 0.9s; }
.viewer-idle .idle-art i:nth-child(8) { animation-delay: 1.05s; }
.viewer-idle .idle-art i:nth-child(9) { animation-delay: 1.2s; }

.viewer-idle > * {
  animation: rise-in 0.5s var(--ease-out) backwards;
}

.viewer-idle > :nth-child(2) { animation-delay: 0.06s; }
.viewer-idle > :nth-child(3) { animation-delay: 0.12s; }

.viewer-status:not(:empty) {
  animation: status-in 0.35s var(--spring);
}

.viewer-tools > * {
  animation: pop-in 0.35s var(--spring) backwards;
}

.guide:not([hidden]) {
  animation: rise-in 0.45s var(--ease-out) backwards;
}

.result.is-in {
  animation: result-in 0.6s var(--spring) backwards;
}

.result.is-in > * {
  animation: rise-in 0.5s var(--ease-out) backwards;
}

.result.is-in > :nth-child(2) { animation-delay: 0.06s; }
.result.is-in > :nth-child(3) { animation-delay: 0.12s; }
.result.is-in > :nth-child(4) { animation-delay: 0.18s; }
.result.is-in > :nth-child(5) { animation-delay: 0.24s; }
.result.is-in > :nth-child(6) { animation-delay: 0.3s; }

.result.is-in .result-icon {
  animation: check-pop 0.55s 0.12s var(--spring) backwards;
}

.opening.is-running .opening-bar span {
  animation: bar-fill var(--dur, 1200ms) linear forwards;
}

.opening.is-running .opening-text {
  animation: soft-blink 0.8s ease-in-out infinite;
}

/* トースト */
.toast {
  animation: toast-in 0.45s var(--spring) backwards;
}

.toast.is-leaving {
  animation: toast-out 0.28s ease-in forwards;
}

/* --------------------------------------------------------------------------
   キーフレーム
   -------------------------------------------------------------------------- */
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-4px) rotate(-3deg); }
}

@keyframes badge-wiggle {
  0%, 86%, 100% { transform: rotate(0deg); }
  89% { transform: rotate(-8deg); }
  92% { transform: rotate(7deg); }
  95% { transform: rotate(-4deg); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.7) rotate(0deg); }
  50% { opacity: 0.9; transform: scale(1.1) rotate(45deg); }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: none; }
}

@keyframes panel-in-right {
  from { opacity: 0; transform: translateX(36px); }
  to { opacity: 1; transform: none; }
}

@keyframes panel-in-left {
  from { opacity: 0; transform: translateX(-36px); }
  to { opacity: 1; transform: none; }
}

@keyframes card-in {
  0% { opacity: 0; transform: translateY(18px) scale(0.9); }
  100% { opacity: 1; transform: none; }
}

@keyframes pick-pop {
  0% { transform: scale(1); }
  30% { transform: scale(0.93); }
  65% { transform: scale(1.05) translateY(-3px); }
  100% { transform: translateY(-2px); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 3px var(--green), 0 0 0 3px rgba(168, 225, 222, 0), 0 14px 28px -14px rgba(40, 117, 76, 0.6); }
  50% { box-shadow: 0 0 0 3px var(--green), 0 0 0 10px rgba(168, 225, 222, 0.75), 0 16px 34px -12px rgba(40, 117, 76, 0.6); }
}

@keyframes check-pop {
  0% { transform: scale(0) rotate(-40deg); }
  70% { transform: scale(1.22) rotate(8deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes art-hop {
  0% { transform: translateY(0); }
  35% { transform: translateY(-9px) scale(1.06); }
  65% { transform: translateY(1px) scale(0.98, 1.02); }
  100% { transform: none; }
}

@keyframes spark-fly {
  0% { opacity: 0; transform: translate(0, 0) scale(0.4) rotate(0deg); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx, 0), var(--dy, -30px)) scale(1) rotate(90deg); }
}

@keyframes skeleton {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

@keyframes stage-pop {
  0% { transform: scale(0.82) rotate(-4deg); opacity: 0.4; }
  60% { transform: scale(1.04) rotate(1deg); opacity: 1; }
  100% { transform: none; }
}

@keyframes done-bounce {
  0% { transform: scale(1); }
  25% { transform: scale(0.94); }
  55% { transform: scale(1.06) rotate(-1.5deg); }
  80% { transform: scale(0.99) rotate(0.5deg); }
  100% { transform: none; }
}

@keyframes shine {
  0% { opacity: 1; transform: translateX(-160%) rotate(18deg); }
  100% { opacity: 1; transform: translateX(520%) rotate(18deg); }
}

@keyframes hint-float {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(-50%, calc(-50% - 5px)); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  18% { transform: translateX(-7px); }
  36% { transform: translateX(6px); }
  54% { transform: translateX(-4px); }
  72% { transform: translateX(3px); }
}

@keyframes ready-pulse {
  0%, 100% { box-shadow: 0 4px 0 var(--btn-edge), 0 12px 20px -14px rgba(29, 90, 57, 0.55), 0 0 0 0 rgba(40, 117, 76, 0.35); }
  50% { box-shadow: 0 4px 0 var(--btn-edge), 0 12px 20px -14px rgba(29, 90, 57, 0.55), 0 0 0 9px rgba(40, 117, 76, 0); }
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75%, 100% { content: "..."; }
}

@keyframes check-draw {
  from { stroke-dashoffset: 24; transform: scale(0.6) rotate(-20deg); }
  to { stroke-dashoffset: 0; transform: none; }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

@keyframes scan-y {
  from { transform: translateY(-20%); }
  to { transform: translateY(470%); }
}

@keyframes sweep-y {
  from { transform: translateY(-30%); }
  to { transform: translateY(380%); }
}

@keyframes blink {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@keyframes march {
  to { stroke-dashoffset: -42; }
}

@keyframes quad-lock {
  0% { opacity: 0; stroke-width: 18; }
  60% { opacity: 1; stroke-width: 4; }
  100% { stroke-width: 6; }
}

@keyframes dot-pop {
  0% { opacity: 0; transform: scale(0); }
  100% { opacity: 1; transform: none; }
}

@keyframes idle-dot {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(0.82); filter: brightness(1.15); }
}

@keyframes status-in {
  from { opacity: 0; transform: translate(-50%, 10px) scale(0.94); }
  to { opacity: 1; transform: translateX(-50%); }
}

@keyframes result-in {
  0% { opacity: 0; transform: translateY(24px) scale(0.96); }
  100% { opacity: 1; transform: none; }
}

@keyframes bar-fill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes soft-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(18px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px) scale(0.95); }
}

/* --------------------------------------------------------------------------
   動きを減らす設定では、動きを止めるか最小にする
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }

  .scan-line,
  .busy-sweep,
  .header-dots,
  .spark {
    display: none !important;
  }

  .stage-shine::before {
    opacity: 0 !important;
  }

  .opening.is-running .opening-bar span {
    transform: scaleX(1);
  }
}
