/* ==========================================================================
   1. Design Tokens & Variables
   ========================================================================== */
:root {
  --foreground: #1a2827;
  --background: #f5fafa;
  --surface: #eef4f3;
  --muted: #6f8584;
  --link: #3d7a7a;
  --link-hover: #245959;
  --rule: #d8e4e2;
  --code-bg: #eef4f3;
  --code-fg: #1a2827;
  --tag-bg: #dfe9e8;
  --tag-fg: #3f5e5d;
  --selection: #d4e0de;
}

html.dark {
  --foreground: #e8edec;
  --background: #16191b;
  --surface: #1c2023;
  --muted: #94a0a0;
  --link: #8fc4c4;
  --link-hover: #b3dada;
  --rule: #2c3235;
  --code-bg: #1c2023;
  --code-fg: #e8edec;
  --tag-bg: #232a2c;
  --tag-fg: #aac2c1;
  --selection: #2a3a3a;
}

html.light {
  --foreground: #1a2827;
  --background: #f5fafa;
  --surface: #eef4f3;
  --muted: #6f8584;
  --link: #3d7a7a;
  --link-hover: #245959;
  --rule: #d8e4e2;
  --code-bg: #eef4f3;
  --code-fg: #1a2827;
  --tag-bg: #dfe9e8;
  --tag-fg: #3f5e5d;
  --selection: #d4e0de;
}

@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --foreground: #e8edec;
    --background: #16191b;
    --surface: #1c2023;
    --muted: #94a0a0;
    --link: #8fc4c4;
    --link-hover: #b3dada;
    --rule: #2c3235;
    --code-bg: #1c2023;
    --code-fg: #e8edec;
    --tag-bg: #232a2c;
    --tag-fg: #aac2c1;
    --selection: #2a3a3a;
  }
}

/* ==========================================================================
   2. Base Elements & Resets
   ========================================================================== */
* {
  box-sizing: border-box;
}

::selection {
  background: var(--selection);
  color: var(--foreground);
}

html {
  font-size: 17px;
}

body {
  font-family:
    "IBM Plex Sans",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  margin: 0;
}

/* ==========================================================================
   3. Typography
   ========================================================================== */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.25;
  margin: 2.25em 0 0.6em;
  letter-spacing: -0.015em;
}

h1 {
  font-size: 1.65rem;
  margin-top: 0;
  letter-spacing: -0.02em;
  font-weight: 700;
}

h2 {
  font-size: 1.55rem;
}
h3 {
  font-size: 1.25rem;
}
h4 {
  font-size: 1.08rem;
}

h5 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

h6 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

p,
li {
  line-height: 1.7;
}

p {
  margin: 0 0 1.1em;
}

ul,
ol {
  padding-left: 1.4em;
  margin: 0 0 1.2em;
}

li + li {
  margin-top: 0.25em;
}

blockquote {
  margin: 1.2em 0;
  padding: 0.2em 1.1em;
  border-left: 3px solid var(--rule);
  color: var(--muted);
  font-style: italic;
}

.callout {
  background: var(--surface);
  border-left: 4px solid var(--link);
  padding: 1rem 1.25rem;
  margin: 1.5em 0;
  border-radius: 0 6px 6px 0;
  font-size: 0.95rem;
}

.callout > :first-child {
  margin-top: 0;
}

.callout > :last-child {
  margin-bottom: 0;
}

hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: 2.5em 0;
}

a:link,
a:visited {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition:
    color 0.15s ease,
    border-color 0.15s ease;
}

a:hover,
a:active {
  color: var(--link-hover);
  border-bottom-color: var(--rule);
}

a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ==========================================================================
   4. Layout Container
   ========================================================================== */
.layout-container {
  max-width: 78rem;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 3rem;
}

main {
  margin-bottom: 4rem;
}

/* ==========================================================================
   5. Header
   ========================================================================== */
header {
  padding: 1.5rem 3rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.5rem;
}

header .header-inner {
  max-width: 78rem;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
}

.weblog-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.015em;
  flex-shrink: 0;
}

.weblog-title a {
  text-decoration: none;
  color: var(--link);
  transition: color 0.15s ease;
}

