
:root {
  --accent-dim: rgba(157, 255, 255, 0.15);

  --space-xs: clamp(0.4rem,  1vw,  0.65rem);
  --space-sm: clamp(0.75rem, 2vw,  1rem);
  --space-md: clamp(1rem,    3vw,  1.5rem);
  --space-lg: clamp(1.5rem,  4vw,  2.5rem);
  --space-xl: clamp(2rem,    5vw,  3.5rem);

  --text-sm:  clamp(0.8rem,  1.8vw, 0.9rem);
  --text-base:clamp(0.95rem, 2.2vw, 1.06rem);
  --text-lg:  clamp(1.05rem, 2.5vw, 1.25rem);
  --text-xl:  clamp(1.3rem,  3.5vw, 1.75rem);
  --text-2xl: clamp(1.6rem,  4.5vw, 2.4rem);
}

.container {
  display: block;
  min-height: 100vh;
}

.forum-body {
  max-width: min(960px, 92vw);
  margin: 0 auto;
  padding: calc(var(--navbar-h) + var(--space-xl)) 0 calc(var(--wave-h) + var(--space-xl));
}

#content-view .forum-body { max-width: min(1240px, 94vw); }

/*  閱讀進度條  */
.read-progress {
  display: none;
  position: fixed;
  top: var(--navbar-h);
  left: 0;
  right: 0;
  height: 3px;
  z-index: 9998;
  transform-origin: 0 50%;
  transform: scaleX(var(--read, 0));
  background: linear-gradient(90deg, var(--accent), var(--teal), var(--gold));
  box-shadow: 0 0 12px rgba(157, 255, 255, 0.6);
  pointer-events: none;
}

body.is-reading .read-progress { display: block; }

/* 支援 scroll-driven animation 就交給 CSS，不支援的由 article.js 更新 --read */
@supports (animation-timeline: scroll()) {
  body.is-reading .read-progress {
    animation: read-grow linear both;
    animation-timeline: scroll(root block);
  }
}

@keyframes read-grow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.list-header { margin-bottom: var(--space-lg); }

.list-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  margin-bottom: 0.7em;
  padding: 0.22em 0.85em;
  border-radius: var(--r-pill);
  background: rgba(125, 255, 176, 0.08);
  border: 1px solid rgba(125, 255, 176, 0.25);
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--lime);
}

.kicker-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 8px var(--lime);
  animation: caret 2s steps(1) infinite;
}

.list-header h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(157, 255, 255, 0.3);
}

.list-header p {
  font-size: var(--text-base);
  color: var(--text-2);
}

.filter-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.7em;
  height: 50px;
  padding: 0 1em;
  border-radius: 14px;
  background: rgba(5, 16, 36, 0.62);
  border: 1px solid var(--line);
  color: var(--text-3);
  cursor: text;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(157, 255, 255, 0.12);
  color: var(--accent);
}

.search-box input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: none;
  border: 0;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);
}

.search-box input::placeholder { color: var(--text-3); }

.search-kbd { transition: opacity 0.2s; }
.search-box:focus-within .search-kbd { opacity: 0; }

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
}

.tag-btn {
  padding: 0.32em 1em;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: rgba(5, 16, 36, 0.5);
  color: var(--text-2);
  font-size: var(--text-sm);
  transition: background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.3s var(--spring);
}

.tag-btn:hover {
  color: #fff;
  border-color: var(--line-2);
  transform: translateY(-1px);
}

.tag-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #062033;
  font-weight: 700;
  box-shadow: 0 0 16px rgba(157, 255, 255, 0.35);
}

.tag-count {
  margin-left: 0.4em;
  font-family: var(--mono);
  font-size: 0.85em;
  opacity: 0.6;
}

.list-count {
  margin-bottom: var(--space-sm);
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--text-3);
}

#article-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  gap: var(--space-md);
}

.card-cell { display: flex; }
.card-cell > .article-card { flex: 1; }

.article-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-md);
  border-radius: 18px;
  background: rgba(9, 28, 56, 0.6);
  border: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: transform 0.4s var(--spring), border-color 0.25s, background 0.25s, box-shadow 0.25s;
}

.article-card:hover {
  transform: translateY(-5px);
  border-color: var(--line-2);
  background: rgba(13, 40, 76, 0.72);
  box-shadow: var(--shadow), 0 0 30px rgba(157, 255, 255, 0.12);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35em;
}

.tag {
  padding: 0.1em 0.7em;
  border-radius: var(--r-pill);
  background: rgba(157, 255, 255, 0.1);
  border: 1px solid rgba(157, 255, 255, 0.32);
  color: var(--accent);
  font-family: var(--mono);
  font-size: var(--text-sm);
}

.badge-new {
  padding: 0.1em 0.7em;
  border-radius: var(--r-pill);
  background: rgba(241, 194, 125, 0.16);
  border: 1px solid rgba(241, 194, 125, 0.5);
  color: var(--gold);
  font-size: var(--text-sm);
  font-weight: 700;
  animation: new-glow 2.4s ease-in-out infinite;
}

