/* --- Modern Minimalist Design System & Layout --- */

:root {
  /* Set color-scheme to allow light-dark() resolution */
  color-scheme: light dark;

  /* Color Palette - Responsive using light-dark() */
  --bg-primary: light-dark(#faedff, #09090b);
  --bg-secondary: light-dark(#f4f4f5, #18181b);
  --text-primary: light-dark(#18181b, #f4f4f5);
  --text-muted: light-dark(#52525b, #a1a1aa);
  --accent: light-dark(#4f46e5, #818cf8);
  --accent-muted: light-dark(#19917b, #d0c465);
  --accent-hover: light-dark(#4338ca, #6366f1);
  --accent-button: light-dark(#4f46e5, #4f46e5);
  --accent-button-hover: light-dark(#4338ca, #6366f1);
  --accent-button-text: light-dark(#e4e4e7, #18181b);
  --accent-button-text-focus: light-dark(#e4e4e7, #e4e4e7);
  --border: light-dark(#e4e4e7, #27272a);
  --code-bg: light-dark(#f4f4f5, #18181b);
  --code-text: light-dark(#18181b, #f4f4f5);
  --code-comment: light-dark(#52525b, #a1a1aa);
  --code-keyword: light-dark(#be185d, #f472b6);
  --code-string: light-dark(#0f766e, #2dd4bf);
  --code-number: light-dark(#92400e, #fbbf24);
  --code-function: light-dark(#1d4ed8, #60a5fa);
  --code-tag: light-dark(#b91c1c, #f87171);
  --code-attr: light-dark(#6d28d9, #c084fc);
  --code-operator: light-dark(#0f172a, #e2e8f0);
  --code-punctuation: light-dark(#3f3f46, #a1a1aa);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Fluid typography using clamp() */
  --text-xs: clamp(0.75rem, 0.7rem + 0.2vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.3vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.4vw, 1.125rem);
  --text-md: clamp(1.125rem, 1.05rem + 0.5vw, 1.25rem);
  --text-lg: clamp(1.25rem, 1.15rem + 0.6vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.35rem + 0.8vw, 1.875rem);
  --text-2xl: clamp(1.875rem, 1.7rem + 1.2vw, 2.5rem);

  /* Spacing */
  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Layout width */
  --max-width: 68ch;
}

/* CSS Reset & Defaults */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  font-size: 100%;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.75;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Base Layout Structure */
.site-wrapper {
  max-width: 75ch;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
  flex-grow: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
}

main {
  flex-grow: 1;
  margin-top: var(--space-2xl);
}

/* Typography elements */
h1,
h2,
h3,
h4 {
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
  margin-top: var(--space-xl);
  margin-bottom: var(--space-sm);
}

h1 {
  font-size: var(--text-2xl);
  margin-top: 0;
}

h2 {
  font-size: var(--text-xl);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-xs);
}

h3 {
  font-size: var(--text-lg);
}

h4 {
  font-size: var(--text-md);
}

p {
  margin-top: 0;
  margin-bottom: var(--space-md);
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

a:hover,
a:focus {
  color: var(--accent-hover);
  text-decoration-thickness: 2px;
}

/* Navigation & Header */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-lg);
}

.logo {
  font-weight: 700;
  font-size: var(--text-md);
  text-decoration: none;
  color: var(--text-primary);
}

.logo:hover {
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.nav-links {
  display: flex;
  gap: var(--space-lg);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-links a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  color: var(--text-primary);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 2px;
}

/* Theme Switcher Toggle */
.theme-toggle {
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  position: relative;
  transition: background-color 0.2s, transform 0.2s;
}

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

.theme-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
}

/* Toggle icon visibility and rotation */
.theme-toggle .sun-icon {
  opacity: 0;
  transform: rotate(90deg) scale(0);
  position: absolute;
}

.theme-toggle .moon-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Transition to dark mode: sun rotates into view, moon rotates out */
:root[data-theme="dark"] .theme-toggle .sun-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

:root[data-theme="dark"] .theme-toggle .moon-icon {
  opacity: 0;
  transform: rotate(-90deg) scale(0);
}

/* Also handle case where no preference is saved, but system is dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }

  :root:not([data-theme="light"]) .theme-toggle .moon-icon {
    opacity: 0;
    transform: rotate(-90deg) scale(0);
  }
}

/* Lists and Collections */
.post-list,
.talk-list {
  list-style: none;
  padding: 0;
  margin: var(--space-xl) 0;
}

.post-item,
.talk-item {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-md);
  border-bottom: 1px dashed var(--border);
}

.post-item:last-child,
.talk-item:last-child {
  border-bottom: none;
}

.item-title {
  margin: 0 0 var(--space-lg) 0;
  font-size: var(--text-lg);
  line-height: var(--space-xl);
}

.item-title a {
  text-decoration: none;
  color: var(--text-primary);
}

.item-title a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.item-meta {
  font-size: var(--text-sm);
  color: var(--accent-muted);
  margin-bottom: var(--space-xs);
}

.item-description {
  margin: 0;
  color: var(--text-muted);
}

/* Talk specific styles */
.talk-links {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
  font-size: var(--text-base);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  border-radius: 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: var(--space-xs);
}

.badge-upcoming {
  background-color: light-dark(#fef3c7, #78350f);
  color: light-dark(#92400e, #fef3c7);
}

/* Article Styles (Singular Post) */
.article-header {
  margin-bottom: var(--space-xl);
}

.article-title {
  margin-bottom: var(--space-xs);
}

.article-content {
  max-width: var(--max-width);
}

.article-content blockquote {
  border-left: 4px solid var(--accent);
  margin: var(--space-lg) 0;
  padding-left: var(--space-md);
  color: var(--text-muted);
  font-style: italic;
}

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

.article-content pre {
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 1.25rem 1.5rem;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  margin: var(--space-lg) 0;
  border: 1px solid var(--border);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  position: relative;
}

.article-content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background-color: var(--bg-secondary);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.article-content pre code {
  background-color: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
  border: none;
  font-size: inherit;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  line-height: 1.6;
  tab-size: 4;
  hyphens: none;
}

/* Scrollbar styles for code blocks */
.article-content pre::-webkit-scrollbar {
  height: 8px;
}

.article-content pre::-webkit-scrollbar-track {
  background: var(--code-bg);
  border-radius: 0 0 8px 8px;
}

.article-content pre::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.article-content pre::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Prism syntax tokens */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--code-comment);
  font-style: italic;
}

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

.token.namespace {
  opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: var(--code-tag);
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: var(--code-string);
}

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

.token.atrule,
.token.attr-value,
.token.keyword {
  color: var(--code-keyword);
}

.token.function,
.token.class-name {
  color: var(--code-function);
}

.token.regex,
.token.important,
.token.variable {
  color: var(--code-number);
}

.token.important,
.token.bold {
  font-weight: bold;
}

.token.italic {
  font-style: italic;
}

.token.entity {
  cursor: help;
}

/* Page intro description */
.page-intro {
  font-size: var(--text-lg);
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: var(--space-xl);
}

/* Section spacing (reusable top margin) */
.section-spaced {
  margin-top: var(--space-2xl);
}

/* Post back-navigation link */
.post-back-link {
  margin-top: var(--space-2xl);
  font-size: var(--text-sm);
}

/* Item title reset — used when an h2/h3 appears inside a list card */
.item-title--reset {
  margin: 0 0 var(--space-2xs) 0;
  border: none;
  padding: 0;
}

/* Consulting / callout block */
.callout {
  margin-top: var(--space-2xl);
  padding: var(--space-md);
  background-color: var(--bg-secondary);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
}

.callout-title {
  margin-top: 0;
  font-size: var(--text-md);
  border: none;
  padding-bottom: 0;
}

.callout-body {
  margin-bottom: 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* Empty / placeholder text */
.text-muted {
  color: var(--text-muted);
}

/* Contact lists */
.contact-links {
  list-style: none;
  padding: 0;
  margin: var(--space-lg) 0;
}

.contact-links li {
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
}

.contact-links a {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: 500;
}

/* Site Footer */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.footer-nav {
  display: flex;
  gap: var(--space-md);
}

.footer-nav a {
  color: var(--text-muted);
  text-decoration: none;
}

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

/* --- Mobile Menu & Responsive Layout --- */
.mobile-menu-toggle {
  display: none;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: var(--space-xs);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    transition: background-color 0.2s, transform 0.2s;
    position: relative;
    z-index: 1000;
  }

  .mobile-menu-toggle:hover,
  .mobile-menu-toggle:focus-visible {
    background-color: var(--bg-secondary);
    outline: none;
  }

  .mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* SVG line transformations */
  .mobile-menu-toggle svg line {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    transform-origin: 12px 12px;
  }

  /* Default hamburger layout (all lines originally at center y=12) */
  .mobile-menu-toggle .line-top {
    transform: translateY(-6px) rotate(0deg);
  }

  .mobile-menu-toggle .line-bottom {
    transform: translateY(6px) rotate(0deg);
  }

  /* Transform burger menu to 'X' */
  .mobile-menu-toggle[aria-expanded="true"] .line-top {
    transform: translateY(0) rotate(45deg);
  }

  .mobile-menu-toggle[aria-expanded="true"] .line-mid {
    opacity: 0;
  }

  .mobile-menu-toggle[aria-expanded="true"] .line-bottom {
    transform: translateY(0) rotate(-45deg);
  }

  /* Premium glassmorphism overlay dropdown */
  .nav-links {
    display: none;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: rgba(250, 237, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 999;
    padding: calc(var(--space-2xl) * 2) var(--space-xl) var(--space-xl) var(--space-xl);
    gap: var(--space-xl);
    align-items: center;
    justify-content: center;
  }

  :root[data-theme="dark"] .nav-links {
    background-color: rgba(9, 9, 11, 0.85);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .nav-links {
      background-color: rgba(9, 9, 11, 0.85);
    }
  }

  .nav-links.is-active {
    display: flex;
    animation: menuFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }

  .nav-links a {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.2s ease, transform 0.2s ease;
    display: block;
    padding: var(--space-xs) var(--space-md);
  }

  .nav-links a:hover,
  .nav-links a[aria-current="page"] {
    color: var(--accent);
    border-bottom: none;
    padding-bottom: var(--space-xs);
    transform: scale(1.05);
  }

  /* Prevent body scrolling when mobile menu is active */
  body.menu-open {
    overflow: hidden;
  }
}

@keyframes menuFadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}