/* ==========================================================================
   layout.css — 導覽列、Banner、頁尾、回到頂端
   ========================================================================== */

/* ============================================================ 導覽列 ==== */

.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  background: rgba(10, 11, 13, 0.55);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid transparent;
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease);
}

.nav.is-solid {
  background: rgba(10, 11, 13, 0.92);
  border-bottom-color: var(--line);
}

.nav__inner {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}

/* ------------------------------------------------------------ 品牌 ---- */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand__mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.brand__title {
  font-family: var(--font-latin);
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 0.005em;
  background: linear-gradient(95deg, #eaf3ff 0%, #a9d1ff 45%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

/* 標誌上的衛星光點只在導覽列閃爍；頁尾的標誌維持靜止 */
.nav .brand__mark .logo-core {
  transform-origin: 33.4px 10.6px;
  animation: logoBlink 2.6s var(--ease) infinite;
}

@keyframes logoBlink {
  0%, 100% { opacity: 0.35; }
  46%      { opacity: 0.4; }
  55%      { opacity: 1; }
  70%      { opacity: 0.45; }
}

/* --------------------------------------------------------- 主選單 ---- */

.nav__menu {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  list-style: none;
  padding: 0;
}

.nav__item { position: relative; }

.nav__link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  color: var(--txt-dim);
  white-space: nowrap;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

.nav__link:hover,
.nav__item:focus-within > .nav__link { color: #fff; background: rgba(74, 158, 255, 0.10); }

.nav__link.is-active {
  color: #fff;
}
.nav__link.is-active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 2px;
  height: 1px;
  background: var(--accent);
}

.nav__caret {
  width: 8px;
  height: 8px;
  border-right: 1.4px solid currentColor;
  border-bottom: 1.4px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  opacity: 0.6;
  transition: transform 0.25s var(--ease);
}
.nav__item:hover .nav__caret { transform: rotate(225deg) translate(-3px, -3px); }

/* --------------------------------------------------------- 子選單 ---- */

.nav__sub {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 190px;
  list-style: none;
  margin: 0;
  padding: 6px;
  background: rgba(22, 27, 33, 0.97);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), visibility 0.2s;
}

.nav__item:hover > .nav__sub,
.nav__item:focus-within > .nav__sub {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.nav__sub a {
  display: block;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--txt-dim);
}
.nav__sub a:hover { background: rgba(74, 158, 255, 0.12); color: #fff; }
.nav__sub a.is-active { color: var(--accent-2); }

/* ------------------------------------------------------- 語言切換 ---- */

.lang {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
  margin-left: 14px;
  flex-shrink: 0;
}

.lang__btn {
  border: 0;
  background: transparent;
  color: var(--txt-mute);
  padding: 6px 13px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.lang__btn:hover { color: var(--txt); }
.lang__btn.is-active { background: var(--accent); color: #06101f; font-weight: 600; }

/* ------------------------------------------------- 行動版漢堡選單 ---- */

.nav__toggle {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  position: relative;
  margin-left: auto;
}

.nav__toggle span {
  position: absolute;
  left: 11px;
  width: 18px;
  height: 1.5px;
  background: var(--txt);
  transition: transform 0.3s var(--ease), opacity 0.2s var(--ease);
}
.nav__toggle span:nth-child(1) { top: 14px; }
.nav__toggle span:nth-child(2) { top: 20px; }
.nav__toggle span:nth-child(3) { top: 26px; }

.nav__toggle.is-open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav__toggle.is-open span:nth-child(2) { opacity: 0; }
.nav__toggle.is-open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

@media (max-width: 1040px) {
  .nav__toggle { display: block; }

  .nav__menu {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    max-height: calc(100vh - var(--nav-h));
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 12px 18px 32px;
    background: rgba(10, 11, 13, 0.98);
    border-bottom: 1px solid var(--line);
    transform: translateY(-12px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;      /* 關閉時不可點，避免蓋住底下的頁面內容 */
    transition: opacity 0.25s var(--ease), transform 0.25s var(--ease), visibility 0.25s;
  }
  .nav__menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
  }

  .nav__link { padding: 13px 4px; font-size: 1rem; }
  .nav__link.is-active::after { display: none; }
  .nav__link.is-active { color: var(--accent-2); }

  .nav__item { border-bottom: 1px solid var(--line); }
  .nav__item:last-child { border-bottom: 0; }

  /* 子選單在行動版直接展開，但 visibility 必須跟著母選單走。
     這裡用 inherit，並以較高的選擇器權重蓋掉桌機版的 hover / focus 規則，
     否則母選單關閉時子選單會被 visible 救回來，變成看不見卻仍可點的連結。 */
  .nav__menu .nav__sub,
  .nav__menu .nav__item:hover > .nav__sub,
  .nav__menu .nav__item:focus-within > .nav__sub {
    position: static;
    opacity: 1;
    visibility: inherit;
    transform: none;
    box-shadow: none;
    background: transparent;
    border: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    margin: 0 0 10px 6px;
    padding: 0 0 0 12px;
  }
  .nav__caret { display: none; }
  .lang { margin-left: 12px; }
}

@media (max-width: 560px) {
  .nav__inner { gap: 10px; padding-inline: 16px; }
  .brand { gap: 9px; min-width: 0; }
  .brand__mark { width: 28px; height: 28px; }
  .brand__title {
    font-size: 0.92rem;
    white-space: normal;          /* 太窄時允許換行，不要把按鈕擠出畫面 */
    line-height: 1.25;
  }
  .lang { margin-left: 0; }
  .lang__btn { padding: 5px 9px; font-size: 0.74rem; }
  .nav__toggle { width: 38px; height: 38px; flex-shrink: 0; }
  .nav__toggle span { left: 10px; width: 17px; }
}

/* ========================================================== Banner ==== */

/* 內頁 Banner：上下左右置中的頁面名稱 */
.banner {
  position: relative;
  min-height: 300px;
  padding-top: var(--nav-h);
  display: grid;
  place-items: center;
  text-align: center;
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg) 0%, #12181f 52%, var(--slate) 140%);
  border-bottom: 1px solid var(--line);
}

/* 距離向量格線：呼應 SAR 的距離／方位取樣網格 */
.banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(140, 170, 200, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140, 170, 200, 0.07) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 70% 80% at 50% 45%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 70% 80% at 50% 45%, #000 20%, transparent 78%);
}

.banner::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 190px;
  height: 1px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.banner__inner { position: relative; padding: 48px 24px; }

.banner__title {
  margin: 0 0 10px;
  font-size: clamp(1.9rem, 4vw, 2.7rem);
}

.banner__en {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.22em;
  color: var(--accent-2);
  opacity: 0.8;
  margin: 0;
}

/* ========================================================== 頁尾 ====== */

.footer {
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  padding-top: 64px;
}

.footer__grid {
  display: grid;
  grid-template-columns: 1.2fr 2fr;
  gap: 48px;
  padding-bottom: 48px;
  align-items: start;
}

.footer__sitemap {
  columns: 3 150px;
  column-gap: 28px;
}

.footer__sitemap li { break-inside: avoid; }

.footer__col h4 {
  font-size: 0.85rem;
  color: var(--txt);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.footer__col ul { list-style: none; padding: 0; margin: 0; }
.footer__col li { margin-bottom: 9px; }
.footer__col a { color: var(--txt-mute); font-size: 0.88rem; }
.footer__col a:hover { color: var(--accent-2); }

.footer__bottom {
  border-top: 1px solid var(--line);
  padding-block: 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  color: var(--txt-mute);
}

/* 兩組單位資訊各自是一個不可分割的單位：空間不夠時整組換到下一行，
   而不是讓「國家科學及技術委員會（NSTC）」從中間被切斷 */
.footer__ops {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 26px;
}

.footer__ops > span { display: inline-block; }
.footer__ops strong { color: var(--txt-dim); font-weight: 500; }

/* 窄螢幕：整個底列改成靠左的直式排列 */
@media (max-width: 720px) {
  .footer__bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
  .footer__ops { flex-direction: column; gap: 6px; }
}

@media (max-width: 860px) {
  .footer__grid { grid-template-columns: 1fr; gap: 36px; }
}

/* =================================================== 回到頂端按鈕 ==== */

.to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 90;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: rgba(22, 27, 33, 0.85);
  backdrop-filter: blur(8px);
  color: var(--txt-dim);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease),
              visibility 0.3s, border-color 0.2s, color 0.2s;
}

.to-top.is-visible { opacity: 1; visibility: visible; transform: none; }

.to-top:hover {
  border-color: var(--accent);
  color: var(--accent-2);
  box-shadow: 0 0 20px rgba(74, 158, 255, 0.25);
}

.to-top svg { width: 17px; height: 17px; }

@media (max-width: 600px) {
  .to-top { right: 16px; bottom: 16px; width: 42px; height: 42px; }
}