@keyframes new-glow {
  50% { box-shadow: 0 0 14px rgba(241, 194, 125, 0.45); }
}

.card-date {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--text-3);
  white-space: nowrap;
}

.card-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 800;
  line-height: 1.45;
  color: #eaf8f8;
}

.card-desc {
  flex: 1;
  margin: 0;
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--text-2);
}

.card-arrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: var(--space-xs);
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--accent);
}

.card-arrow .icon { transition: transform 0.35s var(--spring); }
.article-card:hover .card-arrow .icon { transform: translateX(5px); }

.no-result {
  grid-column: 1 / -1;
  padding: var(--space-lg);
  text-align: center;
  font-size: var(--text-base);
  color: var(--text-3);
}

#back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  margin-bottom: var(--space-md);
  padding: 0.4em 1.05em 0.4em 0.8em;
  border-radius: var(--r-pill);
  background: rgba(157, 255, 255, 0.08);
  border: 1px solid rgba(157, 255, 255, 0.4);
  color: var(--accent);
  font-size: var(--text-sm);
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.3s var(--spring);
}

#back-btn:hover {
  background: rgba(157, 255, 255, 0.18);
  border-color: var(--accent);
  color: #fff;
  transform: translateX(-3px);
}

.article-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-md);
}

.toc-wrap { order: -1; }

.article-glass {
  min-width: 0;
  padding: var(--space-lg) var(--space-xl);
  border-radius: 20px;
  background: rgba(8, 26, 52, 0.72);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.article-header {
  position: relative;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--line);
}

.article-header::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 110px;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  box-shadow: 0 0 10px var(--accent);
}

#article-title {
  margin-bottom: var(--space-sm);
  font-size: var(--text-2xl);
  font-weight: 900;
  line-height: 1.3;
  color: var(--accent);
  text-wrap: balance;
}

#article-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5em 0.8em;
  font-size: var(--text-sm);
  color: var(--text-3);
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

#article-meta .sep { opacity: 0.4; }

/* 目錄 */
#article-toc:empty { display: none; }

.toc-box {
  padding: 0.9em 1em;
  border-radius: 16px;
  background: rgba(5, 16, 36, 0.66);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.toc-box summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--accent);
}

.toc-box summary::-webkit-details-marker { display: none; }

.toc-box summary::after {
  content: "▾";
  transition: transform 0.25s;
}

.toc-box:not([open]) summary::after { transform: rotate(-90deg); }

.toc-box ul {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0.7em 0 0;
  padding: 0;
  list-style: none;
  border-left: 1px solid var(--line);
}

.toc-box a {
  display: block;
  margin-left: -1px;
  padding: 0.3em 0.8em;
  border-left: 2px solid transparent;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-3);
  text-decoration: none;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.toc-box a:hover { color: var(--text); }

.toc-box a.is-current {
  color: var(--accent);
  border-left-color: var(--accent);
  background: linear-gradient(90deg, rgba(157, 255, 255, 0.1), transparent);
}

.toc-h3 a { padding-left: 1.8em; }

/* 寬螢幕：目錄跑到右邊，捲動時黏著 */
@media (min-width: 1200px) {
  .article-shell {
    grid-template-columns: minmax(0, 1fr) 250px;
    align-items: start;
  }

  .toc-wrap {
    order: 0;
    position: sticky;
    top: calc(var(--navbar-h) + 24px);
    max-height: calc(100vh - var(--navbar-h) - 48px);
    overflow-y: auto;
    scrollbar-width: none;
  }
}

/*  內文排版  */
#article-content {
  font-size: var(--text-base);
  line-height: 1.85;
  color: #d1e6f2;
  overflow-wrap: anywhere;
}

#article-content h1,
#article-content h2,
#article-content h3,
#article-content h4 {
  margin: 2em 0 0.6em;
  font-weight: 800;
  line-height: 1.35;
  color: var(--accent);
}

#article-content > :first-child { margin-top: 0; }

#article-content h1 { font-size: var(--text-2xl); }

#article-content h2 {
  position: relative;
  padding: 0 0 0.4em 0.75em;
  font-size: var(--text-xl);
  border-bottom: 1px solid var(--line);
}

#article-content h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.18em;
  bottom: 0.6em;
  width: 4px;
  border-radius: 2px;
  background: linear-gradient(var(--accent), var(--teal));
  box-shadow: 0 0 10px rgba(157, 255, 255, 0.45);
}

#article-content h3 { font-size: var(--text-lg); }

.h-anchor {
  margin-left: 0.4em;
  color: var(--text-3);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}

#article-content :is(h2, h3):hover .h-anchor,
.h-anchor:focus-visible { opacity: 1; }
.h-anchor:hover { color: var(--accent); }

#article-content p { margin: 0 0 1.2em; color: #c6dedf; }
#article-content strong { color: #eefafa; }
#article-content em { color: #e2f4f4; }
#article-content del { color: var(--text-3); }

