/* ============================================================
   Autonomia — 星辰散落，群星集結
   純靜態、無建置流程;由 index.html 直接引用。
   版面走長文敘事:襯線字體、非對稱編排、手繪星圖插圖,
   刻意不用眉標、徽章、狀態燈、章節編號等制式元件。
   內容層疊在固定的 3D 星空畫布之上。
   ============================================================ */

:root {
  color-scheme: dark;

  --bg: #07080d;
  --ink: #f0f2f7;
  --ink-dim: #c9d0de;
  --muted: #9aa3b4;
  --faint: #7d8698;

  --hairline: rgba(200, 212, 236, 0.14);
  --hairline-strong: rgba(200, 212, 236, 0.3);

  --star: #dfe8ff;
  --gold: #e3c88f;

  --scrim: rgba(6, 8, 13, 0.52);

  --serif: "Iowan Old Style", "Palatino Linotype", "Noto Serif TC", "Songti TC",
    "Source Han Serif TC", "PMingLiU", serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --header-h: 60px;
  --ease: cubic-bezier(0.22, 0.61, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 32px);
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.75;
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: rgba(227, 200, 143, 0.3);
  color: #fff;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
}

code {
  font-family: var(--mono);
}

:focus-visible {
  outline: 1px solid var(--star);
  outline-offset: 4px;
}

/* 3D 星空畫布:鋪滿視窗、位於最底層,不吃滑鼠事件。 */
.starfield-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

main,
.site-footer {
  position: relative;
  z-index: 1;
}

.wrap {
  width: 100%;
  max-width: 980px;
  margin-inline: auto;
  padding-inline: clamp(22px, 6vw, 64px);
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 10px 16px;
  border: 1px solid var(--hairline-strong);
  background: #0b0e14;
  font-size: 0.85rem;
  transform: translateY(-200%);
  transition: transform 0.25s var(--ease);
}

.skip-link:focus {
  transform: none;
}

/* ------------------------------------------------------------
   頁首:只有名字與一個連結
   ------------------------------------------------------------ */

.site-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  height: var(--header-h);
  border-bottom: 1px solid transparent;
  transition: background 0.4s ease, border-color 0.4s ease;
}

.site-header.is-scrolled {
  border-bottom-color: var(--hairline);
  background: rgba(7, 8, 13, 0.78);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
  max-width: 980px;
  height: 100%;
  margin-inline: auto;
  padding-inline: clamp(22px, 6vw, 64px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--star);
}

.brand-mark {
  width: 21px;
  height: 21px;
}

.brand-name {
  font-size: 0.92rem;
  letter-spacing: 0.32em;
  color: var(--ink);
}

.header-link {
  font-size: 0.86rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
  transition: color 0.3s ease, border-color 0.3s ease;
}

.header-link:hover {
  color: var(--ink);
  border-bottom-color: var(--hairline-strong);
}

.scroll-progress {
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 1px;
  background: rgba(157, 184, 255, 0.55);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

/* ------------------------------------------------------------
   開卷:非對稱的大字開場,右緣一幅直排對句
   ------------------------------------------------------------ */

.hero {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding-top: var(--header-h);
  padding-bottom: clamp(64px, 10vh, 120px);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(
    ellipse 62% 58% at 34% 46%,
    rgba(6, 8, 13, 0.8),
    rgba(6, 8, 13, 0.32) 55%,
    transparent 78%
  );
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 2;
  max-width: 720px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(3rem, 8.2vw, 6.1rem);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 26px rgba(0, 0, 0, 0.55);
}

.hero-line {
  display: block;
  white-space: nowrap;
}

.hero-line-gather {
  margin-left: 0.62em;
}

.hero-period {
  color: var(--gold);
}

.hero-lead {
  max-width: 34em;
  margin: clamp(28px, 5vh, 44px) 0 0;
  font-size: clamp(1.02rem, 1.5vw, 1.16rem);
  line-height: 2.15;
  color: var(--ink-dim);
  text-shadow: 0 1px 16px rgba(0, 0, 0, 0.5);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px clamp(28px, 4vw, 48px);
  margin: clamp(30px, 5vh, 46px) 0 0;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
}

.hero-next {
  display: inline-block;
  padding-bottom: 4px;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--hairline-strong);
  transition: color 0.3s ease, border-color 0.3s ease;
}

