:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --border: #e2e0dc;
  --border-subtle: rgba(226, 224, 220, 0.65);
  --accent: #2563eb;
  --accent-subtle: rgba(37, 99, 235, 0.1);
  --agent: #7c3aed;
  --frontend: #059669;
  --engineering: #d97706;
  --cross: #0891b2;
  --grok: #be185d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(26, 26, 26, 0.04);
  --font:
    "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --motion: 150ms ease-out;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

html {
  scroll-behavior: auto;
  scroll-padding-top: var(--sticky-top-offset, 17rem);
}
html.guidance-smooth-scroll {
  scroll-behavior: smooth;
}

.site-sticky-top {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
  font-size: 0.875rem;
}
.top-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition:
    color var(--motion),
    background var(--motion),
    box-shadow var(--motion);
}
.top-nav a:hover {
  color: var(--text);
  background: var(--bg);
}
.top-nav a.active {
  color: var(--text);
  font-weight: 600;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}
.top-nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.page-header,
header.page-header {
  background: transparent;
  border-bottom: none;
  padding: 1.25rem 1.25rem 1rem;
  max-width: 45rem;
  margin: 0 auto;
}
.page-header--wide {
  max-width: 1100px;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}
.page-header--guide {
  max-width: 720px;
}
.page-header--compact {
  padding: 0.65rem 1.25rem 0.6rem;
}
.page-header--compact h1 {
  margin-bottom: 0.25rem;
}
.lead--compact {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}
.doc-jump-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.65rem;
  margin-top: 0.15rem;
}
.doc-jump-bar-label {
  flex: 0 0 auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.doc-jump-select {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 28rem;
  font: inherit;
  font-size: 0.875rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.doc-jump-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
@media (max-width: 640px) {
  html {
    scroll-padding-top: var(--sticky-top-offset, 11rem);
  }
  .page-header,
  header.page-header {
    padding: 0.55rem 1rem 0.5rem;
  }
  .page-header--compact {
    padding: 0.55rem 1rem 0.5rem;
  }
  .lead--compact {
    -webkit-line-clamp: 2;
  }
}
.page-header h1,
header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.25rem, 3.5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.lead,
header.page-header > p.lead {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
}
section.panel[id],
main.wide > section.panel[id],
main.article section.panel[id] {
  scroll-margin-top: var(--sticky-top-offset, 17rem);
}

main,
main.article {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}
main.wide {
  max-width: 1100px;
}

section.panel {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  transition:
    border-color var(--motion),
    box-shadow var(--motion);
}
section.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.125rem;
  font-weight: 650;
}
section.panel p,
section.panel ol,
section.panel ul {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9375rem;
}
section.panel p.tip {
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  color: var(--text);
}
ol.spaced li,
ul.spaced li {
  margin-bottom: 0.5rem;
}

blockquote {
  margin: 0.75rem 0;
  padding: 0.65rem 1rem;
  border-left: 3px solid var(--grok);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.step-card {
  margin: 0 0 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.step-card:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
.step-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  color: var(--text);
}

table.roles {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
table.roles th,
table.roles td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
  text-align: left;
  vertical-align: top;
}
table.roles th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text);
}

/* —— 頁首捷徑（guide / index）—— */
.doc-jump {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}
.doc-site-context {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}
.doc-site-context strong {
  color: var(--text);
  font-weight: 600;
}
.doc-jump-heading {
  margin: 0 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.doc-jump--site {
  margin-top: 0.75rem;
}
.doc-jump--inpage {
  margin-top: 0.5rem;
  background: var(--surface);
}
.doc-jump--inpage .doc-jump-heading {
  color: var(--text);
  letter-spacing: 0.04em;
  text-transform: none;
  font-size: 0.75rem;
}
.doc-jump-block {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 0.5rem 0.75rem;
  align-items: start;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-subtle);
}
.doc-jump-block:first-of-type {
  border-top: none;
  padding-top: 0;
}
.doc-jump-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.9;
  padding-top: 0.125rem;
}
.chip-track {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.375rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.125rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.chip-track--wrap {
  flex-wrap: wrap;
  overflow-x: visible;
}
.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  max-width: 14rem;
  padding: 0.375rem 0.625rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
  transition:
    border-color var(--motion),
    background var(--motion),
    color var(--motion),
    box-shadow var(--motion);
}
.chip:hover {
  border-color: #c4c2bc;
  background: var(--bg);
}
.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chip[data-nav-section].is-current,
.chip.is-current {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
  font-weight: 600;
}
.chip--muted {
  color: var(--muted);
  background: var(--bg);
  border-style: dashed;
  border-color: var(--border-subtle);
  font-weight: 500;
}
.chip--muted:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
}
.chip--muted::after {
  content: " ↗";
  font-size: 0.65em;
  opacity: 0.65;
}
.chip--primary {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
  font-weight: 600;
}
.chip--primary:hover {
  filter: brightness(1.06);
}

.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.75rem;
}
.hero-cta a {
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  text-decoration: none;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition:
    border-color var(--motion),
    background var(--motion);
}
.hero-cta a:hover {
  background: var(--bg);
}
.hero-cta a.primary,
.hero-cta a.chip--primary {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
  font-weight: 600;
}
.hero-cta a.secondary {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
}

