:root {
  --bg: #F5EFE0;
  --text: #2A2724;
  --heading: #2A2724;
  --muted: #8A857E;
  --hairline: #E8DFC9;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1A1816;
    --text: #D8D2C7;
    --heading: #E8E2D6;
    --muted: #8A857E;
    --hairline: #2D2A26;
  }
}

[data-theme="dark"] {
  --bg: #1A1816;
  --text: #D8D2C7;
  --heading: #E8E2D6;
  --muted: #8A857E;
  --hairline: #2D2A26;
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}

body {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 17px;
  line-height: 1.75;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: inherit; }

/* === Header === */
.post-header,
.blog-header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg);
  z-index: 10;
}

.back-link {
  text-decoration: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 8px;
  transition: color 0.2s ease;
}

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

.theme-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 8px 10px;
  line-height: 1;
  transition: color 0.2s ease;
}

.theme-toggle:hover { color: var(--text); }

.blog-mark {
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.blog-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.blog-back {
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  opacity: 0.7;
  white-space: nowrap;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.blog-back:hover {
  opacity: 1;
  color: var(--text);
}

/* === Main column === */
.post-main, .blog-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 24px 96px;
}

/* === Post page === */
.post-title {
  font-size: 28px;
  font-weight: 500;
  text-align: center;
  margin: 32px 0 12px;
  color: var(--heading);
  line-height: 1.25;
}

.post-metadata {
  text-align: center;
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 48px;
}

.post-body p { margin: 0 0 1.4em; }
.post-body h2 {
  font-size: 22px;
  font-weight: 500;
  margin: 2em 0 0.5em;
  color: var(--heading);
}
.post-body h3 {
  font-size: 18px;
  font-weight: 500;
  margin: 1.6em 0 0.4em;
  color: var(--heading);
}
.post-body blockquote {
  border-left: 2px solid var(--hairline);
  padding-left: 1em;
  margin: 1.4em 0;
  color: var(--muted);
  font-style: italic;
}
.post-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--hairline);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.post-body pre {
  background: var(--hairline);
  padding: 1em 1.2em;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.5;
  margin: 1.4em 0;
}
.post-body pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.post-body a { text-decoration: underline; }
.post-body a:hover { color: var(--muted); }
.post-body hr {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 2em 0;
}
.post-body ul, .post-body ol {
  margin: 0 0 1.4em;
  padding-left: 1.4em;
}
.post-body li { margin-bottom: 0.4em; }
.post-body img { max-width: 100%; height: auto; }

/* === End-of-post === */
.hairline {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 64px 0 24px;
}

.end-marker {
  text-align: center;
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 48px;
}

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  border-top: 1px solid var(--hairline);
  padding-top: 24px;
}

.post-nav-cell { min-width: 0; }
.post-nav-right { text-align: right; }

.post-nav-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 4px;
}

.post-nav-label.post-nav-end {
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
}

.post-nav-link {
  text-decoration: none;
  font-size: 16px;
  color: var(--text);
  transition: color 0.2s ease;
  display: inline-block;
}

.post-nav-link:hover { color: var(--muted); }

/* === Floating TOC === */
.toc-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--hairline);
  font-family: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.toc-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.toc-panel {
  position: fixed;
  bottom: 70px;
  right: 24px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 16px 20px;
  width: 280px;
  max-width: calc(100vw - 48px);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

.toc-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 12px;
}

.toc-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-panel li {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.4;
}

.toc-panel li.toc-l3 {
  padding-left: 14px;
  font-size: 13px;
  color: var(--muted);
}

.toc-panel a {
  color: inherit;
  text-decoration: none;
}

.toc-panel a:hover {
  color: var(--text);
  text-decoration: underline;
}

/* === Index (bookshelf) === */
.year { margin-bottom: 48px; }

.year-label {
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 16px;
}

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry-item {
  border-bottom: 1px solid var(--hairline);
}

.entry-item:last-child { border-bottom: none; }

.entry-link {
  display: block;
  padding: 16px 0;
  text-decoration: none;
  color: var(--text);
  transition: color 0.2s ease;
}

.entry-link:hover { color: var(--muted); }

.entry-title {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 4px;
  color: var(--text);
}

.entry-meta {
  font-size: 11px;
  font-style: italic;
  color: var(--muted);
}

.empty-note {
  text-align: center;
  font-style: italic;
  color: var(--muted);
  margin-top: 64px;
}

/* === Mobile === */
@media (max-width: 600px) {
  .post-main, .blog-main { padding: 16px 20px 96px; }
  .post-header, .blog-header { padding: 12px 16px; }
  .post-title { font-size: 24px; }
  .post-nav { grid-template-columns: 1fr; gap: 20px; }
  .post-nav-right { text-align: left; }
  .toc-btn { bottom: 16px; right: 16px; }
  .toc-panel { bottom: 60px; right: 16px; }
}
