/* ==========================================================================
   榮格心靈星圖 - 宇宙美學與毛玻璃 CSS 設計系統
   ========================================================================== */

/* 基礎變數與設計標記 */
:root {
  /* 神秘深色系配色 */
  --bg-cosmic: #070614;
  --bg-gradient: linear-gradient(135deg, #05040e 0%, #0c0a20 50%, #130f2c 100%);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* 黃金與星光配色 */
  --color-gold: #f59e0b;
  --color-gold-glow: rgba(245, 158, 11, 0.4);
  --color-nebula: #8b5cf6;
  
  /* 毛玻璃質感 (Glassmorphism) */
  --glass-bg: rgba(12, 10, 29, 0.55);
  --glass-bg-hover: rgba(20, 17, 45, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.6);
  --glass-filter: blur(16px);
  
  /* 字型系統 */
  --font-serif: "Noto Serif TC", "Georgia", serif;
  --font-sans: "Noto Sans TC", "system-ui", sans-serif;
  --font-display: "Cinzel", "Times New Roman", serif;
  
  /* 動畫時間 */
  --transition-smooth: all 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
  --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 網頁重設 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-cosmic);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Canvas 星空背景 */
#starfield {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* 應用程式主包裝器 */
.app-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: width 0.45s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* ==========================================================================
   頂部標頭
   ========================================================================== */
.app-header {
  padding: 30px 40px 10px;
  text-align: center;
  background: linear-gradient(to bottom, rgba(5, 4, 14, 0.9) 0%, rgba(5, 4, 14, 0) 100%);
  pointer-events: auto;
}

.app-header .brand {
  display: inline-block;
  margin-bottom: 8px;
}

.app-header .en-sub {
  display: block;
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.4em;
  color: var(--color-gold);
  margin-bottom: 4px;
}

.app-header h1 {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 2.2rem;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.15);
  display: inline-block;
}

.app-header .en-main {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.25em;
  color: var(--text-secondary);
  margin-top: -2px;
}

.app-header .subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  font-weight: 300;
  margin-top: 10px;
}

/* 領域星系切換器 */
.author-tabs {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 20px auto 5px;
  max-width: 650px;
  padding: 6px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  backdrop-filter: var(--glass-filter);
  z-index: 10;
  position: relative;
  box-shadow: var(--glass-shadow);
}

.author-tab {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 99px;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.author-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

/* 榮格選中狀態：紫色發光 */
.author-tab[data-author="jung"].active {
  background: rgba(192, 132, 252, 0.2);
  color: #c084fc;
  border: 1px solid rgba(192, 132, 252, 0.4);
  box-shadow: 0 0 15px rgba(192, 132, 252, 0.2);
}

/* 佛洛伊德選中狀態：紅色發光 */
.author-tab[data-author="freud"].active {
  background: rgba(244, 63, 94, 0.2);
  color: #f43f5e;
  border: 1px solid rgba(244, 63, 94, 0.4);
  box-shadow: 0 0 15px rgba(244, 63, 94, 0.2);
}

/* 阿德勒選中狀態：綠色發光 */
.author-tab[data-author="adler"].active {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.4);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
}

/* ==========================================================================
   主星圖繪製區域
   ========================================================================== */
.map-container {
  flex: 1 1 0%;
  position: relative;
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
  overflow: visible;
  cursor: grab;
  min-height: 350px;
}

.map-container:active {
  cursor: grabbing;
}

/* SVG 連線軌跡 */
.constellation-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* 連線路徑預設樣式 */
.c-line {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: drawLine 3.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  opacity: 0.25;
  transition: var(--transition-smooth);
}

.c-line.active {
  opacity: 0.8;
  stroke-width: 2.2px;
  filter: drop-shadow(0 0 8px currentColor);
}

.c-line-flow {
  stroke-dasharray: 12 30;
  animation: flowLine 35s linear infinite;
  opacity: 0;
  transition: var(--transition-smooth);
}

.c-line-flow.active {
  opacity: 0.4;
}

/* 連線文字標籤 */
.c-label {
  font-size: 0.72rem;
  font-family: var(--font-sans);
  fill: var(--text-muted);
  text-anchor: middle;
  opacity: 0;
  transition: var(--transition-smooth);
}

.c-label.active {
  opacity: 0.8;
  fill: var(--text-secondary);
}

/* 星點 HTML 塗層 */
.stars-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