.weblog-title a:hover {
  color: var(--link-hover);
  border-bottom: none !important;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

header .shift-left {
  display: none;
}

header nav ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}

header nav li a {
  display: inline-block;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.15rem 0;
  border-bottom: 1px solid transparent;
  transition:
    color 0.15s ease,
    border-color 0.15s ease;
}

header nav li a:hover {
  color: var(--foreground);
  border-bottom-color: var(--rule);
}

.social-icons {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.social-icons a {
  border-bottom: none !important;
  font-size: 1.1rem;
}

.social-icons a:hover {
  color: var(--link-hover);
  border-bottom: none !important;
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
  margin-left: 0.5rem;
}

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

.theme-toggle:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ==========================================================================
   6. Sidebar
   ========================================================================== */
.sidebar {
  font-size: 0.95rem;
  margin-bottom: 4rem;
}

.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.profile-photo {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 0 1.25rem 0;
  border: 3px solid var(--surface);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.profile-name {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.015em;
}

.profile-name a {
  text-decoration: none;
  color: var(--link);
  transition: color 0.15s ease;
}

.profile-name a:hover {
  color: var(--link-hover);
  border-bottom: none !important;
}

.profile-bio {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 1.5rem 0;
}

.profile-about {
  margin: -0.75rem 0 1.5rem 0;
}

.profile-about a {
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.profile-email {
  margin: -0.75rem 0 1.5rem 0;
}

.profile-email a {
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.profile-location {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -0.75rem 0 1.5rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.profile-location i {
  color: var(--muted);
  opacity: 0.8;
}

.profile-meta {
  width: 100%;
  border-top: 1px solid var(--rule);
  padding-top: 1.25rem;
}

.profile-meta + .profile-meta {
  margin-top: 1.5rem;
}

.profile-meta h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 0.75rem 0;
}

.profile-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.profile-links li {
  margin-bottom: 0.5rem;
}

.profile-links a {
  font-weight: 500;
  color: var(--link);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.npm-packages li {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.75rem;
}

.npm-packages li:last-child {
  margin-bottom: 0;
}

.npm-downloads {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

/* ==========================================================================
   7. Article Meta & Elements
   ========================================================================== */
.post-title-wrap {
  position: relative;
}

.post-title-wrap::before {
  content: '';
  position: absolute;
  left: -1.6rem;
  top: 0;
  bottom: 0;
  width: 1.6rem;
}

.copy-link {
  position: absolute;
  left: -1.6rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
  line-height: 1;
}

.post-title-wrap:hover .copy-link {
  opacity: 1;
}

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

.copy-link:focus-visible {
  opacity: 1;
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

@keyframes copy-shake {
  0%, 100% { transform: translateY(-50%) translateX(0); }
  20%, 60% { transform: translateY(-50%) translateX(-4px); }
  40%, 80% { transform: translateY(-50%) translateX(4px); }
}

.copy-link.copy-error {
  color: var(--link-hover);
  animation: copy-shake 0.4s ease;
}
.post-info,
.post-tags {
  font-size: 0.82rem;
  color: var(--muted);
}

.post-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  margin-top: 0.5rem;
  margin-bottom: 1.75rem;
}

.post-info i {
  font-size: 0.85em;
  opacity: 0.7;
}

.tag {
  background: var(--tag-bg);
  color: var(--tag-fg) !important;
  padding: 0.2em 0.55em;
  margin: 0.6em 0.4em 0 0;
  border-radius: 999px;
  text-decoration: none;
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  border: none !important;
  transition: filter 0.15s ease;
}

.tag:hover {
  filter: brightness(0.97);
  border-bottom: none !important;
}

.post-tags {
  margin-top: 1.5rem;
}

/* ==========================================================================
   8. Code Blocks
   ========================================================================== */
code {
  font-family:
    "IBM Plex Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 0.15em 0.35em;
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

pre {
  margin: 1.2em 0;
  padding: 1em 1.1em;
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.55;
}

pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border: 0;
  font-size: 0.88em;
  white-space: pre;
}

/* Prism Syntax Highlighting Tokens */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--muted);
  font-style: italic;
}

.token.punctuation {
  color: var(--foreground);
  opacity: 0.6;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: #c92a2a;
}
html.dark .token.property,
html.dark .token.tag,
html.dark .token.boolean,
html.dark .token.number,
html.dark .token.constant,
html.dark .token.symbol,
html.dark .token.deleted {
  color: #ff8787;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: #2b8a3e;
}
html.dark .token.selector,
html.dark .token.attr-name,
html.dark .token.string,
html.dark .token.char,
html.dark .token.builtin,
html.dark .token.inserted {
  color: #69db7c;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: var(--link);
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: #0c8599;
}
html.dark .token.atrule,
html.dark .token.attr-value,
html.dark .token.keyword {
  color: #66d9e8;
}

.token.function,
.token.class-name {
  color: #862e9c;
}
html.dark .token.function,
html.dark .token.class-name {
  color: #da77f2;
}

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

/* ==========================================================================
   9. Media & Tables
   ========================================================================== */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.2em auto;
  border-radius: 4px;
}

figure {
  margin: 1.5em 0;
}

figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5em;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.2em 0;
  font-size: 0.95em;
}

td,
th {
  padding: 0.6em 0.8em;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}

th {
  font-weight: 600;
  color: var(--muted);
}

/* ==========================================================================
   10. Footer
   ========================================================================== */
footer {
  max-width: 78rem;
  margin: 5em auto 3em;
  border-top: 1px solid var(--rule);
  padding: 1.5rem 3rem 0;
}

.footer-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

footer p {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin: 0;
  white-space: nowrap;
}

.shift-left {
  flex: 1;
  height: 12px;
  background-color: var(--rule);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M8 2 L4 6 L8 10' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  -webkit-mask-repeat: repeat-x;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M8 2 L4 6 L8 10' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  mask-repeat: repeat-x;
  opacity: 0.65;
}

/* ==========================================================================
   11. Lists & Helpers
   ========================================================================== */
h2 + ul,
h2 + .recent-posts {
  margin-top: 0.5em;
}

main ul {
  list-style-type: disc;
}

main ul li {
  margin-bottom: 0.35em;
}

/* ==========================================================================
   12. Landing-page summaries
   ========================================================================== */
.post-summary {
  margin: 0 0 2.5rem 0;
  padding: 0 0 1.75rem 0;
  border-bottom: 1px solid var(--rule);
}

.archive-entry {
  text-align: center;
  padding: 1.25rem 0 0.5rem;
  border-top: 1px solid var(--rule);
}

.archive-entry a {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  border-bottom: none !important;
}

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

.post-summary:last-of-type {
  border-bottom: 0;
  margin-bottom: 1.5rem;
}

.post-summary h2 {
  margin-top: 0;
  font-size: 1.45rem;
}

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

.post-summary h2 a:hover {
  color: var(--link-hover);
  border-bottom: none;
}

.post-summary .summary-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin: -0.3rem 0 0.85rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.post-summary .summary-text {
  color: var(--foreground);
  margin: 0 0 0.75rem 0;
}

.post-summary .read-more {
  font-size: 0.9rem;
  font-weight: 500;
}

/* ==========================================================================
   13. Responsive Media Queries
   ========================================================================== */
@media (min-width: 800px) {
  .layout-container {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 4.5rem;
  }

  main {
    flex: 1;
    min-width: 0;
    max-width: 38rem;
  }

  .sidebar {
    width: 13rem;
    flex-shrink: 0;
    position: sticky;
    top: 2rem;
    margin-bottom: 0;
  }

  .profile-card {
    align-items: flex-start;
    text-align: left;
  }

  .profile-location {
    justify-content: flex-start;
  }

  .npm-downloads {
    margin-left: 1.7rem;
  }

  .social-icons,
  header nav {
    display: none;
  }

  header .shift-left {
    display: block;
    margin: 0 2.5rem;
  }
}

@media (max-width: 600px) {
  html {
    font-size: 16.5px;
  }
  h1 {
    font-size: 1.45rem;
  }
  .weblog-title {
    font-size: 1.3rem;
  }
  header .header-inner {
    gap: 0.75rem 1.5rem;
  }
  .header-right {
    gap: 0.85rem;
  }
}

@media (max-width: 380px) {
  header {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .layout-container,
  footer {
    padding: 0 1rem;
  }
}
