*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

:root {
  --sidebar-width: 200px;
  --bg: #F4F8F4;
  --text: #1a1a1a;
  --text-muted: #888;
  --nav-active: #1a1a1a;
  --nav-inactive: #aaa;
  --border: #e8e8e4;
  --link: #0a9e80;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131311;
    --text: #e0e0dc;
    --text-muted: #5a5a56;
    --nav-active: #e0e0dc;
    --nav-inactive: #4a4a46;
    --border: #242420;
    --link: #4ecdb8;
  }
}

[data-theme="dark"] {
  --bg: #131311;
  --text: #e0e0dc;
  --text-muted: #5a5a56;
  --nav-active: #e0e0dc;
  --nav-inactive: #4a4a46;
  --border: #242420;
  --link: #4ecdb8;
}

[data-theme="light"] {
  --bg: #F4F8F4;
  --text: #1a1a1a;
  --text-muted: #888;
  --nav-active: #1a1a1a;
  --nav-inactive: #aaa;
  --border: #e8e8e4;
  --link: #0a9e80;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
}

/* ── Layout ── */

.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */

.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  padding: 32px 20px 40px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-identity { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.sidebar-avatar { width: 64px; height: 64px; object-fit: contain; display: block; }
.sidebar-name { font-size: 13px; font-weight: 600; letter-spacing: 0.01em; color: var(--text); }
.sidebar-tagline { font-size: 11px; color: var(--text-muted); line-height: 1.5; margin-top: -6px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--nav-inactive);
  padding: 5px 0;
  transition: color 0.12s;
}
.sidebar-nav a:hover, .sidebar-nav a.active { color: var(--nav-active); }

.sidebar-recent {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-recent-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.sidebar-recent-link {
  font-size: 11px;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  border-bottom: 1px solid transparent;
  transition: border-color 0.1s;
}
.sidebar-recent-link:hover { border-bottom-color: var(--text); }

.sidebar-best {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-best:not(:empty) + .sidebar-recent { margin-top: 10px; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.sidebar-footer a { color: var(--text-muted); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.1s; }
.sidebar-footer a:hover { border-bottom-color: var(--text-muted); }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  width: fit-content;
  transition: border-color 0.15s;
}
.theme-toggle:hover { border-color: var(--text-muted); }
.theme-toggle span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.theme-toggle span.active {
  background: var(--text);
  color: var(--bg);
}
.sidebar-footer .theme-toggle { margin-bottom: 6px; }

.mobile-header-controls { display: flex; align-items: center; gap: 12px; }

/* ── Main content ── */

.main {
  flex: 1;
  padding: 52px 56px 80px 52px;
  max-width: 680px;
}

.page-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 40px;
}

/* ── Mobile (hidden on desktop) ── */

.mobile-header { display: none; }
.mobile-nav { display: none; }
.mobile-footer { display: none; }

/* ── Responsive ── */

@media (max-width: 640px) {
  .layout { flex-direction: column; min-height: 100vh; }
  .sidebar { display: none; }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
  }

  .mobile-identity { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
  .mobile-identity img { width: 40px; height: 40px; object-fit: contain; }
  .mobile-identity-text { display: flex; flex-direction: column; gap: 1px; }
  .mobile-identity-text .sidebar-name { font-size: 13px; }
  .mobile-identity-text .sidebar-tagline { margin-top: 0; }

  .hamburger { background: none; border: none; cursor: pointer; padding: 6px; display: flex; flex-direction: column; gap: 5px; }
  .hamburger span { display: block; width: 22px; height: 1.5px; background: var(--text); transition: transform 0.2s, opacity 0.2s; transform-origin: center; }
  .hamburger.open span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
  .hamburger.open span:nth-child(2) { opacity: 0; }
  .hamburger.open span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

  .mobile-nav { flex-direction: column; background: var(--bg); border-bottom: 1px solid var(--border); padding: 8px 20px 12px; gap: 0; position: fixed; left: 0; right: 0; z-index: 9; }
  .mobile-nav.open { display: flex; }
  .mobile-nav a { font-size: 12px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; text-decoration: none; color: var(--nav-inactive); padding: 10px 0; border-bottom: 1px solid var(--border); transition: color 0.12s; }
  .mobile-nav a:last-child { border-bottom: none; }
  .mobile-nav a:hover, .mobile-nav a.active { color: var(--nav-active); }

  .main { padding: 32px 20px 48px; }

  .mobile-footer { display: flex; align-items: center; gap: 16px; padding: 20px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); margin-top: auto; }
  .mobile-footer a { color: var(--text-muted); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.1s; }
  .mobile-footer a:hover { border-bottom-color: var(--text-muted); }
}

