/* Base styles */
:root {
  --primary-color: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --accent-color: #dbeafe;
  --text-color: #1f2937;
  --text-secondary: #4b5563;
  --light-text: #6b7280;
  --background-color: #ffffff;
  --surface-color: #f9fafb;
  --border-color: #e5e7eb;
  --container-width: 1000px;
  --header-height: 70px;
  --transition: 0.2s ease;
  --code-bg: #282c34;
  --header-bg: rgba(255, 255, 255, 0.95);
  --focus-ring: #3b82f6;
  color-scheme: light;
}

/* Dark theme */
[data-theme="dark"] {
  --primary-color: #60a5fa;
  --primary-light: #93c5fd;
  --primary-dark: #3b82f6;
  --accent-color: #1e3a5f;
  --text-color: #f3f4f6;
  --text-secondary: #d1d5db;
  --light-text: #9ca3af;
  --background-color: #111827;
  --surface-color: #1f2937;
  --border-color: #374151;
  --code-bg: #0d1117;
  --header-bg: rgba(17, 24, 39, 0.95);
  --focus-ring: #93c5fd;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.7;
  color: var(--text-color);
  background-color: var(--background-color);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Accessibility helpers */
.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;
}

.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 200;
  padding: 0.75rem 1.25rem;
  background-color: var(--primary-color);
  color: #ffffff;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border-radius: 0 0 6px 0;
  transform: translateY(-120%);
  transition: transform var(--transition);
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  color: #ffffff;
  text-decoration: none;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

main:focus {
  outline: none;
}

main:focus-visible {
  outline: none;
}

/* Header styles */
header.site-header {
  height: var(--header-height);
  background-color: var(--header-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
}

.header-container {
  max-width: var(--container-width);
  width: 100%;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-color);
  text-decoration: none;
  letter-spacing: -0.02em;
}

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

.site-header nav ul {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 2.5rem;
}

.site-header nav li a {
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  transition: color var(--transition);
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.25rem 0;
}

.site-header nav li a:hover {
  color: var(--primary-color);
}

.site-header nav li a.is-active {
  color: var(--primary-color);
  font-weight: 600;
}

.site-header nav li a.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.35rem;
  height: 2px;
  background-color: var(--primary-color);
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.625rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background-color var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-width: 44px;
  min-height: 44px;
}

.theme-toggle:hover {
  background-color: var(--surface-color);
  color: var(--primary-color);
}

.theme-toggle svg {
  width: 24px;
  height: 24px;
}

.theme-toggle .sun-icon {
  display: none;
}

.theme-toggle .moon-icon {
  display: block;
}

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

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

/* Main content styles */
main {
  flex: 1;
  max-width: var(--container-width);
  width: 100%;
  margin: 0 auto;
  padding: 4rem 2rem;
}

/* Profile photo */
.profile-photo {
  width: 220px;
  height: 280px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 3px solid var(--border-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.profile-photo-about {
  float: right;
  margin: 0 0 1.5rem 2rem;
  width: 200px;
  height: 250px;
}

[data-theme="dark"] .profile-photo {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Hero section */
.hero {
  display: flex;
  align-items: center;
  gap: 3rem;
  padding: 3rem 0 4rem;
  margin-bottom: 2rem;
}

.hero-content {
  flex: 1;
}

.hero-title {
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-color);
  margin: 0 0 1rem;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin: 0 0 1.5rem;
  font-weight: 400;
}

.hero-description {
  font-size: 1.1rem;
  color: var(--light-text);
  max-width: 600px;
  margin: 0 0 2rem;
  line-height: 1.8;
}

.hero-links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.hero-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  transition: color var(--transition), background-color var(--transition);
  min-height: 44px;
}

.hero-link:hover {
  color: var(--primary-color);
  background-color: var(--accent-color);
  text-decoration: none;
}

.hero-link svg {
  width: 18px;
  height: 18px;
}

/* Section styles */
.section {
  margin-bottom: 4rem;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0 0 2rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border-color);
  letter-spacing: -0.01em;
}

.section-intro {
  margin: 0 0 2rem;
  color: var(--text-secondary);
  font-size: 1.05rem;
  line-height: 1.7;
  max-width: 42rem;
}

.section-intro p:last-child {
  margin-bottom: 0;
}

.empty-state {
  color: var(--light-text);
  font-size: 1.05rem;
  margin: 1rem 0 0;
}

/* Article styles */
article {
  margin-bottom: 2rem;
}

