:root {
  --bg: #1a1a1a;
  --panel: #222;
  --border: #383838;
  --border-inner: #2a2a2a;
  --text: #d4d4d4;
  --muted: #8a8a8a;
  --accent: #b388ff;
  --accent-2: #80cbc4;
  --button-bg: #2c2040;
  --button-border: #4a2e7a;
  --code-bg: #161616;
  --sticky-topbar-h: 28px;
  --sticky-site-top: 28px;
  --sticky-post-top: 62px;
  --sticky-toc-top: 168px;
  --sticky-anchor-top: 172px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "MS PGothic", "MS UI Gothic", sans-serif;
  font-size: 13px;
  line-height: 1.6;
  min-height: 100%;
}

/* scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: #3a2a55 #1a1a1a;
}
*::-webkit-scrollbar { width: 4px; height: 4px; }
*::-webkit-scrollbar-track { background: #1a1a1a; }
*::-webkit-scrollbar-thumb { background: #3a2a55; border-radius: 2px; }

/* topbar */
#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #202020;
  border-bottom: 1px solid #3a3a3a;
  padding: 5px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: #666;
  display: flex;
  align-items: center;
  gap: 4px;
}
#topbar a { color: var(--accent); text-decoration: none; }
#topbar a:hover { text-decoration: underline; }
#topbar .sep { color: #444; }
#topbar .current { color: #aaa; }

/* site title */
a.site-title {
  display: block;
  text-decoration: none;
  font-size: 18px;
  color: var(--accent);
  font-weight: bold;
  letter-spacing: 1px;
  margin-top: -8px;
  margin-bottom: 16px;
  padding: 8px 0 6px;
  border-bottom: 1px solid #333;
  position: sticky;
  top: var(--sticky-site-top);
  z-index: 9;
  background: var(--bg);
}
a.site-title:hover { text-decoration: none; }
.site-title .seg { display: inline-block; position: relative; transform-origin: center bottom; }

/* outer layout */
#outer {
  position: relative;
  z-index: 1;
  width: min(1020px, 100% - 24px);
  margin: 20px auto 48px;
}

/* two-column layout (index only) */
#layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
#content { flex: 1; min-width: 0; }
#cal-sidebar { flex: 0 0 178px; }

.post-pin-label {
  font-size: 10px;
  color: #7a6a99;
  margin-bottom: 4px;
  letter-spacing: 0.03em;
}
.post-card-pinned {
  border-left-color: #6a4a9a;
}

/* card base */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.card-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

/* tag pill */
.tag {
  display: inline-block;
  background: var(--button-bg);
  color: var(--accent);
  border: 1px solid var(--button-border);
  font-size: 10px;
  padding: 1px 6px;
  letter-spacing: 0.04em;
}

/* hero */
.hero {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.hero-text {
  flex: 1;
  min-width: 0;
}
.hero h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
  color: var(--accent);
  font-weight: normal;
  letter-spacing: 0.02em;
}
.hero p {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}
.vault-hero-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  opacity: 0.4;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.vault-hero-btn:hover { opacity: 0.9; }
.vault-hero-btn img {
  width: 64px;
  height: 64px;
  display: block;
  filter: brightness(0) saturate(100%) invert(79%) sepia(16%) saturate(906%) hue-rotate(209deg) brightness(96%) contrast(92%);
}
.hero-links {
  margin: 2px 0 2px;
}
.hero-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed rgba(179, 136, 255, 0.45);
}
.hero-link:hover {
  color: #d0b0ff;
  border-bottom-color: rgba(208, 176, 255, 0.9);
}
.hero-sep {
  color: #5c4b7f;
  margin: 0 6px;
}

