/* =============== Reset & Base =============== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 1.32rem; /* 10% larger */
}
img {
  max-width: 100%;
  display: block;
}
a {
  color: inherit;
  text-decoration: none;
}
ul {
  list-style: none;
}

/* =============== Design Tokens =============== */
:root {
  --bg: #ffffff;
  --bg-alt: #fafafa;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --max-width: 1400px;
  --code-comment: #a0a1a7;
  --code-keyword: #a626a4;
  --code-string: #50a14f;
  --code-number: #986801;
  --code-function: #4078f2;
  --code-attr: #c18401;
  --wave-color: #0284c7;
  --wave-color-2: #38bdf8;
  --wave-color-3: #7dd3fc;
  --wave-color-4: #06b6d4;
  --wave-color-5: #14b8a8;
  --wave-color-6: #6366f1;
  --wave-color-7: #f59e0b;
  --wave-color-8: #fbbf24;
  --wave-color-9: #34d399;
  --wave-color-10: #f472b6;
  --wave-opacity: 0.18;
}

/* Manual dark mode override (via theme toggle) */
:root.dark-mode,
body.dark-mode {
  --bg: #0f1117;
  --bg-alt: #1a1c23;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #2d3748;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --code-comment: #7f848e;
  --code-keyword: #c678dd;
  --code-string: #98c379;
  --code-number: #d19a66;
  --code-function: #61afef;
  --code-attr: #56b6c2;
  --wave-color: #7dd3fc;
  --wave-color-2: #bae6fd;
  --wave-color-3: #a5b4fc;
  --wave-color-4: #68d7db;
  --wave-color-5: #5ce7d7;
  --wave-color-6: #818cf8;
  --wave-color-7: #fbbf24;
  --wave-color-8: #fcd34d;
  --wave-color-9: #6ee7b7;
  --wave-color-10: #f871b3;
  --wave-opacity: 0.25;
}

/* =============== Wave Animation =============== */
.waves {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 80px;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
#wave-canvas {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Disable wave animation for reduced-motion users */
@media (prefers-reduced-motion: reduce) {
  #wave-canvas {
    display: none;
  }
}

/* =============== Layout =============== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.section {
  padding: 4rem 0;
}
.section-sm {
  padding: 2.5rem 0;
}
.section-title {
  font-size: 2.475rem; /* 10% larger */
  font-weight: 700;
}
.page-title {
  font-size: 2.75rem; /* 10% larger */
  font-weight: 800;
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}
.page-subtitle {
  font-size: 1.32rem; /* 10% larger */
  color: var(--text-muted);
  margin-bottom: 2rem;
  line-height: 1.6;
}
.section-title {
  margin-bottom: 2rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}

/* =============== Header =============== */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  height: auto;
  padding-bottom: 80px;
}
.header-inner {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
}
.logo {
  font-size: 1.98rem; /* 10% larger */
  font-weight: 800;
  letter-spacing: -0.02em;
}
.logo span {
  color: var(--accent);
}
.tagline {
  font-size: 1.14rem; /* 20% larger */
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-weight: 500;
}

/* =============== Navigation =============== */
.nav {
  display: flex;
  align-items: center;
  gap: 2rem;
}

/* =============== Hamburger Menu (mobile) =============== */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 36px;
  height: 28px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: 101;
}
.menu-toggle span {
  display: block;
  width: 100%;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}
.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}
.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* Mobile: nav collapses into hamburger */
@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }
  .nav {
    position: fixed;
    top: 0;
    right: -100%;
    height: 100vh;
    width: 320px;
    max-width: 85vw;
    background: var(--bg);
    flex-direction: column;
    gap: 1.5rem;
    padding: 4rem 1.5rem 2rem;
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
    transition: right 0.3s ease;
    backdrop-filter: none;
  }
  .nav.open {
    right: 0;
  }
  body.nav-open {
    overflow: hidden;
  }
  /* Touch targets for mobile nav links */
  .nav a {
    padding: 0.5rem 0;
  }
}
.nav a {
  font-weight: 500;
  font-size: 1.32rem; /* 10% larger */
  color: var(--text-muted);
  transition: color 0.2s;
  position: relative;
}
.nav a:hover {
  color: var(--accent);
}
.nav a.active {
  color: var(--accent);
}
.nav a.active::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}
.nav .nav-search-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.32rem;
}

