/* ============================================================
   ZBLOG DESIGN SYSTEM  ·  style.css  ·  v4
   ============================================================ */

/* ── 0. Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
img, svg { display: block; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ── 1. Design Tokens ── */
:root {
  --c-text:        #212121;
  --c-muted:       #757575;
  --c-faint:       #BDBDBD;
  --c-link:        #002FA7;
  --c-bg:          #ffffff;
  --c-bg-code:     #F5F5F5;
  --c-border:      #E0E0E0;
  --c-border-lt:   #F0F0F0;
  --c-footer-bg:   #EDEDED;
  --c-icon-bg:     #212121;
  --c-icon-fg:     #ffffff;
  --c-header-bg:   #ffffff;
  --c-header-sh:   rgba(0,0,0,0.06);
  --c-prev-bg:     #f0f4ff;
  --c-prev-bd:     #c5d0f0;
  --c-prev-link:   #3a5fcf;

  --f-sans: "Source Han Sans SC","Noto Sans CJK SC","PingFang SC",
            "DengXian","等线","Microsoft YaHei",system-ui,sans-serif;
  --f-logo: "Helvetica Neue",Helvetica,Arial,sans-serif;
  --f-mono: "SF Mono","Fira Code","Cascadia Code","Consolas",monospace;

  --max-w:   600px;
  --pad-x:   1rem;

  /* header height tokens */
  --hdr-logo-lg: 46px;   /* desktop initial logo size */
  --hdr-logo-sm: 30px;   /* desktop compact / mobile logo size */
  --hdr-wm-lg:   1.5rem; /* desktop initial wordmark */
  --hdr-wm-sm:   1.0625rem; /* desktop compact / mobile wordmark */
  --hdr-nav-lg:  1rem;
  --hdr-nav-sm:  0.875rem;

  --t-hdr: 0.28s;
  --ease:  cubic-bezier(0, 0, 0.2, 1);
}

/* ── 2. Base ── */
body {
  font-family: var(--f-sans);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, h5, h6 { font-weight: normal; }

:focus-visible {
  outline: 2px solid var(--c-link);
  outline-offset: 2px;
}

/* ── 3. Layout shell ── */
#content {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 2rem var(--pad-x) 5rem;
}


/* ══════════════════════════════════════════
   SITE HEADER  —  two-state animated
   ══════════════════════════════════════════ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--c-header-bg);
  /* shadow hidden initially, appears on compact */
  transition:
    box-shadow var(--t-hdr) ease,
    padding    var(--t-hdr) var(--ease);
}

.site-header.is-compact {
  box-shadow: 0 1px 10px var(--c-header-sh);
}

/* Inner bar: logo left, nav right */
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--pad-x);
}

/* ── Logo ── */
.site-logo {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}

.logo-icon {
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  /* animated on desktop */
  transition:
    width  var(--t-hdr) var(--ease),
    height var(--t-hdr) var(--ease);
}

.logo-wordmark {
  font-family: var(--f-logo);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--c-text);
  line-height: 1;
  white-space: nowrap;
  transition: font-size var(--t-hdr) var(--ease);
}

/* ── Desktop Nav ── */
.site-nav {
  display: none; /* shown via media query on desktop */
  align-items: center;
  gap: 2em;
}

.site-nav a {
  font-size: var(--hdr-nav-lg);
  color: var(--c-text);
  transition:
    color      0.15s ease,
    font-size  var(--t-hdr) var(--ease);
}

.site-nav a:hover { color: var(--c-muted); }

.site-header.is-compact .site-nav a { font-size: var(--hdr-nav-sm); }

/* ── Hamburger Button ── */
.nav-toggle {
  display: flex; /* hidden on desktop via media query */
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  padding: 0;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Three lines via pseudo-elements */
.hamburger-icon {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--c-text);
  border-radius: 2px;
  position: relative;
  transition: background 0.2s;
}

.hamburger-icon::before,
.hamburger-icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--c-text);
  border-radius: 2px;
  transition: transform 0.22s ease, top 0.22s ease;
}

