:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Code", Consolas,
    "Courier New", monospace;
  --max-width: 680px;
  --header-h: 64px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fdfcfb;
  --bg-soft: #f5f3f1;
  --bg-code: #f6f4f2;
  --text: #1f1d1c;
  --text-secondary: #6f6a66;
  --text-tertiary: #a8a29d;
  --accent: #d9375c;
  --accent-soft: rgba(217, 55, 92, 0.08);
  --border: rgba(31, 29, 28, 0.09);
  --border-strong: rgba(31, 29, 28, 0.16);
  --shadow: 0 1px 2px rgba(31, 29, 28, 0.04), 0 8px 24px rgba(31, 29, 28, 0.05);
  --orb-1: rgba(255, 154, 158, 0.35);
  --orb-2: rgba(250, 208, 196, 0.45);
  --header-bg: rgba(253, 252, 251, 0.72);
  --selection: rgba(217, 55, 92, 0.15);
  --cal-page: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131110;
  --bg-soft: #1c1a18;
  --bg-code: #1d1a18;
  --text: #ece9e6;
  --text-secondary: #9c968f;
  --text-tertiary: #635e59;
  --accent: #ff7d96;
  --accent-soft: rgba(255, 125, 150, 0.1);
  --border: rgba(236, 233, 230, 0.09);
  --border-strong: rgba(236, 233, 230, 0.18);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --orb-1: rgba(217, 55, 92, 0.16);
  --orb-2: rgba(255, 145, 77, 0.1);
  --header-bg: rgba(19, 17, 16, 0.72);
  --selection: rgba(255, 125, 150, 0.22);
  --cal-page: #221f1d;
}

/* ---------- Reset & base ---------- */

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.85;
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.4s ease, color 0.4s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@media (min-width: 640px) {
  body {
    font-size: 17px;
  }
}

::selection {
  background: var(--selection);
}

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.25s ease;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.site-header .container,
.site-footer .container {
  max-width: none;
  padding: 0 28px;
}

/* Grain texture */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s ease, background-color 0.4s ease,
    backdrop-filter 0.3s ease;
}

.site-header.scrolled {
  border-bottom-color: var(--border);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  background: var(--header-bg);
}

.site-header nav {
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.site-title:hover {
  color: var(--accent);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 6px 12px;
  font-size: 0.92rem;
  color: var(--text-secondary);
  border-radius: 8px;
  transition: color 0.25s ease, background-color 0.25s ease;
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  color: var(--text);
  background: var(--accent-soft);
}

.theme-toggle {
  margin-left: 6px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.25s ease, background-color 0.25s ease,
    transform 0.2s var(--ease-out);
}

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

.theme-toggle:active {
  transform: scale(0.88);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

:root[data-theme="light"] .icon-sun,
:root[data-theme="dark"] .icon-moon {
  display: none;
}

/* ---------- Hero background ---------- */

.hero-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 520px;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
}

.orb-1 {
  width: 420px;
  height: 420px;
  top: -140px;
  right: -80px;
  background: var(--orb-1);
  animation: drift 24s ease-in-out infinite alternate;
}

.orb-2 {
  width: 360px;
  height: 360px;
  top: -60px;
  left: -120px;
  background: var(--orb-2);
  animation: drift 30s ease-in-out infinite alternate-reverse;
}

@keyframes drift {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(40px, 30px) scale(1.12);
  }
}

/* ---------- Post list ---------- */

.section-posts {
  padding-top: 40px;
  padding-bottom: 48px;
}

.year-group {
  position: relative;
  margin-top: 36px;
}

.year-group:first-child {
  margin-top: 0;
}

.year-label {
  position: absolute;
  top: -34px;
  left: -14px;
  font-size: 7.5rem;
  font-weight: 800;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1.5px var(--border-strong);
  pointer-events: none;
  user-select: none;
  z-index: -1;
}

.post-item {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 13px 0;
  transition: transform 0.25s var(--ease-out);
}

.post-item:hover {
  transform: translateX(6px);
}

.post-item .post-title {
  font-size: 1.05rem;
  font-weight: 500;
  transition: color 0.25s ease;
}

.post-item:hover .post-title {
  color: var(--accent);
}

.post-item .leader {
  flex: 1;
  min-width: 24px;
  border-bottom: 1.5px dotted var(--border-strong);
  transform: translateY(-4px);
}

.post-item time {
  flex-shrink: 0;
  font-size: 0.84rem;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* ---------- Article ---------- */

.article {
  padding: 56px 0 64px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-tertiary);
  margin-bottom: 36px;
}

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

.back-link svg {
  width: 14px;
  height: 14px;
  transition: transform 0.25s var(--ease-out);
}

.back-link:hover svg {
  transform: translateX(-3px);
}

.article h1 {
  font-size: clamp(1.6rem, 4.5vw, 2.1rem);
  font-weight: 800;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.article .meta {
  margin-top: 14px;
  margin-bottom: 44px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.article .meta .dot::before {
  content: "·";
  color: var(--text-tertiary);
}

/* Article typography */

.article-content {
  text-align: justify;
}

.article-content > * + * {
  margin-top: 1.1em;
}

.article-content h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 2.2em;
  letter-spacing: -0.005em;
}

.article-content h3 {
  font-size: 1.12rem;
  font-weight: 700;
  margin-top: 1.8em;
}

.article-content a {
  color: var(--accent);
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 100% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: opacity 0.25s ease;
}

.article-content a:hover {
  opacity: 0.75;
}

.article-content ul,
.article-content ol {
  padding-left: 1.4em;
}

.article-content li + li {
  margin-top: 0.35em;
}

.article-content li::marker {
  color: var(--accent);
}

.article-content strong {
  font-weight: 700;
}

.article-content code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 6px;
}

