*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a1a;
  --surface: #212121;
  --surface2: #2a2a2a;
  --text: #919191;
  --text-bright: #c0c0c0;
  --text-muted: #555;
  --border: #2d2d2d;
  --border2: #383838;
  --accent: #888;
  --code-bg: #161616;
  --tag-bg: #252525;
  --hl-theme: url("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark-dimmed.min.css");
}

[data-theme="light"] {
  --bg: #d8d8d8;
  --surface: #d0d0d0;
  --surface2: #c8c8c8;
  --text: #3d3d3d;
  --text-bright: #1a1a1a;
  --text-muted: #888;
  --border: #bfbfbf;
  --border2: #adadad;
  --accent: #666;
  --code-bg: #e4e4e4;
  --tag-bg: #c8c8c8;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
}

/* ── Header ─────────────────────────────────────── */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2rem 2rem 1.5rem;
  max-width: 740px;
  margin: 0 auto;
  width: 100%;
}

.site-title {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  font-weight: 600;
  text-transform: uppercase;
}

.site-title:hover { color: var(--text); }

.theme-toggle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--surface2);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover { border-color: var(--accent); }

/* ── Main ────────────────────────────────────────── */

#app {
  flex: 1;
  max-width: 740px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
  width: 100%;
}

/* ── Post List ───────────────────────────────────── */

.post-list { list-style: none; }

.post-list-item {
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--border);
}

.post-list-item:first-child { border-top: 1px solid var(--border); }

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

.post-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
}

.post-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.post-tag {
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--tag-bg);
  padding: 0.15em 0.55em;
  border-radius: 2px;
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.post-list-title {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
}

.post-list-title a {
  color: var(--text-bright);
  text-decoration: none;
}

.post-list-title a:hover { color: var(--text); text-decoration: underline; text-decoration-color: var(--border2); }

.post-excerpt {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.6;
}

.post-read-more {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.05em;
}

.post-read-more:hover { color: var(--text); }

.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 3rem 0;
  text-align: center;
  letter-spacing: 0.05em;
}

/* ── Single Post ─────────────────────────────────── */

.post-header { margin-bottom: 2.5rem; }

.post-back {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.08em;
  margin-bottom: 1.5rem;
}

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

.post-title {
  font-size: 1.6rem;
  font-weight: 500;
  color: var(--text-bright);
  line-height: 1.3;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── Post Body (rendered markdown) ──────────────── */

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

.post-body h1,
.post-body h2,
.post-body h3,
.post-body h4 {
  color: var(--text-bright);
  font-weight: 500;
  margin: 2rem 0 0.75rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.post-body h1 { font-size: 1.4rem; }
.post-body h2 { font-size: 1.15rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.post-body h3 { font-size: 1rem; }
.post-body h4 { font-size: 0.9rem; color: var(--text); }

.post-body p { margin: 1rem 0; }
.post-body p:first-child { margin-top: 0; }

.post-body a { color: var(--text-bright); text-decoration: underline; text-decoration-color: var(--border2); }
.post-body a:hover { text-decoration-color: var(--accent); }

.post-body strong { color: var(--text-bright); font-weight: 600; }
.post-body em { font-style: italic; }

.post-body ul,
.post-body ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.post-body li { margin: 0.3rem 0; }

.post-body blockquote {
  border-left: 2px solid var(--border2);
  margin: 1.5rem 0;
  padding: 0.25rem 1.25rem;
  color: var(--text-muted);
  font-style: italic;
}

.post-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.88rem;
}

.post-body th,
.post-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}

.post-body th {
  background: var(--surface2);
  color: var(--text-bright);
  font-weight: 500;
}

.post-body img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 2px;
  margin: 1.5rem auto;
  cursor: zoom-in;
}

/* ── Code ────────────────────────────────────────── */

.post-body code {
  font-family: 'SFMono-Regular', 'Fira Code', Consolas, 'Liberation Mono', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  color: var(--text-bright);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.post-body pre {
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  position: relative;
}

.post-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.83rem;
  line-height: 1.65;
  color: inherit;
}

.code-block-wrapper { position: relative; }

.code-copy-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text-muted);
  font-size: 0.65rem;
  padding: 0.2em 0.6em;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 0.05em;
  font-family: inherit;
  transition: color 0.15s;
  z-index: 1;
}

.code-copy-btn:hover { color: var(--text); }

/* ── Embeds ──────────────────────────────────────── */

.embed-wrapper {
  position: relative;
  width: 100%;
  margin: 1.5rem 0;
}

.embed-youtube,
.embed-vimeo {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  background: var(--surface2);
  border-radius: 3px;
}

.embed-youtube iframe,
.embed-vimeo iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

.embed-soundcloud iframe {
  width: 100%;
  border: none;
  display: block;
  border-radius: 3px;
}

.embed-generic iframe {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 3px;
  display: block;
}

/* ── Gallery ─────────────────────────────────────── */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.5rem;
  margin: 1.5rem 0;
}

.gallery-grid img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  cursor: zoom-in;
  margin: 0;
  border-radius: 2px;
  transition: opacity 0.15s;
}

.gallery-grid img:hover { opacity: 0.85; }

/* ── Lightbox ────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 1000;
  padding: 2rem;
  cursor: zoom-out;
}

.lightbox[hidden] { display: none !important; }

.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 2px;
  cursor: default;
}

.lightbox-caption {
  color: #777;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.lightbox-close {
  position: fixed;
  top: 1.25rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: #666;
  font-size: 1.75rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

.lightbox-close:hover { color: #aaa; }

/* ── Footer ──────────────────────────────────────── */

.site-footer {
  max-width: 740px;
  margin: 0 auto;
  padding: 1rem 2rem 1.5rem;
  width: 100%;
  text-align: right;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
}

.site-footer a:hover { color: var(--text); }

/* ── Loading / Error ─────────────────────────────── */

.loading {
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 3rem 0;
  letter-spacing: 0.08em;
}

.error-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 2rem 0;
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 600px) {
  .site-header { padding: 1.5rem 1.25rem 1rem; }
  #app { padding: 0 1.25rem 3rem; }
  .post-title { font-size: 1.3rem; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .gallery-grid img { height: 120px; }
}

/* ── highlight.js theme swap ─────────────────────── */

[data-theme="light"] #hl-theme { }
