/* ==========================================================
   TRUC TRUC 產地探索地球儀 Globe Explorer
   RWD：桌機側欄 / 平板窄側欄 / 手機底部抽屜
   ========================================================== */

.gx-wrap {
  position: relative;
  width: 100%;
  height: 80vh;
  min-height: 480px;
  max-height: 900px;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #101a2b 0%, #060a12 100%);
  border-radius: 12px;
  font-family: "Noto Sans TC", -apple-system, "PingFang TC",
    "Microsoft JhengHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.gx-globe {
  position: absolute;
  inset: 0;
}
.gx-globe canvas { outline: none; }

/* ---------- 標題與提示 ---------- */
.gx-header {
  position: absolute;
  top: 16px;
  left: 20px;
  right: 20px;
  z-index: 5;
  color: var(--gx-text, #fff);
  pointer-events: none;
}
.gx-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}
.gx-header p {
  margin: 4px 0 0;
  font-size: 13px;
  opacity: 0.75;
}

.gx-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
  background: rgba(0, 0, 0, 0.35);
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.5s;
}
.gx-hint.gx-hidden { opacity: 0; }

/* 「點一下啟用地圖」覆蓋層：透明、不擋頁面捲動，點擊後隱藏 */
.gx-guard {
  position: absolute;
  inset: 0;
  z-index: 8; /* 蓋住地球與標記，低於面板(10) */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: transparent;
}
.gx-guard span {
  font-size: 14px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.35);
  padding: 9px 22px;
  border-radius: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}
.gx-guard.gx-off { display: none; }