.hamburger-icon::before { top: -6px; }
.hamburger-icon::after  { top:  6px; }

/* Morph to × */
.nav-toggle[aria-expanded="true"] .hamburger-icon { background: transparent; }
.nav-toggle[aria-expanded="true"] .hamburger-icon::before { transform: rotate(45deg);  top: 0; }
.nav-toggle[aria-expanded="true"] .hamburger-icon::after  { transform: rotate(-45deg); top: 0; }

/* ── Mobile Drawer ── */
/* border-top removed: use header box-shadow as the only divider line */
.nav-drawer {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s var(--ease);
  background: var(--c-header-bg);
  /* border-top: 1px solid var(--c-border-lt); -- removed to avoid double-line issue */
}

.nav-drawer.is-open { max-height: 240px; }

.nav-drawer a {
  display: block;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0.9rem var(--pad-x);
  font-size: 1rem;
  color: var(--c-text);
  border-bottom: 1px solid var(--c-border-lt);
  transition: color 0.1s;
}

.nav-drawer a:last-child { border-bottom: none; }
.nav-drawer a:hover { color: var(--c-muted); }


/* ══════════════════════════════════════════
   MOBILE HERO SECTION
   (homepage only, mobile only)
   ══════════════════════════════════════════ */

.hero-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem var(--pad-x) 2rem;
  text-align: center;
  /* fade + lift when compact header takes over */
  transition:
    opacity   0.25s ease,
    transform 0.3s var(--ease);
}

.hero-section.is-gone {
  opacity: 0;
  transform: translateY(-14px);
  pointer-events: none;
}

.hero-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 0.875rem;
}

.hero-wordmark {
  font-family: var(--f-logo);
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: -0.025em;
  color: var(--c-text);
  margin-bottom: 1rem;
  line-height: 1;
}

.hero-nav {
  display: flex;
  gap: 1.75rem;
}

.hero-nav a {
  font-size: 1rem;
  color: var(--c-text);
  transition: color 0.15s;
}

.hero-nav a:hover { color: var(--c-muted); }


/* ══════════════════════════════════════════
   HOMEPAGE CONTENT
   ══════════════════════════════════════════ */

#AboutBox {
  margin-bottom: 4.5em;
  padding-top: 0.5em;
}

.about-pre {
  font-family: var(--f-mono);
  font-size: 0.8em;
  line-height: 1.8;
  color: var(--c-muted);
  white-space: pre-wrap;
  word-break: break-word;
  background: none;
  border: none;
}

.section-header {
  font-size: 1.25em;
  font-weight: 500;
  margin-bottom: 1.25em;
}

/* Article cards (homepage) — .article-card and .articleBox are identical */
.article-card,
.articleBox {
  margin-bottom: 3em;
}

.article-card h2,
.articleBox h2 {
  font-size: 1.25em;
  font-weight: 500;
  line-height: 1.3;
  margin-bottom: 0.375em;
}

.article-card h2 a:hover,
.articleBox h2 a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.time-spec {
  display: block;
  font-size: 0.875em;
  color: var(--c-muted);
  margin-bottom: 0.5em;
}

.article-card p,
.articleBox p {
  font-size: 0.875em;
  font-weight: 300;
  line-height: 1.65;
}

#ContactBox {
  margin-top: 4em;
  margin-bottom: 2em;
}

#ContactBox h2 {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.875em;
}

#ContactBox p  { font-size: 0.875em; margin-bottom: 0.375em; }
#ContactBox a  { color: var(--c-link); }
#ContactBox a:hover { text-decoration: underline; }


/* ══════════════════════════════════════════
   ARTICLES LIST PAGE  (/articles)
   ══════════════════════════════════════════ */

.page-title {
  font-size: 1.5em;
  font-weight: 500;
  margin-bottom: 1.5em;
}

.year-group { margin-bottom: 2em; }

.year-label {
  display: block;
  font-size: 0.75em;
  color: var(--c-faint);
  margin-bottom: 0.5em;
  letter-spacing: 0.02em;
}

