:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
}

body {
  margin: 0;
  font-family: inherit;
  line-height: inherit;
  background: var(--bg);
  color: var(--fg);
  color-scheme: var(--color-scheme, light);
  transition: background 0.25s ease, color 0.25s ease;
}

body,
body.theme-classic {
  --color-scheme: light;
  --bg: #f8fafc;
  --fg: #111827;
  --muted: rgba(17, 24, 39, 0.6);
  --border: rgba(15, 23, 42, 0.08);
  --card-bg: rgba(255, 255, 255, 0.78);
  --header-bg: rgba(255, 255, 255, 0.82);
  --header-fg: #111827;
  --footer-fg: rgba(17, 24, 39, 0.55);
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --accent-strong: #f97316;
  --accent-strong-soft: rgba(249, 115, 22, 0.22);
  --code-bg: rgba(15, 23, 42, 0.06);
  --shadow-color: rgba(15, 23, 42, 0.12);
}

body.theme-noir {
  --color-scheme: dark;
  --bg: #0b0d14;
  --fg: #e8eafc;
  --muted: rgba(232, 235, 252, 0.6);
  --border: rgba(129, 140, 248, 0.22);
  --card-bg: rgba(20, 24, 38, 0.82);
  --header-bg: rgba(11, 13, 20, 0.92);
  --header-fg: #f8fafc;
  --footer-fg: rgba(232, 235, 252, 0.52);
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.25);
  --accent-strong: #fb923c;
  --accent-strong-soft: rgba(251, 146, 60, 0.32);
  --code-bg: rgba(129, 140, 248, 0.16);
  --shadow-color: rgba(8, 10, 18, 0.55);
}

body.theme-sand {
  --color-scheme: light;
  --bg: #fdf8f1;
  --fg: #2f1b0f;
  --muted: rgba(47, 27, 15, 0.64);
  --border: rgba(217, 119, 6, 0.18);
  --card-bg: rgba(255, 249, 239, 0.82);
  --header-bg: rgba(255, 244, 229, 0.88);
  --header-fg: #2f1b0f;
  --footer-fg: rgba(47, 27, 15, 0.55);
  --accent: #d97706;
  --accent-soft: rgba(217, 119, 6, 0.18);
  --accent-strong: #ea580c;
  --accent-strong-soft: rgba(234, 88, 12, 0.24);
  --code-bg: rgba(217, 119, 6, 0.12);
  --shadow-color: rgba(217, 119, 6, 0.24);
}

.container {
  max-width: min(95vw, 1600px);
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

a:hover,
a:focus {
  text-decoration: underline;
}

.site-header {
  background: var(--header-bg);
  color: var(--header-fg);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 0;
  backdrop-filter: blur(8px);
}

.site-header .container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}

.site-title {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: inherit;
}

