:root {
  --paper: #f4f0e7;
  --paper-deep: #ebe4d6;
  --ink: #191a18;
  --muted: #6f6a60;
  --rule: #d7cdbd;
  --accent: #9b341f;
  --accent-soft: #f0ddd4;
  --code-bg: #201f1c;
  --code-fg: #f1eadf;
  --selection: #e6c86a;
  --heading-selection: rgba(230, 200, 106, 0.42);
  --sidebar-width: clamp(275px, 23vw, 350px);
  --measure: 46rem;
  --font-heading: "Playwrite CA", cursive;
  --font-content: "Overpass", sans-serif;
  --font-accent: "Petit Formal Script", cursive;
}

:root[data-theme="rose"] {
  --paper: #fff3f6;
  --paper-deep: #f7dce4;
  --ink: #2b1920;
  --muted: #75515e;
  --rule: #e6bcc8;
  --accent: #c42f5c;
  --accent-soft: #f7d1dc;
  --code-bg: #2b1d22;
  --code-fg: #fff0f4;
  --selection: #f2a9bd;
  --heading-selection: rgba(242, 169, 189, 0.56);
}

:root[data-theme="sage"] {
  --paper: #f1f8f1;
  --paper-deep: #dcebdd;
  --ink: #17271c;
  --muted: #506957;
  --rule: #bdd5c2;
  --accent: #147a55;
  --accent-soft: #ccebd9;
  --code-bg: #19271f;
  --code-fg: #effaf2;
  --selection: #9fdabb;
  --heading-selection: rgba(159, 218, 187, 0.62);
}

:root[data-theme="mist"] {
  --paper: #f2f6ff;
  --paper-deep: #dce6f7;
  --ink: #18243a;
  --muted: #52627c;
  --rule: #c2d0e8;
  --accent: #3864c8;
  --accent-soft: #d6e2fa;
  --code-bg: #1d2638;
  --code-fg: #f1f5ff;
  --selection: #aac4f4;
  --heading-selection: rgba(170, 196, 244, 0.6);
}

:root[data-theme="lilac"] {
  --paper: #f8f3ff;
  --paper-deep: #e9ddf5;
  --ink: #291c35;
  --muted: #6c577a;
  --rule: #d7c2e6;
  --accent: #7b45b1;
  --accent-soft: #ead7f6;
  --code-bg: #281f31;
  --code-fg: #f8f1ff;
  --selection: #d4afea;
  --heading-selection: rgba(212, 175, 234, 0.6);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--paper);
}

html.has-custom-scrollbar {
  scrollbar-width: none;
}

html.has-custom-scrollbar::-webkit-scrollbar {
  display: none;
}

.page-scrollbar {
  position: fixed;
  z-index: 100;
  top: 24px;
  right: 8px;
  bottom: 24px;
  width: 16px;
  border-radius: 999px;
  background: var(--paper-deep);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--rule) 70%, transparent);
  touch-action: none;
}

.page-scrollbar-thumb {
  position: absolute;
  top: 0;
  right: 3px;
  left: 3px;
  min-height: 48px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 82%, var(--muted));
  cursor: grab;
}

.page-scrollbar-thumb:hover,
.page-scrollbar-thumb:focus-visible {
  background: var(--accent);
}

.page-scrollbar-thumb:active {
  cursor: grabbing;
}

.page-scrollbar-thumb:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -6px;
}

.page-scrollbar[hidden] {
  display: none;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-content);
  font-size: 19px;
  line-height: 1.67;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--selection);
  color: #111;
}

a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, var(--accent) 70%, transparent);
  text-underline-offset: 0.16em;
  text-decoration-thickness: 0.06em;
}

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

.visual-rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  height: 100dvh;
  overflow: hidden;
  background: #cca300;
  border-right: 1px solid rgba(25, 26, 24, 0.14);
}

.visual-rail::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset -20px 0 34px -30px rgba(0, 0, 0, 0.55);
}

.visual-rail img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 50% 48%;
}

.page-shell {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: 0 clamp(28px, 5vw, 88px);
}

.site-header {
  width: min(100%, 74rem);
  min-height: 94px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  font-family: var(--font-accent);
  font-size: clamp(1.45rem, 1.9vw, 1.85rem);
  font-weight: 400;
  line-height: 1;
  text-decoration: none;
  letter-spacing: -0.035em;
  text-transform: lowercase;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(16px, 2.2vw, 30px);
  font-family: var(--font-accent);
  font-size: 0.9rem;
  font-weight: 400;
}