.hero-next:hover {
  color: var(--ink);
  border-bottom-color: var(--star);
}

.hero-couplet {
  position: absolute;
  top: 50%;
  right: clamp(28px, 6vw, 84px);
  z-index: 2;
  display: flex;
  flex-direction: row;
  gap: 22px;
  margin: 0;
  writing-mode: vertical-rl;
  font-size: clamp(0.95rem, 1.4vw, 1.1rem);
  letter-spacing: 0.5em;
  color: var(--muted);
  transform: translateY(-50%);
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.6);
}

.hero-couplet span {
  display: block;
}

.hero-couplet span + span {
  padding-right: 20px;
  border-right: 1px solid var(--hairline);
}

/* ------------------------------------------------------------
   三個樂章:大句為題,長文為體
   ------------------------------------------------------------ */

.movement {
  position: relative;
  padding-block: clamp(110px, 17vh, 190px);
}

.movement::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(
    180deg,
    rgba(6, 8, 13, 0) 0%,
    var(--scrim) 14%,
    var(--scrim) 86%,
    rgba(6, 8, 13, 0) 100%
  );
  pointer-events: none;
}

.movement h2 {
  margin: 0 0 clamp(36px, 6vh, 56px);
  font-size: clamp(1.7rem, 3.9vw, 2.8rem);
  font-weight: 600;
  line-height: 1.55;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 20px rgba(0, 0, 0, 0.5);
}

.prose {
  max-width: 36em;
  font-size: clamp(1.02rem, 1.4vw, 1.12rem);
  line-height: 2.2;
  color: var(--ink-dim);
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.45);
}

.prose p {
  margin: 0 0 1.6em;
}

.prose strong {
  font-weight: 600;
  color: var(--ink);
}

.prose code {
  padding: 0.08em 0.4em;
  border: 1px solid var(--hairline);
  background: rgba(6, 8, 13, 0.6);
  font-size: 0.82em;
  color: var(--star);
  overflow-wrap: anywhere;
}

.prose-close {
  color: var(--ink);
  font-size: 1.12em;
}

/* ------------------------------------------------------------
   星圖:插畫式的 SVG,細線與小星,不做卡片
   ------------------------------------------------------------ */

.chart {
  margin: clamp(56px, 9vh, 88px) 0 0;
  padding: clamp(14px, 3vw, 30px);
  border: 1px solid var(--hairline);
  background: rgba(6, 8, 13, 0.42);
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart figcaption {
  margin-top: 14px;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* 遠處塵埃 */
.dust circle {
  fill: var(--star);
  opacity: 0.22;
}

/* 星體本體 */
.spark {
  fill: none;
  stroke: rgba(223, 232, 255, 0.4);
  stroke-width: 0.8;
}

.core {
  fill: var(--star);
  animation: twinkle 5.5s ease-in-out infinite;
}

.core-gold {
  fill: var(--gold);
}

.core-ivory {
  fill: var(--ink);
}

.core-dim {
  fill: var(--faint);
}

.chart .provider:nth-of-type(odd) .core {
  animation-delay: -2.6s;
}

/* 連向註記的細線 */
.leader {
  fill: none;
  stroke: rgba(200, 212, 236, 0.42);
  stroke-width: 0.9;
}

.star-name {
  font-family: var(--serif);
  font-size: 21px;
  fill: var(--ink);
  letter-spacing: 0.14em;
}

.star-note {
  font-family: var(--serif);
  font-size: 12.5px;
  fill: var(--muted);
  letter-spacing: 0.1em;
}

.provider .star-note {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
}

.gate-hex {
  fill: none;
  stroke: rgba(223, 232, 255, 0.55);
  stroke-width: 1.1;
}

.gate .core {
  animation-duration: 4.2s;
}

.gate-name {
  font-family: var(--serif);
  font-size: 22px;
  fill: var(--ink);
  letter-spacing: 0.22em;
}

/* 集結星圖:光線在進入視野時,一條條畫出來 */
.link-line {
  fill: none;
  stroke: rgba(190, 205, 235, 0.34);
  stroke-width: 0.9;
  stroke-dasharray: 430;
}

.main-line {
  stroke: rgba(223, 232, 255, 0.5);
}

.js .chart-converge .link-line {
  stroke-dashoffset: 430;
  transition: stroke-dashoffset 1.7s var(--ease);
  transition-delay: calc(var(--i, 0) * 110ms + 0.25s);
}

.js [data-reveal].is-visible .chart-converge .link-line {
  stroke-dashoffset: 0;
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

/* ------------------------------------------------------------
   指令與程式:安靜的圖,細框、無窗飾
   ------------------------------------------------------------ */

.code {
  margin: clamp(44px, 7vh, 64px) 0 0;
  border: 1px solid var(--hairline);
  background: rgba(5, 7, 11, 0.66);
}

.code figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.86rem;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
}

.copy-btn {
  padding: 3px 10px;
  border: 1px solid var(--hairline);
  background: transparent;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease;
}

.copy-btn:hover {
  border-color: var(--hairline-strong);
  color: var(--ink);
}

.code pre {
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
}

.code code {
  font-size: 0.8rem;
  line-height: 2;
  color: var(--ink-dim);
}

.tok-com {
  color: var(--faint);
}

.tok-kw {
  color: #aebff2;
}

.tok-str {
  color: #e3c88f;
}

.tok-fn {
  color: var(--star);
}

/* ------------------------------------------------------------
   終卷:收束的詩行與連結
   ------------------------------------------------------------ */

.verse {
  margin: clamp(72px, 12vh, 120px) 0 0;
  font-size: clamp(1.35rem, 2.6vw, 1.85rem);
  line-height: 2.1;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-align: center;
  text-shadow: 0 1px 20px rgba(0, 0, 0, 0.5);
}

.begin-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px clamp(28px, 5vw, 56px);
  margin: clamp(40px, 7vh, 64px) 0 0;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
}

.begin-links a {
  padding-bottom: 3px;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--hairline);
  transition: color 0.3s ease, border-color 0.3s ease;
}

