/* ============================================================
   LaTeX Minimal — Hexo Theme Stylesheet
   ============================================================ */

/* ---- CSS Custom Properties ---- */
:root {
  --font-serif: "Cambria", "Palatino Linotype", "Palatino", "Times New Roman", "STSongti-SC", "Songti SC", "SimSun", "宋体", serif;
  --font-mono: "Consolas", "Menlo", "Monaco", "Courier New", monospace;
  --max-width: 720px;
  --max-width-wide: 960px;
  --toc-width: 220px;
  --gap: 1.5rem;
  --radius: 3px;
  --transition: 180ms ease;
}

/* Dark theme (default) */
[data-theme="dark"] {
  --bg:            #1a1a1c;
  --bg-surface:    #222224;
  --bg-code:       #28282b;
  --bg-toc:        #1e1e20;
  --text:          #d4cfc6;
  --text-muted:    #8a857c;
  --text-faint:    #5c5852;
  --border:        #333334;
  --border-light:  #2a2a2c;
  --accent:        #c2855b;
  --accent-dim:    #8a5e3f;
  --rule:          #3a3a3c;
  --selection-bg:  #3d3326;
  --selection-text:#e0d8c8;
}

/* Light theme */
[data-theme="light"] {
  --bg:            #fdfcf8;
  --bg-surface:    #f6f3ed;
  --bg-code:       #f0ede6;
  --bg-toc:        #f9f7f2;
  --text:          #2d2c28;
  --text-muted:    #6b6760;
  --text-faint:    #a09b92;
  --border:        #ddd8cf;
  --border-light:  #ebe6db;
  --accent:        #a0522d;
  --accent-dim:    #c2855b;
  --rule:          #d5d0c7;
  --selection-bg:  #e8dcc8;
  --selection-text:#2d2c28;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
}

::selection { background: var(--selection-bg); color: var(--selection-text); }

/* ---- Typography ---- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  scroll-margin-top: 2rem;
}

h1 { font-size: 2.2rem; font-weight: 300; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; font-weight: 400; margin-top: 2.5rem; margin-bottom: 1rem; }
h3 { font-size: 1.2rem; font-weight: 500; margin-top: 2rem; margin-bottom: 0.75rem; }
h4 { font-size: 1.05rem; font-weight: 600; margin-top: 1.5rem; margin-bottom: 0.5rem; }

p { margin-bottom: 1rem; }

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

/* Document-style underline for article links */
.article-body a:not(.headerlink):not(.tag) {
  text-decoration: underline;
  text-decoration-color: var(--accent-dim);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.article-body a:not(.headerlink):not(.tag):hover {
  text-decoration-color: var(--accent);
}

blockquote {
  margin: 1.5rem 0;
  padding: 0.5rem 1.25rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-surface);
  font-style: italic;
  color: var(--text-muted);
}
blockquote p:last-child { margin-bottom: 0; }

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: var(--radius);
}

pre {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--bg-code);
  padding: 1.25rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1.5rem 0;
  line-height: 1.6;
  border: 1px solid var(--border);
}
pre code { background: none; padding: 0; font-size: inherit; }

hr {
  border: none;
  height: 1px;
  background: var(--rule);
  margin: 2.5rem 0;
}

/* ---- Focus & Keyboard ---- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  z-index: 1000;
  font-size: 0.9rem;
  border-radius: var(--radius);
}
.skip-link:focus { top: 0.5rem; }

/* ---- Layout ---- */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 1.5rem; }
.container-wide { max-width: var(--max-width-wide); }

/* ---- Header ---- */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
  backdrop-filter: blur(8px);
  transition: background var(--transition), border var(--transition);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.site-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.site-title:hover { color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }

/* Theme Toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition);
  line-height: 1;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Home Page ---- */
.hero { padding: 4rem 0 3rem; text-align: center; }

.hero-avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.5rem;
  font-size: 2rem;
  color: var(--text-muted);
  overflow: hidden;
}

.hero-name { font-size: 2.4rem; font-weight: 300; letter-spacing: -0.03em; margin-bottom: 0.5rem; }
.hero-slogan { font-size: 1.1rem; color: var(--text-muted); font-style: italic; margin-bottom: 2rem; }
.hero-rule { width: 60px; height: 2px; background: var(--accent); margin: 0 auto; }

/* Section label */
.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-weight: 500;
}

/* Post list */
.post-list { list-style: none; margin-bottom: 3rem; }
.post-item {
  border-bottom: 1px solid var(--border-light);
  padding: 1rem 0;
  transition: border var(--transition);
}
.post-item:first-child { border-top: 1px solid var(--border-light); }
.post-item:hover { border-color: var(--accent-dim); }
.post-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  text-decoration: none;
  color: var(--text);
  font-size: 1.05rem;
}
.post-link:hover { color: var(--accent); }
.post-title-text { font-weight: 500; }
.post-date {
  font-size: 0.8rem;
  color: var(--text-faint);
  white-space: nowrap;
  font-family: var(--font-mono);
  font-weight: 400;
}

/* Link grid */
.link-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 4rem; }
.link-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: all var(--transition);
}
.link-item:hover { color: var(--accent); border-color: var(--accent); }
.link-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.7; }
.link-item:hover .link-icon { opacity: 1; }

