/* Layout A (Classic Tech Blog) + Palette 4 (Violet / Modern Tech) */
@import url('https://fonts.googleapis.com/css2?family=Huninn&display=swap');

:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #52525b;
  --faint: #71717a;
  --line: #e4e4ec;
  --accent: #7c3aed;
  --accent-soft: #f3efff;
  --code: #f4f2fa;
}

:root[data-theme="dark"] {
  --bg: #0f0d1a;
  --surface: #181528;
  --text: #f4f4f8;
  --muted: #a6a1c0;
  --faint: #7c7699;
  --line: #2c2745;
  --accent: #a78bfa;
  --accent-soft: #2e1d5e;
  --code: #211d36;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  position: relative;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 45% at 50% -12%, color-mix(in srgb, var(--accent) 5.5%, transparent), transparent 68%),
    radial-gradient(circle at 88% 18%, color-mix(in srgb, #38bdf8 3.5%, transparent), transparent 42%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: 'Huninn', -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.75;
  font-size: 16px;
}

button, input, select, textarea {
  font-family: inherit;
}

:root[data-theme="dark"] body {
  background-image:
    linear-gradient(125deg, transparent 18%, rgba(139, 92, 246, 0.14) 40%, rgba(56, 189, 248, 0.085) 52%, rgba(167, 139, 250, 0.12) 64%, transparent 84%),
    radial-gradient(ellipse 65% 28% at 55% 48%, rgba(167, 139, 250, 0.09), transparent 72%),
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(167, 139, 250, 0.15), transparent 70%);
}

/* Sparse dual-layer stars: GPU-composited opacity fade (0 -> bright -> 0) */
@keyframes starFadeDark {
  0%, 100% { opacity: 0; }
  50%      { opacity: 0.92; }
}
@keyframes starFadeLight {
  0%, 100% { opacity: 0; }
  50%      { opacity: 0.14; }
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  will-change: opacity;
  transform: translateZ(0);
  contain: strict;
}

/* Layer 1: Sparse primary stars (5 dots + 1 four-point star per 680px tile) */
body::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='680' height='680' viewBox='0 0 680 680'%3E%3Cg fill='%237c3aed'%3E%3Ccircle cx='115' cy='135' r='1.4' fill-opacity='0.7'/%3E%3Ccircle cx='355' cy='295' r='1.1' fill-opacity='0.55'/%3E%3Ccircle cx='535' cy='200' r='1.5' fill-opacity='0.65'/%3E%3Ccircle cx='230' cy='495' r='1.3' fill-opacity='0.6'/%3E%3Ccircle cx='595' cy='560' r='1.4' fill-opacity='0.7'/%3E%3Cpath d='M485 105 L487 112 L494 114 L487 116 L485 123 L483 116 L476 114 L483 112 Z' fill-opacity='0.8'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 680px 680px;
  animation: starFadeLight 8s ease-in-out infinite;
}

/* Layer 2: Offset sparse stars (interleaved phase so sky never goes empty) */
body::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='610' height='610' viewBox='0 0 610 610'%3E%3Cg fill='%237c3aed'%3E%3Ccircle cx='84' cy='360' r='1.3' fill-opacity='0.65'/%3E%3Ccircle cx='325' cy='105' r='1.5' fill-opacity='0.7'/%3E%3Ccircle cx='468' cy='420' r='1.3' fill-opacity='0.6'/%3E%3Ccircle cx='520' cy='190' r='1.0' fill-opacity='0.5'/%3E%3Cpath d='M182 276 L183.8 282.2 L190 284 L183.8 285.8 L182 292 L180.2 285.8 L174 284 L180.2 282.2 Z' fill-opacity='0.8'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 610px 610px;
  animation: starFadeLight 11s ease-in-out -5.5s infinite;
}

:root[data-theme="dark"] body::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='680' height='680' viewBox='0 0 680 680'%3E%3Cg fill='%23e9d5ff'%3E%3Ccircle cx='115' cy='135' r='1.5' fill-opacity='0.85'/%3E%3Ccircle cx='355' cy='295' r='1.1' fill-opacity='0.65'/%3E%3Ccircle cx='535' cy='200' r='1.6' fill-opacity='0.8'/%3E%3Ccircle cx='230' cy='495' r='1.3' fill-opacity='0.75'/%3E%3Ccircle cx='595' cy='560' r='1.5' fill-opacity='0.85'/%3E%3Cpath d='M485 105 L487 112 L494 114 L487 116 L485 123 L483 116 L476 114 L483 112 Z' fill='%23c4b5fd' fill-opacity='0.95'/%3E%3C/g%3E%3C/svg%3E");
  animation: starFadeDark 8s ease-in-out infinite;
}

