:root {
  --bg: #f7f7f7;
  --surface: #ffffff;
  --text: #111111;
  --muted: #666666;
  --border: #dddddd;
  --link: #0f62fe;
  --code-bg: #f0f3f8;
  --code-block-bg: #f6f8fa;
  --code-border: #d8dee8;
  --code-text: #1f2328;
  --note-bg: #eeeeee;
  --note-border: #8a8a8a;
  --note-text: #202020;
  --note-link: #3d3d3d;
}

body[data-theme="dark"] {
  --bg: #111111;
  --surface: #1b1b1b;
  --text: #f4f4f4;
  --muted: #b5b5b5;
  --border: #333333;
  --link: #8ab4ff;
  --code-bg: #2d333d;
  --code-block-bg: #0b0f14;
  --code-border: #3f4754;
  --code-text: #e8edf2;
  --note-bg: #242424;
  --note-border: #707070;
  --note-text: #ffffff;
  --note-link: #d0d0d0;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

#home,
#blog {
  scroll-margin-top: 1rem;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: var(--link);
}

.page {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

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

.brand {
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.brand-mark {
  width: 1.8rem;
  height: 1.8rem;
  display: block;
  object-fit: contain;
  border-radius: 0.5rem;
  flex: 0 0 auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav {
  display: flex;
  gap: 0.75rem;
}

.tab-button,
.nav-link {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.tab-button.is-current,
.nav-link.is-current {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.toggle-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

main {
  display: grid;
  gap: 1rem;
  width: 100%;
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  min-width: 0;
}

[data-route-section][hidden] {
  display: none;
}

h1,
h2,
h3,
h4,
p,
ul {
  margin-top: 0;
}

h1 {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

h3,
h4 {
  margin-bottom: 0.75rem;
}

p,
li {
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.intro,
.status-message {
  color: var(--muted);
}

.home-section-title {
  margin-top: 2rem;
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
}

.social-links a {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.social-links a:hover,
.social-links a:focus-visible {
  border-color: var(--link);
  color: var(--link);
  background: rgba(127, 127, 127, 0.06);
}

.post-list {
  display: grid;
  gap: 1rem;
}

.tab-panel[hidden] {
  display: none;
}

.preview-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(127, 127, 127, 0.04);
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.preview-card:hover {
  border-color: var(--link);
  transform: translateY(-2px);
}

.preview-link {
  display: block;
  padding: 1rem;
  text-decoration: none;
  color: inherit;
}

.preview-line {
  margin-bottom: 0.45rem;
}

.preview-line:last-child {
  margin-bottom: 0;
}

.preview-date {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.back-link {
  text-decoration: none;
}

.post-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 15rem;
  gap: 2rem;
  padding-bottom: 1.5rem;
  overflow: visible;
}

.post-article {
  min-width: 0;
}

.post-toc {
  align-self: start;
  border-left: 1px solid var(--border);
  color: var(--muted);
  grid-column: 2;
  grid-row: 1;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding-left: 1rem;
  position: sticky;
  top: 1rem;
}

.post-toc[hidden] {
  display: none;
}

.post-toc h2 {
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 0.65rem;
}

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

.post-toc li {
  line-height: 1.3;
}

.post-toc a {
  border-radius: 6px;
  color: inherit;
  display: block;
  padding: 0.35rem 0.45rem;
  text-decoration: none;
}

.post-toc a:hover,
.post-toc a:focus-visible,
.post-toc a.is-active {
  background: rgba(127, 127, 127, 0.08);
  color: var(--link);
}

.toc-level-h3 {
  padding-left: 0.8rem;
  font-size: 0.92rem;
}

.post-title {
  margin-bottom: 0.5rem;
}

.post-meta {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.post-back {
  margin-bottom: 2rem;
}

.post-content > *:last-child {
  margin-bottom: 0;
}

.post-content {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.post-content h2,
.post-content h3 {
  scroll-margin-top: 1rem;
}

.post-content ul {
  padding-left: 1.25rem;
}

.post-content blockquote {
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-left-width: 5px;
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(127, 127, 127, 0.12), 0 0.75rem 1.75rem rgba(0, 0, 0, 0.12);
  color: var(--note-text);
  margin: 1.25rem 0;
  padding: 1rem 1.1rem 1rem 1.2rem;
}

.post-content blockquote p,
.post-content blockquote li {
  color: inherit;
}

.post-content blockquote a {
  color: var(--note-link);
  font-weight: 600;
}

.post-content blockquote > *:last-child {
  margin-bottom: 0;
}

.post-content blockquote code {
  background: rgba(127, 127, 127, 0.18);
  color: inherit;
}

.post-content img,
.post-content video,
.post-content iframe,
.post-content table,
.post-content .highlight,
.post-content pre {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.post-content .highlight,
.post-content pre {
  background: var(--code-block-bg);
  border: 1px solid var(--code-border);
  border-radius: 0;
  color: var(--code-text);
  margin: 1rem 0;
  padding: 1rem;
}

.post-content .code-frame {
  background: var(--code-block-bg);
  border: 1px solid var(--code-border);
  border-radius: 0;
  color: var(--code-text);
  margin: 1rem 0;
  max-width: 100%;
  overflow: hidden !important;
  padding: 0;
  position: relative;
}

.post-content .code-frame.highlight {
  overflow: hidden !important;
  padding: 0;
}

.code-toolbar {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.5rem 0.5rem 0;
}

.code-button {
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.2;
  padding: 0.35rem 0.55rem;
}

.code-button:hover,
.code-button:focus-visible {
  border-color: var(--link);
  color: var(--link);
}

.post-content .code-scroll {
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
}

.post-content .code-frame pre {
  border: 0;
  border-radius: 0;
  display: block;
  margin: 0;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
  padding: 0.75rem 1rem 1rem;
  white-space: pre-wrap !important;
  word-break: break-word;
}

.post-content .code-frame.is-nowrap pre {
  max-width: none;
  min-width: 100%;
  white-space: pre !important;
  width: max-content;
  word-break: normal;
}

.post-content .code-frame.is-wrapped pre {
  white-space: pre-wrap !important;
  word-break: break-word;
}

.post-content .code-frame.is-nowrap .code-scroll {
  overflow-x: auto;
}

.post-content .code-frame code,
.post-content .code-frame code * {
  background: transparent;
  color: inherit;
  overflow-wrap: normal;
  padding: 0;
  white-space: inherit !important;
  word-break: normal;
}

.post-content .code-frame.is-wrapped code {
  display: block;
  max-width: 100%;
  min-width: 0;
  white-space: pre-wrap !important;
}

.post-content .code-frame.is-wrapped code,
.post-content .code-frame.is-wrapped code * {
  overflow-wrap: anywhere;
  white-space: pre-wrap !important;
  word-break: break-word;
}

.post-content .code-frame.is-nowrap code,
.post-content .code-frame.is-nowrap code * {
  overflow-wrap: normal;
  white-space: pre !important;
  word-break: normal;
}

.post-content .code-frame.is-nowrap code {
  display: inline-block;
  min-width: max-content;
}

.post-content .highlight pre {
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0;
}

.post-content .code-frame.highlight pre {
  padding: 1rem;
}

.post-content img,
.post-content video {
  height: auto;
  margin: 1rem 0;
  border-radius: 0.75rem;
}

.post-content table {
  border-collapse: collapse;
  border: 1px solid var(--border);
  margin: 1rem 0;
  width: max-content;
}

.post-content th,
.post-content td {
  border: 1px solid var(--border);
  line-height: 1.5;
  padding: 0.6rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.post-content th {
  background: rgba(127, 127, 127, 0.12);
  color: var(--text);
  font-weight: 700;
}

.post-content tr:nth-child(even) td {
  background: rgba(127, 127, 127, 0.05);
}

.post-content code {
  font-family: Consolas, monospace;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

.post-content pre code,
.post-content .highlight code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.post-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1rem 0;
  border-radius: 0.75rem;
}

.not-found-page {
  display: grid;
  gap: 1rem;
  justify-items: center;
  min-height: min(64vh, 38rem);
  place-content: center;
  text-align: center;
}

.not-found-copy {
  max-width: 36rem;
}

.not-found-gif {
  display: block;
  max-width: min(100%, 34rem);
  height: auto;
  border-radius: 8px;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer p {
  margin: 0;
}

.footer-social-links {
  justify-content: flex-end;
  margin: 0;
}

.footer-social-links a {
  color: var(--muted);
}

@media (max-width: 560px) {
  .page {
    width: min(100% - 1rem, 1100px);
    padding-top: 1rem;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: 1rem;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .nav {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  section {
    padding: 1rem;
  }

  .post-shell {
    display: block;
  }

  .post-toc {
    border-left: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    max-height: none;
    overflow: visible;
    padding: 0 0 1rem;
    position: static;
  }

  .site-footer {
    align-items: flex-end;
    flex-direction: column;
    text-align: right;
  }

}
