/* 響應式調整 - 使用 CSS 變數統一控制比例 */
:root {
  --branch-size: 112px;
  --center-size: 160px;
  --orbit: 230px;
}

@media (max-width: 640px) {
  :root {
    --branch-size: min(78px, 20vw);
    --center-size: min(92px, 24vw);
    --orbit: calc(38vw);
  }
  .orbit-radius { --orbit-radius: var(--orbit); }
  .center-circle { 
    width: var(--center-size) !important; 
    height: var(--center-size) !important; 
  }
  .center-year { font-size: clamp(7px, 2.5vw, 10px) !important; }
  .center-ganzhi { font-size: clamp(14px, 5.5vw, 20px) !important; }
  .center-general { font-size: clamp(6px, 2.2vw, 9px) !important; line-height: 1.2 !important; }
  .branch-circle { 
    width: var(--branch-size) !important; 
    height: var(--branch-size) !important; 
  }
  .branch-text { font-size: clamp(13px, 4.2vw, 16px) !important; margin-bottom: 2px !important; }
  .branch-label { font-size: clamp(6px, 2vw, 8px) !important; line-height: 1.15 !important; }
}

@media (min-width: 641px) and (max-width: 1024px) {
  :root {
    --branch-size: 100px;
    --center-size: 115px;
    --orbit: 195px;
  }
  .orbit-radius { --orbit-radius: var(--orbit); }
  .center-circle { width: var(--center-size) !important; height: var(--center-size) !important; }
  .branch-circle { width: var(--branch-size) !important; height: var(--branch-size) !important; }
  .branch-text { font-size: 18px !important; }
  .branch-label { font-size: 7pt !important; line-height: 1.05 !important; }
}

@media (min-width: 1025px) {
  .orbit-radius { --orbit-radius: var(--orbit); }
}

/* 神煞標籤容器 - 根據內容量自動縮放 */
.branch-labels-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  transform-origin: top center;
}

/* 標籤數量多時自動縮小字體（桌面版） */
.branch-labels-container.labels-5 .branch-label { font-size: 10px !important; }
.branch-labels-container.labels-6 .branch-label { font-size: 9.5px !important; }
.branch-labels-container.labels-7 .branch-label { font-size: 9px !important; }
.branch-labels-container.labels-8 .branch-label { font-size: 8.5px !important; }

@media (max-width: 640px) {
  .branch-labels-container.labels-5 .branch-label { font-size: 7px !important; }
  .branch-labels-container.labels-6 .branch-label { font-size: 6.5px !important; }
  .branch-labels-container.labels-7 .branch-label { font-size: 6px !important; }
  .branch-labels-container.labels-8 .branch-label { font-size: 5.5px !important; }
}

@keyframes spin-in {
  0% {
    transform: translate(-50%, -50%) rotate(0deg) translateY(var(--orbit-radius, 230px)) rotate(0deg);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, -50%) rotate(var(--angle)) translateY(calc(-1 * var(--orbit-radius, 230px))) rotate(calc(-1 * var(--angle)));
    opacity: 1;
  }
}

.branch-item {
  animation: spin-in 1.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes orbit-spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
    filter: drop-shadow(0 0 0 transparent);
  }
  10% {
    filter: drop-shadow(2px 0 3px rgba(0,0,0,0.25)) 
            drop-shadow(4px 0 6px rgba(0,0,0,0.15));
  }
  50% {
    filter: drop-shadow(4px 0 6px rgba(0,0,0,0.35)) 
            drop-shadow(8px 0 12px rgba(0,0,0,0.25)) 
            drop-shadow(12px 0 18px rgba(0,0,0,0.15));
  }
  90% {
    filter: drop-shadow(2px 0 3px rgba(0,0,0,0.25)) 
            drop-shadow(4px 0 6px rgba(0,0,0,0.15));
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
    filter: drop-shadow(0 0 0 transparent);
  }
}

.orbit-container {
  animation: orbit-spin 2s cubic-bezier(0.45, 0.05, 0.55, 0.95) forwards;
}

/* 為每個地支圓形添加拖影效果 */
.orbit-container.orbit-spinning .branch-item > div > div {
  filter: drop-shadow(3px 0 4px rgba(0,0,0,0.3)) 
          drop-shadow(6px 0 8px rgba(0,0,0,0.2));
}

