/* ─── Light theme ────────────────────────────────────────── */
:root {
  --bg:           #fafaf7;
  --text:         #2d2d2d;
  --muted:        #7a7a72;
  --link:         #D4845A;
  --border:       #e0ddd5;
  --code-bg:      #f0efe8;
  --accent:       #c96442;
  --accent-hover: #a84f33;
  --surface:      #f4f3ed;
  --selection-bg: rgba(201, 100, 66, 0.2);
}

/* ─── Dark theme via system preference (no JS) ───────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #1a1a1d;
    --text:         #e0ddd5;
    --muted:        #9a978f;
    --link:         #D4845A;
    --border:       #3a3a3d;
    --code-bg:      #242428;
    --accent:       #d4845a;
    --accent-hover: #e09570;
    --surface:      #222225;
    --selection-bg: rgba(212, 132, 90, 0.25);
  }
}

/* ─── Explicit theme overrides (JS toggle) ───────────────── */
html[data-theme="light"] {
  --bg:           #fafaf7;
  --text:         #2d2d2d;
  --muted:        #7a7a72;
  --link:         #D4845A;
  --border:       #e0ddd5;
  --code-bg:      #f0efe8;
  --accent:       #c96442;
  --accent-hover: #a84f33;
  --surface:      #f4f3ed;
  --selection-bg: rgba(201, 100, 66, 0.2);
}

html[data-theme="dark"] {
  --bg:           #1a1a1d;
  --text:         #e0ddd5;
  --muted:        #9a978f;
  --link:         #D4845A;
  --border:       #3a3a3d;
  --code-bg:      #242428;
  --accent:       #d4845a;
  --accent-hover: #e09570;
  --surface:      #222225;
  --selection-bg: rgba(212, 132, 90, 0.25);
}

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

/* ─── Selection ─────────────────────────────────────────── */
::selection {
  background: var(--selection-bg);
  color: var(--text);
}

/* ─── Theme transition ──────────────────────────────────── */
body,
a,
.theme-btn,
.lang-btn,
.social-link,
.header-rule,
footer,
.post-content pre,
.post-content code,
.post-content blockquote {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ─── Base ──────────────────────────────────────────────── */
html {
  color-scheme: light dark;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans',
               Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  font-size: 18px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  padding: 0 1.5rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Links ────────────────────────────────────────────── */
a {
  color: var(--link);
  text-decoration: none;
}

/* ─── Page entrance ─────────────────────────────────────── */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Container ─────────────────────────────────────────── */
.container {
  max-width: 740px;
  margin: 0 auto;
  padding: 2.5rem 0 5rem;
  animation: fadeInUp 0.5s ease-out both;
}

/* ─── Header ────────────────────────────────────────────── */
header {
  margin-bottom: 1.5rem;
  padding-top: 0.5rem;
}

.site-title {
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 0.3rem;
}

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

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

.tagline {
  font-size: 1rem;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 0.9rem;
  line-height: 1.4;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

nav {
  display: flex;
  gap: 1.2rem;
}

nav a {
  font-size: 0.95rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
  position: relative;
}

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

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

nav a.active::after {
  width: 100%;
}

nav a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1.5px;
  background: var(--accent);
  transition: width 0.2s ease;
}

nav a:hover::after {
  width: 100%;
}

/* ─── Theme toggle ───────────────────────────────────────── */
.theme-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  color: var(--muted);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.3s ease, transform 0.3s ease;
}

.theme-btn:hover {
  color: var(--accent);
  transform: rotate(15deg);
}

.theme-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* Sun icon visible in dark mode, moon icon visible in light mode */
.theme-btn .icon-sun { display: none; }
.theme-btn .icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
  .theme-btn .icon-sun { display: block; }
  .theme-btn .icon-moon { display: none; }
}

html[data-theme="light"] .theme-btn .icon-sun { display: none; }
html[data-theme="light"] .theme-btn .icon-moon { display: block; }
html[data-theme="dark"] .theme-btn .icon-sun { display: block; }
html[data-theme="dark"] .theme-btn .icon-moon { display: none; }

/* ─── Header buttons (theme + lang) ──────────────────────── */
.header-buttons {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ─── Language toggle ────────────────────────────────────── */
.lang-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  color: var(--muted);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: color 0.3s ease, transform 0.3s ease;
}

.lang-btn:hover {
  color: var(--accent);
  transform: rotate(15deg);
}

.lang-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.lang-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ─── i18n language toggle ───────────────────────────────── */
.i18n-hy { display: none; }

html[data-lang="hy"] .i18n-en { display: none; }
html[data-lang="hy"] div.i18n-hy { display: block; }
html[data-lang="hy"] span.i18n-hy { display: inline; }
html[data-lang="hy"] p.i18n-hy { display: block; }

/* ─── Divider below header ───────────────────────────────── */
.header-rule {
  border: none;
  height: 2px;
  margin: 0 0 2.25rem;
  background: linear-gradient(to right, var(--accent), var(--border) 50%, transparent);
}

/* ─── Post list (homepage) ──────────────────────────────── */
.post-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.post-list li {
  padding: 1.2rem 1.4rem;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  animation: fadeIn 0.4s ease-out both;
}

