/* ========================================
   Tools Enhanced CSS v2.0
   高級リッチデザイン用共通スタイル
   ======================================== */

/* ========================================
   Enhanced CSS Variables
   ======================================== */
:root {
  /* ---- Enhanced colors ---- */
  --color-card-bg: rgba(30, 32, 48, 0.7);
  --color-card-border: rgba(184, 160, 126, 0.25);
  --color-card-border-hover: rgba(184, 160, 126, 0.6);
  --color-glow-gold: rgba(184, 160, 126, 0.4);
  --color-glow-moon: rgba(232, 232, 224, 0.5);

  /* ---- Gradients ---- */
  --gradient-card: linear-gradient(145deg, rgba(30,32,48,0.7) 0%, rgba(22,24,40,0.8) 100%);
  --gradient-shimmer: linear-gradient(90deg, transparent 0%, rgba(184,160,126,0.15) 50%, transparent 100%);
  --gradient-moon: radial-gradient(circle at 35% 35%, #E8E8E0 0%, #B8A07E 40%, #6B7A8F 100%);
  --gradient-score: linear-gradient(135deg, rgba(184,160,126,0.8) 0%, rgba(232,232,224,0.6) 100%);

  /* ---- Shadows ---- */
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --shadow-md: 0 8px 32px rgba(0,0,0,0.3);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 40px rgba(184,160,126,0.4);
  --shadow-inner: inset 0 1px 0 rgba(232,232,224,0.05);

  /* ---- Animation timing ---- */
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ========================================
   Particle Background
   ======================================== */
.particle-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

/* ========================================
   Glassmorphic Card
   ======================================== */
.glass-card {
  background: var(--color-card-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--color-card-border);
  border-radius: 8px;
  box-shadow: var(--shadow-md), var(--shadow-inner);
  position: relative;
  overflow: hidden;
  transition: all 0.4s var(--ease-bounce);
}

.glass-card:hover {
  transform: translateY(-8px) scale(1.02);
  border-color: var(--color-card-border-hover);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

/* Shimmer effect */
.glass-card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: var(--gradient-shimmer);
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
  z-index: 1;
}

.glass-card:hover::before {
  opacity: 1;
  animation: shimmer 2s ease-in-out infinite;
}

/* ========================================
   Circular Progress
   ======================================== */
.circular-progress {
  width: 180px;
  height: 180px;
  position: relative;
  margin: 0 auto;
}

.circular-progress svg {
  transform: rotate(-90deg);
}

.progress-ring {
  fill: none;
  stroke: rgba(107, 122, 143, 0.2);
  stroke-width: 12;
}

.progress-ring-fill {
  fill: none;
  stroke: url(#progressGradient);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 502.4;
  stroke-dashoffset: 502.4;
  transition: stroke-dashoffset 2s var(--ease-smooth);
  filter: drop-shadow(0 0 8px rgba(184, 160, 126, 0.6));
}

.circular-progress[data-animated="true"] .progress-ring-fill {
  stroke-dashoffset: calc(502.4 - (502.4 * var(--progress) / 100));
}

.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-family: var(--font-serif);
  z-index: 2;
}

.progress-number {
  font-size: 2.8rem;
  font-weight: 600;
  color: var(--color-moonlight);
  text-shadow: 0 0 20px rgba(184, 160, 126, 0.5);
  line-height: 1;
}

.progress-unit {
  font-size: 1rem;
  color: var(--color-muted-gold);
  opacity: 0.7;
  margin-top: 0.2em;
}

/* ========================================
   3D Card Flip
   ======================================== */
.flip-container {
  perspective: 1000px;
  width: 180px;
  height: 310px;
}

.flipper {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.8s var(--ease-smooth);
}

.flip-container.flipped .flipper {
  transform: rotateY(180deg);
}

.flip-front,
.flip-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}

.flip-front {
  background: var(--gradient-card);
  border: 1px solid var(--color-card-border);
}

.flip-back {
  background: linear-gradient(145deg, #1E2235 0%, #12152A 100%);
  border: 1px solid var(--color-muted-gold);
  transform: rotateY(180deg);
}

.flip-back.revealed {
  animation: cardReveal 1.2s ease-out forwards;
}

/* ========================================
   Ripple Effect
   ======================================== */
.ripple-btn {
  position: relative;
  overflow: hidden;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(232, 232, 224, 0.3);
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%) scale(0);
  animation: rippleEffect 0.6s ease-out;
  pointer-events: none;
  z-index: 10;
}

/* ========================================
   Toast Notification
   ======================================== */
.toast-notification {
  position: fixed;
  bottom: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 32, 48, 0.95);
  backdrop-filter: blur(10px);
  color: var(--color-moonlight);
  padding: 1em 2em;
  border-radius: 8px;
  border: 1px solid var(--color-card-border-hover);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  transition: bottom 0.3s var(--ease-smooth);
  z-index: 10000;
  white-space: nowrap;
}