/* ── Homepage ── */

.intro { margin-bottom: 56px; }
.intro p { font-size: 16px; line-height: 1.75; max-width: 540px; }
.intro p + p { margin-top: 28px; }
.intro ul { margin: 6px 0 0 18px; }
.intro ul + p { margin-top: 28px; }
.intro li { font-size: 16px; line-height: 1.75; margin-bottom: 6px; }
.intro a { color: var(--link); border-bottom: 1px solid transparent; text-decoration: none; }
.intro a:hover { border-bottom-color: var(--link); }
.intro hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }
.section-gap { height: 24px; }

/* ── Blog listing ── */
.post-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.post-item { display: flex; align-items: baseline; gap: 14px; }
.post-item a.post-title { font-size: 16px; font-weight: 500; color: var(--text); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.1s; }
.post-item a.post-title:hover { border-bottom-color: var(--text); }
.post-date { font-size: 13px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.post-star { font-size: 11px; color: var(--link); flex-shrink: 0; width: 14px; }
.post-star-spacer { flex-shrink: 0; width: 14px; }

/* ── Post pages ── */

.post-header { margin-bottom: 40px; }
.post-heading { font-size: 22px; font-weight: 600; line-height: 1.3; margin-bottom: 12px; }
.post-meta { font-size: 13px; color: var(--text-muted); display: flex; gap: 10px; align-items: center; }

.post-body { font-size: 16px; line-height: 1.8; max-width: 520px; }
.post-body p { margin-bottom: 16px; }
.post-body h2 { font-size: 16px; font-weight: 600; margin: 32px 0 12px; }
.post-body h3 { font-size: 14px; font-weight: 600; margin: 24px 0 10px; }
.post-body ul, .post-body ol { margin: 0 0 20px 18px; }
.post-body li { margin-bottom: 6px; }
.post-body p + ul, .post-body p + ol { margin-top: -8px; }
.post-body a { color: var(--link); border-bottom: 1px solid transparent; text-decoration: none; }
.post-body a:hover { border-bottom-color: var(--link); }
.post-body blockquote { border-left: 2px solid var(--link); padding-left: 16px; color: var(--text); margin: 20px 0; }
.yt-embed { position: relative; padding-bottom: 56.25%; height: 0; margin: 28px 0; }
.yt-embed iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; border-radius: 4px; }
.post-image { margin: 28px 0; }
.post-image img { display: block; width: 100%; height: auto; border-radius: 4px; }
.post-body em { font-style: italic; }
.post-body strong { font-weight: 600; }
.post-body code { font-family: monospace; font-size: 14px; background: var(--border); padding: 1px 5px; border-radius: 3px; }

.related-posts { margin-top: 56px; padding-top: 28px; border-top: 1px solid var(--border); }
.related-label { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 14px; }
.related-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.related-list a { font-size: 15px; color: var(--link); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.1s; }
.related-list a:hover { border-bottom-color: var(--link); }
.backlinks { margin-top: 32px; padding-top: 28px; border-top: 1px solid var(--border); }
.backlinks-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.backlinks-list a { font-size: 15px; color: var(--link); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.1s; }
.backlinks-list a:hover { border-bottom-color: var(--link); }
.backlinks + .related-posts { margin-top: 28px; }
