/* Core variables and typography */
:root {
  --bg: #f7f5f2;
  --text: #1a1a1a;
  --text-secondary: #5d5d5d;
  --accent: #1a1a1a;
  --border: rgba(0, 0, 0, 0.12);
  --highlight: rgba(0, 0, 0, 0.08);
  --radius-pill: 999px;
  --max-width: 44rem;
  --sidebar-width: 14rem;
  --space-x: min(7.25vw, 3.7rem);
  --space-y: 2.25rem;
  font-size: 16px;
}

html.dark {
  --bg: #0f1115;
  --text: #f2f2f2;
  --text-secondary: #b2b2b2;
  --accent: #ffffff;
  --border: rgba(255, 255, 255, 0.2);
  --highlight: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  color: var(--accent);
}

.font-title {
  font-family: "Playfair Display", "Times New Roman", serif;
}

.font-ui {
  font-family: inherit;
}

/* Layout: matches the Astro structure (sidebar + content) */
.page {
  min-height: 100vh;
  padding: var(--space-y) var(--space-x);
}

.page-inner {
  display: block;
}

.sidebar {
  display: none;
}

.content {
  min-width: 0;
}

.mobile-header {
  display: block;
}

.mobile-footer {
  margin-top: 3rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

@media (min-width: 1024px) {
  .page {
    padding: 0;
  }

  .page-inner {
    display: flex;
    justify-content: center;
    gap: 3.5rem;
    padding: 4.5rem 0;
  }

  .sidebar {
    display: block;
    width: var(--sidebar-width);
    flex-shrink: 0;
  }

  .content {
    width: min(var(--max-width), 60vw);
  }

  .mobile-header,
  .site-header-controls {
    display: none;
  }

  .mobile-footer {
    display: none;
  }
}

/* Header */
.site-header {
  margin-bottom: 1.5rem;
}

.site-header.is-post {
  margin-bottom: 1.75rem;
}

.site-title {
  margin: 0 0 0.75rem 0;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.site-header.is-home .site-title {
  font-size: 2.6rem;
}

.site-header.is-post .site-title {
  font-size: 1.9rem;
  color: var(--text-secondary);
}

.site-subtitle {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-secondary);
}

@media (max-width: 1023px) {
  .site-header.is-home .site-title {
    font-size: 2.1rem;
  }

  .site-subtitle {
    display: none;
  }
}

/* Sidebar */
.sidebar-inner {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  font-size: 1rem;
}

.sidebar-title {
  font-size: 1.45rem;
  font-weight: 700;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-footer {
  margin-top: 2rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Theme toggle */
.theme-toggle,
.search-button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  cursor: pointer;
  transition: color 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover,
.search-button:hover {
  color: var(--accent);
}

.theme-toggle-icon {
  display: inline-block;
  transform: translateY(0);
  font-size: 1.1rem;
  line-height: 1;
}

.search-icon {
  display: inline-block;
  transform: translateY(0);
  width: 1.3rem;
  height: 1.3rem;
}

.sidebar-controls {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

/* Sections and list */
.section {
  margin-bottom: 2.5rem;
}

.decorative-line {
  width: 2.25rem;
  height: 2px;
  background: var(--border);
  margin-bottom: 1.5rem;
}

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

.post-item {
  margin-bottom: 1.5rem;
}

@media (min-width: 1024px) {
  .post-item {
    margin-bottom: 2.5rem;
  }
}

.post-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.post-link {
  transition: color 0.2s ease;
}

.post-meta {
  margin-top: 0.35rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.post-desc {
  margin: 0.75rem 0 0;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Single post */
.post-header {
  margin-bottom: 1.5rem;
}

.post .post-title {
  font-size: 2rem;
  letter-spacing: 0.02em;
  font-family: inherit;
}

@media (max-width: 1023px) {
  .post .post-title {
    font-size: 1.7rem;
  }
}

.post-content {
  font-size: 1.05rem;
}

.post-content h2,
.post-content h3,
.post-content h4 {
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  font-family: inherit;
  font-weight: 600;
}

.post-content h2 {
  font-size: 1.4rem;
}

.post-content h3 {
  font-size: 1.2rem;
}

.post-content h4 {
  font-size: 1.05rem;
}

.post-content p {
  margin: 1rem 0;
}

.post-content blockquote {
  border-left: 2px solid var(--border);
  margin: 1.5rem 0;
  padding-left: 1rem;
  color: var(--text-secondary);
}

/* Back button */
.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.back-button:hover {
  color: var(--accent);
}

.post-shell {
  position: relative;
}

@media (min-width: 1024px) {
  .back-button {
    position: absolute;
    left: -3.4rem;
    top: 0.8rem;
    margin-bottom: 0;
  }
}

@media (max-width: 1023px) {
  .back-button {
    display: none;
  }
}

/* Search modal */
.search-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: calc(env(safe-area-inset-top, 0px) + 1.5rem) 0 1.5rem;
}

.search-modal.is-open {
  display: flex;
}

.search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.search-panel {
  position: fixed;
  width: min(36rem, 90vw);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem;
  z-index: 1;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
}

.search-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  background: transparent;
  color: var(--text);
  outline: none;
}

.search-close {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-secondary);
}

.search-results {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  max-height: 55vh;
  overflow: auto;
}

html.modal-open,
body.modal-open {
  overflow: hidden;
  height: 100%;
  touch-action: none;
}

.search-results li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.search-results li:last-child {
  border-bottom: none;
}

.search-results a {
  font-weight: 600;
}

.search-results p {
  margin: 0.35rem 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
  color: var(--text-secondary);
}

.page-link,
.page-number {
  border: none;
  padding: 0.2rem 0.4rem;
  font-size: 0.95rem;
  color: inherit;
}

.page-number.is-current {
  color: var(--accent);
}

.page-link.is-disabled {
  opacity: 0.5;
}

.page-numbers {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.page-ellipsis {
  color: var(--text-secondary);
  padding: 0 0.2rem;
}

/* View Transition styles */
@keyframes reveal {
  from {
    clip-path: inset(var(--from));
  }
}

::view-transition-new(theme-toggle) {
  z-index: 99;
  clip-path: inset(0 0 0 0);
  animation: reveal 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

::view-transition-old(theme-toggle) {
  z-index: -1;
  animation: none;
}

html.dark {
  --from: 0 0 100% 0;
}

html:not(.dark) {
  --from: 100% 0 0 0;
}

html[data-theme-changing] [data-disable-theme-transition] {
  view-transition-name: none !important;
}

/* Content progressive animation (matches Astro pacing) */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(2.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#post-date {
  opacity: 0;
  animation: fadeInUp 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
  animation-delay: 0.1s;
}

#post-content > * {
  opacity: 0;
  animation: fadeInUp 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

#post-content > *:nth-child(1) { animation-delay: 0.15s; }
#post-content > *:nth-child(2) { animation-delay: 0.2s; }
#post-content > *:nth-child(3) { animation-delay: 0.25s; }
#post-content > *:nth-child(4) { animation-delay: 0.3s; }
#post-content > *:nth-child(5) { animation-delay: 0.35s; }
#post-content > *:nth-child(6) { animation-delay: 0.4s; }
#post-content > *:nth-child(7) { animation-delay: 0.45s; }
#post-content > *:nth-child(8) { animation-delay: 0.5s; }
#post-content > *:nth-child(n+9) { animation-delay: 0.55s; }

@media (max-width: 767px) {
  #post-content > *:nth-child(n+8) {
    opacity: 1;
    transform: translateY(0);
    animation: none;
  }
}

/* Back button animation */
@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (min-width: 1024px) {
  #back-button {
    opacity: 0;
    animation: fadeInLeft 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
    animation-delay: 0.2s;
  }
}

/* Reduced motion fallback */
html.reduce-motion #post-date,
html.reduce-motion #post-content > * {
  opacity: 1;
  transform: translateY(0);
  animation: none;
}

html.reduce-motion::view-transition-old(root),
html.reduce-motion::view-transition-new(root) {
  animation: none;
}
.site-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header-controls {
  display: flex;
  gap: 0.2rem;
  align-items: center;
}