article header h1 {
  margin-top: 0;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  color: var(--text-color);
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
}

h1 {
  font-size: 2.25rem;
}

h2 {
  font-size: 1.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

h3 {
  font-size: 1.35rem;
}

p {
  margin-bottom: 1.5rem;
  font-size: 1.05rem;
  color: var(--text-secondary);
  text-align: left;
  max-width: 70ch;
}

article .content > p,
article .content > ul,
article .content > ol,
article .content > blockquote,
article .content > pre,
article .content > table,
article .content > .github-callout,
article .content > .katex-display {
  max-width: 70ch;
}

/* Long-form posts keep a comfortable measure without orphaning full-width media */
article header,
article .toc,
article .post-footer {
  max-width: 70ch;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

ul, ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.5rem;
  font-size: 1.05rem;
  color: var(--text-secondary);
}

/* Code styles */
pre, code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9rem;
}

code {
  background-color: var(--surface-color);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

pre {
  background-color: var(--code-bg) !important;
  color: #abb2bf;
  padding: 1.25rem 1.5rem;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  border: none;
}

pre code {
  background: none !important;
  padding: 0;
  border: none;
  color: inherit;
}

/* Override Hugo syntax highlighting for better contrast */
pre code span {
  background: none !important;
}

/* Article images - constrained to content width */
article img {
  max-width: 600px;
  width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

blockquote {
  border-left: 3px solid var(--primary-color);
  padding: 0.5rem 0 0.5rem 1.5rem;
  margin: 1.5rem 0;
  background-color: var(--surface-color);
  border-radius: 0 8px 8px 0;
}

blockquote p {
  color: var(--text-secondary);
  font-style: italic;
  margin: 0;
}

/* Math rendering styles */
.katex-display {
  padding: 1.5rem 0;
  overflow-x: auto;
}

/* Table styles */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
}

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

th {
  background-color: var(--surface-color);
  font-weight: 600;
  color: var(--text-color);
}

td {
  color: var(--text-secondary);
}

tr:nth-child(even) {
  background-color: var(--surface-color);
}

/* Dark mode image adjustments */
[data-theme="dark"] article img {
  opacity: 0.9;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Post list styles */
.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list li {
  margin-bottom: 0;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.post-list li:first-child {
  padding-top: 0;
}

.post-list li:last-child {
  border-bottom: none;
}

.post-meta {
  color: var(--light-text);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.post-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.01em;
}

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

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

.post-excerpt {
  color: var(--text-secondary);
  font-size: 1rem;
  margin: 0;
  line-height: 1.6;
}

/* Post list header with RSS link */
.list-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.list-header h1 {
  margin: 0;
}

.rss-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--light-text);
  text-decoration: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.rss-link:hover {
  color: #f97316;
  border-color: #f97316;
}

/* Post meta separators and reading time */
.meta-sep {
  margin: 0 0.25rem;
  color: var(--border-color);
}

.reading-time {
  color: var(--light-text);
}

/* Category badge */
.category-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-color);
  background-color: var(--accent-color);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  letter-spacing: 0.01em;
}

/* Tags */
.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.post-tags-header {
  margin-top: 0.5rem;
  margin-bottom: 0;
}

.tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  text-decoration: none;
  transition: color var(--transition), border-color var(--transition), background-color var(--transition);
}

.tag:hover {
  color: var(--primary-color);
  border-color: var(--primary-color);
  background-color: var(--accent-color);
}

/* Post footer tags */
.post-footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

/* Related posts */
.related-posts {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.related-posts h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--light-text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 1rem 0;
}

.related-posts ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.related-posts li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.related-posts a {
  color: var(--text-color);
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  flex: 1;
}

.related-posts a:hover {
  color: var(--primary-color);
}

.related-meta {
  font-size: 0.8rem;
  color: var(--light-text);
  white-space: nowrap;
}

/* Table of Contents */
.toc {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 2.5rem;
  font-size: 0.9rem;
}

.toc-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--light-text);
  margin: 0 0 0.75rem 0;
  text-align: left;
}

.toc ul,
#TableOfContents ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.toc ul ul,
#TableOfContents ul ul {
  padding-left: 1.25rem;
  margin-top: 0.25rem;
}

.toc li,
#TableOfContents li {
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.toc a,
#TableOfContents a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

.toc a:hover,
#TableOfContents a:hover {
  color: var(--primary-color);
}

