:root {
  --background: #f7f6f2;
  --surface: #fbfaf7;
  --surface-muted: #efeee9;
  --text: #20252a;
  --muted: #6b7176;
  --line: #d7d6d0;
  --accent: #4f6475;
  color-scheme: light;
}

:root.dark {
  --background: #191c1f;
  --surface: #1e2225;
  --surface-muted: #24292d;
  --text: #e7e6e1;
  --muted: #a5a8aa;
  --line: #393e42;
  --accent: #aab8c2;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family: Inter, "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.site {
  min-height: 100vh;
  color: var(--text);
  background: var(--background);
}

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: min(1120px, calc(100% - 48px));
  min-height: 88px;
  margin: 0 auto;
  border-bottom: 1px solid var(--line);
}

.identity {
  display: flex;
  flex-direction: column;
  justify-self: start;
  gap: 3px;
}

.identity strong {
  font-size: 15px;
  font-weight: 610;
  letter-spacing: -0.02em;
}

.identity span {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-header nav { display: flex; align-items: center; gap: 32px; }

.site-header nav a {
  position: relative;
  padding: 10px 0;
  color: var(--muted);
  font-size: 13px;
}

.site-header nav a:hover,
.site-header nav a.active { color: var(--text); }

.site-header nav a.active::after {
  position: absolute;
  right: 0;
  bottom: 4px;
  left: 0;
  height: 1px;
  content: "";
  background: var(--text);
}

.theme-button {
  justify-self: end;
  padding: 7px 9px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 10px;
}

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

.page-shell {
  width: min(1120px, calc(100% - 48px));
  min-height: calc(100vh - 166px);
  margin: 0 auto;
}

.page { padding: 78px 0 110px; }

.page-header {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: start;
  padding-bottom: 48px;
  border-bottom: 1px solid var(--text);
}

.page-header > p,
.notes-page-header > div > p {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(42px, 5vw, 68px);
  font-weight: 520;
  letter-spacing: -0.055em;
  line-height: 1;
}

.page-header > span,
.notes-page-header > div > span {
  grid-column: 2;
  max-width: 600px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.project-list { border-bottom: 1px solid var(--line); }

.project-item {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 110px;
  gap: 24px;
  min-height: 250px;
  padding: 40px 0;
  border-bottom: 1px solid var(--line);
}

.project-item:last-child { border-bottom: 0; }

.project-meta {
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
}

.project-content > p:first-child {
  margin: 0 0 11px;
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.project-content h2 {
  margin: 0;
  font-size: clamp(27px, 3vw, 38px);
  font-weight: 520;
  letter-spacing: -0.04em;
}

.project-description {
  max-width: 660px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 26px; }

.tags span {
  padding: 5px 7px;
  color: var(--muted);
  border: 1px solid var(--line);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
}

.project-action { justify-self: end; color: var(--muted); font-size: 12px; }
.project-action a:hover { color: var(--text); }

.notes-page-header {
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: end;
}

.notes-page-header > div > span { display: block; }

.search-field {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 11px 13px;
  border: 1px solid var(--line);
}

.search-field span { color: var(--muted); font-size: 10px; }

.search-field input {
  min-width: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 12px;
}

.search-field input::placeholder { color: var(--muted); }

.note-filters {
  display: flex;
  gap: 8px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.note-filters button {
  padding: 8px 11px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 11px;
}

.note-filters button:hover { color: var(--text); border-color: var(--line); }
.note-filters button.active { color: var(--background); background: var(--text); }

.note-item {
  display: grid;
  grid-template-columns: 120px minmax(220px, 0.75fr) minmax(280px, 1fr) 20px;
  gap: 24px;
  align-items: center;
  width: 100%;
  min-height: 94px;
  padding: 18px 8px 18px 0;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.note-item:hover { background: var(--surface-muted); }

.note-item time {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
}

.note-title { display: flex; flex-direction: column; gap: 7px; }

.note-title small {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  letter-spacing: 0.08em;
}

.note-title strong { font-size: 16px; font-weight: 540; }
.note-description { color: var(--muted); font-size: 12px; line-height: 1.6; }
.note-item > span:last-child { color: var(--muted); }
.empty { padding: 50px 0; color: var(--muted); text-align: center; }

.note-dialog-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 18, 20, 0.52);
}

.note-dialog-backdrop[hidden] { display: none; }

.note-dialog {
  position: relative;
  width: min(560px, 100%);
  padding: 48px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
}

.dialog-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
}

.note-dialog > p:first-of-type {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
}

.note-dialog h2 { margin: 24px 0; font-size: 34px; font-weight: 520; letter-spacing: -0.04em; }
.note-dialog > p:last-of-type, .note-dialog small { color: var(--muted); line-height: 1.8; }
.note-dialog hr { margin: 32px 0; border: 0; border-top: 1px solid var(--line); }

.about-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: clamp(54px, 9vw, 120px);
  padding-top: 56px;
}

.about-avatar {
  align-self: start;
  overflow: hidden;
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.about-avatar img { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.about-text { max-width: 680px; }

.about-text h2 {
  margin: 0 0 34px;
  font-size: clamp(30px, 4vw, 48px);
  font-weight: 520;
  letter-spacing: -0.045em;
  line-height: 1.25;
}

.about-text > p { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.95; }
.about-facts { margin: 42px 0 0; border-top: 1px solid var(--line); }

.about-facts div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 24px;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}

.about-facts dt { color: var(--muted); font-size: 11px; }
.about-facts dd { margin: 0; font-size: 12px; }
.about-links { display: flex; gap: 24px; margin-top: 34px; font-size: 12px; }
.about-links a { padding-bottom: 3px; border-bottom: 1px solid var(--line); }

.site-footer {
  display: flex;
  justify-content: space-between;
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 26px 0;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  letter-spacing: 0.06em;
}

.reading-progress {
  position: fixed;
  z-index: 120;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  pointer-events: none;
}

.reading-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}

.reader-shell {
  width: min(1120px, calc(100% - 48px));
  min-height: calc(100vh - 166px);
  margin: 0 auto;
  padding: 54px 0 110px;
}

.reader-back {
  display: inline-block;
  margin-bottom: 48px;
  color: var(--muted);
  font-size: 11px;
}

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

.reader-heading {
  max-width: 820px;
  padding-bottom: 42px;
  border-bottom: 1px solid var(--text);
}

.reader-heading > p,
.toc > p {
  margin: 0 0 16px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.reader-heading h1 {
  max-width: 800px;
  margin: 0;
  font-size: clamp(36px, 5vw, 62px);
  font-weight: 520;
  letter-spacing: -0.05em;
  line-height: 1.08;
}

.reader-heading > span {
  display: block;
  margin-top: 20px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
}

.reader-grid {
  display: grid;
  grid-template-columns: minmax(0, 820px) minmax(160px, 220px);
  gap: clamp(48px, 8vw, 90px);
  align-items: start;
  padding-top: 52px;
}

.toc {
  position: sticky;
  top: 30px;
  max-height: calc(100vh - 60px);
  overflow: auto;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.toc nav { display: flex; flex-direction: column; gap: 10px; }
.toc a { color: var(--muted); font-size: 10px; line-height: 1.5; }
.toc a:hover { color: var(--text); }
.toc .toc-level-2 { padding-left: 10px; }
.toc .toc-level-3 { padding-left: 20px; }

.markdown-body {
  min-width: 0;
  color: var(--text);
  font-size: 15px;
  line-height: 1.9;
}

.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  scroll-margin-top: 24px;
  font-weight: 560;
  letter-spacing: -0.025em;
  line-height: 1.35;
}
.markdown-body h1 { margin: 2.3em 0 0.8em; font-size: 34px; }
.markdown-body h2 { margin: 2.2em 0 0.75em; padding-bottom: 0.35em; border-bottom: 1px solid var(--line); font-size: 27px; }
.markdown-body h3 { margin: 1.9em 0 0.6em; font-size: 21px; }
.markdown-body h4 { margin: 1.7em 0 0.5em; font-size: 17px; }
.markdown-body p, .markdown-body ul, .markdown-body ol { margin: 1.1em 0; }
.markdown-body li + li { margin-top: 0.35em; }
.markdown-body a { color: var(--accent); border-bottom: 1px solid var(--line); }
.markdown-body blockquote { margin: 1.5em 0; padding: 2px 0 2px 20px; color: var(--muted); border-left: 2px solid var(--accent); }
.markdown-body img { display: block; max-width: 100%; height: auto; margin: 2em auto; border: 1px solid var(--line); }
.markdown-body hr { margin: 3em 0; border: 0; border-top: 1px solid var(--line); }
.markdown-body table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 12px; }
.markdown-body th, .markdown-body td { padding: 10px 12px; text-align: left; border: 1px solid var(--line); }
.markdown-body th { background: var(--surface-muted); font-weight: 560; }
.markdown-body code { padding: 0.15em 0.35em; background: var(--surface-muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.86em; }
.markdown-body pre { position: relative; overflow-x: auto; margin: 1.6em 0; padding: 20px; background: #f1f2f3; border: 1px solid var(--line); line-height: 1.65; }
.dark .markdown-body pre { background: #22272e; }
.markdown-body pre code { padding: 0; background: transparent; }
.copy-code { position: absolute; top: 8px; right: 8px; padding: 4px 7px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); cursor: pointer; font-size: 9px; }
.katex-display, .mermaid { overflow-x: auto; overflow-y: hidden; margin: 2em 0; }
.reader-loading, .reader-error { color: var(--muted); }
.reader-error { padding: 34px; border: 1px solid var(--line); }
.reader-error a { display: inline-block; margin-top: 14px; }

@media (max-width: 760px) {
  .site-header {
    grid-template-columns: 1fr auto;
    width: calc(100% - 32px);
    min-height: 78px;
  }

  .identity span, .theme-button { display: none; }
  .site-header nav { gap: 20px; }
  .page-shell, .site-footer { width: calc(100% - 32px); }
  .page { padding: 56px 0 80px; }
  .page-header, .notes-page-header { grid-template-columns: 1fr; gap: 12px; }
  .page-header > p { display: none; }
  .page-header > span { grid-column: 1; }
  .search-field { margin-top: 18px; }

  .project-item {
    grid-template-columns: 42px 1fr;
    gap: 14px;
    min-height: auto;
  }

  .project-action { grid-column: 2; justify-self: start; }
  .note-filters { overflow-x: auto; }
  .note-filters button { flex: 0 0 auto; }

  .note-item {
    grid-template-columns: 1fr 18px;
    gap: 8px;
    padding: 20px 4px 20px 0;
  }

  .note-item time, .note-description { display: none; }
  .about-layout { grid-template-columns: 1fr; gap: 42px; }
  .about-avatar { width: 190px; }
  .note-dialog { padding: 42px 26px; }
  .site-footer span:last-child { display: none; }
  .reader-shell { width: calc(100% - 32px); padding: 40px 0 80px; }
  .reader-back { margin-bottom: 34px; }
  .reader-grid { grid-template-columns: 1fr; gap: 28px; padding-top: 36px; }
  .toc { position: static; grid-row: 1; max-height: none; padding: 18px; border: 1px solid var(--line); }
  .markdown-body { font-size: 14px; }
  .markdown-body pre { margin-right: -16px; margin-left: -16px; border-right: 0; border-left: 0; }
}

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