/* 單個星點節點 */
.star-node {
  position: absolute;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: var(--transition-smooth);
}

/* 星點核心縮小讓密集區域更通透 */
.star-node .star-core {
  width: 10px;
  height: 10px;
}
.star-node .star-halo {
  width: 22px;
  height: 22px;
}
.star-node .star-halo-outer {
  width: 36px;
  height: 36px;
}

/* 星星核心發光體 */
.star-core {
  position: relative;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #ffffff;
  box-shadow: 0 0 10px 2px #ffffff;
  transition: var(--transition-smooth);
}

/* 呼吸光暈圈 */
.star-halo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid currentColor;
  transform: translate(-50%, -50%) scale(1);
  opacity: 0.4;
  animation: glowPulse 3s ease-in-out infinite;
  pointer-events: none;
  transition: var(--transition-smooth);
}

.star-halo-outer {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px dashed currentColor;
  transform: translate(-50%, -50%) scale(1);
  opacity: 0.15;
  animation: glowPulse 5s ease-in-out infinite reverse;
  pointer-events: none;
  transition: var(--transition-smooth);
}

/* 書名標籤 — 預設只顯示精簡小標，hover 時展開完整名稱 */
.star-label {
  position: absolute;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.7rem;
  color: var(--text-secondary);
  background: rgba(12, 10, 29, 0.75);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  pointer-events: none;
  transition: var(--transition-smooth);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 標籤在上方的節點 */
.star-node[data-label-pos="top"] .star-label {
  top: auto;
  bottom: 30px;
}

/* 星點 Hover 狀態 */
.star-node:hover {
  z-index: 50;
}

.star-node:hover .star-core {
  transform: scale(1.5);
  box-shadow: 0 0 16px 4px #ffffff, 0 0 25px 8px currentColor;
}

.star-node:hover .star-halo {
  transform: translate(-50%, -50%) scale(1.3);
  opacity: 0.8;
}

.star-node:hover .star-label {
  max-width: 200px;
  overflow: visible;
  white-space: nowrap;
  color: #fff;
  background: rgba(12, 10, 29, 0.95);
  border-color: rgba(255, 255, 255, 0.25);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 4px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  z-index: 100;
}

/* 星點選中選中 / 聚焦狀態 (Active) */
.star-node.active {
  z-index: 30;
}

.star-node.active .star-core {
  background-color: #ffffff;
  transform: scale(1.6);
  box-shadow: 0 0 20px 6px #ffffff, 0 0 35px 12px currentColor;
}

.star-node.active .star-halo {
  transform: translate(-50%, -50%) scale(1.5);
  opacity: 0.9;
  border-width: 2px;
  animation: glowPulse 2s ease-in-out infinite;
}

.star-node.active .star-halo-outer {
  transform: translate(-50%, -50%) scale(1.3);
  opacity: 0.4;
  border-style: solid;
}

.star-node.active .star-label {
  background: var(--node-color, var(--color-gold));
  color: #070614;
  font-weight: 900;
  border-color: transparent;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  max-width: 200px;
  overflow: visible;
  white-space: nowrap;
  font-size: 0.82rem;
  z-index: 100;
}

/* 已購藏書特殊樣式：星點外圍增加金色雙重虛線軌道與標籤標記 */
.star-node.owned .star-halo-outer {
  border: 1px dashed var(--color-gold) !important;
  opacity: 0.6;
  width: 52px;
  height: 52px;
}

.star-node.owned .star-label::after {
  content: " 📖";
  font-size: 0.8rem;
}

/* 節點淡出狀態 (當被篩選器隱藏時) */
.star-node.dimmed {
  opacity: 0.15;
  filter: blur(1px);
  pointer-events: none;
}

/* ==========================================================================
   底部篩選器與頁腳
   ========================================================================== */
.app-footer {
  padding: 20px 40px 25px;
  background: linear-gradient(to top, rgba(5, 4, 14, 0.95) 0%, rgba(5, 4, 14, 0.6) 80%, rgba(5, 4, 14, 0) 100%);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 5;
}

.filter-box {
  width: 100%;
  max-width: 1000px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 16px 24px;
  backdrop-filter: var(--glass-filter);
  -webkit-backdrop-filter: var(--glass-filter);
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.filter-title {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--color-gold);
}

.filter-title i {
  margin-right: 4px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 400;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.chip:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.chip.on {
  background: rgba(245, 158, 11, 0.12);
  border-color: var(--color-gold);
  color: var(--color-gold);
  font-weight: 500;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.2);
}

.footer-credit {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ==========================================================================
   側邊欄詳情面板
   ========================================================================== */
.details-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  z-index: 100;
  background: var(--glass-bg);
  border-left: 1px solid var(--glass-border);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.7);
  backdrop-filter: var(--glass-filter);
  -webkit-backdrop-filter: var(--glass-filter);
  transform: translateX(100%);
  transition: transform 0.45s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.details-panel:not([hidden]) {
  transform: translateX(0);
}

.panel-inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 40px 30px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.panel-inner::-webkit-scrollbar {
  width: 6px;
}

.panel-inner::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

/* 關閉按鈕 */
.close-btn {
  position: absolute;
  top: 25px;
  right: 25px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: var(--transition-fast);
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
  transform: rotate(90deg);
}

/* 書籍主資訊區 */
.book-header {
  margin-top: 20px;
  margin-bottom: 24px;
}

.book-theme {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--color-gold);
  border: 1px solid var(--color-gold-glow);
  border-radius: 999px;
  padding: 4px 14px;
  background: rgba(245, 158, 11, 0.05);
  margin-bottom: 12px;
}