.article-list { border-top: 1px solid var(--c-border-lt); }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1em;
  padding: 0.55em 0;
  border-bottom: 1px solid var(--c-border-lt);
}

.list-item a {
  font-size: 0.9375em;
  flex: 1;
  min-width: 0;
}

.list-item a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.list-date {
  font-size: 0.8125em;
  color: var(--c-muted);
  flex-shrink: 0;
  white-space: nowrap;
}


/* ══════════════════════════════════════════
   NOTES LIST PAGE  (/posts)
   ══════════════════════════════════════════ */

.plist-item {
  padding: 0.375em 0 1em;
  border-bottom: 1px solid var(--c-border-lt);
}

.plist-item:last-of-type { border-bottom: none; }

.plist-item h3 {
  font-size: 0.875em;
  font-weight: 500;
  margin-bottom: 0.375em;
}

.plist-item h3 a:hover { text-decoration: underline; }

.plist-item p { font-size: 0.875em; line-height: 1.65; }

.plist-date {
  font-size: 0.75em;
  color: var(--c-muted);
  white-space: nowrap;
}

.pagination {
  margin-top: 2.5em;
  font-size: 0.875em;
  color: var(--c-muted);
}

.pagination a { color: var(--c-link); }
.pagination a:hover { text-decoration: underline; }


/* ══════════════════════════════════════════
   ARTICLE DETAIL PAGE
   ══════════════════════════════════════════ */

article { margin-bottom: 2em; }

.article-title {
  font-size: 1.75em;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 0.5em;
}

.post-desc {
  font-size: 0.875em;
  font-weight: 300;
  color: var(--c-muted);
  line-height: 1.65;
  margin-bottom: 1.75em;
}

/* Article body */
.article-body { line-height: 1.7; }

.article-body h1 { font-size: 1.375em; font-weight: 600; line-height: 1.3; margin: 1.75em 0 0.5em; }
.article-body h2 { font-size: 1.125em; font-weight: 600; line-height: 1.3; margin: 1.5em  0 0.5em; }
.article-body h3 { font-size: 1em;     font-weight: 600; line-height: 1.4; margin: 1.25em 0 0.375em; }
.article-body h4 { font-size: 0.875em; font-weight: 600; line-height: 1.4; margin: 1em    0 0.25em; }

.article-body p { font-size: 1em; line-height: 1.7; margin-bottom: 0.875em; }

.article-body a {
  color: var(--c-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.article-body code {
  font-family: var(--f-mono);
  font-size: 0.875em;
  background: var(--c-bg-code);
  border: 1px solid var(--c-border);
  border-radius: 3px;
  padding: 0.1em 0.35em;
}

.article-body pre {
  font-family: var(--f-mono);
  font-size: 0.875em;
  background: var(--c-bg-code);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 1em;
  overflow-x: auto;
  margin-bottom: 1em;
  line-height: 1.5;
}

.article-body pre code { background: none; border: none; padding: 0; font-size: 1em; }

.article-body img {
  max-width: 100% !important;
  height: auto !important;
  border-radius: 4px;
  margin: 1em 0;
}

.article-body blockquote {
  border-left: 3px solid var(--c-border);
  margin: 1em 0;
  padding: 0.25em 0 0.25em 1em;
  color: var(--c-muted);
}

.article-body ul, .article-body ol { padding-left: 1.5em; margin-bottom: 0.875em; }
.article-body li { margin-bottom: 0.375em; line-height: 1.65; }

/* In-article related notes */
#plist {
  margin-top: 2.5em;
  padding-top: 1.5em;
  border-top: 1px solid var(--c-border);
}

#plist h2 {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--c-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1.25em;
}


/* ── Preview link + card ── */
.article-body a.preview-link {
  display: inline-block;
  padding: 1px 8px;
  margin: 0 2px;
  background: var(--c-prev-bg);
  border: 1px solid var(--c-prev-bd);
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--c-prev-link);
  text-decoration: none;
  vertical-align: baseline;
}