.begin-links a:hover {
  color: var(--ink);
  border-bottom-color: var(--hairline-strong);
}

/* ------------------------------------------------------------
   頁尾
   ------------------------------------------------------------ */

.site-footer {
  border-top: 1px solid var(--hairline);
  background: rgba(5, 6, 10, 0.82);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px 32px;
  padding-block: clamp(36px, 6vh, 56px) 30px;
}

.footer-inner .brand {
  align-items: baseline;
  gap: 12px;
}

.footer-inner .brand-mark {
  width: 17px;
  height: 17px;
  transform: translateY(3px);
}

.footer-line {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
}

.footer-legal {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--faint);
}

/* ------------------------------------------------------------
   進場
   ------------------------------------------------------------ */

.hero h1,
.hero-lead,
.hero-actions,
.hero-couplet {
  animation: rise 1.1s var(--ease) both;
}

.hero h1 {
  animation-delay: 0.05s;
}

.hero-lead {
  animation-delay: 0.22s;
}

.hero-actions {
  animation-delay: 0.36s;
}

.hero-couplet {
  animation-delay: 0.5s;
}

.js [data-reveal] {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease);
}

.js [data-reveal].is-visible {
  opacity: 1;
  transform: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------
   響應式
   ------------------------------------------------------------ */

@media (max-width: 1100px) {
  .hero-couplet {
    display: none;
  }
}

@media (max-width: 640px) {
  .hero h1 {
    font-size: clamp(2.5rem, 12.5vw, 3.4rem);
  }

  .hero-line-gather {
    margin-left: 0.4em;
  }

  .movement h2 {
    font-size: clamp(1.45rem, 6.8vw, 2rem);
  }

  .star-name,
  .gate-name {
    font-size: 17px;
  }

  .star-note {
    font-size: 11px;
  }

  .provider .star-note {
    font-size: 10px;
  }

  .chart {
    padding: 10px;
    overflow-x: auto;
  }

  .chart-svg {
    min-width: 560px;
  }

  .begin-links {
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }
}

/* ------------------------------------------------------------
   減少動態
   ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .js [data-reveal] {
    opacity: 1;
    transform: none;
  }

  .js .chart-converge .link-line {
    stroke-dashoffset: 0;
  }

  .hero h1,
  .hero-lead,
  .hero-actions,
  .hero-couplet {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