.book-title {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 1.85rem;
  line-height: 1.3;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.book-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.book-meta .meta-divider {
  color: var(--text-muted);
}

.book-meta i {
  margin-right: 2px;
}

/* 金句卡片 */
.quote-card {
  position: relative;
  background: rgba(255, 255, 255, 0.02);
  border-left: 3px solid var(--color-gold);
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 28px;
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.01);
}

.quote-text {
  font-family: var(--font-serif);
  font-size: 0.98rem;
  line-height: 1.8;
  color: #f1f5f9;
  letter-spacing: 0.05em;
  font-style: italic;
}

.quote-icon-start {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.03);
}

.quote-icon-end {
  position: absolute;
  bottom: 10px;
  right: 15px;
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.03);
}

/* 詳細內容區 */
.panel-body {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.info-section h3 {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 6px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-section h3 i {
  color: var(--color-gold);
  font-size: 0.95rem;
}

.info-section p {
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text-secondary);
  text-align: justify;
}

/* 章節清單 */
.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chapter-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 12px 16px;
  transition: var(--transition-fast);
}

.chapter-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.chapter-title {
  font-family: var(--font-serif);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.chapter-desc {
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* ==========================================================================
   關鍵幀動畫
   ========================================================================== */
@keyframes glowPulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.4;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.18);
    opacity: 0.18;
  }
}

@keyframes drawLine {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes flowLine {
  to {
    stroke-dashoffset: -1000;
  }
}

/* 響應式佈局適應 */
@media (max-width: 860px) {
  .app-header {
    padding: 20px 20px 5px;
  }
  
  .app-header h1 {
    font-size: 1.7rem;
  }
  
  .author-tabs {
    max-width: 100%;
    margin: 15px auto 4px;
    gap: 6px;
    padding: 4px;
  }
  
  .author-tab {
    font-size: 0.76rem;
    padding: 6px 10px;
  }
  
  .app-footer {
    padding: 10px 15px 15px;
  }
  
  .map-container {
    min-height: 300px;
  }
  
  .filter-box {
    padding: 12px 16px;
    border-radius: 16px;
  }
  
  .chip {
    padding: 6px 12px;
    font-size: 0.78rem;
  }

  .details-panel {
    max-width: 100%;
  }

  .star-label {
    font-size: 0.62rem;
    padding: 1px 5px;
    max-width: 72px;
  }
}

@media (max-width: 480px) {
  .app-header h1 {
    font-size: 1.45rem;
  }
  .app-header .en-sub {
    font-size: 0.65rem;
  }
  .app-header .en-main {
    font-size: 0.8rem;
  }
  .app-header .subtitle {
    font-size: 0.78rem;
  }
}

/* 針對無障礙 / 減少動態 */
@media (prefers-reduced-motion: reduce) {
  .star-halo, .star-halo-outer, .c-line, .c-line-flow {
    animation: none !important;
  }
  .details-panel {
    transition: none !important;
  }
}

/* 當詳情面板打開時，自適應縮小包裝器寬度（避免被側邊欄擋到） */
@media (min-width: 1025px) {
  body.details-open .app-wrap {
    width: calc(100% - 480px);
  }
}

