@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Noto+Sans+TC:wght@400;500;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --bg: #edf2f8;
  --bg-2: #f8fbff;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #dbe4f0;
  --line-strong: #c9d7ea;
  --brand: #0b5fff;
  --brand-2: #1346b8;
  --brand-soft: #eaf1ff;
  --accent: #0ea5a4;
  --code-bg: #0f172a;
  --code-ink: #e2e8f0;
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 6px 20px rgba(15, 23, 42, 0.06);
  --radius: 18px;
}

:root[data-theme='dark'] {
  --bg: #07101d;
  --bg-2: #0b1424;
  --panel: rgba(15, 23, 42, 0.82);
  --panel-strong: #0f172a;
  --ink: #e5edf8;
  --ink-soft: #c7d2e4;
  --muted: #93a4bc;
  --line: #243349;
  --line-strong: #334861;
  --brand: #6ea8ff;
  --brand-2: #8ab8ff;
  --brand-soft: rgba(59, 130, 246, 0.16);
  --accent: #2dd4bf;
  --code-bg: #020817;
  --code-ink: #dbe7fb;
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.38);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at -10% -10%, rgba(11, 95, 255, 0.12), transparent 60%),
    radial-gradient(1000px 420px at 110% 0%, rgba(14, 165, 164, 0.10), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  font-family: 'Manrope', 'Noto Sans TC', system-ui, sans-serif;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  background: color-mix(in srgb, var(--bg-2) 78%, transparent);
  backdrop-filter: blur(14px);
}

.brand {
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: min(36vw, 360px);
  padding: 0.65rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-strong) 92%, transparent);
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
}

.search-wrap input:focus {
  border-color: color-mix(in srgb, var(--brand) 55%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}

.lang-switch {
  display: flex;
  gap: 0.25rem;
  padding: 0.15rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-strong) 92%, transparent);
  border-radius: 999px;
}

.lang-switch a {
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
}

.lang-switch a[aria-current='page'] {
  background: var(--brand-soft);
  color: var(--brand-2);
}

.ghost {
  display: none;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-strong) 92%, transparent);
  border-radius: 10px;
  padding: 0.48rem 0.7rem;
  color: var(--ink-soft);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 260px;
  gap: 1rem;
  max-width: 1500px;
  margin: 0 auto;
  padding: 1rem;
}

.sidebar,
.toc {
  align-self: start;
  position: sticky;
  top: 76px;
  background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 0.8rem;
  backdrop-filter: blur(8px);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar-nav a {
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  color: var(--ink-soft);
  font-weight: 500;
  line-height: 1.35;
}

.sidebar-nav a:hover {
  background: color-mix(in srgb, var(--brand-soft) 50%, transparent);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--brand-soft) 95%, white 5%),
    color-mix(in srgb, var(--brand-soft) 80%, transparent)
  );
  color: var(--brand-2);
  font-weight: 700;
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--line));
}

.content {
  min-width: 0;
  background: var(--panel-strong);
  border: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.35rem 1.45rem;
}

.article {
  color: var(--ink-soft);
}

.article h1,
.article h2,
.article h3,
.article h4 {
  color: var(--ink);
  scroll-margin-top: 96px;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.article h1 {
  font-size: clamp(1.7rem, 2vw + 1rem, 2.3rem);
  margin-top: 0.2rem;
  margin-bottom: 0.95rem;
}

.article h2 {
  margin-top: 1.7rem;
  padding-top: 0.2rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
}

.article p,
.article li {
  line-height: 1.72;
}

.article ul,
.article ol {
  padding-left: 1.2rem;
}

.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.article th,
.article td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #edf2fa;
  text-align: left;
}

.article th {
  background: color-mix(in srgb, var(--panel) 82%, var(--bg-2));
  color: var(--ink);
}

.article img {
  max-width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.14);
}