.site-tagline {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.header-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: inherit;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.theme-toggle:hover,
.theme-toggle:focus {
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.theme-toggle .toggle-icon {
  font-size: 1rem;
}

.rss-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: inherit;
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s ease, transform 0.2s ease;
}

.rss-link:hover,
.rss-link:focus {
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.rss-icon {
  width: 1rem;
  height: 1rem;
}

.newsletter-block {
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  margin: 2rem 0 1rem;
  display: flex;
  justify-content: center;
  background: transparent;
}

.newsletter-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.newsletter-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.newsletter-input {
  border: none;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.9);
  min-width: 200px;
  border: 1px solid var(--border);
}

.newsletter-button {
  border: 1px solid var(--accent-strong);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  background: var(--accent-strong);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.newsletter-button:hover,
.newsletter-button:focus {
  opacity: 0.85;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.post-list {
  list-style: none;
  margin: 1.5rem 0;
  padding: 0;
}

.post-list-item {
  display: flex;
  align-items: center;
  gap: 1.75rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border);
}

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

.post-date {
  font-size: 0.9rem;
  color: var(--muted);
  flex: 0 0 8.5rem;
  min-width: 8.5rem;
  text-align: right;
  letter-spacing: 0.01em;
}

.post-link {
  color: inherit;
  text-decoration: none;
  font-size: 1.05rem;
}

.post-link:hover,
.post-link:focus {
  text-decoration: underline;
  color: var(--accent);
}

.post-info {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.post-excerpt {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.post-read {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.post-read::after {
  content: "→";
  font-size: 0.9rem;
  transition: transform 0.2s ease;
}

.post-read:hover::after,
.post-read:focus::after {
  transform: translateX(2px);
}

.post {
  margin: 1.8rem 0;
}


.post-layout {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr) minmax(200px, 280px);
  align-items: start;
  gap: 2rem;
  margin-top: 1.6rem;
}

.post-layout .post {
  max-width: none;
  min-width: 0;
}

.post-toc {
  position: sticky;
  top: 5.5rem;
  align-self: flex-start;
  padding: 0 0 0 1rem;
  margin-top: 1rem;
  border-left: 1px solid var(--border);
  background: none;
  border-radius: 0;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  box-shadow: none;
}

.post-references {
  position: sticky;
  top: 5.5rem;
  align-self: flex-start;
  padding: 0;
  margin-top: 1.5rem;
  border-left: none;
  background: none;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}

.post-toc,
.post-references {
  max-width: 100%;
}

.toc-title {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.toc-item a {
  color: inherit;
  text-decoration: none;
  font-size: 0.8rem;
  line-height: 1.4;
  word-break: break-word;
}

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

.toc-item.level-3 {
  padding-left: 1rem;
  font-size: 0.75rem;
}

.toc-item.level-4 {
  padding-left: 1.5rem;
  font-size: 0.7rem;
}

.references-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.references-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.reference-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: flex-start;
}

.post-references.is-floating .references-list {
  position: relative;
  display: block;
  height: var(--reference-area-height, auto);
}

.post-references.is-floating .reference-item {
  position: absolute;
  left: 0;
  right: 0;
  transform: translateY(0);
  transition: transform 0.12s ease-out;
}

.reference-number {
  font-weight: 700;
  color: var(--accent-strong);
  font-size: 0.75rem;
}

.reference-body {
  font-size: 0.85rem;
  word-break: break-word;
}

.reference-back {
  font-size: 0.8rem;
  color: var(--accent-strong);
  text-decoration: none;
  margin-top: 0.1rem;
}

.reference-back:hover,
.reference-back:focus {
  color: var(--accent-strong);
  text-decoration: underline;
}

.footnote-ref {
  font-size: 0.75rem;
  vertical-align: super;
  line-height: 1;
  margin-left: 0.15rem;
}

.footnote-ref a {
  color: var(--accent-strong);
  text-decoration: none;
}

.footnote-ref a:hover,
.footnote-ref a:focus {
  text-decoration: underline;
}

.post h1,
.post h2,
.post h3,
.post h4,
.post h5,
.post h6 {
  color: inherit;
  margin: 1.8rem 0 0.85rem;
  line-height: 1.3;
}

.post h1 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 2.2rem;
}

.post h2 {
  font-size: 1.6rem;
}

.post h3 {
  font-size: 1.3rem;
}

.post p {
  margin: 1rem 0;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.6rem 0 1.6rem;
}

.post-tag,
.post-tag:link,
.post-tag:visited,
.post-tag:hover,
.post-tag:focus,
.post-tag:active {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--accent-strong-soft);
  color: var(--accent-strong);
  border: 1px solid rgba(0, 0, 0, 0.08);
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.post-tag:hover,
.post-tag:focus {
  background: var(--accent-strong);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  transform: translateY(-1px);
}

.tag-hero {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 1.8rem 0 1.2rem;
}

.tag-chip {
  align-self: flex-start;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
}

.tag-title {
  margin: 0;
  font-size: 2.1rem;
}

.tag-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

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

.post .post-tags .post-tag,
.post .post-tags .post-tag:link,
.post .post-tags .post-tag:visited,
.post .post-tags .post-tag:hover,
.post .post-tags .post-tag:focus,
.post .post-tags .post-tag:active {
  text-decoration: none;
}

.post img {
  max-width: 100%;
  display: block;
  margin: 2rem auto;
  border-radius: 12px;
  box-shadow: 0 16px 36px var(--shadow-color);
}

.post table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.post th,
.post td {
  border: 1px solid var(--border);
  padding: 0.65rem 0.75rem;
  text-align: left;
}

.post th {
  background: var(--accent-soft);
  font-weight: 600;
}

.post blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 1rem;
  margin: 1.8rem 0;
  color: var(--muted);
  font-style: italic;
  background: var(--accent-soft);
  border-radius: 6px;
}

.post ol {
  padding-left: 1.3rem;
  margin: 1.2rem 0;
}

.post ul {
  padding-left: 1.2rem;
  margin: 1.2rem 0;
}

.post .task-list {
  list-style: none;
  padding-left: 0;
  margin: 1.3rem 0;
}

.post .task-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.35rem 0;
}

.post .task-item input[type="checkbox"] {
  accent-color: var(--accent);
}

.post .task-item label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: inherit;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1rem 1.2rem;
  overflow-x: auto;
  border-radius: 10px;
  font-size: 0.95rem;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  background: var(--code-bg);
  padding: 0.15rem 0.35rem;
  border-radius: 5px;
}

::selection {
  background: var(--accent);
  color: #fff;
}

@media (min-width: 640px) {
  .site-header .container {
    align-items: center;
    justify-content: space-between;
  }

  .site-tagline {
    order: 3;
    width: 100%;
    font-size: 0.9rem;
  }
}

@media (max-width: 1280px) {
  .post-layout {
    grid-template-columns: minmax(150px, 200px) minmax(0, 1fr) minmax(170px, 230px);
    gap: 1.5rem;
  }
}

@media (max-width: 1024px) {
  .post-layout {
    display: block;
    gap: 2rem;
  }

  .post-toc,
  .post-references {
    position: static;
    width: 100%;
    max-height: none;
    margin-top: 0;
  }

  .post-toc {
    margin-bottom: 0.75rem;
  }
}
