:root {
  color-scheme: light;
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  --primary: #ff8c42;
  --primary-dark: #c95f0c;
  --accent: #ffd166;
  --bg: #fffaf3;
  --text: #2f1c0f;
  --muted: #8c6e54;
  --card: rgba(255, 255, 255, 0.85);
  --shadow: 0 12px 24px rgba(47, 28, 15, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #fff5e5, #ffe0b2);
  color: var(--text);
  min-height: 100vh;
}

.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  text-align: center;
  padding: 1.8rem 1.25rem 1.2rem;
}

.header h1 {
  margin: 0;
  font-size: 2.1rem;
  letter-spacing: 0.05em;
  color: var(--primary);
}

.header h1 span {
  color: var(--primary);
}

.tagline {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.ttl-note {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.app {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 1rem 2.2rem;
}

.card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 18px;
  padding: 1.6rem 1.4rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(255, 140, 66, 0.25);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
  margin: 0 auto 1.25rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.footer {
  text-align: center;
  padding: 1.5rem 1rem 2.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.link-button {
  border: none;
  background: none;
  color: var(--primary-dark);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  margin-bottom: 0.5rem;
}

.link-button:disabled {
  color: #bbb;
  cursor: not-allowed;
  text-decoration: none;
}

.form-field {
  margin-bottom: 1rem;
}

.form-field label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.form-field input,
.form-field select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 1rem;
  background: #fff;
}

.birthdate-field {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.birthdate-field select {
  width: 100%;
  min-width: 0;
}

.birthdate-hint {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.form-field small {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.primary-button,
.secondary-button {
  width: 100%;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 10px 20px rgba(255, 140, 66, 0.25);
}

.primary-button:active {
  transform: translateY(1px);
}

.secondary-button {
  margin-top: 0.75rem;
  background: rgba(255, 255, 255, 0.8);
  color: var(--primary-dark);
  border: 1px solid rgba(255, 140, 66, 0.35);
}

.fortune-result {
  display: grid;
  gap: 1rem;
}

.fortune-rank {
  font-size: 2rem;
  text-align: center;
  color: var(--primary-dark);
  letter-spacing: 0.1em;
}


.fortune-greeting {
  margin: 1.2rem auto 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  line-height: 1.5;
}

.fortune-greeting__name {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.fortune-greeting__message {
  font-size: 0.95rem;
}

.fortune-section {
  background: rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  padding: 0.8rem;
  border-left: 4px solid var(--primary);
}

.fortune-section h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.fortune-metadata {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.lucky-pill {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 140, 66, 0.12);
  color: var(--primary-dark);
  font-weight: 600;
  margin-right: 0.4rem;
}

/* 折りたたみセクション */
.fortune-section.collapsible {
  border: 1px solid rgba(255, 140, 66, 0.2);
  border-radius: 8px;
  padding: 0.8rem;
  margin-top: 1rem;
}

.collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0;
}

.collapsible-header:hover {
  color: var(--primary);
}

.toggle-icon {
  font-size: 0.8rem;
  transition: transform 0.3s ease;
}

.fortune-section.collapsible.open .toggle-icon {
  transform: rotate(180deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.fortune-section.collapsible.open .collapsible-content {
  max-height: 500px;
  margin-top: 0.8rem;
}

.omikuji-container {
  position: relative;
  width: 220px;
  height: 200px;
  margin: 1.2rem auto 0;
}

.cookie-animation {
  position: relative;
  width: 100%;
  height: 100%;
}

.cookie-animation .confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.cookie-animation .cookie {
  position: absolute;
  bottom: 12px;
  left: 50%;
  width: 210px;
  max-width: none;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  user-select: none;
}

.cookie-animation .cookie-closed {
  opacity: 1;
}

.cookie-animation.is-open .cookie-closed,
.cookie-animation.is-animating .cookie-closed {
  opacity: 0;
}

.cookie-animation .cookie-left,
.cookie-animation .cookie-right {
  opacity: 0;
  transform: translate(-50%, -10px) rotate(0deg);
  transform-origin: center bottom;
}

.cookie-animation.is-open .cookie-left,
.cookie-animation.is-animating .cookie-left {
  opacity: 1;
}

.cookie-animation.is-open .cookie-right,
.cookie-animation.is-animating .cookie-right {
  opacity: 1;
}

.cookie-animation.is-open .cookie-left {
  transform: translate(-50%, -20px) translateX(-56px) rotate(-6deg);
}

.cookie-animation.is-open .cookie-right {
  transform: translate(-50%, -20px) translateX(56px) rotate(6deg);
}

.cookie-animation.is-animating .cookie-left {
  animation: cookie-left-crack 0.9s forwards ease-out;
}

.cookie-animation.is-animating .cookie-right {
  animation: cookie-right-crack 0.9s forwards ease-out;
}


.cookie-animation .confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.cookie-animation .confetti-image {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 280px;
  max-width: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  transform-origin: center;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.25));
  transition: opacity 0.6s ease-out;
}

.cookie-animation .confetti-layer-1 {
  z-index: 1;
}

.cookie-animation .confetti-layer-2 {
  z-index: 2;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.8);
}

.cookie-animation.is-open .confetti-layer-1 {
  opacity: 1;
  transform: translate(-50%, -50%) scale(0.8);
}

.cookie-animation.is-open .confetti-layer-2 {
  transform: translate(-50%, -50%) scale(0.8);
}

.cookie-animation.is-open.show-layer-2 .confetti-layer-2 {
  opacity: 1;
  transform: translate(-50%, -50%) scale(0.8);
}

.cookie-animation.is-animating .confetti-layer-1 {
  animation: confetti-flash 0.8s ease-out forwards;
}

.cookie-animation .fortune-board {
  z-index: 3;
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out, transform 0.25s ease-out;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.cookie-animation .fortune-board .board-image {
  max-width: 220px;
  width: 65vw;
}

.cookie-animation .fortune-board .board-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #b22222;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  font-family: "Noto Serif JP", "Yu Mincho", serif;
}

.cookie-animation .fortune-board.visible {
  opacity: 1;
  transform: translate(-50%, -52%) scale(0.72);
}

.cookie-animation.is-animating .confetti-piece {
  animation: confetti-pop 1.1s ease-out forwards;
}

.cookie-animation.is-animating .piece-2 { animation-delay: 0.05s; }
.cookie-animation.is-animating .piece-3 { animation-delay: 0.1s; }
.cookie-animation.is-animating .piece-4 { animation-delay: 0.15s; }
.cookie-animation.is-animating .piece-5 { animation-delay: 0.2s; }
.cookie-animation.is-animating .piece-6 { animation-delay: 0.25s; }

@keyframes cookie-left-crack {
  0% {
    opacity: 0;
    transform: translate(-50%, -10px) rotate(0deg);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -20px) translateX(-56px) rotate(-6deg);
  }
}

@keyframes cookie-right-crack {
  0% {
    opacity: 0;
    transform: translate(-50%, -10px) rotate(0deg);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -20px) translateX(56px) rotate(6deg);
  }
}

@keyframes confetti-flash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  45% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.76);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.8);
  }
}

.result-card {
  animation: fade-in 0.5s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.error-message {
  color: #b71c1c;
  background: rgba(183, 28, 28, 0.08);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.success-message {
  color: #1b5e20;
  background: rgba(27, 94, 32, 0.08);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  .header {
    padding-top: 2rem;
  }
  .header h1 {
    font-size: 1.8rem;
  }
  .card {
    padding: 1.6rem 1.25rem;
  }
  .fortune-rank {
    font-size: 1.7rem;
  }
}