@media (hover: hover) {
  .article-body a.preview-link { position: relative; }
  .article-body a.preview-link:hover { background: #e0e8ff; border-color: var(--c-prev-link); }

  .preview-card {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    padding: 12px 14px;
    background: var(--c-bg);
    border: 1px solid #dde3f0;
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
    z-index: 999;
    white-space: normal;
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--c-text);
  }

  .article-body a.preview-link:hover .preview-card { display: block; }
  .preview-title { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 5px; }
  .preview-desc  { display: block; color: var(--c-muted); margin-bottom: 8px; font-size: 0.9em; }
  .preview-goto  { display: block; font-size: 0.82rem; color: var(--c-prev-link); }
}

@media (hover: none) { .preview-card { display: none !important; } }


/* ══════════════════════════════════════════
   COMMENTS
   ══════════════════════════════════════════ */

.comments-section {
  margin-top: 3em;
  padding-top: 1.5em;
  border-top: 1px solid var(--c-border);
}

.comments-section > h3 {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--c-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1.5em;
}

.comment-message {
  font-size: 0.875em;
  padding: 0.625em 0.875em;
  margin-bottom: 1.25em;
  border-left: 3px solid var(--c-text);
  background: var(--c-bg-code);
}

.comment { padding: 1em 0; border-bottom: 1px solid var(--c-border-lt); }

.comment-meta { display: flex; align-items: baseline; gap: 0.75em; margin-bottom: 0.375em; }
.comment-meta strong { font-size: 0.875em; font-weight: 500; }
.comment-date { font-size: 0.75em; color: var(--c-muted); }
.comment-body { font-size: 0.9375em; line-height: 1.65; }
.comment-body p { font-size: 1em; margin-bottom: 0.5em; }
.no-comments { font-size: 0.875em; color: var(--c-muted); padding: 0.5em 0 1em; }

.comment-form {
  margin-top: 2em;
  padding-top: 1.5em;
  border-top: 1px solid var(--c-border);
}

.comment-form h4 {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--c-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1em;
}

.form-field { margin-bottom: 1em; }

.form-field label {
  display: block;
  font-size: 0.75em;
  color: var(--c-muted);
  margin-bottom: 0.375em;
}

.form-field input[type="text"],
.form-field input[type="email"],
.form-field input[type="url"],
.form-field textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 0.9375em;
  color: var(--c-text);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 0.5em 0.625em;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

.form-field input:focus-visible,
.form-field textarea:focus-visible {
  border-color: var(--c-link);
  outline: 2px solid var(--c-link);
  outline-offset: 0;
}

