/**
 * ResumeMate 響應式設計優化 🎨
 *
 * 針對多種裝置尺寸優化的現代響應式CSS，
 * 包含進階網格系統、彈性佈局和性能優化
 */

/* ===========================================
   🔧 CSS 變數 - 便於維護和主題切換
=========================================== */
:root {
  /* 🎨 色彩系統 */
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --accent-gradient: linear-gradient(90deg, #e68c06 0%, #d29f47 100%);
  --bg-gradient: linear-gradient(-45deg, #282a50, #4c408e, #282a50, #1f2937);
  --glass-bg: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.2);

  /* 📐 間距系統 */
  --spacing-xs: 0.5rem; /* 8px */
  --spacing-sm: 1rem; /* 16px */
  --spacing-md: 1.5rem; /* 24px */
  --spacing-lg: 2rem; /* 32px */
  --spacing-xl: 3rem; /* 48px */
  --spacing-2xl: 4rem; /* 64px */

  /* 📏 容器寬度 */
  --container-xs: 100%;
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1280px;
  --container-2xl: 1536px;

  /* 🔤 字體大小 */
  --text-xs: 0.75rem; /* 12px */
  --text-sm: 0.875rem; /* 14px */
  --text-base: 1rem; /* 16px */
  --text-lg: 1.125rem; /* 18px */
  --text-xl: 1.25rem; /* 20px */
  --text-2xl: 1.5rem; /* 24px */
  --text-3xl: 1.875rem; /* 30px */
  --text-4xl: 2.25rem; /* 36px */
  --text-5xl: 3rem; /* 48px */
  --text-6xl: 3.75rem; /* 60px */

  /* ⏱️ 動畫時間 */
  --transition-fast: 0.15s;
  --transition-normal: 0.3s;
  --transition-slow: 0.5s;

  /* 📱 斷點 */
  --breakpoint-xs: 0px;
  --breakpoint-sm: 640px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
  --breakpoint-2xl: 1536px;
}

/* ===========================================
   📱 基礎響應式重置
=========================================== */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: "Inter", "Noto Sans TC", sans-serif;
  line-height: 1.6;
  color: #d1d5db;
  background: var(--bg-gradient);
  background-size: 400% 400%;
  animation: gradient 25s ease infinite;
  overflow-x: hidden; /* 防止水平滾動 */
}

/* ===========================================
   🏗️ 容器系統 - 響應式容器
=========================================== */
.container {
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--spacing-sm);
}

/* 響應式容器寬度 */
@media (min-width: 640px) {
  .container {
    max-width: var(--container-sm);
    padding: 0 var(--spacing-md);
  }
}

@media (min-width: 768px) {
  .container {
    max-width: var(--container-md);
    padding: 0 var(--spacing-lg);
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: var(--container-lg);
    padding: 0 var(--spacing-xl);
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: var(--container-xl);
  }
}

@media (min-width: 1536px) {
  .container {
    max-width: var(--container-2xl);
  }
}

/* ===========================================
   📐 響應式網格系統
=========================================== */
.grid {
  display: grid;
  gap: var(--spacing-md);
}