/* post list */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 11px 13px;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: border-color 140ms ease;
}
.post-card:hover { border-color: #585858; }

.post-card-title {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 3px;
}
.post-card-date {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: 0.03em;
}
.post-card-desc {
  font-size: 12px;
  color: #bcbcbc;
  line-height: 1.45;
}
.post-card-tags {
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* calendar */
#cal-widget {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 12px;
  user-select: none;
}
.cal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.cal-month-label {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: lowercase;
}
.cal-nav {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
  font-family: inherit;
}
.cal-nav:hover { color: var(--accent); }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-dow {
  font-size: 9px;
  color: #555;
  text-align: center;
  padding-bottom: 3px;
  text-transform: lowercase;
}
.cal-day {
  text-align: center;
  font-size: 10px;
  color: #555;
  padding: 3px 1px;
  border-radius: 2px;
  line-height: 1.3;
}
.cal-day.other-month { color: #2e2e2e; }
.cal-day.has-post {
  color: var(--accent);
  background: rgba(179,136,255,0.10);
  cursor: pointer;
}
.cal-day.has-post:hover { background: rgba(179,136,255,0.20); }
.cal-day.today { color: var(--accent-2); font-weight: bold; }
.cal-day.has-post.today {
  color: var(--accent-2);
  background: rgba(128,203,196,0.12);
}

/* post page */
.post-header {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin-bottom: 10px;
  position: sticky;
  top: var(--sticky-post-top);
  z-index: 8;
  isolation: isolate;
  transition: padding 150ms ease, border-color 150ms ease;
}
.post-page #site-title,
.post-page .post-header {
  position: sticky;
  background: var(--bg);
}
.post-page #site-title {
  isolation: isolate;
  overflow: hidden;
}
.post-page #site-title::after,
.post-page .post-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -10px;
  height: 10px;
  background: linear-gradient(to bottom, var(--bg), rgba(26, 26, 26, 0));
  pointer-events: none;
}
.post-page .post-header::before {
  content: "";
  position: absolute;
  left: -1px;
  right: -1px;
  top: -10px;
  height: 10px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  pointer-events: none;
}
.post-header h1 {
  margin: 0 0 5px;
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  color: var(--accent);
  font-weight: normal;
  letter-spacing: 0.02em;
  transition: font-size 150ms ease, margin-bottom 150ms ease;
}
.post-header .post-meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: 0.04em;
  transition: font-size 150ms ease, margin-bottom 150ms ease;
}
.post-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}
.post-stat {
  display: inline-block;
  font-size: 9.5px;
  color: #a78de0;
  background: rgba(179, 136, 255, 0.11);
  border: 1px solid rgba(179, 136, 255, 0.28);
  padding: 1px 6px;
  letter-spacing: 0.04em;
  line-height: 1.45;
}
.post-header .post-desc {
  font-size: 12px;
  color: #bcbcbc;
  line-height: 1.5;
  max-height: 90px;
  opacity: 1;
  transition: max-height 170ms ease, opacity 140ms ease, margin 140ms ease;
}
.post-header .post-card-tags {
  margin-top: 7px;
  max-height: 40px;
  opacity: 1;
  transition: max-height 170ms ease, opacity 140ms ease, margin 140ms ease;
  overflow: hidden;
}
.post-progress {
  margin-top: 9px;
  height: 3px;
  background: #252525;
  border: 1px solid #343434;
  border-radius: 2px;
  overflow: hidden;
}
.post-progress > span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #8f6cd8 0%, #b388ff 58%, #c8afff 100%);
  box-shadow: 0 0 6px rgba(179, 136, 255, 0.28);
  transition: width 80ms linear;
}
.post-header.is-compact {
  padding: 8px 12px;
  border-color: #424242;
}
.post-header.is-compact h1 {
  font-size: clamp(1.05rem, 2.35vw, 1.28rem);
  margin-bottom: 2px;
}
.post-header.is-compact .post-meta {
  font-size: 10px;
  margin-bottom: 1px;
}
.post-header.is-compact .post-stats {
  margin-bottom: 2px;
  gap: 3px;
}
.post-header.is-compact .post-stat {
  font-size: 9px;
  padding: 0 5px;
}
.post-header.is-compact .post-desc,
.post-header.is-compact .post-card-tags {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

#post-layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
#post-layout .prose {
  flex: 1;
  min-width: 0;
}
.toc-sidebar {
  flex: 0 0 192px;
  position: sticky;
  top: var(--sticky-toc-top);
  max-height: calc(100vh - var(--sticky-toc-top) - 12px);
  overflow: hidden;
  transition: top 140ms ease, max-height 140ms ease;
}
.toc-card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 9px 10px;
  max-height: inherit;
  overflow-y: auto;
}
.toc-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #777;
  margin-bottom: 6px;
}
.toc-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toc-link {
  text-decoration: none;
  color: #8f8f8f;
  font-size: 11px;
  line-height: 1.35;
  border-left: 1px solid #343434;
  padding: 2px 0 2px 7px;
  border-radius: 0 2px 2px 0;
}
.toc-link:hover { color: var(--accent); border-left-color: #5b4782; }
.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(179, 136, 255, 0.07);
}
.toc-link.lvl-3 {
  font-size: 10px;
  color: #777;
  margin-left: 7px;
}