/* Theme toggle button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.32rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
}

/* =============== Hero =============== */
.hero {
  text-align: center;
  padding: 5rem 0 3rem;
}
.hero h1 {
  font-size: 3.3rem; /* 10% larger */
  font-weight: 800;
  margin-bottom: 1rem;
  letter-spacing: -0.03em;
}
.hero .hero-tagline {
  font-size: 1.54rem; /* 10% larger */
  color: var(--text-muted);
  font-weight: 400;
}
.hero img {
  border-radius: 8px;
  margin: 2rem auto 0;
  max-height: 300px;
  object-fit: cover;
}

/* =============== Article Cards =============== */
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}
.article-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}
.article-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}
.article-card img {
  aspect-ratio: 16/9;
  object-fit: cover;
  width: 100%;
}
.article-content {
  padding: 1.25rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.article-content .article-meta {
  font-size: 1.1rem; /* 10% larger */
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.article-content .article-meta .separator {
  color: var(--border);
}
.article-content h3 {
  font-size: 1.65rem; /* 10% larger */
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}
.article-content .article-excerpt {
  color: var(--text-muted);
  font-size: 1.32rem; /* 10% larger */
  margin-bottom: 1rem;
  line-height: 1.6;
  flex: 1;
}
.article-content .read-more {
  color: var(--accent);
  font-weight: 600;
  font-size: 1.21rem; /* 10% larger */
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.article-content .read-more:hover {
  color: var(--accent-hover);
}

/* Category pills */
/* =============== Search =============== */
.search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 17, 23, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 1000;
}
.search-overlay.active {
  opacity: 1;
  visibility: visible;
}
.search-overlay .search-container {
  max-width: 600px;
  width: 90%;
}
.search-overlay input {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1.21rem; /* 10% larger */
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-alt);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.search-overlay input:focus {
  border-color: var(--accent);
}
.search-overlay .search-close {
  text-align: right;
  margin-top: 0.75rem;
  font-size: 1.21rem; /* 10% larger */
  color: var(--text-muted);
}

/* =============== Footer =============== */
.site-footer {
  background: var(--bg-alt);
  border-top: 1px solid var(--border);
  padding: 3rem 0 1.5rem;
  font-size: 1.21rem; /* 10% larger */
  color: var(--text-muted);
}
.footer-top {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
  margin-bottom: 2rem;
}
.footer-column h4 {
  font-size: 1.32rem; /* 10% larger */
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
}
.footer-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.footer-links a:hover {
  color: var(--accent);
}
.footer-bottom {
  text-align: center;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}
/* =============== Marquee (Motivational Quotes) =============== */
.marquee-container {
  overflow: hidden;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  height: 4rem;
  min-height: 4rem;
}
.marquee-content {
  white-space: nowrap;
  animation: marquee-scroll 25s linear infinite;
  font-size: 1.2rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding-left: 100%;
  word-break: break-all;
  transition: opacity 0.4s ease;
}
.marquee-content:hover {
  animation-play-state: paused;
}
@keyframes marquee-scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-100%);
  }
}
.marquee-meta {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-style: italic;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

/* =============== Search Results =============== */
.search-results {
  margin-top: 1rem;
  max-height: 320px;
  overflow-y: auto;
}
.search-results .search-result-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  transition: background 0.2s;
  text-decoration: none;
  color: inherit;
}
.search-results .search-result-item:hover {
  background: var(--accent);
  color: #ffffff;
}
.search-results .search-result-item img {
  width: 50px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.search-result-item .search-result-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
  display: block;
}
.search-result-item .search-result-excerpt {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-item:hover .search-result-excerpt {
  color: rgba(255, 255, 255, 0.8);
}
.search-no-results {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
}

/* =============== Related Articles =============== */
.related-article {
  cursor: pointer;
}
.related-article:hover {
  border-color: var(--accent);
}

/* =============== Theme Toggle =============== */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.32rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  transition: background 0.2s;
}
.theme-toggle:hover {
  background: var(--bg-alt);
}
:root.dark-mode .theme-toggle,
body.dark-mode .theme-toggle {
  color: var(--accent);
}