.grid-cols-1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* 響應式網格 */
@media (min-width: 640px) {
  .sm\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .sm\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sm\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .sm\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 768px) {
  .md\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .md\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .md\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .md\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .lg\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .lg\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .lg\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .lg\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .lg\:grid-cols-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .lg\:grid-cols-6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

/* ===========================================
   🧩 彈性佈局系統
=========================================== */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-wrap {
  flex-wrap: wrap;
}

.items-center {
  align-items: center;
}

.items-start {
  align-items: flex-start;
}

.items-end {
  align-items: flex-end;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.justify-around {
  justify-content: space-around;
}

.justify-evenly {
  justify-content: space-evenly;
}

/* ===========================================
   📝 響應式文字系統
=========================================== */
.text-xs {
  font-size: var(--text-xs);
}
.text-sm {
  font-size: var(--text-sm);
}
.text-base {
  font-size: var(--text-base);
}
.text-lg {
  font-size: var(--text-lg);
}
.text-xl {
  font-size: var(--text-xl);
}
.text-2xl {
  font-size: var(--text-2xl);
}
.text-3xl {
  font-size: var(--text-3xl);
}
.text-4xl {
  font-size: var(--text-4xl);
}
.text-5xl {
  font-size: var(--text-5xl);
}
.text-6xl {
  font-size: var(--text-6xl);
}

/* 響應式文字大小 */
@media (max-width: 640px) {
  .text-6xl {
    font-size: var(--text-4xl);
  }
  .text-5xl {
    font-size: var(--text-3xl);
  }
  .text-4xl {
    font-size: var(--text-2xl);
  }
  .text-3xl {
    font-size: var(--text-xl);
  }
}

@media (max-width: 480px) {
  .text-6xl {
    font-size: var(--text-3xl);
  }
  .text-5xl {
    font-size: var(--text-2xl);
  }
  .text-4xl {
    font-size: var(--text-xl);
  }
  .text-3xl {
    font-size: var(--text-lg);
  }
}

/* ===========================================
   📱 導航列響應式優化
=========================================== */
.nav-mobile-menu {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  padding: var(--spacing-lg);
  z-index: 40;
}

.nav-mobile-menu.active {
  display: block;
  animation: slideDown var(--transition-normal) ease-out;
}

.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  cursor: pointer;
  padding: var(--spacing-xs);
}

.mobile-menu-toggle span {
  width: 24px;
  height: 2px;
  background-color: #d1d5db;
  margin: 2px 0;
  transition: all var(--transition-fast) ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

@media (max-width: 768px) {
  .nav-desktop {
    display: none;
  }

  .mobile-menu-toggle {
    display: flex;
  }
}

/* ===========================================
   📋 卡片組件響應式
=========================================== */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: var(--spacing-lg);
  transition:
    transform var(--transition-normal) ease,
    box-shadow var(--transition-normal) ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
  .card {
    padding: var(--spacing-md);
  }
}

@media (max-width: 480px) {
  .card {
    padding: var(--spacing-sm);
    border-radius: 8px;
  }
}

/* ===========================================
   💬 聊天介面響應式
=========================================== */
.chat-container {
  max-width: 100%;
  margin: 0 auto;
}

@media (min-width: 768px) {
  .chat-container {
    max-width: 600px;
  }
}

@media (min-width: 1024px) {
  .chat-container {
    max-width: 800px;
  }
}

.chat-iframe {
  width: 100%;
  height: 400px;
  border: none;
  border-radius: 12px;
  background: var(--glass-bg);
}

@media (min-width: 768px) {
  .chat-iframe {
    height: 500px;
  }
}

@media (min-width: 1024px) {
  .chat-iframe {
    height: 600px;
  }
}

/* ===========================================
   🎪 技能標籤響應式
=========================================== */
.skill-tag {
  display: inline-block;
  background: var(--glass-bg);
  color: #d1d5db;
  padding: var(--spacing-xs) var(--spacing-sm);
  margin: var(--spacing-xs);
  border-radius: 20px;
  font-size: var(--text-sm);
  border: 1px solid var(--glass-border);
  transition: all var(--transition-fast) ease;
}

.skill-tag:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

@media (max-width: 480px) {
  .skill-tag {
    font-size: var(--text-xs);
    padding: calc(var(--spacing-xs) * 0.75) var(--spacing-xs);
    margin: calc(var(--spacing-xs) * 0.5);
  }
}

/* ===========================================
   ⚡ 性能優化樣式
=========================================== */

/* 圖片響應式和懶載入 */
.responsive-img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  transition: opacity var(--transition-normal) ease;
}

.responsive-img[loading="lazy"] {
  opacity: 0;
}

.responsive-img.loaded {
  opacity: 1;
}

/* GPU 加速動畫 */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
}

/* 減少動畫 - 尊重用戶偏好 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===========================================
   🌓 暗色模式支援（預備）
=========================================== */
@media (prefers-color-scheme: dark) {
  :root {
    /* 可以在這裡定義暗色主題變數 */
  }
}

/* ===========================================
   📱 特定裝置優化
=========================================== */

/* 超小螢幕 (< 375px) */
@media (max-width: 375px) {
  .container {
    padding: 0 var(--spacing-xs);
  }

  .nav-brand {
    font-size: var(--text-lg);
  }

  .hero-title {
    font-size: var(--text-2xl);
  }
}

/* 平板橫向 (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  .section-padding {
    padding: var(--spacing-xl) 0;
  }
}

/* 大螢幕優化 (> 1440px) */
@media (min-width: 1440px) {
  .container {
    max-width: 1400px;
  }

  .section-padding {
    padding: var(--spacing-2xl) 0;
  }
}

/* ===========================================
   🖱️ 觸控和滑鼠互動優化
=========================================== */

/* 觸控裝置優化 */
@media (hover: none) and (pointer: coarse) {
  .interactive-element {
    min-height: 44px; /* iOS 建議最小觸控尺寸 */
    min-width: 44px;
  }

  .hover\:scale-105:hover {
    transform: none; /* 移除觸控裝置上的hover效果 */
  }
}

/* 滑鼠裝置優化 */
@media (hover: hover) and (pointer: fine) {
  .hover-effect:hover {
    transform: translateY(-2px);
    transition: transform var(--transition-fast) ease;
  }
}

/* ===========================================
   🎯 可訪問性增強
=========================================== */

/* 聚焦指示器 */
*:focus {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* 跳過導航連結 */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--glass-bg);
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 100;
}

.skip-link:focus {
  top: 6px;
}

/* 螢幕閱讀器隱藏 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===========================================
   🎨 動畫增強
=========================================== */
@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

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

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

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* ===========================================
   🚀 載入狀態和骨架屏