.toc-mobile {
  display: none;
  margin-bottom: 8px;
}
.toc-mobile details {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 7px 10px;
}
.toc-mobile summary {
  list-style: none;
  cursor: pointer;
  color: #999;
  font-size: 11px;
  letter-spacing: 0.03em;
}
.toc-mobile summary::-webkit-details-marker { display: none; }
.toc-mobile summary::after {
  content: '▾';
  float: right;
  color: #666;
}
.toc-mobile details[open] summary::after { content: '▴'; }
.toc-mobile .toc-list { margin-top: 6px; }

@media (min-width: 641px) {
  .post-page .post-header {
    padding: 11px 13px;
    margin-bottom: 8px;
  }
  .post-page .post-header h1 {
    font-size: clamp(1.14rem, 2.4vw, 1.48rem);
    line-height: 1.3;
    margin-bottom: 4px;
  }
  .post-page .post-header .post-meta {
    font-size: 10.5px;
    margin-bottom: 4px;
  }
  .post-page .post-stats {
    gap: 4px;
    margin-bottom: 5px;
  }
  .post-page .post-stat {
    font-size: 9px;
    padding: 0 5px;
  }
  .post-page .post-header .post-desc {
    font-size: 12px;
    line-height: 1.45;
    max-height: 2.9em;
  }
  .post-page .post-progress {
    margin-top: 7px;
    height: 3px;
  }
}

/* prose */
.prose {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 18px 20px;
  line-height: 1.75;
  font-size: 13px;
  color: var(--text);
}

