:root {
  --bg: #f7f5ef;
  --paper: #fffdf8;
  --ink: #1c1f23;
  --muted: #6c7076;
  --line: #e3ded2;
  --accent: #2f6f5e;
  --accent-soft: #dcebe4;
  --shadow: 0 1px 2px rgba(28, 31, 35, .05), 0 8px 24px rgba(28, 31, 35, .06);
  --radius: 14px;
  --mono: "Cascadia Mono", "Consolas", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", ui-monospace, monospace;
  --sans: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  background-image:
    radial-gradient(rgba(28, 31, 35, .055) 1px, transparent 1px),
    linear-gradient(180deg, rgba(47, 111, 94, .04), rgba(247, 245, 239, 0) 42%);
  background-size: 22px 22px, 100% 100%;
  background-attachment: fixed;
}

/* ---------- game of life backdrop ---------- */
#life-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: .95;
}

/* ---------- shell ---------- */
.shell {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 56px 28px 96px;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 48px;
}

.profile {
  position: sticky;
  top: 56px;
  align-self: start;
  padding: 24px 20px 26px;
  max-width: 470px;
  border: 1px solid rgba(227, 222, 210, .85);
  border-radius: 18px;
  background: rgba(255, 253, 248, .55);
  -webkit-backdrop-filter: blur(6px) saturate(115%);
  backdrop-filter: blur(6px) saturate(115%);
  box-shadow: 0 1px 2px rgba(28, 31, 35, .04), 0 12px 32px rgba(28, 31, 35, .06);
}

.avatar {
  width: 104px;
  height: 104px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 5px 5px 0 rgba(47, 111, 94, .16), var(--shadow);
  image-rendering: pixelated;
}

.profile h1 { margin: 20px 0 4px; font-size: 26px; letter-spacing: -.01em; }

.profile .handle {
  font: 500 13px/1.4 var(--mono);
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.profile .handle::after {
  content: "▌";
  display: inline-block;
  margin-left: 3px;
  color: var(--accent);
  animation: blink 1.2s steps(1, end) infinite;
}
@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }

