/* ==========================================================================
   Potter Notes — 全站样式
   只用系统字体与本地资源。颜色集中在 :root 变量中，方便统一修改。
   ========================================================================== */

/* ---------- 颜色与基础变量 ---------- */
:root {
  --bg: #fbfaf7;
  --surface: #f2f0ea;
  --text: #1f2328;
  --text-soft: #3d434b;
  --muted: #5b626b;
  --border: #e2ded4;
  --accent: #1d6b58;
  --accent-soft: #e3efe9;
  --code-bg: #f2f0ea;
  --selection: #cfe5db;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    "Source Han Sans SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", "Noto Sans Mono CJK SC", monospace;

  --width: 72rem;
  --reading: 42rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  --radius: 6px;

  color-scheme: light;
}

/* 跟随系统深色模式（用户未手动选择浅色时） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141619;
    --surface: #1c1f23;
    --text: #e7e5e0;
    --text-soft: #c9c7c1;
    --muted: #9ea4ab;
    --border: #2d3137;
    --accent: #6fc7aa;
    --accent-soft: #1d2d28;
    --code-bg: #1c1f23;
    --selection: #2b4a3f;
    color-scheme: dark;
  }
}

/* 用户手动选择深色 */
:root[data-theme="dark"] {
  --bg: #141619;
  --surface: #1c1f23;
  --text: #e7e5e0;
  --text-soft: #c9c7c1;
  --muted: #9ea4ab;
  --border: #2d3137;
  --accent: #6fc7aa;
  --accent-soft: #1d2d28;
  --code-bg: #1c1f23;
  --selection: #2b4a3f;
  color-scheme: dark;
}

/* ---------- 重置 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 5rem;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

::selection {
  background: var(--selection);
}

img,
svg {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}

p,
ul,
ol,
pre,
blockquote,
table {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---------- 通用工具类 ---------- */
.container {
  width: 100%;
  max-width: var(--width);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 100;
  padding: 0.5rem 0.9rem;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  text-decoration: none;
}

.skip-link:focus {
  top: 1rem;
}

/* ---------- 顶部导航 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(160%) blur(8px);
  -webkit-backdrop-filter: saturate(160%) blur(8px);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .site-header {
    background: var(--bg);
  }
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 4rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-right: auto;
  color: var(--text);
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 1.6rem;
  height: 1.6rem;
  flex: none;
}

.site-nav ul {
  display: flex;
  gap: 0.25rem;
  padding: 0;
  list-style: none;
}

.site-nav a {
  display: block;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  color: var(--text-soft);
  font-size: 0.95rem;
  text-decoration: none;
}

.site-nav a:hover {
  background: var(--surface);
  color: var(--text);
}

.site-nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  background: var(--surface);
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--surface);
  color: var(--text);
}

.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
}

/* 按当前主题切换图标 */
.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
  }
}

/* 未启用 JavaScript 时隐藏主题按钮 */
.no-js .theme-toggle {
  display: none;
}

@media (max-width: 34rem) {
  .header-inner {
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
    padding-block: 0.6rem;
  }

  .site-nav {
    order: 3;
    width: 100%;
    margin-inline: -0.7rem;
  }

  .site-nav ul {
    gap: 0;
  }
}

/* ---------- 页面主体与区块 ---------- */
main {
  display: block;
}

.section {
  padding-block: clamp(3rem, 7vw, 5rem);
}

.section + .section {
  border-top: 1px solid var(--border);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.section-title {
  font-size: clamp(1.35rem, 2.6vw, 1.6rem);
}

.section-lead {
  margin-top: 0.5rem;
  color: var(--muted);
}

.section-link {
  flex: none;
  font-size: 0.95rem;
}

.eyebrow {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

/* ---------- 首页简介 ---------- */
.hero {
  padding-block: clamp(3.5rem, 10vw, 7rem) clamp(3rem, 7vw, 5rem);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: center;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.hero h1 .accent {
  color: var(--accent);
}

.hero-text {
  max-width: 34rem;
  margin-top: 1.25rem;
  color: var(--text-soft);
  font-size: 1.08rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2rem;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 550;
  text-decoration: none;
}

.button:hover {
  background: var(--surface);
  text-decoration: none;
}

.button-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.button-primary:hover {
  background: var(--text-soft);
  border-color: var(--text-soft);
}

/* 终端样式的小装饰块 */
.terminal {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
}

.terminal-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
}

.terminal-bar span[aria-hidden] {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--border);
}

.terminal-bar .terminal-title {
  margin-left: 0.5rem;
}

.terminal pre {
  margin: 0;
  padding: 1rem 1.1rem 1.2rem;
  overflow-x: auto;
  color: var(--text-soft);
}

.terminal .prompt {
  color: var(--accent);
  user-select: none;
}

.terminal .dim {
  color: var(--muted);
}

@media (max-width: 52rem) {
  .hero-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- 笔记列表 ---------- */
.post-list {
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.post-item {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr);
  gap: 0.25rem 2rem;
  padding-block: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.post-item time {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.9;
}

.post-item h3 {
  font-size: 1.12rem;
}

.post-item h3 a {
  color: var(--text);
  text-decoration: none;
}

.post-item h3 a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.post-summary {
  margin-top: 0.35rem;
  color: var(--text-soft);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.7rem;
  padding: 0;
  list-style: none;
}

.tag {
  display: inline-block;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.7;
}

@media (max-width: 40rem) {
  .post-item {
    grid-template-columns: 1fr;
  }
}

.year-group + .year-group {
  margin-top: 3rem;
}

.year-heading {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
}

/* ---------- 项目 ---------- */
.notice {
  margin-bottom: 2rem;
  padding: 0.8rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-soft);
  font-size: 0.95rem;
}

.project-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2.5rem;
  padding: 0;
  list-style: none;
}

.project {
  padding-top: 1.25rem;
  border-top: 2px solid var(--text);
}

.project-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.project h3 {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 600;
}

.badge {
  flex: none;
  padding: 0 0.45rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.6;
}

.project p {
  margin-top: 0.6rem;
  color: var(--text-soft);
}

.project dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  margin: 1rem 0 0;
  font-size: 0.88rem;
}