=========================================== */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.1) 25%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.1) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes ripple {
  0% {
    transform: scale(0);
    opacity: 0.6;
  }
  100% {
    transform: scale(4);
    opacity: 0;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateX(2px);
  }
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ===========================================
   🎯 進階互動效果
=========================================== */

/* 導航欄隱藏效果 */
.navbar-hidden {
  transform: translateY(-100%);
  transition: transform var(--transition-normal) ease-in-out;
}

/* 鍵盤導航指示器 */
.keyboard-navigation *:focus {
  outline: 2px solid #667eea !important;
  outline-offset: 2px !important;
  border-radius: 4px;
}

/* 螢幕閱讀器專用 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 動畫完成狀態 */
.animation-complete {
  animation-fill-mode: forwards;
}

/* 交錯動畫組 */
[data-stagger] > * {
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-stagger].animate-fade-in-up > * {
  opacity: 1;
  transform: translateY(0);
}

/* 視差效果元素 */
[data-parallax] {
  transition: transform 0.1s ease-out;
}

/* 進階卡片懸停效果 */
.card,
.project-card,
.skill-card {
  transition: all var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
  backface-visibility: hidden;
}

.card:hover,
.project-card:hover,
.skill-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow:
    0 20px 40px rgba(0, 0, 0, 0.2),
    0 8px 16px rgba(102, 126, 234, 0.1);
}

/* 按鈕增強效果 */
button,
.btn,
.chat-example {
  position: relative;
  overflow: hidden;
  transition: all var(--transition-fast) ease;
}

button:active,
.btn:active,
.chat-example:active {
  transform: scale(0.98);
}

/* 通知系統增強 */
.notification {
  animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.notification.slide-out {
  animation: slideOutRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 滾動進度條 */
#scroll-progress {
  background: linear-gradient(90deg, #667eea, #764ba2, #e68c06);
  background-size: 200% 100%;
  animation: gradient 3s ease infinite;
}

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

  .parallax,
  [data-parallax] {
    transform: none !important;
  }
}

/* 觸控設備優化 */
@media (hover: none) and (pointer: coarse) {
  .card:hover,
  .project-card:hover,
  .skill-card:hover {
    transform: none;
    box-shadow: none;
  }

  /* 為觸控設備增加點擊反饋 */
  .card:active,
  .project-card:active,
  .skill-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
}

/* 高對比模式支援 */
@media (prefers-contrast: high) {
  :root {
    --glass-bg: rgba(0, 0, 0, 0.8);
    --glass-border: rgba(255, 255, 255, 0.8);
  }

  .card,
  .project-card,
  .skill-card {
    border: 2px solid rgba(255, 255, 255, 0.8);
  }
}

/* 暗色模式支援增強 */
@media (prefers-color-scheme: dark) {
  :root {
    --glass-bg: rgba(0, 0, 0, 0.3);
    --glass-border: rgba(255, 255, 255, 0.1);
  }
}

/* ===========================================
   📊 調試和開發輔助
=========================================== */
.debug-grid {
  background-image: linear-gradient(rgba(255, 0, 0, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 0, 0, 0.1) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* 只在開發環境顯示 */
.dev-info {
  position: fixed;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px;
  font-size: 12px;
  border-radius: 4px;
  z-index: 9999;
  display: none;
}

@media (max-width: 640px) {
  .dev-info::after {
    content: " | SM";
  }
}

@media (min-width: 640px) and (max-width: 768px) {
  .dev-info::after {
    content: " | MD";
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .dev-info::after {
    content: " | LG";
  }
}

@media (min-width: 1024px) {
  .dev-info::after {
    content: " | XL";
  }
}

/* ===========================================
   🍔 漢堡菜單 - 行動裝置導航
=========================================== */

/* 漢堡按鈕樣式 */
#hamburger-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#hamburger-btn:focus {
  outline: none;
}

/* 漢堡按鈕中的線條 */
.hamburger-line {
  width: 24px;
  height: 2px;
  background-color: currentColor;
  border-radius: 2px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}

/* 漢堡按鈕打開時的動畫 */
#hamburger-btn.active .hamburger-line:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

#hamburger-btn.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

#hamburger-btn.active .hamburger-line:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

/* 行動菜單抽屜 */
.mobile-menu-drawer {
  animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(24px);
}

.mobile-menu-drawer.hidden {
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* 行動菜單中的連結 */
.mobile-menu-drawer a {
  transition: all 0.2s ease;
}

.mobile-menu-drawer a:active {
  transform: scale(0.98);
}

/* 在 md 以上螢幕隱藏漢堡按鈕 */
@media (min-width: 768px) {
  #hamburger-btn {
    display: none !important;
  }

  .mobile-menu-drawer {
    display: none !important;
  }
}

/* 防止滾動當菜單打開 */
body.menu-open {
  overflow: hidden;
}
