/* ===================================================
   九型人格測驗 — style.css
   主題：新海誠畫風 · 深邃夜空藍 + 黃昏金光
   =================================================== */

/* ── 設計 Tokens ── */
:root {
  --color-bg:           #0a0e1a;
  --color-surface:      #141b2d;
  --color-surface-alt:  #1c2540;
  --color-border:       #2a3556;
  --color-text:         #e8ecf4;
  --color-text-muted:   #7b8db5;
  --color-accent:       #f0a030;
  --color-accent-hover: #d88a20;
  --color-accent-glow:  rgba(240, 160, 48, 0.3);
  --color-success:      #4ECDC4;
  --color-warning:      #F39C12;
  --color-error:        #E74C3C;

  --color-ad-bg:        #141b2d;
  --color-ad-border:    #2a3556;

  --font-serif: 'Noto Serif TC', serif;
  --font-sans:  'Noto Sans TC', 'Inter', system-ui, sans-serif;
  --font-en:    'Inter', system-ui, sans-serif;

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px;
  --space-4: 16px; --space-5: 20px; --space-6: 24px;
  --space-8: 32px; --space-10: 40px;

  --radius-sm: 6px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow:    0 8px 32px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 40px var(--color-accent-glow);
}

/* ── 全域 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  position: relative;
  width: 100%;
  min-height: 100vh;
}

/* ── 畫面切換 ── */
.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  padding: var(--space-6);
  animation: fadeIn 0.6s ease-out;
}
.screen.active { display: flex; flex-direction: column; align-items: center; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================================================
   封面頁
   =================================================== */
#screen-cover {
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.cover-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(240,160,48,0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(155,89,182,0.1) 0%, transparent 50%),
    radial-gradient(ellipse at 20% 70%, rgba(52,152,219,0.08) 0%, transparent 50%),
    var(--color-bg);
  z-index: 0;
}

.cover-content {
  position: relative; z-index: 1;
  text-align: center;
  max-width: 600px;
}

/* 粒子效果（封面背景） */
.cover-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.particle {
  position: absolute;
  border-radius: 50%;
  background: var(--color-accent);
  animation: particleFloat linear infinite;
  opacity: 0;
}
@keyframes particleFloat {
  0%   { transform: translateY(0) scale(0); opacity: 0; }
  10%  { opacity: 0.6; }
  90%  { opacity: 0.6; }
  100% { transform: translateY(-100vh) scale(1); opacity: 0; }
}

/* 封面標題 */
.cover-title {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}
.title-sub {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--color-accent);
  letter-spacing: 4px;
  text-transform: uppercase;
}
.title-main {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--color-text), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}
.title-en {
  font-family: var(--font-en);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  letter-spacing: 2px;
  font-weight: 400;
}

.cover-desc {
  color: var(--color-text-muted);
  font-size: 1.05rem;
  margin-bottom: var(--space-10);
  line-height: 1.6;
}

/* 性別選擇器 — 迷幻展開動畫 */
.gender-selector {
  animation: psychedelicReveal 1.2s ease-out 0.3s both;
}

@keyframes psychedelicReveal {
  0% {
    opacity: 0;
    transform: scale(0.8) rotate(-2deg);
    filter: blur(10px) hue-rotate(-30deg);
  }
  40% {
    filter: blur(3px) hue-rotate(20deg);
  }
  70% {
    transform: scale(1.02) rotate(0.5deg);
    filter: blur(1px) hue-rotate(5deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: blur(0) hue-rotate(0deg);
  }
}

.gender-label {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.gender-buttons {
  display: flex;
  gap: var(--space-5);
  justify-content: center;
}

.gender-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-8);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}
.gender-btn::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, var(--color-accent-glow), transparent 70%);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.gender-btn:hover {
  border-color: var(--color-accent);
  transform: translateY(-4px);
  box-shadow: var(--shadow-glow);
}
.gender-btn:hover::before { opacity: 1; }
.gender-btn:active { transform: translateY(-2px); }