.project dt {
  color: var(--muted);
}

.project dd {
  margin: 0;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

@media (max-width: 56rem) {
  .project-list {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
}

/* ---------- 关于 ---------- */
.about-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 2rem clamp(2rem, 6vw, 5rem);
}

.about-body > * + * {
  margin-top: 1rem;
}

.about-body p {
  color: var(--text-soft);
}

.about-body h3 {
  margin-top: 2rem;
  font-size: 1rem;
}

.plain-list {
  padding-left: 1.2rem;
  color: var(--text-soft);
}

.plain-list li + li {
  margin-top: 0.3rem;
}

@media (max-width: 48rem) {
  .about-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- 页脚 ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: 2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 2rem;
}

.footer-inner p {
  margin: 0;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  padding: 0;
  list-style: none;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--text);
  text-decoration: underline;
}

.back-to-top {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.back-to-top svg {
  width: 0.9rem;
  height: 0.9rem;
}

/* ---------- 页面标题（列表页、404） ---------- */
.page-head {
  padding-block: clamp(3rem, 8vw, 5rem) 2rem;
}

.page-head h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
}

.page-head p {
  max-width: var(--reading);
  margin-top: 0.75rem;
  color: var(--text-soft);
}

.page-body {
  padding-bottom: clamp(3rem, 8vw, 5rem);
}

/* ---------- 文章页 ---------- */
.article {
  max-width: var(--reading);
  margin-inline: auto;
  padding-block: clamp(2.5rem, 7vw, 4.5rem);
}

.breadcrumb {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.breadcrumb li + li::before {
  content: "/";
  margin-right: 0.4rem;
  color: var(--border);
}

.breadcrumb a {
  color: var(--muted);
}

.article-header h1 {
  font-size: clamp(1.75rem, 4.5vw, 2.3rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.article-meta .tags {
  margin-top: 0;
}

.article-header {
  padding-bottom: 2rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.toc {
  margin-bottom: 2.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.93rem;
}

.toc h2 {
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.toc ol {
  padding-left: 1.2rem;
}

.toc a {
  color: var(--text-soft);
  text-decoration: none;
}

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

/* 文章正文排版 */
.prose {
  color: var(--text-soft);
  font-size: 1.04rem;
  line-height: 1.85;
}

.prose > * + * {
  margin-top: 1.15em;
}

.prose h2 {
  margin-top: 2.4em;
  font-size: 1.35rem;
  color: var(--text);
}

.prose h3 {
  margin-top: 1.8em;
  font-size: 1.1rem;
  color: var(--text);
}

.prose h2 + *,
.prose h3 + * {
  margin-top: 0.7em;
}

.prose strong {
  color: var(--text);
  font-weight: 600;
}

.prose ul,
.prose ol {
  padding-left: 1.4rem;
}

.prose li + li {
  margin-top: 0.35em;
}

.prose blockquote {
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.prose code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.prose pre {
  position: relative;
  padding: 1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.65;
  tab-size: 2;
}

.prose pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}

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

.prose th,
.prose td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.prose th {
  color: var(--text);
  font-weight: 600;
}

.prose td code {
  white-space: nowrap;
}

.prose .callout {
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.97rem;
}

/* 代码块复制按钮（由 script.js 添加） */
.code-block {
  position: relative;
}

.copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  line-height: 1.6;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.code-block:hover .copy-button,
.copy-button:focus-visible,
.copy-button[data-state] {
  opacity: 1;
}

@media (hover: none) {
  .copy-button {
    opacity: 1;
  }
}

.copy-button:hover {
  color: var(--text);
}

/* 上一篇 / 下一篇 */
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.post-nav a {
  display: block;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.post-nav a:hover {
  background: var(--surface);
}

.post-nav span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.post-nav strong {
  display: block;
  margin-top: 0.15rem;
  font-weight: 550;
  line-height: 1.5;
}

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

@media (max-width: 34rem) {
  .post-nav {
    grid-template-columns: 1fr;
  }

  .post-nav .next {
    grid-column: auto;
  }
}

/* ---------- 打印 ---------- */
@media print {
  .site-header,
  .site-footer,
  .post-nav,
  .copy-button,
  .skip-link {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }
}