/* ---- Article Layout ---- */
.article-wrapper {
  display: grid;
  grid-template-columns: var(--toc-width) 1fr;
  gap: 2rem;
  max-width: var(--max-width-wide);
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  align-items: start;
}

/* ---- Table of Contents ---- */
.toc-sidebar {
  position: sticky;
  top: 5rem;
  max-height: calc(100vh - 7rem);
  overflow-y: auto;
  font-size: 0.85rem;
  padding-right: 1rem;
  border-right: 1px solid var(--border);
  transition: border var(--transition);
}

.toc-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
  font-weight: 500;
}

/* Hexo toc() output styles */
.toc-list { list-style: none; }
.toc-list .toc-list-item { margin-bottom: 0.3rem; }
.toc-list .toc-list-link {
  display: block;
  padding: 0.2rem 0;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  padding-left: 0.75rem;
  transition: all var(--transition);
  line-height: 1.4;
}
.toc-list .toc-list-link:hover,
.toc-list .toc-list-link:focus {
  color: var(--accent);
  border-left-color: var(--accent-dim);
}
.toc-list .toc-list-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* Nested TOC — collapsed by default, expand on hover/focus */
.toc-list .toc-list-child {
  list-style: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms ease;
}
.toc-sidebar:hover .toc-list-child,
.toc-sidebar:focus-within .toc-list-child {
  max-height: 500px;
}
.toc-list .toc-list-child .toc-list-link { padding-left: 1.75rem; font-size: 0.8rem; }

/* Mobile TOC toggle */
.toc-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-family: var(--font-serif);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  transition: all var(--transition);
}
.toc-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Article Content ---- */
.article-main { min-width: 0; }
.article-header { margin-bottom: 2rem; }
.article-title {
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
  line-height: 1.2;
}
.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}
.article-meta time { font-family: var(--font-mono); font-size: 0.8rem; }

/* Tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.5rem; }
.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  padding: 0.15em 0.55em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  transition: all var(--transition);
  letter-spacing: 0.02em;
}
.tag:hover { color: var(--accent); border-color: var(--accent); }

/* Article body */
.article-body { font-size: 1rem; line-height: 1.8; }
.article-body h2 { padding-bottom: 0.4rem; border-bottom: 1px solid var(--rule); }

/* Heading anchor links (Hexo headerlink) */
.headerlink {
  opacity: 0;
  font-size: 0.85em;
  color: var(--text-faint);
  margin-left: 0.3em;
  transition: opacity var(--transition);
  text-decoration: none;
  font-weight: 400;
}
.headerlink::after { content: "#"; }
h2:hover .headerlink,
h3:hover .headerlink,
h4:hover .headerlink,
.headerlink:focus { opacity: 1; }
.headerlink:hover { color: var(--accent); }

/* ---- Post Navigation ---- */
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.post-nav-link {
  display: block;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: all var(--transition);
}
.post-nav-link:hover { border-color: var(--accent); }
.post-nav-direction {
  display: block;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 0.2rem;
}
.post-nav-label {
  display: block;
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.post-nav-link:hover .post-nav-label { color: var(--accent); }
.post-nav-next { text-align: right; }

/* ---- Article Actions ---- */
.article-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  justify-content: center;
}
.article-action-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.article-action-link:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Back to Top ---- */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all var(--transition);
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.back-to-top.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.back-to-top:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Footer ---- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-faint);
}
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--accent); }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .article-wrapper { grid-template-columns: 180px 1fr; gap: 1.5rem; }
  :root { --toc-width: 180px; }
}

@media (max-width: 768px) {
  html { font-size: 17px; }
  .article-wrapper { grid-template-columns: 1fr; max-width: var(--max-width); }
  .toc-sidebar {
    position: static; max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0; padding-bottom: 0.75rem;
    margin-bottom: 1.5rem;
  }
  .toc-toggle { display: inline-block; }
  .toc-content { max-height: 0; overflow: hidden; transition: max-height 300ms ease; }
  .toc-content.open { max-height: 600px; }
  .toc-content .toc-list-child { max-height: none; }
  .hero { padding: 3rem 0 2rem; }
  .hero-name { font-size: 1.8rem; }
  .hero-slogan { font-size: 1rem; }
  .post-nav { grid-template-columns: 1fr; }
  .back-to-top { bottom: 1.5rem; right: 1rem; width: 36px; height: 36px; font-size: 1rem; }
  .site-header { padding: 0.75rem 0; }
}

@media (max-width: 480px) {
  html { font-size: 16px; }
  .container, .header-inner, .article-wrapper { padding-left: 1rem; padding-right: 1rem; }
  .hero-name { font-size: 1.6rem; }
  .article-title { font-size: 1.5rem; }
  h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; }
  .post-link { flex-direction: column; gap: 0.2rem; }
  .link-grid { gap: 0.5rem; }
  .link-item { font-size: 0.8rem; padding: 0.3rem 0.7rem; }
}

@media (min-width: 1400px) {
  :root { --max-width: 760px; --max-width-wide: 1040px; --toc-width: 240px; }
  html { font-size: 19px; }
}

@media print {
  .toc-sidebar, .back-to-top, .theme-toggle, .site-header,
  .post-nav, .article-actions, .site-footer { display: none; }
  body { font-size: 12pt; color: #000; background: #fff; }
  .article-wrapper { display: block; max-width: 100%; padding: 0; }
  a { color: #000; text-decoration: underline; }
}

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