/* ===== CSS Variables ===== */
:root {
  /* Light theme (default) */
  --bg: #fafafa;
  --bg-secondary: #f0f0f0;
  --text: #1a1a1a;
  --text-secondary: #666;
  --accent: #e07850;
  --accent-hover: #c96842;
  --accent-subtle: #f5e6e0;
  --border: #e0e0e0;
  --code-bg: #f5f5f5;
  --code-text: #1a1a1a;

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

  /* Typography */
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-base: 1.125rem;
  --font-size-lg: 1.5rem;
  --font-size-xl: 2rem;
  --line-height: 1.7;

  /* Layout */
  --max-width: 680px;
  --nav-height: 60px;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-secondary: #141414;
  --text: #e8e8e8;
  --text-secondary: #999;
  --accent: #f08860;
  --accent-hover: #ff9a75;
  --accent-subtle: #2a1f1c;
  --border: #2a2a2a;
  --code-bg: #141414;
  --code-text: #e8e8e8;
}

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

/* ===== Base ===== */
html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ===== Typography ===== */
h1, h2, h3 {
  line-height: 1.3;
  font-weight: 500;
  letter-spacing: -0.01em;
}

h1 {
  font-size: var(--font-size-xl);
  letter-spacing: -0.02em;
}
h2 { font-size: var(--font-size-lg); }
h3 { font-size: var(--font-size-base); }

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

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--accent-hover);
}