section.panel.is-inview {
  border-color: rgba(37, 99, 235, 0.28);
  box-shadow:
    var(--shadow-sm),
    0 0 0 1px var(--accent-subtle);
}
section.panel.is-inview > h2 {
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
@media (max-width: 520px) {
  .doc-jump-block {
    grid-template-columns: 1fr;
    gap: 0.375rem;
  }
  .doc-jump-label {
    line-height: 1.3;
  }
}

.flow-steps {
  display: grid;
  gap: 0.75rem;
}
@media (min-width: 640px) {
  .flow-steps {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 900px) {
  .flow-steps {
    grid-template-columns: repeat(4, 1fr);
  }
}
.flow-step {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  font-size: 0.875rem;
  color: var(--muted);
}
.flow-step strong {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

nav.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
nav.filters button {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition:
    border-color var(--motion),
    background var(--motion),
    color var(--motion);
}
nav.filters button:hover {
  border-color: #c4c2bc;
  background: var(--bg);
}
nav.filters button.active {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}
nav.filters button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.grid {
  display: grid;
  gap: 1rem;
}
@media (min-width: 640px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 960px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

article.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
article.card:hover {
  border-color: #c4c2bc;
}
article.card.card--interactive {
  cursor: pointer;
  transition:
    border-color var(--motion),
    box-shadow var(--motion);
}
article.card.card--interactive:hover {
  box-shadow: var(--shadow-sm);
}
article.card.card--interactive:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
article.card.hidden {
  display: none;
}

/* —— Skill 卡片 modal —— */
body.skill-modal-open {
  overflow: hidden;
}
.skill-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
}
.skill-modal.is-open {
  display: flex;
}
.skill-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 27, 24, 0.45);
}
.skill-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(42rem, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
}
.skill-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.skill-modal-heading h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}
.skill-modal-meta {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}
.skill-modal-close {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}
.skill-modal-close:hover {
  background: var(--border-subtle);
}
.skill-modal-body {
  overflow: auto;
  padding: 1rem 1.15rem;
  flex: 1;
  min-height: 0;
}
.skill-modal-footer {
  padding: 0.65rem 1.1rem;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.skill-modal-repo-link {
  font-size: 0.8125rem;
  word-break: break-all;
}
.skill-modal-status {
  color: var(--muted);
  font-size: 0.9rem;
}
.skill-modal-error {
  color: var(--text);
}
.skill-modal-fallback {
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.skill-modal-prose h1,
.skill-modal-prose h2,
.skill-modal-prose h3 {
  margin: 1rem 0 0.5rem;
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
}
.skill-modal-prose h1:first-child,
.skill-modal-prose h2:first-child {
  margin-top: 0;
}
.skill-modal-prose p,
.skill-modal-prose li {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.55;
}
.skill-modal-prose ul,
.skill-modal-prose ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}
.skill-modal-prose code {
  font-size: 0.8em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.skill-modal-prose pre {
  overflow: auto;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.8rem;
}
.skill-modal.is-loading .skill-modal-body {
  opacity: 0.65;
}
.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
}
.badge-agent {
  background: #ede9fe;
  color: var(--agent);
}
.badge-grok {
  background: #fce7f3;
  color: var(--grok);
}
.badge-social {
  background: #fce7f3;
  color: var(--grok);
}
.badge-video {
  background: #f3e8ff;
  color: #7c3aed;
}
.badge-frontend {
  background: #d1fae5;
  color: var(--frontend);
}
.badge-engineering {
  background: #ffedd5;
  color: var(--engineering);
}
.badge-cross {
  background: #cffafe;
  color: var(--cross);
}
.badge-ops {
  background: #e0e7ff;
  color: #4338ca;
}
.badge-securities {
  background: #fef3c7;
  color: #b45309;
}
.badge-kind-rule {
  background: #fef2f2;
  color: #b91c1c;
}
.badge-kind-guide {
  background: #ecfdf5;
  color: #047857;
}
.badge-kind-workflow {
  background: #eff6ff;
  color: #1d4ed8;
}
.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: flex-end;
  flex-shrink: 0;
}
article.card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}
article.card .slug {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}
article.card .summary {
  font-size: 0.875rem;
  color: var(--muted);
  flex: 1;
}
article.card .when {
  font-size: 0.8125rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.relations {
  font-size: 0.8125rem;
  color: var(--muted);
}
.relations code {
  font-size: 0.75rem;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.five-pack {
  display: grid;
  gap: 0.75rem;
}
@media (min-width: 700px) {
  .five-pack {
    grid-template-columns: repeat(5, 1fr);
  }
}
.five-pack .flow-step {
  min-height: 6.5rem;
}
.five-pack .flow-step em {
  display: block;
  font-style: normal;
  font-size: 0.7rem;
  margin-top: 0.35rem;
}

.diagram-wrap {
  overflow-x: auto;
}

footer {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted);
  padding: 1.5rem 1rem;
}
footer a {
  color: var(--accent);
  text-decoration: none;
}

code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.article a,
.page-header a:not(.chip),
.panel a {
  color: var(--accent);
  text-decoration: none;
}
.article a:hover,
.page-header a:not(.chip):hover,
.panel a:hover {
  text-decoration: underline;
}
.page-header a.chip:hover {
  text-decoration: none;
}