.prose h2 {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: normal;
  margin: 26px 0 9px;
  padding-bottom: 5px;
  border-bottom: 1px solid #2e2e2e;
  letter-spacing: 0.02em;
}
.prose h2:first-child { margin-top: 0; }
.prose h3 {
  font-size: 0.95rem;
  color: var(--accent-2);
  font-weight: normal;
  margin: 18px 0 7px;
}
.prose h2,
.prose h3 { scroll-margin-top: var(--sticky-anchor-top); }
.prose h4 {
  font-size: 0.88rem;
  color: #aaa;
  font-weight: normal;
  margin: 14px 0 5px;
  text-transform: lowercase;
  letter-spacing: 0.06em;
}
.prose p { margin: 0 0 11px; }
.prose p:last-child { margin-bottom: 0; }
.prose a { color: var(--accent); text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose strong { color: #e0e0e0; }
.prose em { color: #c0c0c0; }
.prose hr { border: none; border-top: 1px solid #2e2e2e; margin: 22px 0; }
.prose ul, .prose ol { margin: 0 0 11px 20px; padding: 0; }
.prose li { margin-bottom: 4px; line-height: 1.65; }
.prose blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding: 3px 12px;
  color: var(--muted);
  font-size: 12px;
}
.prose code {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 11.5px;
  background: var(--code-bg);
  color: #c8c8c8;
  padding: 1px 5px;
  border: 1px solid var(--border-inner);
}
.prose pre {
  background: var(--code-bg);
  border: 1px solid #2c2c2c;
  padding: 11px 13px;
  overflow-x: auto;
  margin: 12px 0;
  line-height: 1.5;
}
.prose pre code { background: none; border: none; padding: 0; font-size: 11.5px; color: #c8c8c8; }

/* tables */
.prose table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12px; }
.prose th {
  background: #1e1e2a;
  color: var(--accent);
  font-weight: normal;
  text-align: left;
  padding: 5px 9px;
  border: 1px solid #333;
  letter-spacing: 0.04em;
}
.prose td { padding: 4px 9px; border: 1px solid var(--border-inner); color: #c0c0c0; }
.prose tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* image display widget */
.image-display {
  margin: 10px 0 12px;
  padding: 8px;
  background: #202020;
  border: 1px solid #3a3a3a;
}
.image-display-head {
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.image-display-title {
  color: #9a82cf;
  text-transform: lowercase;
  letter-spacing: 0.07em;
  font-size: 10px;
  white-space: nowrap;
}
.image-display-active-caption {
  color: #8f8f8f;
  font-size: 10px;
  line-height: 1.4;
  text-align: right;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-display-viewer {
  background: #171717;
  border: 1px solid #3a2a55;
  padding: 6px;
  margin-bottom: 6px;
}
.image-display-focus {
  overflow: hidden;
  border: 1px solid #4a2e7a;
  background: #111;
}
.image-display-viewer img {
  display: block;
  width: 100%;
  max-height: min(46vh, 360px);
  object-fit: contain;
  border: 0;
  background: transparent;
  transform-origin: 50% 50%;
  transform: scale(1);
  cursor: zoom-in;
  transition: transform 140ms ease;
}
.image-display-viewer.is-zoom-pan img {
  transform: scale(2.1);
  cursor: zoom-out;
}
.image-display-caption {
  margin-top: 4px;
  color: #8f8f8f;
  font-size: 10px;
  line-height: 1.4;
}
.image-display-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 5px;
}
.image-display-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid #4a2e7a;
  background: #171717;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.image-display-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 190ms ease;
}
.image-display-thumb:hover,
.image-display-thumb:focus-visible {
  border-color: #b388ff;
  box-shadow: 0 0 0 1px rgba(179, 136, 255, 0.28) inset;
}
.image-display-thumb:hover img,
.image-display-thumb:focus-visible img {
  transform: scale(1.18);
}
.image-display-thumb.active {
  border-color: #cdb7ff;
  box-shadow: 0 0 0 1px rgba(205, 183, 255, 0.42) inset;
}

/* KaTeX */
.katex-display { margin: 14px 0; overflow-x: auto; padding: 2px 0; }

/* footer */
footer {
  text-align: center;
  color: #555;
  font-size: 11px;
  padding: 16px 10px 24px;
  position: relative;
  z-index: 1;
}

/* responsive */
@media (max-width: 640px) {
  #outer { width: calc(100% - 16px); margin: 12px auto 24px; }
  #layout { flex-direction: column; }
  #cal-sidebar { flex: none; width: 100%; }
  .site-title {
    font-size: 15px;
    margin-bottom: 12px;
    position: static !important;
    top: auto;
  }
  .prose { padding: 13px 13px; }
  .post-header {
    padding: 10px 12px;
    position: sticky;
    top: calc(var(--sticky-post-top) + 2px);
    z-index: 8;
    margin-bottom: 8px;
  }
  .post-header h1 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .post-stats {
    gap: 3px;
    margin-bottom: 5px;
  }
  .post-stat {
    font-size: 9px;
    padding: 0 5px;
    letter-spacing: 0.02em;
  }
  .post-progress {
    margin-top: 7px;
    height: 4px;
    border-radius: 3px;
  }
  .post-header.is-compact {
    padding: 7px 10px;
  }
  .post-header.is-compact h1 {
    font-size: 0.98rem;
  }
  #post-layout {
    display: block;
  }
  .toc-sidebar { display: none !important; }
  .toc-mobile {
    display: block;
    position: static;
    top: auto;
    z-index: auto;
    margin-bottom: 10px;
  }
  .toc-mobile details {
    padding: 6px 9px;
  }
  .image-display {
    padding: 6px;
  }
  .image-display-head {
    display: block;
    margin-bottom: 5px;
  }
  .image-display-active-caption {
    margin-top: 2px;
    text-align: left;
  }
  .image-display-viewer img {
    max-height: 42vh;
  }
  .image-display-strip {
    grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
    gap: 4px;
  }
}