.toast-notification.show {
  bottom: 40px;
}

/* ========================================
   Loading Spinner
   ======================================== */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(184, 160, 126, 0.2);
  border-top-color: var(--color-muted-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
}

/* ========================================
   Custom Select
   ======================================== */
.custom-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--color-deep-navy);
  border: 1px solid rgba(107, 122, 143, 0.4);
  border-radius: 4px;
  color: var(--color-moon-white);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.6em 2.5em 0.6em 1em;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236B7A8F'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.custom-select:hover {
  border-color: rgba(184, 160, 126, 0.5);
}

.custom-select:focus {
  border-color: var(--color-card-border-hover);
  box-shadow: 0 0 0 3px rgba(184, 160, 126, 0.1);
  outline: none;
}

/* ========================================
   Enhanced Buttons
   ======================================== */
.calc-btn,
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.9em 2em;
  background: transparent;
  border: 1px solid rgba(184, 160, 126, 0.5);
  border-radius: 4px;
  color: var(--color-muted-gold);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.calc-btn:hover,
.action-btn:hover {
  background: rgba(184, 160, 126, 0.1);
  border-color: rgba(184, 160, 126, 0.8);
  color: var(--color-moonlight);
  transform: translateY(-2px);
}

.calc-btn:active,
.action-btn:active {
  transform: translateY(0) scale(0.98);
}

.calc-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Button loading state */
.calc-btn .btn-loading {
  display: none;
}

.calc-btn.loading .btn-text {
  display: none;
}

.calc-btn.loading .btn-loading {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

/* ========================================
   Progress Bar
   ======================================== */
.progress-bar-wrap {
  position: sticky;
  top: 0;
  background: rgba(10, 17, 40, 0.95);
  backdrop-filter: blur(10px);
  padding: 1em 0;
  z-index: 100;
  border-bottom: 1px solid var(--color-card-border);
}

.progress-bar {
  max-width: 680px;
  height: 4px;
  background: rgba(107, 122, 143, 0.2);
  border-radius: 2px;
  margin: 0 auto 0.5em;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--gradient-score);
  border-radius: 2px;
  transition: width 0.4s var(--ease-smooth);
  box-shadow: 0 0 8px rgba(184, 160, 126, 0.6);
}

.progress-text {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-blue-grey);
  letter-spacing: 0.08em;
}

/* ========================================
   Typing Effect
   ======================================== */
.typing-text {
  overflow: hidden;
  border-right: 2px solid var(--color-muted-gold);
  white-space: nowrap;
  animation: typing 2s steps(40) forwards,
             blinkCursor 0.75s step-end infinite;
}

.typing-text.finished {
  border-right: none;
  animation: none;
}

/* ========================================
   Badge Components
   ======================================== */
.tool-badge {
  position: absolute;
  top: 1em;
  right: 1em;
  background: rgba(184, 160, 126, 0.2);
  border: 1px solid rgba(184, 160, 126, 0.4);
  border-radius: 12px;
  padding: 0.3em 0.8em;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted-gold);
  animation: badgePulse 2s ease-in-out infinite;
  z-index: 3;
}

.bond-type-badge {
  display: inline-block;
  padding: 0.6em 1.4em;
  background: linear-gradient(135deg, rgba(184, 160, 126, 0.2) 0%, rgba(232, 232, 224, 0.1) 100%);
  border: 1px solid var(--color-card-border-hover);
  border-radius: 20px;
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  color: var(--color-moonlight);
  animation: badgePulse 2s ease-in-out infinite;
  margin: 1.5em 0;
}

/* Badge variants */
.bond-type-badge[data-type="twin"] {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 223, 0, 0.1) 100%);
  border-color: rgba(255, 215, 0, 0.4);
  color: #FFD700;
}

.bond-type-badge[data-type="soulmate"] {
  background: linear-gradient(135deg, rgba(100, 180, 220, 0.2) 0%, rgba(100, 180, 220, 0.1) 100%);
  border-color: rgba(100, 180, 220, 0.4);
  color: #64B4DC;
}

.bond-type-badge[data-type="karma"] {
  background: linear-gradient(135deg, rgba(220, 100, 140, 0.2) 0%, rgba(220, 100, 140, 0.1) 100%);
  border-color: rgba(220, 100, 140, 0.4);
  color: #DC648C;
}

/* ========================================
   Moon Sphere
   ======================================== */
.moon-sphere {
  width: 200px;
  height: 200px;
  margin: 0 auto;
  position: relative;
  border-radius: 50%;
  background: var(--gradient-moon);
  box-shadow: 0 0 40px rgba(232, 232, 224, 0.4),
              inset -20px -20px 60px rgba(10, 17, 40, 0.6);
  animation: moonGlow 4s ease-in-out infinite;
}