.article-content pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  overflow-x: auto;
  line-height: 1.7;
  text-align: left;
}

.article-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85em;
}

.article-content blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  padding: 14px 20px;
  color: var(--text-secondary);
}

.article-content blockquote > * + * {
  margin-top: 0.6em;
}

.article-content img {
  max-width: 100%;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.article-content hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 2.4em auto;
  width: 60%;
}

/* Article footer */

.article-end {
  margin-top: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-tertiary);
  font-size: 0.85rem;
}

.article-end::before,
.article-end::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Desk calendar ---------- */

.section-calendar {
  padding-bottom: 56px;
  display: flex;
  justify-content: center;
}

.calendar {
  width: min(560px, 100%);
  perspective: 1400px;
}

.cal-stand {
  position: relative;
  border-radius: 18px 18px 14px 14px;
  background: var(--cal-page);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* spiral binding */
.cal-binding {
  position: absolute;
  top: -9px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-evenly;
  z-index: 5;
}

.cal-binding i {
  width: 7px;
  height: 18px;
  border: 2px solid var(--text-tertiary);
  border-radius: 5px;
  background: var(--bg);
}

.cal-pages {
  position: relative;
  overflow: visible;
}

.cal-page {
  padding: 34px 30px 26px;
  border-radius: 18px 18px 14px 14px;
  background: var(--cal-page);
  backface-visibility: hidden;
}

.cal-page-under {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.cal-page-front {
  position: relative;
  z-index: 1;
  transform-origin: top center;
}

.cal-page-front.flipping {
  animation: page-flip 0.65s ease-in forwards;
}

@keyframes page-flip {
  0% {
    transform: rotateX(0);
    opacity: 1;
  }
  100% {
    transform: rotateX(-150deg);
    opacity: 0;
  }
}

.cal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
}

.cal-year {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-tertiary);
}

.cal-month {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--accent);
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.cal-week .wk {
  color: var(--accent);
  opacity: 0.75;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-grid .day {
  appearance: none;
  border: none;
  background: none;
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--text-secondary);
  padding: 11px 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease,
    transform 0.15s var(--ease-out);
}

.cal-grid .day:hover {
  background: var(--accent-soft);
  color: var(--accent);
  transform: scale(1.08);
}

.cal-grid .day.today {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.cal-grid .day.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  color: var(--accent);
}

.cal-hint {
  margin-top: 12px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* quote popover */
.cal-quote {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  width: min(460px, calc(100vw - 48px));
  background: var(--cal-page);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 26px 28px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s var(--ease-out);
  pointer-events: none;
}

.cal-quote.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

.cal-quote-date {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.cal-quote-text {
  font-size: 1.02rem;
  line-height: 1.9;
  color: var(--text);
}

.cal-quote-hint {
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* ---------- Footer ---------- */

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 12px 0;
  font-size: 0.82rem;
  color: var(--text-tertiary);
}

.site-footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.site-footer a {
  color: var(--text-secondary);
}

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

.footer-heart {
  color: var(--accent);
  display: inline-block;
  animation: heartbeat 2.4s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 40%, 80%, 100% { transform: scale(1); }
  20%, 60% { transform: scale(1.18); }
}

/* ---------- 404 ---------- */

.not-found {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 24px;
}

.not-found .code {
  font-size: 6rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: transparent;
  -webkit-text-stroke: 2px var(--border-strong);
  line-height: 1;
}

.not-found p {
  margin: 18px 0 28px;
  color: var(--text-secondary);
}

.not-found .home-btn {
  padding: 9px 22px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 0.92rem;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.not-found .home-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

/* ---------- Reading progress ---------- */

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2.5px;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), #ff914d);
  transform-origin: 0 50%;
  transform: scaleX(0);
  z-index: 200;
}

/* ---------- Back to top ---------- */

.back-top {
  position: fixed;
  right: 26px;
  bottom: 30px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.3s ease, visibility 0.3s ease,
    transform 0.3s var(--ease-out), color 0.25s ease, border-color 0.25s ease;
  z-index: 90;
}

.back-top.show {
  opacity: 1;
  visibility: visible;
  transform: none;
}

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

.back-top svg {
  width: 18px;
  height: 18px;
}

/* ---------- Entrance animation ---------- */

.anim {
  opacity: 0;
  animation: fade-up 0.8s var(--ease-out) forwards;
  animation-delay: calc(var(--d, 0) * 90ms);
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- View transition (theme switch) ---------- */

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

/* ---------- Scrollbar ---------- */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
  border: 2px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }

  .anim {
    opacity: 1;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  .year-label {
    font-size: 5.5rem;
    top: -24px;
    left: -8px;
  }

  .post-item time {
    font-size: 0.78rem;
  }

  .article-content {
    text-align: left;
  }
}
