:root {
  color-scheme: light;
  --background: #ffffff;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-subtle: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e2e8f0;
  --link: #2563eb;
  --link-hover: #1d4ed8;
  --code: #f1f5f9;
  --quote: #f8fafc;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  --header-height: 64px;
}

:root.dark {
  color-scheme: dark;
  --background: #111111;
  --surface: rgba(17, 17, 17, 0.86);
  --surface-subtle: #171717;
  --text: #f1f5f9;
  --muted: #a3a3a3;
  --faint: #737373;
  --border: #292929;
  --link: #3b82f6;
  --link-hover: #60a5fa;
  --code: #1f1f1f;
  --quote: #171717;
  --shadow: none;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 24px);
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--background);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  transition: background-color 160ms ease, color 160ms ease;
}

a { color: var(--link); text-underline-offset: 3px; }
a:hover { color: var(--link-hover); }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
}

.nav {
  width: min(100%, 80rem);
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.brand:hover { color: var(--text); }
.brand img { width: 32px; height: 32px; object-fit: cover; }
.brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-links { display: flex; align-items: center; gap: 24px; }
.nav-links a { color: var(--muted); font-size: 14px; text-decoration: none; }
.nav-links a:hover { color: var(--text); }

.layout {
  width: min(100%, 80rem);
  min-height: calc(100vh - var(--header-height) - 138px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 16rem) minmax(0, 48rem) minmax(0, 16rem);
  flex: 1;
}

.page { min-width: 0; padding: 0 48px 64px; }
.page main { min-width: 0; padding-top: 16px; }

.page-title {
  margin: 8px 0 0;
  color: var(--text);
  font-size: clamp(2rem, 4vw, 2.25rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
}

.page-title.centered { text-align: center; }

.post-list { margin-top: 24px; }
.post-card { margin: 0 0 42px; }
.post-card h2 { margin: 0; font-size: 24px; line-height: 1.35; letter-spacing: -0.015em; }
.post-card h2 a { display: block; color: var(--text); text-decoration: none; }
.post-card h2 a:hover { color: var(--link); }
.post-card p { margin: 18px 0 0; color: var(--muted); line-height: 1.75; }
.post-card .read-more { color: var(--link); text-decoration: underline; }
.post-card time { display: block; margin-top: 18px; color: var(--faint); font-size: 14px; }

.breadcrumb {
  margin: 8px 0 24px;
  display: flex;
  gap: 8px;
  align-items: center;
  overflow: hidden;
  color: var(--faint);
  font-size: 14px;
  white-space: nowrap;
}

.breadcrumb a { flex: none; text-decoration: none; }
.breadcrumb span:last-child { overflow: hidden; text-overflow: ellipsis; }
.published { display: block; margin-top: 16px; color: var(--faint); font-size: 14px; }

.tags { margin: 14px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; list-style: none; }
.tags li { padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 12px; }

.content { margin-top: 36px; color: var(--text); line-height: 1.75; overflow-wrap: anywhere; }
.content > :first-child { margin-top: 0; }
.content p { margin: 20px 0; }
.content h2, .content h3, .content h4 { position: relative; color: var(--text); letter-spacing: -0.02em; }
.content h2 { margin: 44px 0 16px; padding-bottom: 4px; font-size: 30px; line-height: 1.25; }
.content h3 { margin: 34px 0 14px; font-size: 24px; line-height: 1.35; }
.content h4 { margin: 28px 0 12px; font-size: 20px; }
.heading-anchor { margin-left: 8px; color: var(--faint); font-weight: 400; text-decoration: none; opacity: 0; }
.content h2:hover .heading-anchor, .content h3:hover .heading-anchor, .heading-anchor:focus { opacity: 1; }
.content strong { color: var(--text); font-weight: 650; }
.content hr { height: 1px; margin: 40px 0; border: 0; background: var(--border); }
.content blockquote { margin: 24px 0; padding: 2px 20px; border-left: 4px solid var(--border); background: var(--quote); color: var(--muted); }
.content blockquote p { margin: 12px 0; }
.content ul, .content ol { margin: 20px 0; padding-left: 28px; }
.content li { margin: 8px 0; padding-left: 4px; }
.content code { padding: 2px 5px; border-radius: 5px; background: var(--code); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875em; }
.content pre { overflow-x: auto; padding: 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--code); }
.content pre code { padding: 0; background: transparent; }
.content img { max-width: 100%; height: auto; }
.content iframe { max-width: 100%; background: var(--surface-subtle); }

.table-wrap { width: 100%; margin: 24px 0; overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { min-width: 140px; padding: 12px 14px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-subtle); }
tr:last-child td { border-bottom: 0; }
th:last-child, td:last-child { border-right: 0; }

.about-content { text-align: center; }
.about-content img { display: block; max-width: 240px; margin: 0 auto 32px; border-radius: 12px; }
.photos-content iframe { width: 100%; min-height: 75vh; border: 0; border-radius: 8px; }

.toc { min-width: 0; padding: 32px 20px 40px; }
.toc nav { position: sticky; top: calc(var(--header-height) + 28px); max-height: calc(100vh - var(--header-height) - 96px); overflow-y: auto; }
.toc p { margin: 0 0 14px; color: var(--text); font-size: 14px; font-weight: 600; }
.toc ul { margin: 0; padding: 0; list-style: none; }
.toc li { margin: 9px 0; line-height: 1.35; }
.toc li.toc-level-3 { padding-left: 12px; }
.toc a { display: block; color: var(--muted); font-size: 13px; text-decoration: none; }
.toc a:hover, .toc a.active { color: var(--link); }
.to-top { display: none; }

.post-pager { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.post-pager a { color: var(--text); text-decoration: none; }
.post-pager a:hover { color: var(--link); }
.post-pager a span { display: block; margin-bottom: 5px; color: var(--faint); font-size: 12px; }
.post-pager .newer { text-align: right; }

.site-footer { border-top: 1px solid var(--border); background: var(--surface-subtle); }
.footer-inner { width: min(100%, 80rem); margin: 0 auto; padding: 16px 24px 24px; }
.theme-toggle { display: inline-flex; align-items: center; gap: 7px; padding: 6px 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; }
.theme-toggle:hover { color: var(--text); }
.footer-inner hr { margin: 10px 0 20px; border: 0; border-top: 1px solid var(--border); }
.footer-inner p { margin: 0; color: var(--faint); font-size: 13px; }

.not-found { padding: 80px 0; text-align: center; }
.not-found .error-code { margin: 0; color: var(--link); font-size: 64px; font-weight: 800; }
.not-found h1 { margin: 8px 0; }
.not-found p { color: var(--muted); }
.button { display: inline-block; margin-top: 18px; padding: 10px 16px; border-radius: 8px; background: var(--text); color: var(--background); text-decoration: none; }
.button:hover { color: var(--background); opacity: 0.88; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 48rem) minmax(0, 1fr); }
  .left-rail { display: none; }
  .page { grid-column: 2; }
  .toc { display: none; }
}

@media (max-width: 800px) {
  :root { --header-height: 60px; }
  .nav { padding: 0 20px; }
  .nav-links { gap: 18px; }
  .layout { display: block; width: 100%; }
  .page { padding: 0 24px 56px; }
  .page main { padding-top: 18px; }
  .page-title { font-size: 30px; }
  .post-card h2 { font-size: 21px; }
  .content h2 { font-size: 26px; }
  .content h3 { font-size: 21px; }
}

@media (max-width: 480px) {
  .brand strong { max-width: 170px; }
  .nav-links { gap: 14px; }
  .page { padding-inline: 20px; }
  .post-pager { grid-template-columns: 1fr; }
  .post-pager .newer { text-align: left; }
}

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