.profile .bio { margin: 18px 0 0; font-size: 15px; line-height: 1.75; color: #3d4249; }
.profile .bio strong { color: var(--ink); font-weight: 600; }

.profile .links { margin: 22px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.profile .links a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: 500 13px/1 var(--mono);
  text-decoration: none;
}
.profile .links a:hover { border-color: var(--accent); color: var(--accent); }
.profile .links a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.profile .stat {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
  font: 500 14px/1.95 var(--sans);
  color: var(--muted);
}
.profile .stat b, .profile .stat .num {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.heat-block { margin-top: 18px; }
.heat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
  font: 500 12px/1 var(--mono);
  color: var(--muted);
  letter-spacing: .02em;
}
.heat-note { opacity: .75; }
.heat {
  display: grid;
  grid-template-rows: repeat(7, 6px);
  grid-auto-flow: column;
  grid-auto-columns: 6px;
  gap: 2px;
  width: max-content;
}
.heat .h {
  width: 6px;
  height: 6px;
  border-radius: 1.5px;
  background: #ebe8e0;
}
.heat .h.l1 { background: #d3e8dc; }
.heat .h.l2 { background: #9bd2bf; }
.heat .h.l3 { background: #55b295; }
.heat .h.l4 { background: #1f7f68; }
.heat .is-pad { visibility: hidden; }
.heat-empty { font: 500 12px/1.6 var(--mono); color: var(--muted); }

/* ---------- feed ---------- */
.feed-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 22px;
}
.feed-head h2 {
  margin: 0;
  font: 600 14px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
}
.feed-head h2::before {
  content: "◆";
  margin-right: 8px;
  color: var(--accent);
  font-size: 9px;
  vertical-align: 1px;
}
.feed-head .more {
  color: var(--accent);
  text-decoration: none;
  font: 500 14px/1 var(--mono);
  white-space: nowrap;
}
.refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--accent);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, transform .3s ease;
}
.refresh-btn:hover { border-color: var(--accent); background: var(--accent-soft); transform: rotate(90deg); }
.refresh-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.refresh-btn:active { transform: rotate(180deg) scale(.94); }
.feed-head .more:hover { text-decoration: underline; }
.feed-head .more:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.feed-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.feed-col { display: grid; gap: 18px; min-width: 0; }

/* Static two-column fallback (narrow screens). */
.feed-static { display: block; }
.feed-flow { display: none; }

/* Wide screens: three columns drifting downwards at a constant speed. */
@media (min-width: 1360px) {
  .feed-static { display: none; }
  .feed-flow {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 5%, #000 95%, transparent 100%);
    mask-image: linear-gradient(180deg, transparent 0, #000 5%, #000 95%, transparent 100%);
  }
  .flow-col { overflow: hidden; min-width: 0; }
  .flow-track {
    display: grid;
    gap: 16px;
    will-change: transform;
    transform: translateY(0);
  }
}

.note-card {
  display: block;
  background: rgba(255, 253, 248, .74);
  -webkit-backdrop-filter: blur(9px) saturate(120%);
  backdrop-filter: blur(9px) saturate(120%);
  border: 1px solid rgba(227, 222, 210, .85);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 2px rgba(28, 31, 35, .05), 0 10px 28px rgba(28, 31, 35, .07);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, background .18s ease;
  animation: rise .55s cubic-bezier(.2, .7, .2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 55ms);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px) scale(.985); }
  to { opacity: 1; transform: none; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .note-card { background: rgba(255, 253, 248, .94); }
}
.note-card:hover {
  transform: translateY(-3px);
  border-color: rgba(47, 111, 94, .35);
  background: rgba(255, 253, 248, .84);
  box-shadow: 0 2px 4px rgba(28,31,35,.05), 0 18px 36px rgba(28,31,35,.12);
}
.note-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.note-card .cover {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #eceae3;
  border-bottom: 1px solid var(--line);
  opacity: .82;
  transition: transform .5s cubic-bezier(.2, .7, .2, 1), opacity .2s ease;
  transform-origin: center;
}
.note-card:hover .cover { transform: scale(1.035); opacity: .96; }

.note-card .body { padding: 16px 17px 18px; }
.note-card.is-text .body { padding-top: 19px; padding-bottom: 20px; }
.note-card.is-text::before {
  content: "";
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent 72%);
  opacity: .5;
}

.note-card .meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font: 500 12.5px/1.2 var(--mono);
  color: var(--muted);
  letter-spacing: .01em;
}
.note-card .meta time { color: var(--muted); }
.note-card .tag { padding: 3px 7px; border-radius: 999px; background: var(--accent-soft); color: #26594b; font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.note-card h3 { margin: 10px 0 0; font-size: 16.5px; line-height: 1.45; letter-spacing: -.005em; }
.note-card .excerpt {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-card .excerpt mjx-container { font-size: 1em; vertical-align: middle; }
.note-card .excerpt mjx-container svg { max-width: 100%; height: auto; }
.note-card .excerpt .katex { font-size: 1.02em; }
.note-card .excerpt .katex-display { margin: 0; }
.note-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.66;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-card .read { margin: 12px 0 0; font: 500 12.5px/1 var(--mono); color: var(--accent); letter-spacing: .02em; }

.empty-note {
  padding: 40px 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* ---------- notes page ---------- */
.page-head { margin-bottom: 30px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.page-head .back { font: 500 13px/1 var(--mono); color: var(--muted); text-decoration: none; }
.page-head .back:hover { color: var(--accent); }
.page-head h1 { margin: 14px 0 6px; font-size: 30px; letter-spacing: -.01em; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; }

.shell.single { display: block; max-width: 1080px; padding-top: 48px; }

.footer {
  margin-top: 64px;
  padding-top: 20px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font: 500 12.5px/1.8 var(--mono);
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--accent); }

/* ---------- responsive ---------- */
/* Narrow screens: no masonry, just a plain single-column list. */
@media (max-width: 1359px) {
  .feed-grid { grid-template-columns: minmax(0, 1fr); }
  .feed-col { display: contents; }
}

@media (max-width: 960px) {
  .shell { display: block; padding: 32px 18px 80px; }
  .profile { position: static; padding: 20px 18px 22px; margin-bottom: 6px; }
  .avatar { width: 84px; height: 84px; }
  .profile h1 { font-size: 23px; margin-top: 16px; }
  .profile .bio { margin-top: 14px; }
  .profile .stat { margin-top: 18px; }
  .feed-head { margin: 34px 0 18px; }
  .feed-grid { grid-template-columns: minmax(0, 1fr); }
  .feed-col { display: contents; }
  .note-card { background: rgba(255, 253, 248, .9); }
  .note-card .cover { aspect-ratio: 16 / 9; }
}

@media (min-width: 1360px) {
  /* Wide screens: the flow takes everything right of the 470px profile column. */
  body.home { overflow: hidden; }
  body.home .shell {
    max-width: none;
    height: 100vh;
    padding: 40px;
    gap: 40px;
    grid-template-columns: minmax(0, 470px) minmax(0, 1fr);
  }
  body.home main { display: flex; flex-direction: column; min-height: 0; height: 100%; }
  body.home .footer { margin-top: 14px; padding-top: 12px; }
  .shell.single { max-width: 1080px; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .note-card { transition: none; animation: none; }
  .note-card:hover { transform: none; }
  .note-card:hover .cover { transform: none; }
  .profile .handle::after { animation: none; }
}
@media (min-width: 1360px) {
  .feed-grid { gap: 20px; }
  .note-card { background: rgba(255, 253, 248, .68); }
}