.moon-shadow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, transparent 30%, rgba(10, 17, 40, 0.7) 100%);
  transition: opacity 0.6s ease;
}

/* Moon phases */
.moon-sphere[data-phase="new"] .moon-shadow {
  opacity: 1;
  background: radial-gradient(circle, rgba(10, 17, 40, 0.9) 50%, transparent 100%);
}

.moon-sphere[data-phase="full"] .moon-shadow {
  opacity: 0;
}

/* ========================================
   Timeline
   ======================================== */
.phase-timeline {
  position: relative;
  padding-left: 60px;
  max-width: 680px;
  margin: 0 auto;
}

.phase-timeline::before {
  content: '';
  position: absolute;
  left: 20px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(184, 160, 126, 0.3) 10%,
    rgba(184, 160, 126, 0.3) 90%,
    transparent 100%
  );
}

.phase-event {
  position: relative;
  margin-bottom: 2.5em;
  padding: 1.5em;
  background: rgba(30, 32, 48, 0.6);
  border-left: 3px solid var(--phase-color, var(--color-muted-gold));
  backdrop-filter: blur(8px);
  border-radius: 0 8px 8px 0;
  animation: slideInRight 0.6s ease backwards;
  animation-delay: calc(var(--item-index, 0) * 0.1s);
  transition: all 0.3s ease;
}

.phase-event:hover {
  background: rgba(30, 32, 48, 0.8);
  transform: translateX(4px);
  border-left-color: var(--color-card-border-hover);
}

.phase-event::before {
  content: var(--phase-emoji, '🌙');
  position: absolute;
  left: -49px;
  top: 1.2em;
  width: 32px;
  height: 32px;
  background: var(--color-deep-navy);
  border: 2px solid var(--phase-color, var(--color-muted-gold));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  z-index: 2;
}

/* ========================================
   Keyframe Animations
   ======================================== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.9;
  }
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 20px rgba(184, 160, 126, 0.3);
  }
  50% {
    box-shadow: 0 0 40px rgba(184, 160, 126, 0.6);
  }
}

@keyframes shimmer {
  0%, 100% {
    transform: translate(0, 0) rotate(0deg);
  }
  50% {
    transform: translate(10%, 10%) rotate(5deg);
  }
}

@keyframes moonGlow {
  0%, 100% {
    box-shadow: 0 0 40px rgba(232, 232, 224, 0.4), inset -20px -20px 60px rgba(10, 17, 40, 0.6);
  }
  50% {
    box-shadow: 0 0 80px rgba(232, 232, 224, 0.7), inset -20px -20px 60px rgba(10, 17, 40, 0.6);
  }
}

@keyframes typing {
  from { width: 0; }
  to {
    width: 100%;
    border-right: none;
  }
}

@keyframes blinkCursor {
  50% { border-color: transparent; }
}

@keyframes cardReveal {
  0% {
    filter: brightness(1);
    transform: scale(1);
  }
  50% {
    filter: brightness(1.5);
    transform: scale(1.05);
  }
  100% {
    filter: brightness(1);
    transform: scale(1);
  }
}

@keyframes shuffle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-20px) rotate(-8deg); }
  50% { transform: translateY(-10px) rotate(4deg); }
  75% { transform: translateY(-25px) rotate(-6deg); }
}

@keyframes rippleEffect {
  to {
    transform: translate(-50%, -50%) scale(4);
    opacity: 0;
  }
}

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

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

/* ========================================
   Utility Classes
   ======================================== */
.fade-in-up {
  animation: fadeInUp 0.8s ease forwards;
}

.slide-in-right {
  animation: slideInRight 0.6s ease forwards;
}

.scale-in {
  animation: scaleIn 0.5s ease forwards;
}

.glow-effect {
  animation: glow 2s ease-in-out infinite;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 768px) {
  .circular-progress {
    width: 150px;
    height: 150px;
  }

  .progress-number {
    font-size: 2.2rem;
  }

  .moon-sphere {
    width: 160px;
    height: 160px;
  }

  .phase-timeline {
    padding-left: 50px;
  }

  .phase-timeline::before {
    left: 15px;
  }

  .phase-event::before {
    left: -44px;
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }

  .toast-notification {
    font-size: 0.85rem;
    padding: 0.8em 1.5em;
    max-width: 90%;
  }
}

/* ========================================
   Accessibility
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .glass-card {
    border-width: 2px;
  }

  .custom-select,
  .calc-btn,
  .action-btn {
    border-width: 2px;
  }
}

/* Focus visible for keyboard navigation */
button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--color-muted-gold);
  outline-offset: 3px;
}