/* 選中樣式延遲顯示 */
@keyframes highlight-fade-in {
  0% {
    background-color: white;
    border-color: rgb(148 163 184);
    border-width: 3px;
    transform: scale(1);
  }
  30% {
    transform: scale(1.25);
    background-color: rgb(255, 252, 230);
    border-color: rgb(250, 204, 21);
  }
  50% {
    transform: scale(0.92);
  }
  65% {
    transform: scale(1.08);
  }
  80% {
    transform: scale(0.98);
  }
  100% {
    background-color: rgb(254 249 195);
    border-color: rgb(234 179 8);
    border-width: 4px;
    transform: scale(1);
  }
}

.user-branch-highlight {
  animation: highlight-fade-in 1s cubic-bezier(0.34, 1.56, 0.64, 1) 2s forwards;
  background-color: white;
  border-color: rgb(148 163 184);
}

/* 統一表單輸入框樣式 */
.form-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: 0.375rem;
  border: 1px solid #d1d5db;
  padding: 0 0.75rem;
  font-size: 1rem;
  line-height: 1;
  height: 44px;
  background-color: #fff;
  color: #1f2937;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Select 下拉框自定義樣式 */
select.form-input {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
  cursor: pointer;
}

/* 移除 Safari/Chrome 預設的下拉箭頭 */
select.form-input::-ms-expand {
  display: none;
}

/* 修復 iOS Safari 日期輸入框樣式 */
input[type="datetime-local"]::-webkit-datetime-edit {
  padding: 0;
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  margin-left: 4px;
}

/* iOS 日期輸入框空值提示 - 解決空白顯示問題 */
.date-input-wrapper {
  position: relative;
}

/* 未選擇時，隱藏輸入框的空白內容 */
.date-input-wrapper:not(.has-value):not(.is-focused) input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper {
  opacity: 0;
}

/* 自定義 placeholder 文字 */
.date-input-wrapper .placeholder-text {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  pointer-events: none;
  font-size: 16px;
  transition: opacity 0.2s;
}

/* 有值或聚焦時隱藏 placeholder */
.date-input-wrapper.has-value .placeholder-text,
.date-input-wrapper.is-focused .placeholder-text {
  opacity: 0;
}

/* 有值或聚焦時顯示輸入框內容 */
.date-input-wrapper.has-value input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper,
.date-input-wrapper.is-focused input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper {
  opacity: 1;
}

/* 手機端地支圓內標籤字號調整 */
@media (max-width: 640px) {
  .branch-label {
    font-size: 8pt !important;
    line-height: 1.1 !important;
  }
  .branch-text {
    font-size: 1rem !important;
  }
}

/* 查詢結果從下到上漸顯動畫 */
@keyframes fade-in-up {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-fade-in {
  opacity: 0;
  animation: fade-in-up 0.6s ease-out 3s forwards;
}

/* 分享按鈕縮放出現動畫 */
@keyframes scale-in {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.share-btn-appear {
  opacity: 0;
  animation: scale-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 3.5s forwards;
}

/* 共享按鈕樣式 */
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  background-size: 200% 200%;
  background-position: 0% 50%;
  color: white;
  padding: 10px 20px;
  border-radius: 25px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  transition: all 0.4s ease;
  position: relative;
  overflow: hidden;
}

.share-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.4) 50%,
    transparent 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  transform: skewX(-35deg);
}

.share-btn:hover {
  transform: translateY(-3px);
  background-position: 100% 50%;
  box-shadow: 0 8px 25px rgba(240, 147, 251, 0.5),
              0 0 40px rgba(102, 126, 234, 0.3);
}

.share-btn:hover::before {
  opacity: 1;
  animation: shimmer 2.2s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 200%;
  }
}

.share-btn:active {
  transform: translateY(-1px);
}

.share-btn svg {
  width: 18px;
  height: 18px;
  transition: transform 0.3s ease;
}

.share-btn:hover svg {
  transform: scale(1.1) rotate(15deg);
}

/* 分享成功提示 */
.share-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
}

.share-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ===== Disclaimer Page Styles ===== */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fade-in 0.6s ease-out forwards;
}

.fade-in-delay {
  opacity: 0;
  animation: fade-in 0.6s ease-out 0.3s forwards;
}