/* GitHub callout */
.github-callout {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  margin: 1.25rem 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.github-callout svg {
  flex-shrink: 0;
  color: var(--text-color);
}

.github-callout span {
  color: var(--text-secondary);
}

.github-callout a {
  font-weight: 600;
  color: var(--primary-color);
}

.github-callout a:hover {
  text-decoration: underline;
}

/* Publication list styles */
.publication-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.publication-item {
  display: flex;
  gap: 1.5rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-color);
}

.publication-item:first-child {
  padding-top: 0;
}

.publication-item:last-child {
  border-bottom: none;
}

.publication-year {
  flex-shrink: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary-color);
  background-color: var(--accent-color);
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  height: fit-content;
}

.publication-content {
  flex: 1;
}

.publication-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  line-height: 1.4;
}

.publication-title a {
  color: var(--text-color);
}

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

.publication-authors {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin: 0 0 0.25rem 0;
}

.publication-venue {
  font-size: 0.875rem;
  color: var(--light-text);
  font-style: italic;
  margin: 0;
}

.section-more {
  margin-top: 1.5rem;
  font-size: 0.95rem;
}

.section-more a {
  color: var(--primary-color);
  font-weight: 500;
}

/* About page styles */
/* About page inherits main container width */

.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.skill-category h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0 0 0.75rem;
}

.skill-category ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.skill-category li {
  font-size: 0.95rem;
  color: var(--text-secondary);
  padding: 0.25rem 0;
}

/* Footer styles */
footer {
  background-color: var(--surface-color);
  border-top: 1px solid var(--border-color);
  padding: 3rem 0;
  margin-top: auto;
}

.footer-container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-link {
  color: var(--text-secondary);
  transition: color var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
}

.footer-link:hover {
  color: var(--primary-color);
  background-color: var(--background-color);
}

.footer-link svg {
  width: 22px;
  height: 22px;
}

footer p {
  font-size: 0.875rem;
  color: var(--light-text);
  margin: 0;
}

footer a {
  color: var(--text-secondary);
}

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

/* 404 page */
.error-page {
  text-align: center;
  padding: 4rem 0;
}

.error-code {
  font-size: 8rem;
  font-weight: 700;
  color: var(--border-color);
  line-height: 1;
  margin: 0;
}

.error-title {
  font-size: 1.5rem;
  margin: 1rem 0;
}

.error-description {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  min-height: 44px;
  background-color: var(--primary-color);
  color: white;
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none;
  transition: background-color var(--transition);
}

.btn:hover {
  background-color: var(--primary-dark);
  color: white;
  text-decoration: none;
}

.btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

/* Responsive styles */
@media screen and (max-width: 768px) {
  :root {
    --header-height: 60px;
  }

  .header-container {
    padding: 0 1.5rem;
  }

  .site-header nav ul {
    gap: 1.5rem;
  }

  main {
    padding: 3rem 1.5rem;
  }

  .hero {
    flex-direction: column-reverse;
    text-align: center;
    padding: 2rem 0 3rem;
    gap: 2rem;
  }

  .hero-content {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .hero-links {
    justify-content: center;
  }

  .profile-photo {
    width: 180px;
    height: 220px;
  }

  .profile-photo-about {
    float: none;
    display: block;
    margin: 0 auto 1.5rem;
    width: 160px;
    height: 200px;
  }

  .hero-title {
    font-size: 2.25rem;
  }

  .hero-subtitle {
    font-size: 1.1rem;
  }

  h1 {
    font-size: 1.875rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .section-title {
    font-size: 1.25rem;
  }

  .site-logo {
    font-size: 1.125rem;
  }

  .footer-container {
    padding: 0 1.5rem;
  }
}

@media screen and (max-width: 480px) {
  .header-container {
    flex-wrap: wrap;
    row-gap: 0.5rem;
    padding: 0.5rem 1rem;
  }

  .site-header {
    height: auto;
    min-height: var(--header-height);
  }

  .site-header nav {
    order: 3;
    width: 100%;
  }

  .site-header nav ul {
    gap: 0.25rem 1rem;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .site-header nav li a {
    font-size: 0.875rem;
    min-height: 40px;
  }

  .site-header nav li a.is-active::after {
    bottom: 0.2rem;
  }

  main {
    padding: 2rem 1rem;
  }

  .hero-title {
    font-size: 1.875rem;
  }

  .hero-links {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-link {
    justify-content: center;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .error-code {
    font-size: 5rem;
  }

  p,
  article header,
  article .toc,
  article .post-footer,
  article .content > p,
  article .content > ul,
  article .content > ol {
    max-width: none;
  }
}