.post-list li:nth-child(1) { animation-delay: 0.05s; }
.post-list li:nth-child(2) { animation-delay: 0.1s; }
.post-list li:nth-child(3) { animation-delay: 0.15s; }
.post-list li:nth-child(4) { animation-delay: 0.2s; }
.post-list li:nth-child(5) { animation-delay: 0.25s; }
.post-list li:nth-child(6) { animation-delay: 0.3s; }
.post-list li:nth-child(7) { animation-delay: 0.35s; }
.post-list li:nth-child(8) { animation-delay: 0.4s; }
.post-list li:nth-child(9) { animation-delay: 0.45s; }
.post-list li:nth-child(10) { animation-delay: 0.5s; }

.post-list li:hover {
  background: var(--surface);
  border-color: var(--border);
  transform: translateX(4px);
}

.post-title-link {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  display: block;
  margin-bottom: 0.25rem;
  transition: color 0.2s ease;
}

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

.post-date {
  font-size: 0.82rem;
  color: var(--muted);
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.post-excerpt {
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 0.2rem;
}

/* ─── Empty state (no posts) ────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1.5rem;
  animation: fadeIn 0.6s ease-out both;
}

.empty-icon {
  color: var(--muted);
  opacity: 0.4;
  margin-bottom: 1.5rem;
}

.empty-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.empty-text {
  font-size: 1rem;
  color: var(--muted);
  line-height: 1.7;
  max-width: 380px;
  margin: 0 auto;
}

/* ─── Single post header ────────────────────────────────── */
.post-header {
  margin-bottom: 2rem;
}

.post-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
}

.post-header .post-meta {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.4rem;
}

/* ─── Post content ──────────────────────────────────────── */
.post-content h2,
.post-content h3 {
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin: 2rem 0 0.5rem;
}

.post-content h2 {
  font-size: 1.45rem;
  letter-spacing: -0.01em;
}

.post-content h3 {
  font-size: 1.2rem;
  font-weight: 600;
}

.post-content p { margin-bottom: 1.2rem; }

.post-content a {
  color: var(--link);
  transition: color 0.2s ease;
}

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

.post-content code {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono',
               ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo,
               Consolas, 'DejaVu Sans Mono', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.post-content pre {
  background: var(--code-bg);
  padding: 1.2rem 1.5rem;
  overflow-x: auto;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  border-left: 3px solid var(--accent);
  line-height: 1.5;
}

.post-content pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  border-radius: 0;
}

.post-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 2rem 0;
  padding: 1rem 1.5rem;
  font-style: italic;
  color: var(--muted);
  background: var(--surface);
  border-radius: 0 6px 6px 0;
}

.post-content blockquote p:last-child {
  margin-bottom: 0;
}

.post-content img {
  max-width: 100%;
  display: block;
  margin: 1.5rem auto;
  border-radius: 6px;
}

.post-content ul,
.post-content ol {
  padding-left: 1.75rem;
  margin-bottom: 1.2rem;
}

.post-content li { margin-bottom: 0.3rem; }

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

/* ─── Back link ─────────────────────────────────────────── */
.back-link {
  display: inline-block;
  margin-bottom: 2rem;
  font-size: 0.95rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease, transform 0.2s ease;
}

.back-link:hover {
  color: var(--accent);
  transform: translateX(-3px);
}

/* ─── Reading progress bar ──────────────────────────────── */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: var(--accent);
  z-index: 1000;
  transition: width 0.1s linear;
}

/* ─── Footer ────────────────────────────────────────────── */
footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

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

.social-link {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  line-height: 1;
  padding: 8px;
  border-radius: 50%;
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.25s ease;
}

.social-link:hover {
  color: var(--accent);
  background: var(--surface);
  transform: translateY(-3px);
}

.social-link svg { display: block; }

/* ─── Reduced motion ────────────────────────────────────── */
@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;
  }
}

/* ─── Tablet ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .container {
    padding: 2rem 0 4rem;
  }

  .post-list li {
    padding: 1rem 1.2rem;
  }
}

/* ─── Mobile ────────────────────────────────────────────── */
@media (max-width: 580px) {
  body {
    font-size: 16px;
    padding: 0 1rem;
  }

  .container {
    padding: 1.5rem 0 3rem;
  }

  .site-title {
    font-size: 1.6rem;
  }

  .tagline {
    font-size: 0.88rem;
  }

  .header-row {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  nav {
    gap: 1rem;
  }

  nav a {
    font-size: 0.9rem;
  }

  .post-header h1 {
    font-size: 1.5rem;
  }

  .post-content h2 { font-size: 1.2rem; }
  .post-content h3 { font-size: 1.05rem; }

  .post-list li {
    padding: 1rem;
    border-radius: 6px;
  }

  .post-title-link {
    font-size: 1.05rem;
  }

  .post-list li:hover {
    transform: none;
  }

  footer {
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding-top: 1.2rem;
    margin-top: 3rem;
  }

  .footer-social {
    gap: 1.2rem;
  }

  .social-link {
    padding: 10px;
  }

  .post-content pre {
    padding: 1rem;
    border-radius: 4px;
    font-size: 0.9em;
  }

  .post-content blockquote {
    margin: 1.5rem 0;
    padding: 0.8rem 1rem;
  }

  .reading-progress {
    height: 2px;
  }
}