.form-field textarea { min-height: 6em; resize: vertical; line-height: 1.6; }
.form-field .errorlist { list-style: none; margin: 0.375em 0 0; }
.form-field .errorlist li { font-size: 0.75em; color: #B00020; }

.comment-form button[type="submit"] {
  font-family: inherit;
  font-size: 0.875em;
  font-weight: 500;
  color: var(--c-icon-fg);
  background: var(--c-icon-bg);
  border: none;
  border-radius: 4px;
  padding: 0.75em 1.75em;
  min-height: 2.75rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.comment-form button[type="submit"]:hover { opacity: 0.78; }

/* Back to top */
.back-to-top { margin-top: 2em; font-size: 0.875em; }
.back-to-top a { color: var(--c-muted); }
.back-to-top a:hover { color: var(--c-text); }


/* ══════════════════════════════════════════
   SITE FOOTER  —  全宽通栏
   ══════════════════════════════════════════ */

.site-footer {
  background: var(--c-footer-bg);
  margin-top: 4em;
  padding: 2.25em var(--pad-x) 2em;
  text-align: center;
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.875em;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c-icon-bg);
  color: var(--c-icon-fg);
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.icon-btn:hover { opacity: 0.72; transform: scale(1.06); }

.footer-copy {
  font-size: 0.75em;
  color: var(--c-muted);
  line-height: 1.6;
}

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


/* ══════════════════════════════════════════
   DARK MODE
   ══════════════════════════════════════════ */

@media (prefers-color-scheme: dark) {
  :root {
    --c-text:      #E0E0E0;
    --c-muted:     #9E9E9E;
    --c-faint:     #4A4A4A;
    --c-link:      #6B9FFF;
    --c-bg:        #121212;
    --c-bg-code:   #1E1E1E;
    --c-border:    #424242;
    --c-border-lt: #2C2C2C;
    --c-footer-bg: #1E1E1E;
    --c-icon-bg:   #D8D8D8;
    --c-icon-fg:   #141414;
    --c-header-bg: #1A1A1A;
    --c-header-sh: rgba(0,0,0,0.35);
    --c-prev-bg:   #1a2248;
    --c-prev-bd:   #2e3f80;
  }
}


/* ══════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════ */

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


/* ══════════════════════════════════════════
   DESKTOP  (≥ 640px)
   Two-state header: initial tall → compact on scroll
   ══════════════════════════════════════════ */

@media (min-width: 640px) {

  /* ── Header initial state: taller ── */
  .site-header {
    padding: 16px 0;   /* ~78px total with 46px icon */
  }

  .header-inner { height: auto; }

  /* Logo: larger initially */
  .logo-icon    { width: var(--hdr-logo-lg); height: var(--hdr-logo-lg); }
  .logo-wordmark { font-size: var(--hdr-wm-lg); }

  /* ── Header compact state (after scroll) ── */
  .site-header.is-compact {
    padding: 8px 0;    /* ~50px total */
  }

  .site-header.is-compact .logo-icon    { width: var(--hdr-logo-sm); height: var(--hdr-logo-sm); }
  .site-header.is-compact .logo-wordmark { font-size: var(--hdr-wm-sm); }

  /* Show desktop nav, hide mobile elements */
  .site-nav   { display: flex; }
  .nav-toggle { display: none; }
  .nav-drawer { display: none !important; }

  /* Hero section hidden on desktop */
  .hero-section { display: none; }

  /* Content starts with breathing room */
  #content { padding-top: 2.5rem; }
}


/* ══════════════════════════════════════════
   MOBILE  (≤ 639px)
   Homepage: FLIP animation — hero elements morph into header (JS-driven)
   Non-homepage: two-state compact animation like desktop
   ══════════════════════════════════════════ */

@media (max-width: 639px) {

  /* Header compact size tokens (used as FLIP animation end state) */
  .logo-icon    { width: 34px; height: 34px; }
  .logo-wordmark { font-size: 1.0625rem; }
  .header-inner { height: 56px; }

  /* ── Non-homepage: sticky, two-state compact animation like desktop ── */
  body:not(.page-index) .site-header {
    padding: 8px 0;
    box-shadow: none;
  }
  body:not(.page-index) .header-inner { height: auto; }
  body:not(.page-index) .logo-icon    { width: 40px; height: 40px; }
  body:not(.page-index) .logo-wordmark { font-size: 1.15rem; }

  body:not(.page-index) .site-header.is-compact {
    padding: 4px 0;
    box-shadow: 0 1px 8px var(--c-header-sh);
  }
  body:not(.page-index) .site-header.is-compact .logo-icon    { width: var(--hdr-logo-sm); height: var(--hdr-logo-sm); }
  body:not(.page-index) .site-header.is-compact .logo-wordmark { font-size: var(--hdr-wm-sm); }

  /* ── Homepage: FLIP animation completed state ── */
  /* After FLIP animation completes, header needs compact styling */
  body.page-index .site-header.is-compact {
    padding: 4px 0;
    box-shadow: 0 1px 8px var(--c-header-sh);
  }
  body.page-index .site-header.is-compact .logo-icon {
    width: var(--hdr-logo-sm); height: var(--hdr-logo-sm);
  }
  body.page-index .site-header.is-compact .logo-wordmark {
    font-size: var(--hdr-wm-sm);
  }

  /* Remove drawer border-top on mobile homepage (both initial and compact state) */
  /* Use header box-shadow as the only divider line */
  body.page-index .nav-drawer {
    border-top: none !important;
  }

  /* Hero visible only on mobile homepage */
  .hero-section { display: flex; }

  #content { padding-top: 0; }
}