.site-nav a {
  color: var(--ink);
  text-decoration: none;
}

.site-nav a:hover { color: var(--ink); }

.theme-picker {
  position: relative;
  line-height: 1;
}

.theme-picker summary {
  display: grid;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  border: 0;
  place-items: center;
  list-style: none;
  cursor: pointer;
}

.theme-picker summary::-webkit-details-marker {
  display: none;
}

.theme-current,
.theme-option {
  border-radius: 50%;
}

.theme-current {
  width: 0.72rem;
  height: 0.72rem;
  background: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 24%, transparent);
}

.theme-options {
  position: absolute;
  z-index: 10;
  top: calc(100% + 0.55rem);
  right: 0;
  display: none;
  gap: 0.7rem;
  padding: 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--paper);
  box-shadow: 0 12px 28px rgba(25, 26, 24, 0.12);
}

.theme-picker[open] .theme-options {
  display: flex;
}

.theme-option {
  width: 1rem;
  height: 1rem;
  padding: 0;
  border: 0;
  background: var(--swatch);
  cursor: pointer;
}

.theme-option[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--ink);
}

.theme-option:focus-visible,
.theme-picker summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

main {
  width: min(100%, 74rem);
}

.post {
  width: min(100%, var(--measure));
  padding: clamp(56px, 7vw, 104px) 0 70px;
  font-family: var(--font-content);
  font-size: 20px;
  font-weight: 200;
}

.post-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.8rem 0;
  margin-bottom: 2.4rem;
}

.post-header h1 {
  grid-column: 1 / -1;
}

h1, h2 {
  font-family: var(--font-heading);
  font-weight: 300;
  text-wrap: balance;
}

h1::selection,
h2::selection {
  background: var(--heading-selection);
  color: var(--ink);
}

h1 {
  max-width: 13ch;
  margin: 0;
  font-size: clamp(2.4rem, 4.5vw, 4.25rem);
  font-weight: 500;
  line-height: 1.16;
  letter-spacing: -0.02em;
}

.post-meta {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: flex-end;
  justify-self: end;
  color: var(--muted);
  font-family: var(--font-accent);
  font-size: 0.95rem;
  font-weight: 400;
  text-align: right;
}

.post-meta a {
  color: var(--muted);
}

.post-categories {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem 0.7rem;
}

.post-category {
  font-size: 1.1rem;
  font-weight: 400;
}

.post-meta .post-category {
  color: var(--accent);
}

.post p,
.post li {
  max-width: 68ch;
}

.post p {
  margin: 1.25rem 0;
}

h2 {
  margin: 3.4rem 0 1rem;
  font-size: clamp(1.75rem, 2.7vw, 2.3rem);
  font-weight: 400;
  line-height: 1.22;
  letter-spacing: -0.025em;
}

.note,
blockquote {
  margin: 2rem 0;
  padding: 1rem 1.15rem 1rem 1.3rem;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 72%, var(--paper));
  font-size: 0.97em;
}

.note strong,
blockquote strong {
  font-weight: 600;
}

blockquote p {
  margin: 0;
}

.post figure {
  margin: 2.5rem 0;
  text-align: center;
}

.post figure img,
.post > img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 75vh;
  height: auto;
  margin: 2rem auto;
  object-fit: contain;
}

.post figure img {
  margin-bottom: 0.75rem;
}

.post figcaption {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  margin: 1.7rem 0 2rem;
  padding: 1.35rem 1.45rem;
  border-radius: 2px;
  background: var(--code-bg);
  color: var(--code-fg);
  box-shadow: 0 10px 30px rgba(44, 35, 20, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 400;
  line-height: 1.6;
  scrollbar-color: color-mix(in srgb, var(--code-fg) 55%, transparent) var(--code-bg);
  tab-size: 2;
}

pre::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

pre::-webkit-scrollbar-track,
pre::-webkit-scrollbar-corner {
  background: var(--code-bg);
}

pre::-webkit-scrollbar-track:horizontal {
  margin-inline: 12px;
}

pre::-webkit-scrollbar-thumb {
  border-color: var(--code-bg);
  background: color-mix(in srgb, var(--code-fg) 55%, transparent);
}

pre::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--code-fg) 78%, transparent);
}