.gender-icon-wrap {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  position: relative; z-index: 1;
  transition: background 0.3s ease;
}
.gender-btn:hover .gender-icon-wrap {
  background: rgba(240,160,48,0.15);
  border-color: var(--color-accent);
}
.gender-icon {
  width: 28px; height: 28px;
  color: var(--color-text-muted);
  transition: color 0.3s ease;
}
.gender-btn:hover .gender-icon { color: var(--color-accent); }
.gender-btn span { position: relative; z-index: 1; }

/* ===================================================
   答題頁
   =================================================== */
#screen-quiz {
  padding-top: var(--space-4);
  max-width: 680px;
  margin: 0 auto;
}

/* 進度條 */
.quiz-header {
  width: 100%;
  margin-bottom: var(--space-6);
}
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-surface-alt);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: var(--space-2);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-accent), #ffcc70);
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}
.question-counter {
  text-align: center;
  font-family: var(--font-en);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* 題目情境插圖 */
.question-illustration-wrap {
  width: 100%;
  max-width: 520px;
  margin: 0 auto var(--space-5);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}
.question-illustration {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
  transition: opacity 0.4s ease;
}
.question-illustration.fade-out { opacity: 0; }

/* 題目文字 */
.question-text {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-text);
  margin-bottom: var(--space-6);
  line-height: 1.6;
}

/* 選項容器 */
.options-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: 80px;
}

.option-btn {
  display: block;
  width: 100%;
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s ease;
  line-height: 1.5;
  position: relative;
  overflow: hidden;
}
.option-btn::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--color-accent);
  transform: scaleY(0);
  transition: transform 0.25s ease;
}
.option-btn:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-accent);
  transform: translateX(4px);
}
.option-btn:hover::before { transform: scaleY(1); }
.option-btn:active { transform: translateX(2px); }

.option-btn.selected {
  background: rgba(240,160,48,0.12);
  border-color: var(--color-accent);
}
.option-btn.selected::before { transform: scaleY(1); }

/* ===================================================
   結果頁
   =================================================== */
#screen-result {
  padding-top: var(--space-8);
  max-width: 700px;
  margin: 0 auto;
  justify-content: center;
}

.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.result-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--color-accent), #9B59B6, #3498DB, var(--color-accent));
  background-size: 200% 100%;
  animation: gradientShift 4s ease infinite;
}
@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

.result-image-wrap {
  width: 100%; max-width: 480px; height: 260px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 2px solid var(--color-accent);
  box-shadow: 0 0 30px var(--color-accent-glow);
}
.result-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.result-type-badge {
  display: inline-block;
  padding: var(--space-1) var(--space-4);
  background: rgba(240,160,48,0.15);
  border: 1px solid var(--color-accent);
  border-radius: 20px;
  color: var(--color-accent);
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: var(--space-3);
}

.result-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: var(--space-2);
  background: linear-gradient(135deg, var(--color-text), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-alias {
  font-family: var(--font-en);
  font-size: 1rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
  font-weight: 400;
  letter-spacing: 1px;
}

.result-description {
  color: var(--color-text);
  font-size: 0.95rem;
  line-height: 1.8;
  margin-bottom: var(--space-8);
  text-align: left;
  padding: 0 var(--space-4);
}

/* 結果詳情 */
.result-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  margin-bottom: var(--space-8);
  text-align: left;
}

.detail-section {
  padding: var(--space-5);
  background: var(--color-surface-alt);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.detail-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: var(--space-3);
}
.detail-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
}

.detail-section p {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--color-text-muted);
}

/* 展開按鈕（手機分析展開/收合） */
.btn-expand {
  display: none; /* 桌面版隱藏 */
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3);
  margin-top: var(--space-4);
  background: transparent;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-expand:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.btn-expand .btn-icon {
  transition: transform 0.3s ease;
}
.btn-expand.expanded .btn-icon {
  transform: rotate(180deg);
}

