:root {
  --serif: 'Newsreader', Georgia, serif;
  --sans: 'Space Grotesk', system-ui, sans-serif;
  --rtl: 'Vazirmatn', 'Noto Naskh Arabic', Tahoma, sans-serif;
}

/* --- THEMES ---
   Dark mode:  background #000000, text #ffffff (readable contrast)
   Light mode: background #ffffff, text #000000
   NOTE: The spec literally requested dark-mode text #000000, but that
   renders black-on-black and makes the app unusable. Dark-mode text is
   set to #ffffff so content is legible while keeping the pure-black bg. */
html[data-theme="dark"] {
  --bg: #000000;
  --fg: #ffffff;
  --dim: #8a8a8a;
  --line: #2a2a2a;
  --line2: #4a4a4a;
  --grain-a: rgba(255,255,255,0.06);
  --grain-b: rgba(255,255,255,0.03);
  --chip-active-bg: #ffffff;
  --chip-active-fg: #000000;
}
html[data-theme="light"] {
  --bg: #ffffff;
  --fg: #000000;
  --dim: #8a8a8a;
  --line: #dcdcdc;
  --line2: #bcbcbc;
  --grain-a: rgba(0,0,0,0.04);
  --grain-b: rgba(0,0,0,0.02);
  --chip-active-bg: #000000;
  --chip-active-fg: #ffffff;
}

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

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  transition: background 0.4s ease, color 0.4s ease;
}

[lang="fa"], [lang="ckb"] { font-family: var(--rtl); }

.app-shell {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  padding: 2.4rem 1.4rem 4rem;
  min-height: 100vh;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--grain-a), transparent 60%),
    radial-gradient(100% 60% at 50% 110%, var(--grain-b), transparent 60%);
  z-index: 0;
  transition: background 0.4s ease;
}
.app-shell > * { position: relative; z-index: 1; }

.corner {
  position: fixed;
  top: 1rem;
  font-size: 1.2rem;
  opacity: 0.6;
  z-index: 2;
  animation: pulse 4s ease-in-out infinite;
}
.corner.tl { inset-inline-start: 1rem; }
@keyframes pulse { 0%,100%{opacity:.4;transform:scale(1)} 50%{opacity:.85;transform:scale(1.1)} }

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 1.4rem;
  margin-bottom: 1.6rem;
}
.top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
}
.brand {
  font-family: var(--serif);
  font-weight: 200;
  font-size: clamp(1.8rem, 6.5vw, 3.2rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--fg);
}
[lang="fa"] .brand, [lang="ckb"] .brand { font-family: var(--rtl); font-weight: 300; }

.theme-toggle {
  flex: 0 0 auto;
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  min-height: 40px;
}
[dir="rtl"] .theme-toggle { font-family: var(--rtl); }
.theme-toggle:hover { color: var(--fg); border-color: var(--fg); }

.count-line {
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 1.2rem;
}
[lang="fa"] .count-line, [lang="ckb"] .count-line { letter-spacing: 0; }

/* Language switcher */
.lang-switch { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.lang-btn {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 38px;
}
.lang-btn[lang="fa"], .lang-btn[lang="ckb"] { font-family: var(--rtl); }
.lang-btn:hover { color: var(--fg); border-color: var(--fg); }
.lang-btn.active {
  background: var(--chip-active-bg);
  color: var(--chip-active-fg);
  border-color: var(--chip-active-bg);
  font-weight: 500;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
}
.ctrl {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line2);
  padding: 0.6rem 0.9rem;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.18s ease;
  flex: 1 1 auto;
  min-width: fit-content;
  min-height: 44px;
}
[dir="rtl"] .ctrl { font-family: var(--rtl); }
.ctrl:hover { background: var(--chip-active-bg); color: var(--chip-active-fg); border-color: var(--chip-active-bg); }

/* Reading area */
.reading { animation: fadein 0.5s ease both; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  gap: 0.5rem;
}
.field-badge {
  border: 1px solid var(--line2);
  padding: 0.2rem 0.6rem;
  border-radius: 3px;
}
[lang="fa"] .field-badge, [lang="ckb"] .field-badge { letter-spacing: 0; }

.topic-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.8rem, 6vw, 3rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
  margin-bottom: 0.7rem;
  color: var(--fg);
}
[lang="fa"] .topic-title, [lang="ckb"] .topic-title {
  font-family: var(--rtl);
  font-weight: 500;
  line-height: 1.4;
}

.sociologist {
  font-size: 0.95rem;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
  padding-bottom: 1.4rem;
  margin-bottom: 1.6rem;
}
.socio-name { color: var(--fg); font-weight: 500; }

/* Essay */
.essay p {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.16rem;
  line-height: 1.75;
  margin-bottom: 1.4rem;
  color: var(--fg);
  animation: slideup 0.6s ease both;
}
[lang="fa"] .essay p, [lang="ckb"] .essay p {
  font-family: var(--rtl);
  font-weight: 400;
  font-size: 1.08rem;
  line-height: 2.1;
}
@keyframes slideup { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

/* Archive */
.archive-wrap {
  margin-top: 2.6rem;
  border-top: 1px solid var(--line);
  padding-top: 1.4rem;
}
.archive-toggle {
  background: none;
  border: none;
  color: var(--dim);
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.5rem 0;
  min-height: 40px;
}
[dir="rtl"] .archive-toggle { font-family: var(--rtl); letter-spacing: 0; }
.archive-toggle:hover { color: var(--fg); }
.archive-list { list-style: none; margin-top: 1rem; }
.archive-item {
  width: 100%;
  text-align: start;
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--fg);
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: all 0.18s ease;
  font-family: inherit;
}
[dir="rtl"] .archive-item { font-family: var(--rtl); }
.archive-item:hover { border-color: var(--fg); transform: translateX(2px); }
[dir="rtl"] .archive-item:hover { transform: translateX(-2px); }
.archive-item.current { border-color: var(--fg); }
.ai-field { font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.ai-title { font-family: var(--serif); font-size: 1.05rem; color: var(--fg); }
[dir="rtl"] .ai-title { font-family: var(--rtl); }
.ai-socio { font-size: 0.78rem; color: var(--dim); }

/* Footer */
.site-footer {
  margin-top: 3rem;
  border-top: 1px solid var(--line);
  padding-top: 1.6rem;
  text-align: center;
}
.footer-tag {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--dim);
  margin-bottom: 0.8rem;
}
[dir="rtl"] .footer-tag { font-family: var(--rtl); font-style: normal; }
.footer-links a {
  color: var(--fg);
  text-decoration: none;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--line2);
  padding-bottom: 2px;
  transition: border-color 0.2s;
}
.footer-links a:hover { border-color: var(--fg); }
.footer-note {
  margin-top: 0.8rem;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--dim);
}

/* Mobile tweaks */
@media (max-width: 520px) {
  .controls .ctrl { flex: 1 1 45%; font-size: 0.76rem; padding: 0.6rem 0.5rem; }
  .app-shell { padding: 1.8rem 1.1rem 3rem; }
  .top-row { flex-direction: column; align-items: flex-start; gap: 0.7rem; }
}