.code-block {
  overflow: hidden;
  margin: 1.7rem 0 2rem;
  border-radius: 2px;
  background: var(--code-bg);
  box-shadow: 0 10px 30px rgba(44, 35, 20, 0.08);
}

.code-block pre {
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.6rem;
  padding: 0.45rem 0.75rem 0.45rem 1.1rem;
  border-bottom: 1px solid rgba(241, 234, 223, 0.12);
  color: #c8c0b4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.code-copy {
  padding: 0.35rem 0.55rem;
  border: 1px solid rgba(241, 234, 223, 0.22);
  border-radius: 2px;
  color: var(--code-fg);
  background: transparent;
  font: inherit;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-transform: none;
}

.code-copy:hover,
.code-copy:focus-visible {
  border-color: var(--code-fg);
  outline: none;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.82em;
}

pre code {
  display: block;
  font-size: 0.82em;
  font-weight: 400;
}

p code,
li code {
  padding: 0.06em 0.28em;
  border-radius: 3px;
  background: var(--paper-deep);
  color: #342d26;
}

.code-comment { color: #b8b0a5; }

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: #aaa297; }

.token.punctuation { color: #ddd5ca; }

.token.namespace { opacity: 0.8; }

.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted { color: #ef8d72; }

.token.boolean,
.token.number { color: #e8c76d; }

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted { color: #afd18d; }

.token.operator,
.token.entity,
.token.url { color: #dec08a; }

.token.atrule,
.token.attr-value,
.token.keyword { color: #d6a8e5; }

.token.function,
.token.class-name { color: #8fc9d4; }

.token.regex,
.token.important,
.token.variable { color: #efb17a; }

.token.important,
.token.bold { font-weight: 700; }

.token.italic { font-style: italic; }

.token.entity { cursor: help; }

.katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0;
}

ul {
  padding-left: 1.15rem;
}

li {
  margin: 0.42rem 0;
  padding-left: 0.15rem;
}

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

.post-footer {
  margin-top: 4.1rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}

.post-footer h2 {
  margin: 0 0 1rem;
}

.recent-notes {
  display: grid;
  gap: 0.75rem;
}

.recent-notes a {
  color: var(--ink);
  font-size: 1.15rem;
}

.writing-list {
  display: grid;
  gap: 2.5rem;
  margin-top: 3rem;
}

.writing-list article {
  border-top: 1px solid var(--rule);
  padding-top: 1.25rem;
}

.writing-list time {
  color: var(--muted);
  font-family: var(--font-accent);
  font-size: 0.9rem;
}

.writing-list h2 {
  margin: 0.45rem 0 1rem;
}

.writing-list h2 a {
  text-decoration: none;
}

.writing-list p {
  margin: 0;
}

.site-footer {
  width: min(100%, 74rem);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 24px 0 36px;
  border-top: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--font-accent);
  font-size: 0.9rem;
  font-weight: 400;
}

@media (max-width: 900px) {
  :root { --sidebar-width: 0px; }

  .visual-rail {
    position: relative;
    width: 100%;
    height: 220px;
    border-right: 0;
    border-bottom: 1px solid rgba(25, 26, 24, 0.12);
  }

  .visual-rail img {
    object-position: center 34%;
  }

  .page-shell {
    margin-left: 0;
    padding: 0 clamp(20px, 5vw, 48px);
  }

  .site-header {
    min-height: 82px;
  }

  .post {
    padding-top: 58px;
  }
}

@media (max-width: 620px) {
  body { font-size: 18px; }

  .page-scrollbar {
    right: 3px;
    width: 10px;
  }

  .page-scrollbar-thumb {
    right: 2px;
    left: 2px;
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.7rem;
    padding: 22px 0 18px;
  }

  .site-nav {
    gap: 1.2rem;
    font-size: 0.82rem;
  }

  .post {
    padding-top: 45px;
    font-size: 19px;
  }

  h1 {
    font-size: clamp(2.2rem, 11vw, 3.2rem);
  }

  .post-meta {
    font-size: 0.76rem;
  }

  pre {
    margin-left: -10px;
    margin-right: -10px;
    padding: 1.1rem;
  }

  .code-block {
    margin-left: -10px;
    margin-right: -10px;
  }

  .code-block pre {
    margin: 0;
  }

  .site-footer {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