/* 按鈕 */
.result-actions {
  display: flex;
  gap: var(--space-4);
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-icon { width: 18px; height: 18px; flex-shrink: 0; }

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--color-accent-glow);
}

.btn-secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  border-color: var(--color-accent);
  transform: translateY(-2px);
}

/* ===================================================
   V2 浮動底部橫幅廣告
   =================================================== */
.quiz-ad-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.4s ease;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}
.quiz-ad-banner.visible { transform: translateY(0); }

.quiz-ad-close {
  position: absolute;
  top: var(--space-2); right: var(--space-3);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all 0.2s ease;
  z-index: 2;
}
.quiz-ad-close:hover {
  color: var(--color-text);
  border-color: var(--color-accent);
}

/* 廣告 Slot 基底 */
.ad-slot {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  position: relative;
}
.ad-slot.ad-loaded::before { display: none; }
.ad-slot--result {
  margin-top: var(--space-6);
  width: 100%;
}

/* ===================================================
   RWD
   =================================================== */
@media (max-width: 768px) {
  .screen { padding: var(--space-3); }

  .title-main { font-size: 2.2rem; }
  .cover-desc { font-size: 0.95rem; margin-bottom: var(--space-6); }

  .gender-buttons { flex-direction: column; gap: var(--space-3); }
  .gender-btn {
    flex-direction: row;
    padding: var(--space-4) var(--space-6);
  }
  .gender-icon-wrap { width: 44px; height: 44px; }
  .gender-icon { width: 22px; height: 22px; }

  .question-illustration { height: 160px; }
  .question-text { font-size: 1.15rem; margin-bottom: var(--space-4); }
  .options-container { padding-bottom: 60px; }

  /* ── 結果頁手機：截圖分享最佳化 ── */
  #screen-result {
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
    justify-content: center;
    min-height: 100vh;
  }

  .result-card {
    padding: var(--space-3);
    border-radius: var(--radius-lg);
  }

  .result-image-wrap {
    width: 100%; max-width: 100%; height: 260px;
    margin-bottom: var(--space-3);
    border-width: 2px;
    border-radius: var(--radius);
    box-shadow: 0 0 20px var(--color-accent-glow);
  }

  .result-type-badge {
    font-size: 0.7rem;
    padding: 2px 12px;
    margin-bottom: 4px;
  }

  .result-title {
    font-size: 1.4rem;
    margin-bottom: 0;
  }

  .result-alias {
    font-size: 0.8rem;
    margin-bottom: var(--space-2);
  }

  .result-description {
    font-size: 0.82rem;
    line-height: 1.55;
    margin-bottom: var(--space-3);
    padding: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* 手機版展開按鈕可見 */
  .btn-expand { display: flex; }

  /* 手機版 details 預設隱藏 */
  .result-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, margin 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    margin-bottom: 0;
  }
  .result-details.expanded {
    max-height: 800px;
    opacity: 1;
    margin-bottom: var(--space-4);
  }

  .result-details {
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }
  .detail-section {
    padding: var(--space-3);
  }
  .detail-title {
    font-size: 0.85rem;
    margin-bottom: var(--space-2);
  }
  .detail-section p {
    font-size: 0.8rem;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .result-actions {
    gap: var(--space-3);
  }
  .btn {
    padding: 10px 20px;
    font-size: 0.88rem;
  }
  .btn-icon { width: 16px; height: 16px; }

  .ad-slot--result { margin-top: var(--space-3); }
}

@media (max-width: 430px) {
  /* 針對 iPhone 14 Pro Max 等標準手機尺寸微調 */
  .title-main { font-size: 1.8rem; }
  .question-illustration { height: 130px; }

  .result-image-wrap {
    height: 260px;
  }
  .result-title { font-size: 1.35rem; }
  .result-description {
    font-size: 0.82rem;
    -webkit-line-clamp: 3;
  }
  .detail-section p {
    -webkit-line-clamp: 2;
  }
}
