:root {
  --bg: #f5efe6;
  --bg-secondary: #ebe4d6;
  --text: #4a3f35;
  --text-heading: #2d2518;
  --text-muted: #7a6f62;
  --accent: #8b5a2b;
  --accent-light: #c4956a;
  --border: #d4c9b8;
  --border-light: #e8e0d2;
  --code-bg: #ebe4d6;
  --link: #7a4a2a;
  --link-hover: #5a3a1a;
  --tag-bg: #d4c9b8;
  --tag-text: #5a4f3a;
  --shadow: rgba(45, 37, 24, 0.08) 0 2px 8px;
  --shadow-lg: rgba(45, 37, 24, 0.15) 0 4px 20px;

  --font-primary: "Ubuntu", system-ui, sans-serif;
  --font-heading: "Ubuntu", system-ui, sans-serif;
  --font-mono: "Ubuntu Mono", ui-monospace, monospace;

  font-family: var(--font-primary);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #2e2d2d;
    --bg-secondary: #272727;
    --text: #e3dbc9;
    --text-heading: #e4d0a5;
    --text-muted: #8a7f72;
    --accent: #688164;
    --accent-light: #d4a87a;
    --border: #474f46;
    --border-light: #2a2520;
    --code-bg: #1918166f;
    --link: #d19d83;
    --link-hover: #b38e57;
    --tag-bg: #1515152a;
    --tag-text: #edcd9bb5;
    --posts-list-title: #688164;
    --shadow: rgba(0, 0, 0, 0.3) 0 2px 8px;
    --shadow-lg: rgba(0, 0, 0, 0.5) 0 4px 20px;
  }

  .hljs {
    background: var(--code-bg);
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

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

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-heading);
  color: var(--text-heading);
  font-weight: 500;
  line-height: 1.3;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}
h2 {
  font-size: 1.75rem;
  margin: 1.5rem 0 0.75rem;
}
h3 {
  font-size: 1.25rem;
  margin: 1.25rem 0 0.5rem;
}

p {
  margin-bottom: 1rem;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

img {
  max-width: 100%;
  height: auto;
}

blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--text-muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

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

th {
  background: var(--bg-secondary);
  font-weight: 500;
}

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

li {
  margin-bottom: 0.25rem;
}

/* ── Header ─────────────────────────────────────────────── */

.site-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-heading);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  white-space: nowrap;
}

.logo-img {
  height: 2rem;
  width: 2rem;
  border-radius: 4px;
  object-fit: contain;
}

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

.nav-links a {
  color: var(--text-muted);
  font-size: 0.9rem;
}

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

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Search ─────────────────────────────────────────────── */

.search-box {
  position: relative;
}

.search-box input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  width: 200px;
  font-family: inherit;
  color: var(--text);
  transition:
    width 0.25s ease,
    padding 0.25s ease;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .search-box input {
    width: 36px;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    text-indent: -9999px;
    overflow: hidden;
    white-space: nowrap;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%237a6f62' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
  }

  .search-box input:focus,
  .search-box input.expanded {
    width: calc(100vw - 2rem);
    padding: 0.75rem 1rem;
    text-indent: 0;
    background-image: none;
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
    z-index: 300;
    box-shadow: var(--shadow-lg);
  }
}

.search-results {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.25rem;
  max-height: 300px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  z-index: 1000;
}

@media (max-width: 768px) {
  .search-box input:focus ~ .search-results,
  .search-box input.expanded ~ .search-results {
    position: fixed;
    top: 3.5rem;
    left: 0.5rem;
    right: 0.5rem;
    margin-top: 0;
  }
}

.search-result-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
}

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

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

.search-result-item a:hover {
  color: var(--accent);
}

/* ── Language Dropdown ───────────────────────────────────── */

.lang-dropdown {
  position: relative;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    border-color 0.2s,
    color 0.2s;
  line-height: 1;
}

.lang-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.lang-btn svg {
  flex-shrink: 0;
}

.lang-flag {
  width: 24px;
  height: 18px;
  border-radius: 2px;
  object-fit: cover;
}

.lang-dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lang-dropdown-menu img {
  width: 24px;
  height: 18px;
  border-radius: 2px;
  object-fit: cover;
}

.lang-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  min-width: 120px;
  overflow: hidden;
  z-index: 200;
}

.lang-dropdown-menu.open {
  display: block;
}

.lang-dropdown-menu a {
  display: block;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  color: var(--text);
  transition: background 0.15s;
}

.lang-dropdown-menu a:hover {
  background: var(--bg-secondary);
}