:root[data-theme="dark"] body::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='610' height='610' viewBox='0 0 610 610'%3E%3Cg fill='%23ddd6fe'%3E%3Ccircle cx='84' cy='360' r='1.4' fill-opacity='0.8'/%3E%3Ccircle cx='325' cy='105' r='1.6' fill-opacity='0.85'/%3E%3Ccircle cx='468' cy='420' r='1.3' fill-opacity='0.75'/%3E%3Ccircle cx='520' cy='190' r='1.0' fill-opacity='0.65'/%3E%3Cpath d='M182 276 L183.8 282.2 L190 284 L183.8 285.8 L182 292 L180.2 285.8 L174 284 L180.2 282.2 Z' fill='%23a78bfa' fill-opacity='0.95'/%3E%3C/g%3E%3C/svg%3E");
  animation: starFadeDark 11s ease-in-out -5.5s infinite;
}

@media (prefers-reduced-motion: reduce) {
  body::before, body::after { animation: none !important; opacity: 0.45; }
}

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

/* Top Navigation Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 clamp(18px, 3vw, 36px);
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 17px;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}
.brand .brand-sub {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-link {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
}
.nav-link:hover {
  background: var(--code);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

/* Theme toggle button */
.theme-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  margin-left: 6px;
}
.theme-btn:hover { background: var(--code); border-color: var(--accent); }
.theme-btn svg { width: 17px; height: 17px; }
.theme-btn .moon,
:root[data-theme="dark"] .theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .moon { display: block; }

/* Main 2-column layout */
.container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 36px clamp(18px, 3vw, 36px) 80px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 36px;
  align-items: start;
}

/* Main column */
.main-col { min-width: 0; }

.blog-header { margin-bottom: 24px; }
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
.blog-header h1 {
  font-size: clamp(26px, 3.6vw, 36px);
  line-height: 1.25;
  margin: 8px 0 10px;
  letter-spacing: -0.02em;
}
.blog-header .lead {
  font-size: 15.5px;
  color: var(--muted);
  margin: 0;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pill:hover { border-color: var(--accent); color: var(--text); }
.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
.search-input {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  min-width: 210px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* Post cards */
.post-list {
  display: grid;
  gap: 16px;
}
.post-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 24px;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.post-card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 8px 28px color-mix(in srgb, var(--accent) 16%, transparent);
}
.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--faint);
  margin-bottom: 10px;
}
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
}
.post-card h2 {
  font-size: 19px;
  line-height: 1.4;
  margin: 0 0 8px;
  color: var(--text);
}
.post-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14.5px;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.tag {
  font-size: 12px;
  color: var(--muted);
  background: var(--code);
  padding: 2px 9px;
  border-radius: 6px;
}
.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 14px;
  display: none;
}

/* Right Sidebar Widgets */
.sidebar {
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.widget {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}
.widget-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 14px;
}

/* Profile widget */
.profile-widget { text-align: center; }
.profile-widget .avatar {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  border: 1px solid var(--line);
  margin: 0 auto 12px;
  display: block;
}
.profile-widget h3 { margin: 0 0 4px; font-size: 18px; }
.profile-widget .bio {
  font-size: 13.5px;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.6;
}
.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 0;
  margin-bottom: 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.profile-stats b {
  display: block;
  font-size: 18px;
  color: var(--accent);
  line-height: 1.2;
}
.profile-stats span {
  font-size: 12px;
  color: var(--faint);
}
.btn-outline {
  display: inline-block;
  width: 100%;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
}
.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

/* Category list widget */
.cat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.cat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.cat-btn:hover { background: var(--code); color: var(--text); }
.cat-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cat-btn .count {
  font-size: 12px;
  background: var(--code);
  color: var(--faint);
  padding: 1px 8px;
  border-radius: 999px;
}
.cat-btn.active .count {
  background: var(--accent);
  color: var(--bg);
}

