/* ── Reset & Base ────────────────────────────────────── */

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

:root {
  --bg: #fafaf8;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --accent: #5a6f8a;
  --accent-hover: #475a6f;
  --border: #e0deda;
  --code-bg: #f4f3f1;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --content-width: 720px;
  --page-padding: clamp(1rem, 5vw, 2rem);
}

/* Dark mode via prefers-color-scheme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414;
    --text: #e0e0e0;
    --text-muted: #999;
    --accent: #8aa4c2;
    --accent-hover: #a3bbd6;
    --border: #2a2a2a;
    --code-bg: #1e1e1e;
  }
}

/* Explicit dark/light toggle */
[data-theme="dark"] {
  --bg: #141414;
  --text: #e0e0e0;
  --text-muted: #999;
  --accent: #8aa4c2;
  --accent-hover: #a3bbd6;
  --border: #2a2a2a;
  --code-bg: #1e1e1e;
}

[data-theme="light"] {
  --bg: #fafaf8;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --accent: #5a6f8a;
  --accent-hover: #475a6f;
  --border: #e0deda;
  --code-bg: #f4f3f1;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ── Layout ──────────────────────────────────────────── */

.site-header {
  padding: 0.75rem var(--page-padding);
}

.nav {
  max-width: var(--content-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.15s;
}

.nav-links a:hover {
  color: var(--text);
}

.site-main {
  flex: 1;
  max-width: var(--content-width);
  width: 100%;
  margin: 0 auto;
  padding: 3rem var(--page-padding);
}

/* ── Theme Toggle ────────────────────────────────────── */

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

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

.icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

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

/* ── Back Link ───────────────────────────────────────── */

.back-link {
  display: inline-block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  transition: color 0.15s;
}

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

/* ── Blog Index ──────────────────────────────────────── */

.blog-index h1,
.projects-index h1,
.page-header h1 {
  font-size: clamp(1.8rem, 1.5rem + 1.5vw, 2.5rem);
  font-weight: 700;
  margin-bottom: 2.5rem;
}

.post-list {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.post-entry h2 {
  font-size: clamp(1.2rem, 1rem + 0.75vw, 1.5rem);
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.post-entry h2 a,
.post-entry a {
  color: var(--text);
  text-decoration: none;
}

.post-entry a:hover h2,
.post-entry h2 a:hover {
  color: var(--accent);
}

.post-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.separator {
  color: var(--border);
}

.tag {
  color: var(--accent);
  font-size: 0.85rem;
}

.post-tags {
  margin-left: 0.75rem;
}

.post-tags .tag {
  margin-right: 0.4rem;
}

.post-description {
  color: var(--text-muted);
  line-height: 1.5;
}

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

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

.post-header h1 {
  font-size: clamp(1.8rem, 1.5rem + 1.5vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.6rem;
}

.post-content {
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.1rem);
  line-height: 1.7;
}

.post-content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 2.5rem 0 1rem;
}

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

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

.post-content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s;
}

.post-content a:hover {
  text-decoration-color: var(--accent);
}

.post-content ul,
.post-content ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
}

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

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

.post-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1.25rem;
  margin: 1.5rem 0;
  color: var(--text-muted);
  font-style: italic;
}

.post-content img,
.post-content picture {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 1.5rem 0;
  display: block;
}

.post-content .full-bleed {
  width: 100vw;
  max-width: 100vw;
  margin-left: calc(-1 * var(--page-padding));
  margin-right: calc(-1 * var(--page-padding));
  border-radius: 0;
}

/* Video embeds */

.post-content .video-embed {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  margin: 1.5rem 0;
  border-radius: 4px;
}

.post-content .video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Code */

.post-content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
}

.post-content pre {
  background: var(--code-bg);
  padding: 1.25rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.5rem 0;
  line-height: 1.5;
}

.post-content pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

/* Shiki dual theme support */
.shiki {
  background: var(--code-bg) !important;
  padding: 1.25rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.5rem 0;
}

.shiki code {
  background: none !important;
  padding: 0;
}

html:not([data-theme="dark"]) .shiki .shiki-dark,
html:not([data-theme]) .shiki .shiki-dark {
  display: none;
}

html[data-theme="dark"] .shiki .shiki-light {
  display: none;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .shiki .shiki-light {
    display: none;
  }
  html:not([data-theme="light"]) .shiki .shiki-dark {
    display: inline;
  }
}

/* ── Page ────────────────────────────────────────────── */

.page-content {
  line-height: 1.7;
}

.page-content p {
  margin-bottom: 1.25rem;
}

.page-content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
}

.page-content a:hover {
  text-decoration-color: var(--accent);
}

.page-content picture,
.page-content img {
  max-width: 360px;
  height: auto;
  border-radius: 6px;
  margin: 0 auto 1.5rem;
  display: block;
}

/* ── Projects ────────────────────────────────────────── */

.project-list {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.project-entry {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.project-cover {
  flex-shrink: 0;
  width: 200px;
}

.project-cover img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.project-info h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.project-info a {
  color: var(--text);
  text-decoration: none;
}

.project-info a:hover h2 {
  color: var(--accent);
}

@media (max-width: 600px) {
  .project-entry {
    flex-direction: column;
  }
  .project-cover {
    width: 100%;
  }
}

/* ── HTML Content (scrolly posts) ────────────────────── */

.html-content .post-content {
  max-width: none;
}