.lang-dropdown-menu a.active {
  color: var(--accent);
  font-weight: 600;
}

/* ── Hamburger (hidden on desktop) ───────────────────────── */

.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  width: 36px;
  height: 36px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition:
    transform 0.3s,
    opacity 0.3s;
  margin: 0 auto;
}

.hamburger.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger.active span:nth-child(2) {
  opacity: 0;
}

.hamburger.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── Side Panel ──────────────────────────────────────────── */

.side-panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.3s;
}

.side-panel-overlay.open {
  display: block;
  opacity: 1;
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 280px;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  padding: 5rem 1.5rem 2rem;
}

.side-panel.open {
  transform: translateX(0);
}

.side-panel-nav {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 2rem;
}

.side-panel-nav a {
  display: block;
  padding: 0.75rem 0;
  font-size: 1rem;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
}

.side-panel-nav a:last-child {
  border-bottom: none;
}

.side-panel-nav a:hover {
  color: var(--accent);
}

.side-panel-tags h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.side-panel-tags .tag-filter {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.side-panel-tags .tag-filter .tag {
  cursor: pointer;
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  text-align: left;
  transition:
    background 0.2s,
    color 0.2s,
    border-color 0.2s;
  font-size: 0.9rem;
  font-family: inherit;
  background: none;
}

.side-panel-tags .tag-filter .tag:hover {
  border-color: var(--accent);
}

.side-panel-tags .tag-filter .tag.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

[dir="rtl"] .side-panel {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
}

[dir="rtl"] .side-panel.open {
  transform: translateX(0);
}

/* ── Site Content ────────────────────────────────────────── */

.site-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
  flex: 1;
  width: 100%;
}

.post-title,
.page-title {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.post-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.tag:hover {
  background: var(--accent-light);
  color: var(--bg);
}

mark {
  background: var(--accent-light);
  color: var(--text-heading);
  padding: 0 2px;
  border-radius: 2px;
}

/* ── Desktop Tag Sidebar (home page) ─────────────────────── */

.home-layout {
  display: flex;
  gap: 2rem;
}

.site-content:has(.home-layout) {
  max-width: 1100px;
}

.home-layout .posts-list {
  flex: 1;
  min-width: 0;
}

.tag-sidebar {
  position: sticky;
  top: 5rem;
  align-self: start;
  width: 220px;
  flex-shrink: 0;
}

.tag-sidebar-title {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.tag-filter {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tag-filter .tag {
  cursor: pointer;
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  text-align: left;
  transition:
    background 0.2s,
    color 0.2s,
    border-color 0.2s;
  font-size: 0.9rem;
  font-family: inherit;
}

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

.tag-filter .tag.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.post-content,
.page-content {
  line-height: 1.8;
}

.post-card {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border-light);
}

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

.post-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.post-card h2 a {
  color: var(--text-heading);
}

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

.post-excerpt {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.posts-list {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid var(--accent);
  background: var(--bg-secondary);
  padding: 2rem;
  border-radius: 8px;
  margin-bottom: 2rem;
}

.posts-list h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.latest-posts-title {
  color: var(--posts-list-title);
}

/* ── Mobile ──────────────────────────────────────────────── */

@media (max-width: 768px) {
  .nav {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .nav-links {
    display: none;
  }

  .hamburger {
    display: flex;
    order: 10;
  }

  .lang-btn {
    padding: 0.35rem 0.5rem;
  }

  .lang-btn svg {
    display: none;
  }

  .site-content {
    padding: 1rem;
  }

  h1 {
    font-size: 2rem;
  }
  h2 {
    font-size: 1.5rem;
  }

  .post-title,
  .page-title {
    font-size: 2rem;
  }

  .home-layout {
    flex-direction: column;
  }

  .tag-sidebar {
    width: 100%;
    position: static;
  }
}

/* ── RTL ─────────────────────────────────────────────────── */

[dir="rtl"] {
  font-family: "Vazirmatn", var(--font-primary);
}

[dir="rtl"] .nav-links {
  flex-direction: row-reverse;
}

[dir="rtl"] .nav-right {
  margin-left: 0;
  margin-right: auto;
}

[dir="rtl"] .lang-dropdown-menu {
  right: auto;
  left: 0;
}

[dir="rtl"] blockquote {
  border-left: none;
  border-right: 4px solid var(--accent);
  padding-left: 0;
  padding-right: 1rem;
}

[dir="rtl"] ul,
[dir="rtl"] ol {
  padding-left: 0;
  padding-right: 1.5rem;
}

[dir="rtl"] .tag-filter .tag {
  text-align: right;
}