#article-content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(157, 255, 255, 0.45);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s;
}

#article-content a:hover { text-decoration-color: var(--accent); }
#article-content a.h-anchor { text-decoration: none; }

#article-content ul,
#article-content ol {
  margin-bottom: 1.2em;
  padding-left: 1.5em;
  color: #c6dedf;
}

#article-content li { margin-bottom: 0.4em; }
#article-content li::marker { color: var(--accent); }

#article-content img {
  border-radius: 12px;
  border: 1px solid var(--line);
}

#article-content code:not(pre code) {
  padding: 0.15em 0.45em;
  border-radius: 5px;
  background: rgba(157, 255, 255, 0.1);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.88em;
}

/* 程式碼區塊：上面一條放語言跟複製按鈕 */
.code-block {
  margin: var(--space-md) 0;
  border-radius: 12px;
  border: 1px solid rgba(157, 255, 255, 0.16);
  background: rgba(3, 12, 28, 0.88);
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: 0.35em 0.5em 0.35em 1em;
  background: rgba(255, 255, 255, 0.035);
  border-bottom: 1px solid rgba(157, 255, 255, 0.1);
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-3);
}

.code-lang {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  letter-spacing: 0.06em;
}

.code-lang::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.25em 0.7em;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 0.78rem;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.copy-btn:hover {
  color: var(--accent);
  border-color: var(--line-2);
  background: rgba(157, 255, 255, 0.06);
}

.copy-btn.done { color: var(--lime); }

#article-content pre {
  margin: var(--space-md) 0;
  border-radius: 10px;
  border: 1px solid rgba(157, 255, 255, 0.15);
  font-size: var(--text-sm);
  overflow: auto;
}

#article-content .code-block pre {
  margin: 0;
  border: 0;
  border-radius: 0;
}

#article-content pre code {
  font-family: var(--mono);
  line-height: 1.65;
}

#article-content pre code.hljs {
  padding: 1em 1.2em;
  background: transparent;
}

#article-content blockquote {
  margin: var(--space-md) 0;
  padding: var(--space-sm) var(--space-md);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: rgba(13, 45, 82, 0.5);
  color: var(--text-2);
}

#article-content blockquote p:last-child { margin-bottom: 0; }

#article-content hr {
  margin: var(--space-lg) 0;
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(157, 255, 255, 0.45), transparent);
}

/* 表格由 article.js 包一層 .table-wrap，手機上可以橫向捲動 */
.table-wrap {
  margin-bottom: var(--space-md);
  overflow-x: auto;
}

#article-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

#article-content th,
#article-content td {
  padding: 0.6em 1em;
  border: 1px solid rgba(157, 255, 255, 0.15);
  text-align: left;
}

#article-content th {
  background: rgba(13, 45, 82, 0.75);
  color: var(--accent);
  font-family: var(--mono);
}

#article-content tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }

/* Mermaid 圖表容器 */
#article-content .mermaid {
  margin: var(--space-md) 0;
  padding: var(--space-md);
  border-radius: 12px;
  border: 1px solid rgba(157, 255, 255, 0.15);
  background: rgba(13, 45, 82, 0.4);
  text-align: center;
  overflow-x: auto;
}

#article-content .mermaid svg { max-width: 100%; height: auto; }

/* KaTeX 數學式 */
#article-content .katex { color: #e2f4f4; font-size: 1.05em; }

#article-content .math-block {
  margin: var(--space-md) 0;
  padding: 0.3em 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
}

#article-content .katex-display { margin: 0; }

/* 找不到文章 */
.error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2em;
  padding: var(--space-lg) 0;
  text-align: center;
}

.error-card img {
  width: min(300px, 75%);
  padding: 10px;
  border-radius: 14px;
  background: #fffdf6;
  box-shadow: var(--shadow);
  transform: rotate(-2deg);
}

.error-msg {
  font-size: var(--text-base);
  color: #ff9aad;
}

/* 上一篇 / 下一篇 */
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.post-nav:empty { display: none; }

.post-link {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  padding: 1em 1.2em;
  border-radius: 16px;
  background: rgba(9, 28, 56, 0.6);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: transform 0.4s var(--spring), border-color 0.25s, background 0.25s;
}

.post-link:hover {
  transform: translateY(-3px);
  border-color: var(--line-2);
  background: rgba(13, 40, 76, 0.72);
}

.post-link small {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--text-3);
}

.post-link strong {
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--accent);
}

.post-link.next {
  grid-column: 2;
  text-align: right;
}

@media (max-width: 600px) {
  .forum-body { max-width: calc(100vw - 28px); }
  #content-view .forum-body { max-width: calc(100vw - 20px); }

  .article-glass {
    padding: var(--space-md) var(--space-sm);
    border-radius: 16px;
  }

  .search-kbd { display: none; }

  .post-nav { grid-template-columns: 1fr; }
  .post-link.next { grid-column: auto; }
}
