*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --border: #e8e6e1;
  --border-hover: #c8c4bc;
  --text-primary: #1a1a18;
  --text-secondary: #6b6860;
  --text-muted: #9e9b94;
  --tag-bg: #f0ede8;
  --tag-text: #4a4843;
  --accent-bg: #f0faf9;
  --accent-border: #a7e8e3;
  --accent-text: #0f7b73;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --r: 10px;
  --rs: 6px;
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'DM Mono', monospace;
  --mw: 740px;
  --px: 20px;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: clip;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: clip;
}

a { color: inherit; text-decoration: none; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: var(--mw);
  margin: 0 auto;
  padding: 0 var(--px);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: .95rem;
  letter-spacing: -.02em;
  flex-shrink: 0;
  overflow: hidden;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: var(--text-primary);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.brand-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.nav-link {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: var(--rs);
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--tag-bg);
  color: var(--text-primary);
}

.nav-link.active {
  color: var(--text-primary);
  font-weight: 600;
}

.btn-post {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 14px;
  background: var(--text-primary);
  color: var(--bg);
  border: none;
  border-radius: 20px;
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s;
}

.btn-post:hover { background: #333; }
.btn-post .btn-long { display: inline; }
.btn-post .btn-short { display: none; }

.wrap {
  max-width: var(--mw);
  margin: 0 auto;
  padding: 0 var(--px);
}

.breadcrumbs-wrap { padding-top: 12px; }

.breadcrumbs {
  font-size: .8rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

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

.breadcrumbs a:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 5px 0;
  margin-top: 10px;
  transition: color .15s;
}

.back-link:hover { color: var(--text-primary); }

.article-wrap {
  padding-top: 16px;
  padding-bottom: 36px;
}

.article-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.article-head {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.article-category {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent-text);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 12px;
}

.article-title {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.12;
  margin: 0 0 12px;
  color: var(--text-primary) !important;
  opacity: 1 !important;
  text-align: left;
  text-wrap: balance;
}

.article-head h1,
.article-head .article-title {
  color: var(--text-primary) !important;
  opacity: 1 !important;
}

.article-excerpt {
  font-size: .96rem;
  color: var(--text-secondary);
  line-height: 1.68;
  margin-bottom: 14px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: .76rem;
  font-weight: 500;
}

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 12px;
}

.tag-sm {
  height: 22px;
  padding: 0 8px;
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .72rem;
  color: var(--tag-text);
  display: inline-flex;
  align-items: center;
}

.toc-box {
  margin-top: 16px;
  background: #fcfbf9;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
}

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.toc-title {
  font-size: .86rem;
  font-weight: 600;
  color: var(--text-primary);
}

.toc-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  height: 28px;
  padding: 0 10px;
  font-family: var(--font);
  font-size: .74rem;
  font-weight: 500;
  cursor: pointer;
}

.toc-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 230px;
  overflow: hidden;
  transition: max-height .2s ease;
}

.toc-list.expanded {
  max-height: 1200px;
}

.toc-list a {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: .84rem;
  line-height: 1.45;
  color: var(--text-secondary);
  background: transparent;
  text-align: left;
  word-break: break-word;
}

.toc-list a:hover {
  background: var(--tag-bg);
  color: var(--text-primary);
}

.toc-list a.toc-h3 {
  padding-left: 22px;
  font-size: .79rem;
  color: var(--text-muted);
}

.toc-empty {
  font-size: .78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.article-body {
  padding: 20px;
}

.article-content > *:first-child { margin-top: 0 !important; }
.article-content > *:last-child { margin-bottom: 0 !important; }

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
  color: var(--text-primary);
  line-height: 1.22;
  scroll-margin-top: 86px;
  letter-spacing: -.03em;
}

.article-content h2 {
  font-size: 1.45rem;
  font-weight: 600;
  margin: 28px 0 12px;
}

.article-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 22px 0 10px;
}

.article-content h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 18px 0 8px;
}

.article-content p {
  font-size: .96rem;
  line-height: 1.78;
  color: var(--text-secondary);
  margin: 12px 0;
}

.article-content ul,
.article-content ol {
  margin: 14px 0;
  padding-left: 20px;
  color: var(--text-secondary);
}

.article-content li {
  margin: 7px 0;
  font-size: .95rem;
  line-height: 1.72;
}

.article-content a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.article-content strong { color: var(--text-primary); }

.article-content blockquote {
  margin: 18px 0;
  padding: 14px 16px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: var(--r);
  color: var(--text-secondary);
}

.article-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.article-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 20px auto;
  border-radius: var(--r);
}

.article-content figure { margin: 20px 0; }

.article-content figcaption {
  font-size: .76rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 7px;
}

.article-content code {
  font-family: var(--mono);
  font-size: .86em;
  background: #f4f1ec;
  color: #2d2a26;
  padding: 2px 6px;
  border-radius: 5px;
}

.article-content pre {
  background: #1f1f1d;
  color: #f7f6f3;
  border-radius: var(--r);
  padding: 14px;
  overflow-x: auto;
  margin: 18px 0;
}

.article-content pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 22px 0;
  display: block;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
}

.article-content th,
.article-content td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  min-width: 140px;
  font-size: .84rem;
  color: var(--text-secondary);
  background: var(--surface);
}

.article-content th {
  background: #fbf9f6;
  color: var(--text-primary);
  font-weight: 600;
}

.article-content iframe {
  width: 100%;
  max-width: 100%;
  border: 0;
  border-radius: var(--r);
  margin: 18px 0;
}

.article-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn-primary,
.btn-outline {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--rs);
  font-family: var(--font);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.btn-primary:hover { background: #333; }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-outline:hover { border-color: var(--border-hover); }

.related-block {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.related-title {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.related-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.related-item {
  display: block;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.related-item:first-child {
  border-top: none;
  padding-top: 0;
}

.related-item h3 {
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.42;
  margin-bottom: 5px;
  color: var(--text-primary);
}

.related-item:hover h3 { color: var(--accent-text); }

.related-meta {
  font-size: .74rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 40px;
}

.footer-inner {
  max-width: var(--mw);
  margin: 0 auto;
  padding: 16px var(--px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-links { display: flex; gap: 16px; }

.footer-links a {
  font-size: .8rem;
  color: var(--text-muted);
}

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

.footer-copy {
  font-size: .8rem;
  color: var(--text-muted);
}

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 16px;
}

.modal-bg.show { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 430px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  position: relative;
}

.modal-x {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.modal-x:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.modal-box h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 9px;
}

.modal-box p {
  font-size: .86rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 9px;
}

.modal-acts {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 14px;
  background: var(--text-primary);
  color: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .82rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 9500;
}

#readProgress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent-text);
  z-index: 9999;
  transition: width .1s linear;
}

@media (max-width: 640px) {
  :root { --px: 14px; }

  .nav-link { display: none !important; }
  .btn-post .btn-long { display: none; }
  .btn-post .btn-short { display: inline; }
  .btn-post {
    width: 28px;
    height: 28px;
    padding: 0 !important;
    font-size: 15px !important;
    border-radius: 50% !important;
  }

  .article-title { font-size: 1.4rem; }
  .article-body { padding: 16px; }
  .article-head { padding: 16px; }
  .article-content h2 { font-size: 1.22rem; }
  .article-content h3 { font-size: 1.04rem; }
  .article-actions { flex-direction: column; }
  .btn-primary, .btn-outline { width: 100%; }

  .toc-list {
    max-height: 210px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  html { scroll-behavior: auto; }
}