.gx-legal {
  position: absolute;
  bottom: 14px;
  right: 14px;
  z-index: 5;
  color: var(--gx-text, #fff);
  opacity: 0.55;
  font-size: 11px;
  pointer-events: none;
}

/* ---------- 國家標記（HTML marker） ---------- */
.gx-marker {
  cursor: pointer;
  transform: translate(-50%, -100%);
  text-align: center;
  pointer-events: auto;
  user-select: none;
  transition: transform 0.15s, opacity 0.3s;
}
/* 選取產區/城市時隱藏國旗標記，避免遮住放大後的區域 */
.gx-scope-active .gx-marker {
  opacity: 0;
  pointer-events: none;
}

/* ---------- 城市/小產區的大頭針標記 ----------
   外層設 0×0 錨點，內容以針尖對齊座標，不受定位方式影響 */
.gx-pin {
  width: 0;
  height: 0;
  overflow: visible;
  position: relative;
  pointer-events: none;
}
.gx-pin-inner {
  position: absolute;
  left: 0;
  bottom: 3px; /* 補償針尖旋轉外凸，讓尖端正好落在座標上 */
  transform: translateX(-50%);
  width: max-content;
  text-align: center;
  animation: gx-pin-drop 0.4s ease-out;
}
.gx-pin .gx-pin-label {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
  color: #1c1c1c;
  background: var(--gx-hl, #ffd94d);
  padding: 3px 12px;
  border-radius: 14px;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.gx-pin .gx-pin-head {
  width: 20px;
  height: 20px;
  margin: 0 auto;
  background: var(--gx-hl, #ffd94d);
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 0 14px var(--gx-hl, #ffd94d);
  animation: gx-pin-pulse 1.4s ease-in-out infinite;
}
@keyframes gx-pin-drop {
  from { transform: translateX(-50%) translateY(-16px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
@keyframes gx-pin-pulse {
  0%, 100% { box-shadow: 0 0 8px var(--gx-hl, #ffd94d); }
  50% { box-shadow: 0 0 22px var(--gx-hl, #ffd94d); }
}
.gx-marker:hover { transform: translate(-50%, -100%) scale(1.15); }
.gx-marker .gx-marker-flag {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}
.gx-marker .gx-marker-label {
  display: inline-block;
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 5px 13px;
  border-radius: 16px;
  white-space: nowrap;
}
.gx-marker .gx-marker-pin {
  width: 2px;
  height: 10px;
  margin: 2px auto 0;
  background: rgba(255, 255, 255, 0.6);
}

/* ---------- 側欄 / 抽屜面板 ---------- */
.gx-panel {
  position: absolute;
  z-index: 10;
  background: transparent; /* 標題區透明，地圖穿透可見 */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* 桌機：右側欄 */
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 92%;
  transform: translateX(105%);
  transition: transform 0.35s cubic-bezier(0.22, 0.8, 0.3, 1);
  border-radius: 12px 0 0 12px;
}
.gx-panel.gx-open { transform: translateX(0); }

.gx-panel-head {
  position: relative;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 10px 48px 8px 16px; /* 右側留給關閉鈕 */
  color: var(--gx-text, #fff);
  background: transparent;
  text-shadow: var(--gx-text-shadow, 0 1px 6px rgba(0, 0, 0, 0.85));
  flex-shrink: 0;
}
.gx-panel-head .gx-country-flag { display: none; } /* 不顯示國碼/國旗 */
.gx-panel-head h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
}
.gx-panel-head p {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0.92;
}

.gx-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  box-sizing: border-box;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 14px;
  line-height: 26px;
  text-align: center;
  cursor: pointer;
}
.gx-close:hover { background: rgba(255, 255, 255, 0.32); }

.gx-drag-handle { display: none; }

.gx-panel-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 18px 24px;
  background: #fff;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.35);
}

/* 產區 chips */
.gx-region-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 14px;
}
.gx-chip {
  border: 1.5px solid var(--gx-theme, #b98a4e);
  color: var(--gx-theme, #b98a4e);
  background: #fff;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s;
}
.gx-chip:hover { background: rgba(0, 0, 0, 0.04); }
.gx-chip.gx-active {
  background: var(--gx-theme, #b98a4e);
  color: #fff;
}
.gx-chip-city { border-style: dashed; } /* 城市層：虛線框區別於產區 */

.gx-region-desc {
  font-size: 13.5px;
  color: #555;
  line-height: 1.7;
  margin: 0 0 14px;
}

/* YouTube 輕量嵌入 */
.gx-video {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  margin: 0 0 16px;
  background: #000;
  cursor: pointer;
}
.gx-video img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.85;
}
.gx-video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.gx-video .gx-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 62px;
  height: 44px;
  background: rgba(200, 30, 30, 0.9);
  border-radius: 10px;
}
.gx-video .gx-play::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 55%;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 10px 0 10px 17px;
  border-color: transparent transparent transparent #fff;
}

/* 產品格 */
.gx-products-title {
  font-size: 15px;
  font-weight: 700;
  color: #333;
  margin: 4px 0 10px;
}
.gx-products {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.gx-product {
  display: block;
  text-decoration: none;
  border: 1px solid #eee;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  transition: box-shadow 0.15s, transform 0.15s;
}
.gx-product:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}
.gx-product img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: #f5f5f5;
}
.gx-product .gx-p-name {
  font-size: 13px;
  color: #333;
  line-height: 1.45;
  padding: 8px 10px 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.9em;
}
.gx-product .gx-p-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--gx-theme, #b98a4e);
  padding: 2px 10px 10px;
}

.gx-loading,
.gx-empty {
  text-align: center;
  color: #888;
  font-size: 13.5px;
  padding: 24px 0;
}
.gx-spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 10px;
  border: 3px solid #eee;
  border-top-color: var(--gx-theme, #b98a4e);
  border-radius: 50%;
  animation: gx-spin 0.8s linear infinite;
}
@keyframes gx-spin { to { transform: rotate(360deg); } }

.gx-more {
  display: block;
  text-align: center;
  margin: 16px auto 0;
  padding: 10px 22px;
  width: fit-content;
  border-radius: 24px;
  background: var(--gx-theme, #b98a4e);
  color: #fff !important;
  font-size: 14px;
  text-decoration: none;
}
.gx-more:hover { opacity: 0.88; }

/* ---------- 平板 ---------- */
@media (max-width: 1024px) {
  .gx-panel { width: 380px; }
}

/* ---------- 手機：底部抽屜 ---------- */
@media (max-width: 767px) {
  .gx-wrap {
    height: 85vh;
    height: 85dvh;
    min-height: 420px;
    border-radius: 0;
  }
  .gx-header h2 { font-size: 18px; }
  .gx-header p { font-size: 12px; }
  .gx-marker .gx-marker-flag { font-size: 30px; } /* 放大點擊目標 */
  .gx-marker .gx-marker-label { font-size: 12.5px; padding: 3px 10px; }

  .gx-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 58%;
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
  }
  .gx-panel.gx-open { transform: translateY(0); }
  .gx-panel {
    transition: transform 0.35s cubic-bezier(0.22, 0.8, 0.3, 1),
      height 0.3s ease;
  }
  /* 點商品區或上滑：放大到 80%，看更多商品 */
  .gx-panel.gx-open.gx-expanded { height: 80%; }
  /* 收合狀態：只露出標籤列（把手＋國名），地圖完整可見 */
  .gx-panel.gx-open.gx-collapsed {
    transform: translateY(calc(100% - 64px));
  }
  .gx-panel-head { cursor: pointer; }
  /* 收合時標題列需要底色當作可點的標籤 */
  .gx-panel.gx-open.gx-collapsed .gx-panel-head {
    background: var(--gx-tabbg, rgba(15, 20, 30, 0.78));
    border-radius: 14px 14px 0 0;
  }

  .gx-drag-handle {
    display: block;
    width: 44px;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.5);
    margin: 8px auto 0;
    flex-shrink: 0;
  }
  .gx-panel-head { padding-top: 8px; }
  .gx-panel-head h3 { font-size: 19px; }
  .gx-products { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

@media (max-width: 380px) {
  .gx-products { grid-template-columns: 1fr 1fr; }
  .gx-product .gx-p-name { font-size: 12.5px; }
}

/* 減少動態偏好 */
@media (prefers-reduced-motion: reduce) {
  .gx-panel { transition: none; }
}
