/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Theme Variables */
:root {
  --bg: #ffffff;
  --bg-secondary: #f6f8fa;
  --text: #1f2328;
  --text-secondary: #656d76;
  --border: #d0d7de;
  --link: #0969da;
  --tag-post: #ddf4ff;
  --tag-post-text: #0969da;
  --tag-music: #dafbe1;
  --tag-music-text: #1a7f37;
  --tag-pdf: #fff8c5;
  --tag-pdf-text: #9a6700;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --border: #30363d;
  --link: #58a6ff;
  --tag-post: #388bfd26;
  --tag-post-text: #58a6ff;
  --tag-music: #238636;
  --tag-music-text: #3fb950;
  --tag-pdf: #9e6a03;
  --tag-pdf-text: #d29922;
}

/* Typography */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout */
header, main, footer {
  max-width: 800px;
  margin: 0 auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

/* Header */
header {
  padding-top: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

#theme-toggle:hover {
  background-color: var(--bg-secondary);
}

.icon-sun, .icon-moon {
  display: none;
}

[data-theme="light"] .icon-moon,
:root:not([data-theme]) .icon-moon {
  display: inline;
}

[data-theme="dark"] .icon-sun {
  display: inline;
}

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

/* Sections */
section {
  margin-bottom: 3rem;
}

section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Tags */
.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.15rem 0.5rem;
  border-radius: 2rem;
  text-transform: lowercase;
}

.tag-post {
  background-color: var(--tag-post);
  color: var(--tag-post-text);
}

.tag-music {
  background-color: var(--tag-music);
  color: var(--tag-music-text);
}

.tag-pdf {
  background-color: var(--tag-pdf);
  color: var(--tag-pdf-text);
}

/* Pinned Grid */
.pinned-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.pinned-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pinned-card h3 {
  font-size: 1rem;
  font-weight: 600;
}

.pinned-card h3 a {
  color: var(--text);
}

.pinned-card h3 a:hover {
  color: var(--link);
}

.pinned-card p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  flex-grow: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pinned-card time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Timeline */
.timeline-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.timeline-item:last-child {
  border-bottom: none;
}