.article pre {
  overflow: auto;
  background: linear-gradient(180deg, #111827, #0b1220);
  color: var(--code-ink);
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 0.95rem;
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.article code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.94em;
}

.article :not(pre) > code {
  background: color-mix(in srgb, var(--brand-soft) 80%, transparent);
  color: var(--brand-2);
  border: 1px solid color-mix(in srgb, var(--brand) 18%, var(--line));
  border-radius: 6px;
  padding: 0.12rem 0.3rem;
}

.article blockquote {
  margin: 1.05rem 0;
  padding: 0.45rem 0.95rem;
  border-left: 4px solid var(--accent);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 10%, var(--panel-strong)),
    color-mix(in srgb, var(--accent) 4%, var(--panel-strong))
  );
  color: color-mix(in srgb, var(--ink-soft) 88%, var(--accent));
  border-radius: 10px;
}

.article hr {
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  margin: 1.4rem 0;
}

.toc h2 {
  font-size: 0.95rem;
  margin: 0.1rem 0 0.55rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.toc-list {
  margin: 0;
  padding-left: 1rem;
}

.toc-list li {
  margin: 0.35rem 0;
  color: var(--muted);
}

.toc-list li.d3,
.toc-list li.d4,
.toc-list li.d5 {
  margin-left: 0.75rem;
  font-size: 0.94rem;
}

.toc-list a {
  color: var(--ink-soft);
}

.toc-list a:hover {
  color: var(--brand-2);
}

.toc-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 1rem 1.5rem;
  color: var(--muted);
}

.site-footer a {
  display: inline-block;
  padding: 0.25rem 0.45rem;
  border-radius: 8px;
}

.site-footer a:hover {
  background: rgba(255,255,255,0.65);
  text-decoration: none;
}

.search-results {
  margin-bottom: 1rem;
  border: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
  border-radius: 14px;
  padding: 0.8rem;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--panel) 86%, var(--bg-2)),
    color-mix(in srgb, var(--panel-strong) 95%, transparent)
  );
}

.search-results .item {
  padding: 0.65rem 0;
  border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}

.search-results .item:first-child {
  border-top: 0;
  padding-top: 0;
}

.search-results .item a {
  color: var(--ink);
}

.search-results .item a:hover strong {
  color: var(--brand-2);
}

.search-results .meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0.1rem 0 0.25rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.hljs {
  color: var(--code-ink);
  background: transparent;
}

:root[data-theme='dark'] .brand {
  color: #f4f7ff;
}

:root[data-theme='dark'] .search-wrap input::placeholder {
  color: #8ea2be;
}

:root[data-theme='dark'] .sidebar-nav a.active {
  box-shadow: inset 0 0 0 1px rgba(138, 184, 255, 0.12);
}

:root[data-theme='dark'] .article table {
  background: rgba(15, 23, 42, 0.35);
}

:root[data-theme='dark'] .article th,
:root[data-theme='dark'] .article td {
  border-bottom-color: rgba(148, 163, 184, 0.14);
}

:root[data-theme='dark'] .article img {
  border-color: rgba(148, 163, 184, 0.2);
}

:root[data-theme='dark'] .site-footer a:hover {
  background: rgba(255,255,255,0.04);
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 860px) {
  .ghost {
    display: inline-block;
  }

  .search-wrap input {
    width: 42vw;
    min-width: 140px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 0.75rem;
  }

  .sidebar {
    position: fixed;
    top: 64px;
    left: 0.75rem;
    right: 0.75rem;
    z-index: 30;
    display: none;
    max-height: 72vh;
    overflow: auto;
    background: rgba(255,255,255,0.97);
  }

  .sidebar.open {
    display: block;
  }

  .content {
    padding: 1rem;
    border-radius: 14px;
  }
}

@media (max-width: 640px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.65rem;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .search-wrap {
    flex: 1 1 100%;
    width: 100%;
  }

  .search-wrap input {
    width: 100%;
  }

  .article h1 {
    font-size: 1.55rem;
  }
}

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