/* =============== Table of Contents =============== */
.toc {
  position: sticky;
  top: 6rem;
  align-self: start;
}
.toc h4 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.toc-list {
  list-style: none;
  font-size: 0.95rem;
}
.toc-list li {
  margin-bottom: 0.35rem;
}
.toc-list a {
  color: var(--text-muted);
  transition: color 0.2s;
  display: block;
  padding: 0.15rem 0;
}
.toc-list a:hover {
  color: var(--accent);
}
.toc-list a.active {
  color: var(--accent);
  font-weight: 600;
}
.toc-list .toc-sub {
  margin-left: 1.25rem;
  margin-top: 0.25rem;
}

/* =============== Article Layout with TOC =============== */
.article-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 3rem;
}
.article-main {
  min-width: 0;
}

/* =============== Responsive =============== */
@media (max-width: 1024px) {
  .article-layout {
    grid-template-columns: 1fr;
  }
  .toc {
    position: relative;
    top: 0;
    margin-bottom: 2rem;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 0 1rem;
  }
  .header-inner {
    flex-wrap: wrap;
    gap: 1rem;
  }
  .nav {
    gap: 1rem;
  }
  .hero h1 {
    font-size: 2.53rem; /* 10% larger */
  }
  .hero {
    padding: 3rem 0 2rem;
  }
  .section {
    padding: 3rem 0;
  }
  .section-title {
    font-size: 1.76rem; /* 10% larger */
  }
}

/* =============== Enhancements (enhancements.js) =============== */

/* ---------- 閱讀進度條 ---------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  transform-origin: 0 50%;
  transform: scaleX(0);
  z-index: 200;
  pointer-events: none;
}

/* ---------- 程式碼複製按鈕 ---------- */
.code-block {
  position: relative;
}
.copy-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s, color 0.15s, border-color 0.15s;
}
.code-block:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}
.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.copy-btn.copied {
  color: #22c55e;
  border-color: #22c55e;
  opacity: 1;
}

/* ---------- 回到頂部按鈕 ---------- */
.back-to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s, visibility 0.25s, background 0.15s;
  z-index: 150;
}
.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.back-to-top:hover {
  background: var(--accent-hover);
}

/* ---------- 文章卡片滑鼠發光 ---------- */
.article-card {
  position: relative;
}
.article-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  transition: opacity 0.25s;
  background: radial-gradient(
    320px circle at var(--mx, 50%) var(--my, 50%),
    rgba(96, 165, 250, 0.16),
    transparent 65%
  );
  pointer-events: none;
}
.article-card:hover::after {
  opacity: 1;
}
.article-card:hover {
  transform: translateY(-4px);
  border-color: rgba(96, 165, 250, 0.45);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.12);
}

/* ---------- 首頁終端機視窗 ---------- */
.terminal-window {
  max-width: 640px;
  margin: 2.5rem auto 0;
  text-align: left;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  font-family: "Fira Code", "SF Mono", Consolas, monospace;
}
.terminal-titlebar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: #161b22;
  border-bottom: 1px solid #30363d;
}
.terminal-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.dot-r { background: #ff5f57; }
.dot-y { background: #febc2e; }
.dot-g { background: #28c840; }
.terminal-caption {
  margin-left: auto;
  font-size: 0.75rem;
  color: #8b949e;
}
.terminal-body {
  padding: 1rem 1.25rem;
  font-size: 0.95rem;
  line-height: 1.7;
  color: #c9d1d9;
  min-height: 3.6em;
}
.terminal-prompt {
  color: #7ee787;
  user-select: none;
}
.terminal-command {
  color: #e6edf3;
}
.terminal-cursor::after {
  content: '▊';
  color: #58a6ff;
  animation: terminal-blink 1s steps(1) infinite;
}
@keyframes terminal-blink {
  50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .terminal-cursor::after {
    animation: none;
  }
}

/* ---------- highlight.js 配色（One Light / One Dark，跟著主題走）---------- */
.hljs-comment,
.hljs-quote {
  color: var(--code-comment);
  font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-doctag,
.hljs-formula {
  color: var(--code-keyword);
}
.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string {
  color: var(--code-string);
}
.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-template-variable,
.hljs-variable {
  color: var(--code-number);
}
.hljs-title,
.hljs-section,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
  color: var(--code-function);
}
.hljs-attr,
.hljs-type,
.hljs-built_in,
.hljs-builtin-name,
.hljs-class .hljs-title {
  color: var(--code-attr);
}
.hljs-emphasis {
  font-style: italic;
}
.hljs-strong {
  font-weight: 700;
}