/* ===== Layout ===== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* ===== Navigation ===== */
nav {
  position: sticky;
  top: 0;
  height: var(--nav-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

nav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.nav-brand {
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: color 0.2s ease, letter-spacing 0.2s ease;
}

.nav-brand:hover {
  color: var(--accent);
  letter-spacing: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.nav-links a {
  position: relative;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  transition: color 0.2s ease;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  width: 0;
  height: 1.5px;
  background: var(--accent);
  transition: width 0.25s cubic-bezier(0.25, 0.1, 0.25, 1),
              left 0.25s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.nav-links a:hover::after,
.nav-links a.active::after {
  width: 100%;
  left: 0;
}

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

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-xs);
  color: var(--text-secondary);
  font-size: 1.25rem;
  line-height: 1;
  transition: color 0.2s ease,
              transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center;
}

.theme-toggle:hover {
  color: var(--accent);
  transform: scale(1.1);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle.switching {
  animation: theme-spin 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== Main Content ===== */
main {
  padding: var(--space-xl) 0;
  min-height: calc(100vh - var(--nav-height) - 100px);
}

/* ===== Page Header ===== */
.page-header {
  margin-bottom: var(--space-xl);
}

.page-header h1 {
  margin-bottom: var(--space-xs);
}

.page-header .subtitle {
  color: var(--text-secondary);
  font-size: var(--font-size-base);
}

/* ===== Posts List ===== */
.posts-list {
  list-style: none;
}

.post-item {
  padding: var(--space-md) 0;
  padding-left: var(--space-sm);
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  margin-left: calc(-1 * var(--space-sm));
  transition: border-left-color 0.2s ease,
              transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1),
              background-color 0.2s ease;
}

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

.post-item:hover {
  border-left-color: var(--accent);
  transform: translateX(4px);
  background: var(--accent-subtle);
}

.post-item a {
  display: block;
  color: var(--text);
}

.post-item a:hover .post-title {
  color: var(--accent);
}

.post-title {
  font-size: var(--font-size-base);
  font-weight: 500;
  margin-bottom: var(--space-xs);
  transition: color 0.2s ease;
}

.post-date {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  transition: transform 0.25s cubic-bezier(0.25, 0.1, 0.25, 1) 0.05s;
}

.post-item:hover .post-date {
  transform: translateX(2px);
}

.view-all {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: var(--space-md);
  font-size: var(--font-size-sm);
  transition: color 0.2s ease, gap 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.view-all::after {
  content: '\2192';
  transition: transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.view-all:hover {
  gap: 0.6em;
}

.view-all:hover::after {
  transform: translateX(3px);
}

/* ===== Single Post ===== */
.post-hero {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: var(--space-lg);
}

.post-header {
  margin-bottom: var(--space-xl);
}

.post-header h1 {
  margin-bottom: var(--space-xs);
}

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

.post-content p {
  margin-bottom: var(--space-md);
}

.post-content img {
  max-width: 100%;
  height: auto;
  margin: var(--space-lg) 0;
  border-radius: 4px;
}

.post-content h2 {
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
}

.post-content a {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: text-decoration-thickness 0.15s ease,
              text-underline-offset 0.15s ease,
              color 0.15s ease;
}

.post-content a:hover {
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

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

.post-content figure {
  margin: var(--space-lg) 0;
}

.post-content figcaption {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: var(--space-xs);
  font-style: italic;
}

.post-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: var(--space-md);
  margin: var(--space-md) 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* Inline code */
.post-content code {
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.85em;
  background: var(--bg-secondary);
  color: var(--accent);
  padding: 0.2em 0.5em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* Code blocks */
.post-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-lg) 0;
  overflow-x: auto;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar for code blocks */
.post-content pre::-webkit-scrollbar {
  height: 6px;
}

.post-content pre::-webkit-scrollbar-track {
  background: transparent;
}

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

.post-content pre::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.post-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--code-text);
  font-size: 0.875rem;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.post-content em {
  font-style: italic;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: var(--space-xl);
  font-size: var(--font-size-sm);
  transition: color 0.2s ease, gap 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.back-link::before {
  content: '\2190';
  transition: transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.back-link:hover {
  gap: 0.6em;
}

.back-link:hover::before {
  transform: translateX(-3px);
}

/* ===== Projects ===== */
.projects-list {
  list-style: none;
}

.project-item {
  padding: var(--space-lg) 0;
  padding-left: var(--space-md);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  margin-left: calc(-1 * var(--space-md));
  transition: border-left-color 0.25s ease,
              transform 0.25s cubic-bezier(0.25, 0.1, 0.25, 1),
              background-color 0.25s ease;
}

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

.project-item:hover {
  border-left-color: var(--accent);
  transform: translateX(6px);
  background: var(--accent-subtle);
}

.project-item h2 {
  margin-bottom: var(--space-xs);
}

.project-item h2 a {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3em;
  color: var(--text);
  transition: color 0.2s ease;
}

.project-item h2 a::after {
  content: '\2197';
  font-size: 0.8em;
  transition: transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.project-item:hover h2 a::after {
  transform: translate(2px, -2px);
}

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

.project-item p {
  color: var(--text-secondary);
  margin-bottom: 0;
  transition: transform 0.25s cubic-bezier(0.25, 0.1, 0.25, 1) 0.05s;
}

.project-item:hover p {
  transform: translateX(2px);
}

/* ===== About ===== */
.about-content {
  margin-bottom: var(--space-xl);
}

.social-links {
  display: flex;
  gap: var(--space-md);
}

.social-links a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-sm);
  padding: 0.4em 0;
}

.social-links a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--accent);
  transition: width 0.25s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.social-links a:hover::after {
  width: 100%;
}

/* ===== Footer ===== */
footer {
  padding: var(--space-lg) 0;
  border-top: 1px solid var(--border);
}

footer .container {
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
}

.footer-links a {
  color: var(--text-secondary);
  transition: color 0.2s ease, transform 0.2s ease;
}

.footer-links a:hover {
  color: var(--accent);
  transform: translateY(-2px);
}

.footer-links svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ===== Utilities ===== */
.loading {
  color: var(--text-secondary);
  font-style: italic;
}

/* ===== Animations ===== */
@keyframes theme-spin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Page load entrance animations */
main .container > * {
  animation: fade-up 0.4s cubic-bezier(0.25, 0.1, 0.25, 1) backwards;
}

main .container > *:nth-child(1) { animation-delay: 0.05s; }
main .container > *:nth-child(2) { animation-delay: 0.1s; }
main .container > *:nth-child(3) { animation-delay: 0.15s; }
main .container > *:nth-child(4) { animation-delay: 0.2s; }
main .container > *:nth-child(5) { animation-delay: 0.25s; }

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  :root {
    --font-size-base: 1rem;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.5rem;
  }

  .nav-links {
    gap: var(--space-sm);
  }
}