.timeline-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.timeline-meta time {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.timeline-item h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.timeline-item p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Footer */
footer {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

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

footer a:hover {
  color: var(--link);
}

/* Responsive */
@media (max-width: 480px) {
  .pinned-grid {
    grid-template-columns: 1fr;
  }

  header h1 {
    font-size: 1.25rem;
  }
}


/* --- BLOG POST STYLES --- */

/* Navigation */
.post-nav {
  margin-bottom: 2rem;
}

.post-nav a {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.post-nav a:hover {
  color: var(--link);
}

/* Post Header */
.post-header {
  padding-left: 0px;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.post-header h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}

/* Post Content Typography 
   Since the global reset removes margins, we must add them back 
   specifically for the blog content to ensure readability. */

.post-content {
  font-size: 1.05rem; /* Slightly larger for reading */
}

.post-content p {
  margin-bottom: 1.5rem;
}

.post-content .lead {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.post-content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.post-content h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.post-content ul, 
.post-content ol {
  margin-bottom: 1.5rem;
  padding-left: 2rem; /* Bring back bullet indentation */
}

.post-content li {
  margin-bottom: 0.5rem;
}

.post-content blockquote {
  border-left: 4px solid var(--border);
  padding-left: 1rem;
  margin-left: 0;
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
  font-style: italic;
}

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
}

/* Code Blocks */
.post-content pre {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.post-content code {
  font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
  font-size: 0.85em;
  background-color: var(--bg-secondary);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

.post-content pre code {
  background-color: transparent;
  padding: 0;
  font-size: 0.9em;
  color: var(--text);
}

[data-theme="dark"] .post-content code,
[data-theme="dark"] .post-content pre code {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-weight: 450;
}

/* --- TABLE OF CONTENTS --- */

.toc {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}

.toc-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.toc > ol {
  list-style: none;
  padding-left: 0;
  margin: 0;
  counter-reset: toc-counter;
}

.toc > ol > li {
  counter-increment: toc-counter;
  margin-bottom: 0.5rem;
  transition: transform 0.15s ease;
}

.toc > ol > li::before {
  content: counter(toc-counter) ".";
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  margin-right: 0.5rem;
}

.toc > ol > li:hover {
  transform: translateX(4px);
}

.toc a {
  color: var(--text);
  font-size: 0.95rem;
}

.toc a:hover {
  color: var(--link);
}

.toc .toc-sub {
  list-style: none;
  padding-left: 1.5rem;
  margin-top: 0.5rem;
}

.toc .toc-sub li {
  margin-bottom: 0.35rem;
  transition: transform 0.15s ease;
}

.toc .toc-sub li::before {
  content: "—";
  color: var(--text-secondary);
  margin-right: 0.5rem;
}

.toc .toc-sub li:hover {
  transform: translateX(4px);
}

.toc .toc-sub a {
  font-size: 0.875rem;
}

/* --- ENHANCED CODE BLOCKS --- */

.code-block {
  position: relative;
  margin-bottom: 1.5rem;
  transition: box-shadow 0.2s ease;
}

.code-block:hover {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .code-block:hover {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 0.5rem 1rem;
  font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, monospace;
  font-size: 0.8rem;
}

.code-block-filename {
  color: var(--text);
  font-weight: 500;
}

.code-block-lang {
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

[data-theme="dark"] .code-block-header,
[data-theme="dark"] .code-block pre code {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-weight: 450;
}

.code-block pre,
.code-block pre[class*="language-"] {
  margin: 0;
  border-radius: 0 0 6px 6px;
  border-top: none;
}

.code-block .copy-btn {
  position: absolute;
  top: 2.75rem;
  right: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, background-color 0.15s ease;
  font-family: inherit;
}

.code-block:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

.copy-btn.copied {
  color: var(--tag-music-text);
}

/* --- PRISM.JS THEME OVERRIDES --- */

/* Reset Prism's default background */
.post-content pre[class*="language-"] {
  background-color: var(--bg-secondary);
}

.post-content code[class*="language-"] {
  color: var(--text);
  text-shadow: none;
}

/* Light theme tokens */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--text-secondary);
}

.token.punctuation {
  color: var(--text);
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol {
  color: #0550ae;
}

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

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: #cf222e;
}

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

.token.function,
.token.class-name {
  color: #8250df;
}

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

/* Dark theme tokens */
[data-theme="dark"] .token.comment,
[data-theme="dark"] .token.prolog,
[data-theme="dark"] .token.doctype,
[data-theme="dark"] .token.cdata {
  color: #8b949e;
}

[data-theme="dark"] .token.punctuation {
  color: var(--text);
}

[data-theme="dark"] .token.property,
[data-theme="dark"] .token.tag,
[data-theme="dark"] .token.boolean,
[data-theme="dark"] .token.number,
[data-theme="dark"] .token.constant,
[data-theme="dark"] .token.symbol {
  color: #79c0ff;
}

[data-theme="dark"] .token.selector,
[data-theme="dark"] .token.attr-name,
[data-theme="dark"] .token.string,
[data-theme="dark"] .token.char,
[data-theme="dark"] .token.builtin {
  color: #a5d6ff;
}

[data-theme="dark"] .token.operator,
[data-theme="dark"] .token.entity,
[data-theme="dark"] .token.url,
[data-theme="dark"] .language-css .token.string,
[data-theme="dark"] .style .token.string {
  color: #ff7b72;
}

[data-theme="dark"] .token.atrule,
[data-theme="dark"] .token.attr-value,
[data-theme="dark"] .token.keyword {
  color: #ff7b72;
}

[data-theme="dark"] .token.function,
[data-theme="dark"] .token.class-name {
  color: #d2a8ff;
}

[data-theme="dark"] .token.regex,
[data-theme="dark"] .token.important,
[data-theme="dark"] .token.variable {
  color: #ffa657;
}

/* --- MERMAID DIAGRAMS --- */

.mermaid {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* --- ANIMATIONS --- */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.post-content > h2,
.post-content > h3 {
  animation: fadeInUp 0.4s ease-out;
}

.post-content > p,
.post-content > ul,
.post-content > ol,
.post-content > blockquote,
.post-content > .code-block,
.post-content > .mermaid,
.post-content > .toc {
  animation: fadeInUp 0.3s ease-out;
}

/* Smooth scroll for TOC anchor links */
html {
  scroll-behavior: smooth;
}

/* Animated link underlines */
.post-content a:not(.toc a) {
  position: relative;
}

.post-content a:not(.toc a)::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1px;
  background-color: var(--link);
  transition: width 0.2s ease;
}

.post-content a:not(.toc a):hover::after {
  width: 100%;
}

/* --- RESPONSIVE ADJUSTMENTS --- */

@media (max-width: 480px) {
  .toc {
    padding: 1rem;
  }

  .code-block-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .mermaid {
    padding: 1rem;
  }

  .code-block .copy-btn {
    top: 3.25rem;
  }
}