/* Tag cloud widget */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.tag-btn {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: 12.5px;
  font-family: inherit;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.tag-btn .t-count {
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.tag-btn:hover,
.tag-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.tag-btn:hover .t-count,
.tag-btn.active .t-count {
  color: var(--accent);
}

/* Dedicated /blog/tags.html page */
.tags-overview {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 24px;
}
.tags-overview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 13.5px;
  color: var(--muted);
}
.tags-overview-head strong { color: var(--accent); }
.tag-groups {
  display: grid;
  gap: 16px;
}
.tag-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  scroll-margin-top: 84px;
}
.tag-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.tag-group-head h2 {
  font-size: 17px;
  margin: 0;
  color: var(--accent);
}
.tag-group-head .count-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--code);
  padding: 2px 10px;
  border-radius: 999px;
}
.tag-post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.tag-post-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.tag-post-item a {
  color: var(--text);
  font-weight: 500;
  font-size: 15px;
}
.tag-post-item a:hover { color: var(--accent); text-decoration: none; }
.tag-post-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--faint);
  flex-shrink: 0;
}
.widget-foot-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 13px;
  font-weight: 600;
}

/* TOC widget (Article page) */
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.toc-list a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13.5px;
}
.toc-list a:hover {
  background: var(--code);
  color: var(--accent);
  text-decoration: none;
}
.toc-list .n {
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* Article page content */
.article-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: clamp(22px, 4vw, 40px);
}
.breadcrumb {
  font-size: 13.5px;
  color: var(--faint);
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.article-header {
  padding-bottom: 22px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.article-header h1 {
  font-size: clamp(24px, 3.6vw, 34px);
  line-height: 1.3;
  margin: 12px 0 14px;
  letter-spacing: -0.015em;
}
.article-body h2 {
  font-size: 21px;
  margin: 34px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 84px;
}
.article-body h3 { font-size: 17.5px; margin: 24px 0 8px; }
.article-body p { margin: 0 0 16px; color: var(--text); }
.article-body ul, .article-body ol {
  margin: 0 0 18px;
  padding-left: 22px;
}
.article-body li { margin: 6px 0; }

.article-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code);
  padding: 2px 6px;
  border-radius: 5px;
}
.code-block {
  position: relative;
  margin: 18px 0 22px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--code);
  overflow: hidden;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 65%, var(--code));
}
.code-lang {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.code-block pre {
  margin: 0;
  padding: 15px 18px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.65;
}
.code-block pre code { background: none; padding: 0; font-size: inherit; }
.copy-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

/* Syntax highlighting tokens (Light / Dark) */
.tok-kw  { color: #7c3aed; font-weight: 600; }
.tok-str { color: #059669; }
.tok-num { color: #d97706; }
.tok-cmt { color: #71717a; font-style: italic; }
.tok-var { color: #db2777; }
.tok-fn  { color: #2563eb; }
.tok-key { color: #7c3aed; }

:root[data-theme="dark"] .tok-kw  { color: #c084fc; }
:root[data-theme="dark"] .tok-str { color: #34d399; }
:root[data-theme="dark"] .tok-num { color: #fbbf24; }
:root[data-theme="dark"] .tok-cmt { color: #71717a; }
:root[data-theme="dark"] .tok-var { color: #f472b6; }
:root[data-theme="dark"] .tok-fn  { color: #60a5fa; }
:root[data-theme="dark"] .tok-key { color: #a78bfa; }

.callout {
  border-left: 3px solid var(--accent);
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0 10px 10px 0;
  padding: 14px 18px;
  margin: 20px 0;
  font-size: 14.5px;
  color: var(--muted);
}
.callout strong { color: var(--text); }

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14.5px;
}
.article-body th, .article-body td {
  border: 1px solid var(--line);
  padding: 10px 14px;
  text-align: left;
}
.article-body th { background: var(--code); font-weight: 600; }

.post-nav {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 14px;
}
.post-nav a {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.post-nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.site-foot {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px clamp(18px, 3vw, 36px) 40px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: var(--faint);
}

@media (max-width: 880px) {
  .container {
    grid-template-columns: 1fr;
    padding-top: 24px;
  }
  .sidebar { position: static; }
  .brand .brand-sub { display: none; }
}
