/* Tokens moved to /tokens/{primitives,semantic,components}.css — loaded before this file. */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  background: var(--color-surface-page); color: var(--color-text-default);
  font-family: 'IBM Plex Sans Arabic', 'Inter', -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
  direction: rtl;
}
body {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow-x: hidden;
}
body > div { display: contents; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--color-brand) 40%, transparent); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--color-brand) 70%, transparent); }
::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--color-brand) 40%, transparent) transparent; }
body::before {
  content: ''; position: fixed; inset: 0;
  background: var(--grid-fade);
  pointer-events: none; z-index: 0;
}
main, nav, footer { position: relative; z-index: 1; }

/* ── Global: selection, cursor glow ── */
::selection { background: color-mix(in srgb, var(--color-brand) 35%, transparent); color: var(--color-text-default); }
body::after {
  content: ''; position: fixed; width: 300px; height: 300px;
  border-radius: 50%; pointer-events: none; z-index: -1;
  background: radial-gradient(circle, color-mix(in srgb, var(--color-brand) 6%, transparent) 0%, transparent 70%);
  transform: translate(-50%, -50%);
  transition: left .1s ease-out, top .1s ease-out;
  left: var(--cursor-x, -200px); top: var(--cursor-y, -200px);
}
html { background: var(--color-surface-page); }
body { background: transparent; }

/* ── Square motif ── */
.sq-mark {
  display: inline-block;
  width: var(--c-sq-mark); height: var(--c-sq-mark);
  background: var(--color-brand);
  flex-shrink: 0;
}
.sq-mark--sm {
  display: inline-block;
  width: var(--c-sq-mark-sm); height: var(--c-sq-mark-sm);
  background: var(--color-brand);
  flex-shrink: 0;
}
.sq-frame {
  border: var(--border-accent);
  background: color-mix(in srgb, var(--color-brand) 4%, var(--color-surface-page));
}
.sq-bar {
  position: relative;
}
.sq-bar::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: var(--border-bar-w);
  height: 100%;
  background: var(--color-brand);
}
.nav__monogram-square {
  width: var(--c-mono-size); height: var(--c-mono-size);
  background: var(--color-brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-surface-page); /* TODO(token-semantics): should be --color-interactive-primary-text — see TODO_TOKENS.md */
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

/* NAV */
.nav {
  height: var(--c-nav-height);
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 var(--c-nav-px);
  border-bottom: var(--border-rule);
  backdrop-filter: blur(8px); /* intentionally literal: 8px backdrop blur — visual-effect value, not a size dimension */
  background: color-mix(in srgb, var(--color-surface-page) 72%, transparent);
  position: sticky; top: 0; z-index: 50;
  width: 100%; max-width: 100%;
}
.nav__monogram {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-base); color: var(--color-brand); letter-spacing: 0.04em;
  direction: ltr;
  text-decoration: none;
}
.nav__monogram span { color: var(--color-text-muted); }
.nav__right { display: flex; gap: var(--c-nav-gap); align-items: center; }
.nav__links { display: flex; gap: var(--c-nav-gap); font-size: var(--text-base); }
.nav__links a {
  color: var(--color-text-muted); text-decoration: none;
  transition: color 0.2s; font-weight: 500;
}
.nav__links a:hover { color: var(--color-text-default); }
.nav__split-btn { position: relative; display: flex; direction: ltr; }
.nav__split-main {
  padding: var(--c-toggle-btn-py) var(--space-3) var(--c-toggle-btn-py) var(--c-toggle-btn-px);
  background: var(--color-brand); color: var(--color-surface-page);
  border: none; border-radius: var(--c-pill-radius) 0 0 var(--c-pill-radius);
  font-family: 'IBM Plex Sans Arabic', 'Inter', system-ui, sans-serif;
  font-size: var(--text-base); font-weight: 500;
  text-decoration: none; cursor: pointer; transition: filter 0.2s;
}
.nav__split-main:hover { filter: brightness(1.1); }
.nav__split-arrow {
  padding: var(--c-toggle-btn-py) var(--space-3);
  background: var(--color-brand); color: var(--color-surface-page);
  border: none; border-radius: 0 var(--c-pill-radius) var(--c-pill-radius) 0;
  border-left: 1px solid color-mix(in srgb, var(--color-surface-page) 30%, var(--color-brand));
  font-size: 14px; cursor: pointer;
  transition: background 0.2s;
  display: flex; align-items: center; justify-content: center;
  position: relative; width: 36px;
}
.nav__split-arrow:hover { background: color-mix(in srgb, var(--color-brand) 85%, white); }
.nav__split-arrow-up { position: absolute; opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s; }
.nav__split-arrow-down { transition: opacity .3s, transform .3s; }
.nav__split-arrow:hover .nav__split-arrow-up { opacity: 1; transform: translateY(0); }
.nav__split-arrow:hover .nav__split-arrow-down { opacity: 0; transform: translateY(-4px); }
.nav__split-menu {
  position: absolute; top: calc(100% + var(--space-2)); left: 0;
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--c-pill-radius);
  box-shadow: var(--shadow-card);
  min-width: 200px;
  z-index: 100; overflow: hidden;
  display: flex; flex-direction: column;
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility 0s .3s;
  pointer-events: none;
}
.nav__split-arrow:hover + .nav__split-menu,
.nav__split-menu:hover,
.nav__split-menu.show {
  opacity: 1; visibility: visible;
  transition: opacity .2s, visibility 0s 0s;
  pointer-events: auto;
}
.nav__split-menu::before {
  content: ''; position: absolute; top: calc(-1 * var(--space-3)); left: 0; right: 0; height: var(--space-3);
}
.nav__split-menu a {
  padding: var(--space-2-5) var(--space-4);
  color: var(--color-text-muted); text-decoration: none;
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-sm);
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s;
}
.nav__split-menu a:hover {
  background: var(--color-surface-elevated); color: var(--color-brand);
}
.theme-toggle {
  display: flex; background: var(--color-surface-card);
  border: var(--border-rule); border-radius: var(--c-pill-radius); padding: var(--c-toggle-pad);
  direction: ltr;
}
.theme-toggle button {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs); letter-spacing: 0.06em;
  padding: var(--c-toggle-btn-py) var(--c-toggle-btn-px); border-radius: var(--c-pill-radius);
  transition: all 0.2s;
}
.theme-toggle button.active { background: var(--color-interactive-primary); color: var(--color-surface-page); /* TODO(token-semantics): should be --color-interactive-primary-text — see TODO_TOKENS.md */ font-weight: 500; }

/* HERO */
.hero {
  min-height: calc(100svh - var(--c-nav-height));
  max-width: var(--c-content-max); margin: 0 auto; width: 100%;
  padding: var(--space-8) var(--space-12);
  display: grid;
  grid-template-columns: 1fr var(--c-hero-portrait-max);
  gap: var(--c-hero-gap);
  align-items: center;
}

.status-line {
  font-size: var(--text-sm);
  color: var(--color-text-faint); margin-bottom: var(--space-6);
  display: flex; align-items: center; gap: var(--space-2-5);
}
.status-dot {
  width: var(--c-status-dot-size); height: var(--c-status-dot-size); border-radius: var(--radius-sharp);
  background: var(--color-brand); box-shadow: 0 0 8px var(--color-brand);
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.hero__name-ar {
  font-size: clamp(40px, 5vw, 60px);
  font-weight: 700; letter-spacing: -0.01em;
  line-height: 1.1; color: var(--color-text-default);
  margin-bottom: var(--space-2);
}
.hero__name-ar .arrow {
  color: var(--color-brand); font-weight: 300; font-size: 0.65em;
  margin-inline-start: var(--space-1-5);
}
.hero__name-en {
  font-family: 'Inter', sans-serif;
  font-size: clamp(15px, 1.3vw, 18px);
  color: var(--color-text-muted); font-weight: 400;
  letter-spacing: 0.02em; direction: ltr;
  text-align: right;
  margin-bottom: var(--space-7);
}

.hero__lede-ar {
  font-size: clamp(18px, 1.65vw, 22px);
  font-weight: 400; line-height: 1.75;
  color: var(--color-text-default); margin-bottom: var(--space-3-5);
}
.hero__lede-ar em {
  color: var(--color-brand); font-style: normal; font-weight: 600;
}
.hero__lede-en {
  font-family: 'Inter', sans-serif;
  font-size: clamp(13px, 1.05vw, 15px);
  line-height: 1.6; color: var(--color-text-muted);
  direction: ltr; text-align: right;
  margin-bottom: var(--space-7);
}

.hero__meta {
  display: flex; flex-direction: column; gap: var(--space-2-5);
  font-size: var(--text-base);
  color: var(--color-text-muted);
  padding-top: var(--c-writing-py); border-top: var(--border-rule);
  margin-bottom: var(--space-6);
}
.hero__meta-item { display: flex; gap: var(--space-2-5); align-items: baseline; }
.hero__meta-item .label {
  color: var(--color-text-faint);
  font-size: var(--text-sm);
  font-weight: 500;
  min-width: 80px; /* intentionally literal: label-column min-width controls vertical alignment of meta items */
}

.socials {
  display: flex; align-items: center; gap: var(--space-2-5);
  direction: ltr; flex-wrap: wrap;
  justify-content: flex-end;
}
.socials__sep {
  width: 1px; height: var(--space-5-5);
  background: var(--color-border-default);
  margin: 0 var(--space-1-5);
}
.social {
  display: flex; align-items: center; justify-content: center;
  width: var(--c-social-size); height: var(--c-social-size);
  border-radius: var(--c-social-radius);
  background: var(--color-surface-card);
  border: none;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: all 0.2s;
  position: relative;
}
.social[title]:hover::after {
  content: attr(title);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--color-brand); color: var(--color-surface-page);
  padding: 3px 8px; border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
  white-space: nowrap; z-index: 10; pointer-events: none;
}
.social:hover {
  background: color-mix(in srgb, var(--color-interactive-primary) 15%, var(--color-surface-card));
  color: var(--color-interactive-primary);
  transform: translateY(-2px); /* intentionally literal: 2px hover-lift on .social */
}
.social svg { width: var(--c-social-icon); height: var(--c-social-icon); display: block; }

.hero__portrait {
  aspect-ratio: 4/5;
  max-width: var(--c-hero-portrait-max);
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  background: var(--color-surface-card);
  box-shadow: var(--shadow-card);
  border: var(--border-rule);
}
.hero__portrait img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: center 22%;
  transition: transform 0.6s ease, opacity 0.4s ease;
  position: absolute; inset: 0;
}
.hero__portrait:hover img { transform: scale(1.03); }
.hero__portrait::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,0.45) 100%);
}
.portrait-meta {
  position: absolute; bottom: var(--c-portrait-bottom); left: var(--space-5); right: var(--space-5);
  display: flex; justify-content: space-between; align-items: end;
  z-index: 2;
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs);
  color: rgba(255,255,255,0.92); letter-spacing: 0.06em;
  direction: ltr;
}

/* SECTION HEADS */
.section-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: var(--c-section-head-mb);
}
.section-head h2 {
  font-size: var(--text-md); font-weight: 600; color: var(--color-text-default);
  display: flex; align-items: center; gap: var(--space-3);
}
.section-head h2::before {
  content: ''; width: 10px; height: 10px;
  background: var(--color-brand); display: inline-block;
}
.section-head__count {
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-sm);
  color: var(--color-text-faint); direction: ltr;
}

/* RESEARCH */
.research { max-width: var(--c-content-max); margin: 0 auto; width: 100%; padding: var(--space-12) var(--space-12); }
.research__grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4);
}
.card {
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--c-card-radius); padding: var(--c-card-pad);
  display: flex; flex-direction: column;
  min-height: var(--c-card-min-h);
  transition: border-color 0.25s, transform 0.25s, box-shadow 0.25s;
  cursor: pointer;
  position: relative; overflow: hidden;
  /* Card is rendered as <a>, so reset link styling — the click affordance
     is the hover lift + accent border, not underlined blue text. */
  color: inherit;
  text-decoration: none;
}
.card:visited, .card:hover, .card:focus { color: inherit; text-decoration: none; }
.card:hover {
  border-color: var(--card-accent, var(--color-brand));
  transform: translateY(-3px); box-shadow: var(--shadow-card); /* intentionally literal: 3px hover-lift on .card (deeper than .social's 2px because cards are larger) */
}
.card--published { --card-accent: var(--color-brand); }
.card--active { --card-accent: var(--color-brand); }
.card--design { --card-accent: var(--color-brand); }
.card__head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--c-card-head-mb); direction: ltr;
}
.pill {
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: 0.14em;
  padding: var(--c-pill-pad); border-radius: var(--c-pill-radius); border: 1px solid;
}
.pill--published { color: var(--color-brand); border-color: var(--color-brand);
  background: color-mix(in srgb, var(--color-brand) 8%, transparent); }
.pill--active { color: var(--color-brand); border-color: var(--color-brand);
  background: color-mix(in srgb, var(--color-brand) 8%, transparent); }
.pill--design { color: var(--color-brand); border-color: var(--color-brand);
  background: color-mix(in srgb, var(--color-brand) 8%, transparent); }
.card__index {
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs); color: var(--color-text-faint);
}
.card__metric {
  font-family: 'JetBrains Mono', monospace; font-weight: 400;
  font-size: clamp(26px, 3vw, 34px);
  color: var(--color-text-default); margin-bottom: var(--space-1-5);
  letter-spacing: -0.01em;
  direction: ltr; text-align: left;
}
.card__metric-label {
  font-size: var(--text-sm); color: var(--color-text-muted);
  margin-bottom: var(--c-card-head-mb); line-height: 1.6;
  font-family: 'JetBrains Mono', monospace;
  direction: ltr; text-align: left;
}
.card__title-ar {
  font-size: var(--text-md); font-weight: 500; line-height: 1.55;
  margin-top: auto; color: var(--color-text-default);
}
.card__title-en {
  font-family: 'Inter', sans-serif;
  font-size: var(--text-sm); color: var(--color-text-faint);
  direction: ltr; text-align: left;
  margin-top: var(--space-1-5); line-height: 1.5;
}
.card__caption {
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs);
  color: var(--color-text-faint); margin-top: var(--space-2-5);
  direction: ltr; text-align: left;
}

/* WRITING */
.writing { max-width: var(--c-content-max); margin: 0 auto; width: 100%; padding: var(--space-8) var(--space-12) var(--space-16); }
.writing__list { display: flex; flex-direction: column; border-top: var(--border-rule); }
.writing__item {
  display: flex; flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-1); border-bottom: var(--border-rule);
  text-decoration: none; color: var(--color-text-default);
  transition: background 0.2s, padding 0.2s;
  position: relative;
}
.writing__item::before {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--border-bar-w);
  background: var(--color-brand);
  opacity: 0;
  transition: opacity 0.2s;
}
.writing__item:hover::before {
  opacity: 1;
}
.writing__item:hover {
  background: var(--color-surface-elevated);
  padding-inline-start: var(--space-4); padding-inline-end: var(--space-4);
}
.writing__meta {
  display: flex; justify-content: space-between; align-items: baseline;
  direction: ltr;
}
.writing__date {
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs); color: var(--color-text-faint);
  direction: ltr; flex-shrink: 0;
}
.writing__lang {
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs);
  color: var(--color-text-faint); letter-spacing: 0.04em;
  direction: ltr;
  flex-shrink: 0;
}
.writing__titles {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: var(--space-4);
}
.writing__title-ar {
  font-size: var(--text-sm); font-weight: 500; line-height: 1.45; color: var(--color-text-default);
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  direction: rtl;
}
.writing__title-en {
  font-family: 'Inter', sans-serif;
  font-size: var(--text-sm); color: var(--color-text-faint); line-height: 1.4;
  direction: ltr; text-align: left;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* PORTRAIT — light/dark variants. Both images render; CSS hides the wrong
   one based on the html[data-theme] attribute set by ThemeToggle. */
.portrait-img--light { opacity: 0; }
[data-theme="light"] .portrait-img--dark { opacity: 0; }
[data-theme="light"] .portrait-img--light { opacity: 1; }
.portrait-img { transition: opacity 0.4s ease; }

/* BLOG POST PAGE — /blog/<slug> reading view */
.post-page { padding: var(--space-8) 0 var(--space-16); position: relative; z-index: 1; direction: ltr; }

/* Hero — full width, outside the layout */
.post-hero {
  display: block;
  width: 100%;
  max-width: var(--c-post-hero-max);
  height: auto;
  aspect-ratio: 1200/630; object-fit: cover;
  border-radius: var(--radius-md); border: var(--border-rule);
  margin: 0 auto var(--space-10);
}

/* 2-column: article + sidebar */
.post-layout { position: relative; max-width: var(--c-content-max); margin: 0 auto; padding: 0 var(--space-12); }
.post { max-width: var(--c-post-body-max); margin: 0 auto; }

/* ── Sticky sidebar — far right ── */
.post-sidebar {
  width: var(--c-post-sidebar-w);
  position: fixed;
  right: var(--space-12);
  top: var(--space-16);
  direction: rtl; text-align: right;
  max-height: calc(100vh - 96px); /* intentionally literal: 96px = nav height (64px) + breathing gap (32px) */
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 10;
}
.sidebar-divider { height: 1px; background: var(--color-border-default); margin: var(--space-4) 0; }

/* TOC */
.toc__title {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs); font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--color-text-muted); margin: 0 0 var(--space-2-5);
}
.toc__list { list-style: none; padding: 0; margin: 0; }
.toc__item { margin: 0; }
.toc__link {
  display: block; padding: var(--space-1) 0;
  font-size: var(--text-sm); line-height: 1.45;
  color: var(--color-text-muted); text-decoration: none;
  border-right: 2px solid transparent; /* intentionally literal: 2px right-border indicator for active TOC entries */
  padding-right: var(--space-2-5);
  transition: color .15s, border-color .15s;
}
.toc__link:hover { color: var(--color-text-default); }
.toc__link.active {
  color: var(--color-interactive-primary); font-weight: 500;
  border-right-color: var(--color-interactive-primary);
}

/* Newsletter card */
.newsletter {
  position: relative;
  border: var(--border-rule);
  border-radius: var(--c-newsletter-radius);
  background: color-mix(in srgb, var(--color-text-default) 2%, var(--color-surface-page));
  padding: var(--c-newsletter-pad);
}
.newsletter__close {
  position: absolute;
  top: var(--space-1-5);
  left: var(--space-1-5);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
  padding: var(--space-0-5) var(--space-1);
  line-height: 1;
  border-radius: var(--radius-sharp);
  transition: color .15s, background .15s;
}
.newsletter__close:hover {
  color: var(--color-text-muted);
  background: color-mix(in srgb, var(--color-text-default) 6%, transparent);
}
.newsletter__title {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs); font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--color-text-muted); margin: 0 0 var(--space-1);
}
.newsletter__desc {
  font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.4;
  margin: 0 0 var(--space-2);
}
.newsletter__form { display: flex; flex-direction: column; gap: var(--space-1-5); }
.newsletter__input {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs); padding: var(--space-1-5) var(--space-2-5);
  border: var(--border-rule); border-radius: var(--radius-sm);
  background: var(--color-surface-page); color: var(--color-text-default);
  outline: none; transition: border-color .15s;
}
.newsletter__input:focus { border-color: var(--color-interactive-primary); }
.newsletter__input::placeholder { color: var(--color-text-faint); }
.newsletter__btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs); font-weight: 600;
  letter-spacing: .04em;
  padding: var(--space-1-5) var(--space-2-5);
  border: var(--border-rule); border-radius: var(--radius-sm);
  background: transparent; color: var(--color-text-muted);
  cursor: pointer; transition: border-color .15s, color .15s;
}
.newsletter__btn:hover { border-color: var(--color-interactive-primary); color: var(--color-interactive-primary); }
.newsletter__btn:disabled { opacity: .5; cursor: default; }
.newsletter__msg {
  font-size: var(--text-xs); color: var(--color-brand); margin-top: var(--space-1);
  min-height: 0;
}
.newsletter__msg.success { min-height: 1em; }

/* Hide sidebar on small screens */
@media (max-width: 1200px) { /* intentionally literal: @media query, CSS variables not supported */
  .post-sidebar { display: none; }
}
.post-back { display: inline-block; font-family: 'JetBrains Mono', monospace; font-size: var(--text-sm); color: var(--color-text-muted); text-decoration: none; margin-bottom: var(--space-6); padding: var(--space-1-5) var(--space-3); border: var(--border-rule); border-radius: var(--radius-sm); letter-spacing: .04em; }
.post-back:hover { color: var(--color-interactive-primary); border-color: var(--color-interactive-primary); }
.post-head { padding-bottom: var(--space-6); margin-bottom: var(--space-8); border-bottom: var(--border-rule); }
.post-meta { display: flex; gap: var(--space-3); flex-wrap: wrap; font-family: 'JetBrains Mono', monospace; font-size: var(--text-sm); color: var(--color-text-muted); letter-spacing: .04em; text-transform: uppercase; margin-bottom: var(--space-4); }
.post-meta__sep { color: var(--color-text-faint); }
.post-title-ar { font-size: var(--text-2xl); font-weight: 600; line-height: 1.3; margin: 0 0 var(--space-2); letter-spacing: -.01em; }
.post-title-en { font-family: 'JetBrains Mono', monospace; font-size: var(--text-base); color: var(--color-text-muted); margin: 0; letter-spacing: .02em; }
.post-body { font-size: var(--text-md); line-height: 1.85; color: var(--color-text-default); }
.post-body h2 { font-size: var(--text-2xl); font-weight: 600; margin: var(--space-12) 0 var(--space-4); letter-spacing: -.01em; }
.post-body h3 { font-size: var(--text-xl); font-weight: 600; margin: var(--c-post-margin-hr) 0 var(--space-3); }
.post-body p { margin: 0 0 var(--space-4); }
.post-body strong, .post-body b { color: var(--color-text-default); font-weight: 600; }
.post-body em { color: var(--color-brand); font-style: normal; font-weight: 500; }
.post-body a { color: var(--color-brand); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: var(--c-link-underline-offset); }
.post-body blockquote { border-inline-start-width: var(--border-bar-w); border-inline-start-style: solid; border-inline-start-color: var(--color-brand); padding: var(--c-blockquote-pad); margin: var(--space-6) 0; color: var(--color-text-muted); }
.post-body code { font-family: 'JetBrains Mono', monospace; font-size: .92em; background: var(--color-surface-elevated); padding: var(--space-0-5) var(--space-1-5); border-radius: var(--radius-sm); }
.post-body pre { background: var(--color-surface-elevated); border: var(--border-rule); border-radius: var(--radius-md); padding: var(--space-4) var(--space-4); overflow-x: auto; margin: var(--space-6) 0; }
.post-body pre code { background: transparent; padding: 0; }
.post-body ul, .post-body ol { padding-inline-start: var(--space-6); margin: 0 0 var(--space-4); }
.post-body li { margin: 0 0 var(--space-2); }
.post-body hr { border: none; border-top: var(--border-rule); margin: var(--c-post-margin-hr) 0; }
.post-body img { max-width: 100%; border-radius: var(--radius-md); margin: var(--space-6) 0; }

/* ── Footnotes / citations ── */
.post-body .fn { font-size: inherit; vertical-align: baseline; }
.post-body .fn a {
  color: var(--color-brand); font-weight: 600;
  text-decoration: none;
  padding: 0 var(--space-0-5);
  border-radius: var(--radius-sharp);
  transition: background .15s;
}
.post-body .fn a:hover {
  background: color-mix(in srgb, var(--color-brand) 15%, transparent);
}

/* Back-arrow in ref list */
.post-body .ref-list .ref-back {
  color: var(--color-brand); font-size: var(--text-sm);
  text-decoration: none; margin-inline-start: var(--space-1);
  opacity: .5; transition: opacity .15s;
}
.post-body .ref-list .ref-back:hover { opacity: 1; }

/* Flash highlight for footnote in text */
@keyframes fn-highlight {
  0%   { background: color-mix(in srgb, var(--color-brand) 25%, transparent); border-radius: var(--radius-sharp); }
  100% { background: transparent; }
}
.post-body .fn.fn-flash {
  animation: fn-highlight 5s ease-out forwards;
}

/* Reference list items */
.post-body .ref-list { list-style: none; padding: 0; margin: var(--space-6) 0 0; }
.post-body .ref-list li {
  display: flex; gap: var(--space-2); align-items: baseline;
  padding: var(--space-2) var(--space-3);
  margin: 0;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); line-height: 1.65;
  transition: background .3s;
}
.post-body .ref-list li + li { border-top: var(--border-rule); }
.post-body .ref-list .ref-num {
  color: var(--color-brand); font-weight: 600;
  font-size: var(--text-sm); font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0; min-width: var(--space-6);
}
.post-body .ref-list .ref-label {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .04em;
  padding: 1px var(--space-1-5); border-radius: var(--radius-sharp);
  text-transform: uppercase; flex-shrink: 0;
  margin-inline-start: auto; white-space: nowrap;
}
.post-body .ref-list .ref-label.citation { background: color-mix(in srgb, var(--color-brand) 15%, transparent); color: var(--color-brand); }
.post-body .ref-list .ref-label.note { background: color-mix(in srgb, var(--color-text-muted) 12%, transparent); color: var(--color-text-muted); }
.post-body .ref-list .ref-text { color: var(--color-text-muted); }
.post-body .ref-list .ref-text a { color: var(--color-brand); }

/* Highlight animation when target is reached */
@keyframes ref-highlight {
  0%   { background: color-mix(in srgb, var(--color-brand) 25%, transparent); }
  100% { background: transparent; }
}
.post-body .ref-list li.ref-flash {
  animation: ref-highlight 5s ease-out forwards;
}

.post-foot { margin-top: var(--space-12); padding-top: var(--space-6); border-top: var(--border-rule); }

/* LIVE-DOCUMENT SECTIONS (#101)
   Rendered when post.json has a `sections` array. Pinned sections appear
   first inside .post-pinned-block with teal border all sides, title-only
   rows with expand/collapse. Dimmed repeats appear in-place. */
.post-section { margin: 0 0 var(--space-3); padding-block: var(--space-1); scroll-margin-top: var(--c-section-scroll-margin); }
.post-section__title {
  font-size: var(--text-2xl); font-weight: 600; margin: var(--c-post-margin-hr) 0 var(--space-1);
  letter-spacing: -.01em; line-height: 1.4;
}
.post-section__meta {
  display: flex; flex-wrap: wrap; gap: var(--space-2-5); align-items: center;
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs);
  color: var(--color-text-muted); letter-spacing: .06em; text-transform: uppercase;
  margin: 0 0 var(--space-4);
}
.section-subtopic {
  display: inline-block;
  padding: var(--space-0-5) var(--space-2);
  border: var(--border-rule);
  border-radius: var(--radius-sm);
  color: var(--color-text-default);
  text-transform: none;
  letter-spacing: 0;
}
.section-date { color: var(--color-text-faint); }

/* ── Pinned block (redesigned) ── */
.post-pinned-block {
  margin: var(--space-4) 0 0;
  border: 1.5px solid var(--color-brand);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--color-brand) 4%, transparent);
  overflow: hidden;
}
.post-pinned-block__header {
  display: flex; align-items: center; gap: var(--space-1-5);
  padding: var(--space-1-5) var(--space-3-5);
  border-bottom: 1px solid color-mix(in srgb, var(--color-brand) 15%, var(--color-border-default));
}
.pinned-badge {
  background: var(--color-brand); color: var(--color-surface-page); /* TODO(token-semantics): should be --color-interactive-primary-text — see TODO_TOKENS.md */
  padding: var(--space-0-5) var(--space-2); border-radius: var(--radius-sharp);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .06em;
}
.pinned-expand-all {
  margin-inline-start: auto;
  color: var(--color-interactive-primary); font-size: var(--text-xs);
  cursor: pointer; opacity: .7;
  background: none; border: none; font-family: inherit;
}
.pinned-expand-all:hover { opacity: 1; text-decoration: underline; }

/* Pinned section row (title + date + arrow) */
.post-pinned-section {
  padding: var(--space-2) var(--space-3-5);
  border-bottom: 1px solid color-mix(in srgb, var(--color-brand) 10%, transparent);
  cursor: pointer;
}
.post-pinned-section { scroll-margin-top: var(--c-section-scroll-margin); }
.post-pinned-section:last-child { border-bottom: none; }
.post-pinned-section:hover {
  background: color-mix(in srgb, var(--color-brand) 4%, transparent);
}
.post-pinned-section__row {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2-5);
}
.post-pinned-section__title {
  font-size: var(--text-sm); font-weight: 600; color: var(--color-text-default);
  margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.post-pinned-section__meta {
  display: flex; align-items: baseline; gap: var(--space-2); white-space: nowrap; flex-shrink: 0;
}
.post-pinned-section__date {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs); color: var(--color-text-faint);
}
.post-pinned-section__arrow {
  color: var(--color-brand); font-size: var(--text-xs);
  transition: transform .15s ease;
}
.post-pinned-section__arrow.open { transform: rotate(180deg); }

/* Expanded pinned section body */
.post-pinned-section__body {
  display: none;
  margin-top: var(--space-2); padding-top: var(--space-2);
  border-top: 1px solid color-mix(in srgb, var(--color-brand) 10%, transparent);
  font-size: var(--text-base); line-height: 1.75; color: var(--color-text-default);
  text-align: justify; hyphens: auto;
}
.post-pinned-section__body.open { display: block; }
.post-pinned-section__body strong,
.post-pinned-section__body b { color: var(--color-brand); font-weight: 600; }
.post-pinned-section__body a { color: var(--color-brand); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: var(--c-link-underline-offset); }
.post-pinned-section__body sup { font-size: var(--text-xs); color: var(--color-brand); font-weight: 500; }
.post-pinned-section__body sup a { text-decoration: none; font-weight: 600; }
.post-pinned-section__body blockquote { border-inline-start-width: var(--border-bar-w); border-inline-start-style: solid; border-inline-start-color: var(--color-brand); padding: var(--c-blockquote-pad); margin: var(--space-6) 0; color: var(--color-text-muted); }
.post-pinned-section__body p { margin: 0 0 var(--space-4); }

/* ── Dimmed in-place repeat of pinned sections ── */
.dimmed-pinned-repeat {
  border: 1px dashed color-mix(in srgb, var(--color-brand) 25%, var(--color-border-default));
  border-radius: var(--radius-sm);
  padding: var(--space-2-5) var(--space-3-5);
  background: color-mix(in srgb, var(--color-brand) 3%, transparent);
  margin: var(--space-4) 0;
  scroll-margin-top: var(--c-section-scroll-margin);
}
.dimmed-pinned-repeat__header {
  display: flex; align-items: baseline; gap: var(--space-2);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-1-5);
  border-bottom: 1px solid color-mix(in srgb, var(--color-brand) 8%, var(--color-border-default));
}
.dimmed-pinned-repeat__note {
  font-size: var(--text-xs); color: var(--color-brand); font-weight: 500;
  white-space: nowrap;
}
.dimmed-pinned-repeat__note-sep { color: var(--color-text-faint); margin: 0 var(--space-0-5); }
.dimmed-pinned-repeat__title {
  font-size: var(--text-sm); color: var(--color-text-default); margin: 0; font-weight: 600;
}
.dimmed-pinned-repeat__date {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-xs); color: var(--color-text-faint); white-space: nowrap; flex-shrink: 0;
  margin-inline-start: auto;
}
.dimmed-pinned-repeat__body {
  font-size: var(--text-base); line-height: 1.7; color: var(--color-text-muted);
  text-align: justify; hyphens: auto;
}
.dimmed-pinned-repeat__body p { margin: 0 0 var(--space-2-5); }
.dimmed-pinned-repeat__body p:last-child { margin-bottom: 0; }
.dimmed-pinned-repeat__body strong,
.dimmed-pinned-repeat__body b { color: var(--color-brand); font-weight: 600; }
.dimmed-pinned-repeat__body a { color: var(--color-brand); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: var(--c-link-underline-offset); }
.dimmed-pinned-repeat__body blockquote { border-inline-start-width: var(--border-bar-w); border-inline-start-style: solid; border-inline-start-color: var(--color-brand); padding: var(--c-blockquote-pad); margin: var(--space-4) 0; color: var(--color-text-muted); }
.dimmed-pinned-repeat__body ul, .dimmed-pinned-repeat__body ol { padding-inline-start: var(--space-6); margin: 0 0 var(--space-4); }
.dimmed-pinned-repeat__body li { margin: 0 0 var(--space-1-5); }
.dimmed-pinned-repeat__body sup { font-size: var(--text-xs); color: var(--color-brand); font-weight: 500; }
.dimmed-pinned-repeat__body sup a { text-decoration: none; font-weight: 600; }

/* ── Takeaways box ── */
.post-takeaways {
  border: 1px solid color-mix(in srgb, var(--color-brand) 35%, var(--color-border-default));
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, color-mix(in srgb, var(--color-brand) 8%, transparent), color-mix(in srgb, var(--color-brand) 3%, transparent));
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
}
.post-takeaways__badge {
  display: block;
  color: var(--color-brand); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: .06em; margin-bottom: var(--space-2);
}
.post-takeaways ul {
  list-style: none; padding: 0; margin: 0;
}
.post-takeaways li {
  padding: var(--space-1) 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-brand) 8%, transparent);
  font-size: var(--text-sm); line-height: 1.6; color: var(--color-text-default);
  display: flex; gap: var(--space-2); align-items: flex-start;
  text-align: justify; hyphens: auto;
}
.post-takeaways li:last-child { border-bottom: none; padding-bottom: 0; }
.post-takeaways li::before {
  content: "●"; color: var(--color-brand); font-size: var(--space-1-5);
  margin-top: var(--space-1-5); flex-shrink: 0;
}
.post-takeaways li p { margin: 0; }
.post-takeaways li strong { color: var(--color-brand); font-weight: 600; }
.post-takeaways li a { color: var(--color-brand); text-decoration: underline; text-underline-offset: 2px; } /* intentionally literal: 2px underline-offset, deliberately tighter than --c-link-underline-offset (3px) because takeaways use smaller text */

/* Section body typography — bold in accent, justified */
.post-section__body { font-size: var(--text-md); line-height: 1.85; color: var(--color-text-default); text-align: justify; hyphens: auto; }
.post-section__body h3 { font-size: var(--text-xl); font-weight: 600; margin: var(--c-post-margin-hr) 0 var(--space-3); }
.post-section__body p { margin: 0 0 var(--space-4); }
.post-section__body strong, .post-section__body b { color: var(--color-brand); font-weight: 600; }
.post-section__body em { color: var(--color-brand); font-style: normal; font-weight: 500; }
.post-section__body a { color: var(--color-brand); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: var(--c-link-underline-offset); }
.post-section__body sup { font-size: var(--text-xs); color: var(--color-brand); font-weight: 500; }
.post-section__body sup a { text-decoration: none; font-weight: 600; }
.post-section__body blockquote { border-inline-start-width: var(--border-bar-w); border-inline-start-style: solid; border-inline-start-color: var(--color-brand); padding: var(--c-blockquote-pad); margin: var(--space-6) 0; color: var(--color-text-muted); }
.post-section__body code { font-family: 'JetBrains Mono', monospace; font-size: .92em; background: var(--color-surface-elevated); padding: var(--space-0-5) var(--space-1-5); border-radius: var(--radius-sm); }
.post-section__body ul, .post-section__body ol { padding-inline-start: var(--space-6); margin: 0 0 var(--space-4); }
.post-section__body li { margin: 0 0 var(--space-2); }
.post-section__body hr { border: none; border-top: var(--border-rule); margin: var(--c-post-margin-hr) 0; }
.post-section__body img { max-width: 100%; border-radius: var(--radius-md); margin: var(--space-6) 0; }

.post-preamble { font-size: var(--text-md); line-height: 1.85; color: var(--color-text-default); text-align: justify; hyphens: auto; }
.post-preamble p { margin: 0 0 var(--space-4); }
.post-preamble hr { border: none; border-top: var(--border-rule); margin: var(--c-post-margin-hr) 0; }


/* TAG PILLS — used on blog post meta, /writing entries, /tag and /category headers */
.post-meta__link { color: var(--color-text-muted); text-decoration: none; border-bottom: 1px dashed var(--color-border-default); transition: color .15s, border-color .15s; }
.post-meta__link:hover { color: var(--color-interactive-primary); border-color: var(--color-interactive-primary); }
.sidebar-tags { display: flex; flex-wrap: wrap; gap: var(--space-1-5); }
.sidebar-tags .tag-pill { font-size: var(--text-xs); padding: var(--c-tag-pad); }

.post-tags { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1-5); margin-bottom: var(--space-4); }
.tag-pill {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-sm);
  letter-spacing: .04em;
  padding: var(--space-1) var(--space-2-5);
  border: var(--border-rule);
  border-radius: var(--radius-sharp);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color .15s, border-color .15s, background .15s;
}
.tag-pill:hover { color: var(--color-interactive-primary); border-color: var(--color-interactive-primary); background: color-mix(in srgb, var(--color-interactive-primary) 8%, transparent); }
.tag-pill--header { background: color-mix(in srgb, var(--color-brand) 10%, transparent); border-color: var(--color-brand); color: var(--color-brand); margin-inline-start: var(--space-3); vertical-align: middle; }

/* INDEX PAGES — /writing, /tag/<x>, /category/<x> */
/* WRITING PAGE (/writing) */
.writing-page { max-width: var(--c-content-max); margin: 0 auto; width: 100%; padding: var(--space-6) var(--space-12) var(--space-16); position: relative; z-index: 1; }
.writing-page .post-back { margin-bottom: var(--space-4); }
.writing-page__head { margin-bottom: var(--space-5); }
.writing-page__head h1 { font-size: var(--text-lg); font-weight: 600; margin: 0; letter-spacing: -.01em; }

/* toolbar — single row */
.wp-toolbar {
  display: flex; align-items: stretch; gap: var(--space-2);
  padding: var(--space-2);
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--radius-sm); margin-bottom: var(--space-2);
  flex-wrap: wrap;
}
.wp-search { display: flex; align-items: center; gap: var(--space-2); flex: 1; min-width: 200px; padding: 0 var(--space-2); }
.wp-search svg { color: var(--color-text-faint); flex-shrink: 0; }
.wp-search input { flex: 1; min-width: 0; background: transparent; border: none; color: var(--color-text-default); font-family: inherit; font-size: var(--text-sm); outline: none; }
.wp-search input::placeholder { color: var(--color-text-faint); }
.wp-toolbar-btn {
  display: inline-flex; align-items: center; gap: var(--space-1-5);
  padding: var(--space-1-5) var(--space-3);
  border: var(--border-rule); border-radius: var(--radius-sm);
  background: transparent; color: var(--color-text-muted);
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  cursor: pointer; transition: color .15s, border-color .15s, background .15s;
  flex-shrink: 0;
}
.wp-toolbar-btn:hover { color: var(--color-text-default); border-color: var(--color-text-muted); }
.wp-toolbar-btn.has-selection { color: var(--color-brand); border-color: var(--color-brand); background: color-mix(in srgb, var(--color-brand) 10%, transparent); }
.wp-toolbar-btn .count { font-size: 10px; padding: 1px 4px; background: var(--color-brand); color: var(--color-surface-page); border-radius: 2px; }
.wp-toolbar select {
  padding: var(--space-1-5) var(--space-3); background: transparent; border: var(--border-rule);
  border-radius: var(--radius-sm); color: var(--color-text-muted);
  font-family: 'JetBrains Mono', monospace; font-size: 11px; cursor: pointer; outline: none;
  flex-shrink: 0;
}
.wp-toolbar select:focus, .wp-toolbar select:hover { color: var(--color-text-default); border-color: var(--color-brand); }

/* expandable tag panel */
.wp-tag-row {
  display: none; align-items: center; gap: var(--space-2);
  padding: var(--space-1-5) var(--space-2);
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--radius-sm); margin-bottom: var(--space-2);
  animation: slideDown .2s ease;
  overflow-x: auto;
  scrollbar-width: none;
}
.wp-tag-row::-webkit-scrollbar { display: none; }
.wp-tag-row.open { display: flex; }
.wp-tag-search-btn {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); padding: var(--space-1);
  border-radius: var(--radius-sm); flex-shrink: 0;
  transition: color .15s;
}
.wp-tag-search-btn:hover { color: var(--color-text-default); }
.wp-tag-search-btn.active { color: var(--color-brand); }
.wp-tag-search-input {
  display: none; width: 120px; background: transparent;
  border: none; border-bottom: 1px solid var(--color-border-default);
  color: var(--color-text-default); font-family: inherit;
  font-size: var(--text-sm); outline: none; flex-shrink: 0;
  padding: var(--space-0-5) 0;
}
.wp-tag-search-input.open { display: block; }
.wp-tag-search-input::placeholder { color: var(--color-text-faint); }
.wp-tag-list {
  display: flex; flex-wrap: nowrap; gap: var(--space-1-5);
  flex: 1; min-width: 0;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.wp-tag {
  padding: 2px var(--space-2); border: var(--border-rule); border-radius: var(--radius-sm);
  background: transparent; color: var(--color-text-muted);
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.wp-tag:hover { color: var(--color-text-default); }
.wp-tag.active { color: var(--color-brand); border-color: var(--color-brand); background: color-mix(in srgb, var(--color-brand) 10%, transparent); }

/* selected tags chips */
.wp-chips { display: flex; flex-wrap: wrap; gap: var(--space-1-5); margin-bottom: var(--space-2); min-height: 0; }
.wp-chips:empty { display: none; }
.wp-chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2); background: color-mix(in srgb, var(--color-brand) 15%, transparent);
  border: 1px solid var(--color-brand); border-radius: var(--radius-sm);
  color: var(--color-brand); font-family: 'JetBrains Mono', monospace; font-size: 11px;
}
.wp-chip-x { background: none; border: none; color: inherit; cursor: pointer; opacity: 0.7; padding: 0 0 0 var(--space-1); font-size: 12px; line-height: 1; }
.wp-chip-x:hover { opacity: 1; }
.wp-divider { display: none; }
.wp-filters { display: none; }
.wp-count { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--color-text-faint); letter-spacing: .04em; margin-bottom: var(--space-3); }
.wp-empty { text-align: center; padding: var(--space-10); color: var(--color-text-muted); }

/* cards — same 2-row format as homepage */
.wp-list { display: flex; flex-direction: column; gap: var(--space-1); }
.wp-card { border: var(--border-rule); border-radius: var(--radius-sm); background: var(--color-surface-card); transition: border-color .2s; }
.wp-card:hover { border-color: var(--color-brand); }
.wp-card__link { display: block; padding: var(--space-3) var(--space-4); text-decoration: none; color: inherit; }
.wp-card__meta { display: flex; justify-content: space-between; align-items: baseline; direction: ltr; margin-bottom: var(--space-1); }
.wp-card__date { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--color-text-faint); }
.wp-card__lang { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--color-brand); letter-spacing: .04em; }
.wp-card__titles { display: flex; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-1-5); }
.wp-card__title-ar { font-size: var(--text-sm); font-weight: 500; color: var(--color-text-default); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; }
.wp-card__title-en { font-family: 'Inter', sans-serif; font-size: var(--text-sm); color: var(--color-text-faint); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: left; }
.wp-card__tags { display: flex; flex-wrap: wrap; gap: var(--space-1-5); }
.wp-card__tag { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--color-text-faint); letter-spacing: .04em; }

/* OLD INDEX PAGE (used by /writing before redesign) */
.index .post-back { margin-bottom: var(--space-8); }
.index h1 { font-size: var(--text-2xl); font-weight: 600; margin: 0; letter-spacing: -.01em; }
.index__group { margin-bottom: var(--space-12); }
.index__year {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-base);
  font-weight: 400;
  color: var(--color-text-faint);
  letter-spacing: .08em;
  margin: var(--space-8) 0 var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: var(--border-rule);
}
.index__entry { padding-block: var(--space-1); border-bottom: var(--border-rule); }
.index__entry:last-child { border-bottom: none; }
.index__entry .writing__item { border-bottom: none; padding-bottom: var(--space-2); }
.index__tags { display: flex; flex-wrap: wrap; gap: var(--space-1-5); padding: 0 var(--space-6) var(--space-4); }

/* "View all" link below the homepage writing list */
.writing__more { margin-top: var(--space-4); padding-top: var(--space-4); display: flex; justify-content: flex-end; }
.writing__more-link {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-sm);
  letter-spacing: .06em;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-1-5) var(--space-3);
  border: var(--border-rule);
  border-radius: var(--radius-sm);
  transition: color .15s, border-color .15s;
}
.writing__more-link:hover { color: var(--color-interactive-primary); border-color: var(--color-interactive-primary); }

/* RESEARCH DETAIL PAGE — /research/<id> */
.research-detail-page { max-width: 760px; margin: 0 auto; padding: var(--space-8) var(--space-6) var(--space-16); position: relative; z-index: 1; } /* intentionally literal: page-specific reading width, between post-body (600) and content-max (1320) */
.research-detail .post-back { display: inline-block; font-family: 'JetBrains Mono', monospace; font-size: var(--text-sm); color: var(--color-text-muted); text-decoration: none; margin-bottom: var(--space-6); padding: var(--space-1-5) var(--space-3); border: var(--border-rule); border-radius: var(--radius-sm); letter-spacing: .04em; }
.research-detail .post-back:hover { color: var(--color-interactive-primary); border-color: var(--color-interactive-primary); }
.research-detail__head { padding-bottom: var(--space-6); margin-bottom: var(--space-8); border-bottom: var(--border-rule); }
.research-detail__row { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-6); }
.research-detail__metric { font-family: 'JetBrains Mono', monospace; font-size: var(--text-3xl); font-weight: 500; letter-spacing: -.01em; color: var(--color-text-default); margin-bottom: var(--space-1-5); }
.research-detail__metric-label { font-family: 'JetBrains Mono', monospace; font-size: var(--text-sm); color: var(--color-text-muted); margin-bottom: var(--space-7); line-height: 1.5; }
.research-detail__title-ar { font-size: var(--text-2xl); font-weight: 600; line-height: 1.4; margin: 0 0 var(--space-2); letter-spacing: -.01em; }
.research-detail__title-en { font-family: 'JetBrains Mono', monospace; font-size: var(--text-base); color: var(--color-text-muted); margin: 0 0 var(--space-3); letter-spacing: .02em; }
.research-detail__caption { font-size: var(--text-sm); color: var(--color-text-faint); font-style: italic; margin: 0; }
.research-detail__body { font-size: var(--text-md); line-height: 1.85; color: var(--color-text-default); direction: ltr; unicode-bidi: isolate; }
.research-detail__body h2 { font-size: var(--text-lg); font-weight: 600; margin: var(--space-6) 0 var(--space-3); }
.research-detail__body p { margin: 0 0 var(--space-4); }
.research-detail__link { margin: var(--space-8) 0; }
.btn-outline {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-sm);
  letter-spacing: .04em;
  padding: var(--c-btn-pad);
  border: 1px solid var(--color-interactive-primary);
  border-radius: var(--c-btn-radius);
  color: var(--color-interactive-primary);
  text-decoration: none;
  transition: background .15s;
}
.btn-outline:hover { background: color-mix(in srgb, var(--color-interactive-primary) 10%, transparent); }

/* FOOTER */
.footer {
  max-width: var(--c-content-max); margin: 0 auto; width: 100%;
  padding: var(--space-8) var(--space-12) var(--space-12);
  border-top: var(--border-rule);
  display: flex; justify-content: space-between; align-items: center;
  font-size: var(--text-sm); color: var(--color-text-faint);
}
.footer__year { font-family: 'JetBrains Mono', monospace; direction: ltr; }
.footer__right { display: flex; align-items: center; gap: var(--space-4); direction: ltr; }
.footer__links { display: flex; gap: var(--space-4); }
.footer__links a {
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text-muted); text-decoration: none;
}
.footer__links a:hover { color: var(--color-text-default); }
.footer__lock {
  padding: var(--c-toggle-btn-py) var(--c-toggle-btn-px);
  border: var(--border-rule);
  border-radius: var(--c-pill-radius);
  display: inline-flex; align-items: center;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: opacity .15s, color .15s, border-color .15s;
}
.footer__lock:hover {
  color: var(--color-interactive-primary);
  border-color: var(--color-interactive-primary);
}

.placeholder-page { max-width: var(--c-content-max); margin: 0 auto; padding: var(--space-8) var(--space-12) var(--space-16); position: relative; z-index: 1; }
.placeholder-page__inner { text-align: center; padding: var(--space-16) 0; }
.placeholder-page__inner h1 { font-size: var(--text-2xl); font-weight: 600; margin-bottom: var(--space-4); color: var(--color-text-default); }
.placeholder-page__inner p { color: var(--color-text-muted); font-size: var(--text-base); }

/* CONTACT PAGE */
.contact-page { max-width: var(--c-content-max); margin: 0 auto; width: 100%; padding: var(--space-6) var(--space-12); position: relative; z-index: 1; }
.contact-header { margin-bottom: var(--space-5); display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.contact-header h1 { font-size: var(--text-xl); font-weight: 600; margin: 0; letter-spacing: -.01em; }
.contact-lede { font-size: var(--text-sm); line-height: 1.5; color: var(--color-text-muted); margin: 0; flex: 1; min-width: 240px; }
.contact-lede-en { display: none; }

/* layout: form + alt side by side */
.contact-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: var(--space-5); align-items: start; }
@media (max-width: 800px) { .contact-grid { grid-template-columns: 1fr; } }

/* form */
.contact-form {
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--radius-sm); padding: var(--space-5);
}
.contact-form__row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.contact-form__field { margin-bottom: var(--space-3); }
.contact-form__field label {
  display: block; font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--color-text-faint);
  letter-spacing: .08em; text-transform: uppercase;
  margin-bottom: var(--space-1-5);
}
.contact-form__field input,
.contact-form__field textarea {
  width: 100%; padding: var(--space-2) var(--space-3);
  background: var(--color-surface-elevated); border: var(--border-rule);
  border-radius: var(--radius-sm); color: var(--color-text-default);
  font-family: inherit; font-size: var(--text-sm);
  transition: border-color .15s;
}
/* Custom select — styled like split-button menu */
.cf-select { position: relative; }
.cf-select__btn {
  width: 100%; padding: var(--space-2) var(--space-3);
  background: var(--color-surface-elevated); border: var(--border-rule);
  border-radius: var(--radius-sm); color: var(--color-text-default);
  font-family: inherit; font-size: var(--text-sm);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  cursor: pointer; transition: border-color .15s;
  text-align: start;
}
.cf-select__btn:hover { border-color: color-mix(in srgb, var(--color-brand) 40%, var(--color-border-default)); }
.cf-select.open .cf-select__btn { border-color: var(--color-brand); }
.cf-select__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-select__arrow {
  position: relative; color: var(--color-brand);
  width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; flex-shrink: 0;
}
.cf-select__arrow-down { transition: opacity .2s, transform .2s; }
.cf-select__arrow-up { position: absolute; opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s; }
.cf-select.open .cf-select__arrow-down { opacity: 0; transform: translateY(-4px); }
.cf-select.open .cf-select__arrow-up { opacity: 1; transform: translateY(0); }

.cf-select__menu {
  display: none; position: absolute; top: calc(100% + var(--space-2)); left: 0; right: 0;
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  z-index: 100; overflow: hidden;
  flex-direction: column;
}
.cf-select.open .cf-select__menu { display: flex; }
.cf-select__opt {
  padding: var(--space-2-5) var(--space-4);
  background: transparent; border: none;
  color: var(--color-text-muted); text-align: start;
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-sm);
  letter-spacing: 0.04em;
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.cf-select__opt:hover {
  background: var(--color-surface-elevated); color: var(--color-brand);
}
.contact-form__field input:focus,
.contact-form__field textarea:focus {
  outline: none; border-color: var(--color-brand);
}
.contact-form__field textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.contact-form__submit {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2-5) var(--space-5);
  background: var(--color-brand); color: var(--color-surface-page);
  border: none; border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono', monospace; font-size: var(--text-xs);
  letter-spacing: .06em; font-weight: 500;
  cursor: pointer; transition: filter .15s;
}
.contact-form__submit:hover { filter: brightness(1.1); }
.contact-form__submit:disabled { opacity: .6; cursor: wait; }

/* Phone (country code + number) */
.contact-form__phone { display: flex; gap: var(--space-2); }
.contact-form__phone-cc {
  flex-shrink: 0; padding: var(--space-2) var(--space-3);
  background: var(--color-surface-elevated); border: var(--border-rule);
  border-radius: var(--radius-sm); color: var(--color-text-default);
  font-family: inherit; font-size: var(--text-sm); cursor: pointer;
  max-width: 160px;
}
.contact-form__phone input[type="tel"] { flex: 1; }

/* Submit row + status text */
.contact-form__actions {
  display: flex; align-items: center; gap: var(--space-3);
  flex-wrap: wrap; margin-top: var(--space-3);
}
.contact-form__status {
  font-size: var(--text-sm); flex: 1;
}
.contact-form__status--err  { color: #ef4444; }
.contact-form__status--ok   { color: #22c55e; }
.contact-form__status--info { color: var(--color-text-muted); }

/* Honeypot — off-screen */
.contact-form__honeypot {
  position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden;
}

/* alt contact — vertical card list */
.contact-alt h2 {
  font-size: 11px; font-weight: 500; color: var(--color-text-faint);
  letter-spacing: .08em; text-transform: uppercase;
  font-family: 'JetBrains Mono', monospace;
  margin: 0 0 var(--space-3); display: flex; align-items: center; gap: var(--space-2);
}
.contact-alt h2::before { content: ''; width: 8px; height: 8px; background: var(--color-brand); display: inline-block; flex-shrink: 0; }
.contact-alt__grid { display: flex; flex-direction: column; gap: var(--space-2); }
.contact-alt__card {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-3-5); background: var(--color-surface-card);
  border: var(--border-rule); border-radius: var(--radius-sm);
  text-decoration: none; transition: border-color .15s, transform .15s;
  position: relative;
}
.contact-alt__card:hover { border-color: var(--color-brand); transform: translateX(-2px); }
.contact-alt__card svg { color: var(--color-brand); flex-shrink: 0; }
.contact-alt__card-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.contact-alt__label { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--color-brand); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 2px; }
.contact-alt__value { font-size: var(--text-sm); color: var(--color-text-default); }
.contact-alt__card-arrow { color: var(--color-text-faint); font-size: 12px; transition: transform .15s, color .15s; }
.contact-alt__card:hover .contact-alt__card-arrow { color: var(--color-brand); transform: translateX(-3px); }

/* ── RESPONSIVE ── */

/* ── Tablet (≤980px) ── */
@media (max-width: 980px) { /* intentionally literal: @media query, CSS variables not supported */
  /* NAV */
  .nav { padding: 0 var(--space-5); min-height: 56px; flex-wrap: wrap; gap: var(--space-3); } /* intentionally literal: 56px mobile nav height override (default --c-nav-height is 64px) */
  .nav__links { display: none; }
  .nav__split-menu { min-width: 160px; }

  /* HERO */
  .hero {
    grid-template-columns: 1fr;
    gap: var(--space-8);
    padding: var(--space-8) var(--space-5);
    min-height: auto;
  }
  .hero__portrait { max-width: 320px; order: -1; margin-inline: auto; } /* intentionally literal: mobile portrait cap */
  /* Right-align both languages on mobile so the hero reads like the rest
     of an RTL portfolio (Arabic + English flush to the trailing edge). */
  .hero__name-ar { text-align: right; }
  .hero__name-en { text-align: right; }
  .hero__lede-en { text-align: right; }
  .socials { justify-content: center; }
  .hero__meta-item .label { min-width: 70px; } /* intentionally literal: narrower label column on mobile */

  /* RESEARCH */
  .research { padding-inline: var(--space-5); }
  .research__grid { grid-template-columns: 1fr; }

  /* WRITING (homepage) */
  .writing { padding-inline: var(--space-5); }
  /* .writing__item is flex — no grid-template-columns needed */
  .writing__lang { display: none; }

  /* FOOTER */
  .footer { flex-direction: column; gap: var(--space-4); padding: var(--space-6) var(--space-5); }
  .footer__right { flex-wrap: wrap; justify-content: center; }

  /* WRITING PAGE (/writing) */
  .writing-page { padding: var(--space-6) var(--space-5) var(--space-16); }

  /* BLOG POST */
  .post-page { padding: var(--space-6) 0 var(--space-16); width: 100%; max-width: 100vw; overflow-x: hidden; }
  .post-layout { padding: 0 var(--space-4); max-width: 100%; box-sizing: border-box; }
  .post { padding: 0; max-width: 100%; box-sizing: border-box; }
  .post-hero { display: none; } /* hide og:image banner on mobile — title block serves instead */
  .post-body { max-width: 100%; overflow-wrap: break-word; }

  /* RESEARCH DETAIL */
  .research-detail-page { padding: var(--space-6) var(--space-5) var(--space-16); }
  .research-detail__metric-label { direction: ltr; unicode-bidi: isolate; } /* fix BIDI scramble in metric label */

  /* CONTACT PAGE */
  .contact-page { padding: var(--space-6) var(--space-5); }

  /* PLACEHOLDER PAGE (about) */
  .placeholder-page { padding: var(--space-8) var(--space-5) var(--space-16); max-width: 100%; overflow-x: hidden; box-sizing: border-box; }
  .placeholder-page__inner { max-width: 100%; }
}

/* ── Small mobile (≤640px) ── */
@media (max-width: 640px) { /* intentionally literal: @media query, CSS variables not supported */
  /* HERO — tighter on small screens */
  .hero { padding: var(--space-6) var(--space-4); gap: var(--space-6); }
  .hero__name-ar { font-size: 32px; } /* intentionally literal: mobile clamp override */
  .hero__lede-ar { font-size: 16px; } /* intentionally literal: mobile clamp override */
  .hero__portrait { max-width: 280px; } /* intentionally literal: small mobile portrait cap */
  .hero__meta-item .label { min-width: 60px; }
  .status-line { font-size: var(--text-xs); }

  /* NAV — split button smaller */
  .nav__split-menu { min-width: 140px; }
  .nav__split-main { padding: 6px 10px; font-size: var(--text-sm); } /* intentionally literal: mobile split button shrink */
  .nav__split-arrow { width: 30px; } /* intentionally literal: mobile arrow shrink */

  /* RESEARCH CARDS — stack metric and title */
  .card__metric { font-size: 24px; } /* intentionally literal: mobile metric shrink */

  /* WRITING (homepage) — title rows stack */
  .writing__titles { flex-direction: column; gap: var(--space-1); }
  .writing__title-ar, .writing__title-en { white-space: normal; overflow: visible; text-overflow: unset; }

  /* WRITING PAGE (/writing) */
  .writing-page__head h1 { font-size: var(--text-md); }
  .wp-toolbar { flex-wrap: wrap; gap: var(--space-1-5); }
  .wp-search { min-width: 100%; order: -1; } /* intentionally literal: search takes full row on mobile */
  .wp-card__titles { flex-direction: column; gap: var(--space-1); }
  .wp-card__title-ar, .wp-card__title-en { white-space: normal; overflow: visible; text-overflow: unset; }

  /* BLOG POST (further tightening at 640px) */
  .post-head { padding-bottom: var(--space-4); margin-bottom: var(--space-6); }
  .post-title-ar { font-size: var(--text-xl); }
  .post-meta { font-size: var(--text-xs); }
  .post-body { font-size: var(--text-base); }
  .post-body h2 { font-size: var(--text-xl); }
  .post-body h3 { font-size: var(--text-lg); }

  /* CONTACT PAGE */
  .contact-form__row { grid-template-columns: 1fr; }
  .contact-header { flex-direction: column; align-items: flex-start; }
  .contact-lede { min-width: 0; }

  /* RESEARCH DETAIL */
  .research-detail__title-ar { font-size: var(--text-xl); }
  .research-detail__metric { font-size: var(--text-2xl); }

  /* SECTION HEAD */
  .section-head h2 { font-size: var(--text-sm); }
  .section-head h2::before { width: 8px; height: 8px; } /* intentionally literal: smaller square on mobile */

  /* FOOTER */
  .footer { font-size: var(--text-xs); }
  .footer__links { gap: var(--space-2-5); }
}

/* ─────────────────────────────────────────────────────────────────────
   CHAT BUBBLE (global organism — lib/components/chat_bubble.dart)
   Real-chat UI: avatar header, streaming bubbles, sticky input bar.
   ───────────────────────────────────────────────────────────────────── */
.chat-panel [hidden] { display: none !important; }
.chat-hp { position: absolute; left: -9999px; width: 1px; height: 1px; }

/* When the chat panel is open, freeze the entire document so mobile
   browsers stop animating the URL bar on touch-scroll (which was
   making the chat input visibly jump around as the viewport resized).
   JS sets this class on <html> in lockBody(). */
html.chat-locked {
  overflow: hidden !important;
  height: 100% !important;
  position: fixed !important;
  width: 100% !important;
  /* Belt: also reject document-level touch panning so the browser
     can't pick up a "scroll the page" intent at all. Inner scrollable
     regions (chat-feed, textarea) override this themselves. */
  touch-action: none;
}

/* Toggle button (FAB) */
.chat-bubble {
  position: fixed;
  bottom: var(--c-chat-bubble-bottom); right: var(--c-chat-bubble-side);
  z-index: 200;
  width: var(--c-chat-bubble-size); height: var(--c-chat-bubble-size);
  border-radius: var(--c-chat-bubble-radius);
  background: var(--color-brand); color: var(--color-interactive-primary-text);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--c-chat-bubble-shadow);
  transition: transform .18s ease, box-shadow .18s ease, filter .15s;
}
.chat-bubble:hover { filter: brightness(1.1); transform: translateY(-2px); }
.chat-bubble:focus-visible { outline: 2px solid var(--color-brand); outline-offset: 3px; }
.chat-bubble__icon { display: inline-flex; transition: opacity .15s, transform .15s; }
.chat-bubble__icon--close { position: absolute; opacity: 0; transform: rotate(-45deg); }
.chat-bubble.open .chat-bubble__icon--open { opacity: 0; transform: rotate(45deg); }
.chat-bubble.open .chat-bubble__icon--close { opacity: 1; transform: rotate(0); }

/* Panel — desktop floating card; mobile takes a fuller surface so the
   input bar stays usable when the keyboard opens. */
.chat-panel {
  direction: rtl; /* force layout direction so user/bot bubble sides are stable */
  position: fixed;
  bottom: calc(var(--c-chat-bubble-bottom) + var(--c-chat-bubble-size) + var(--space-4));
  right: var(--c-chat-bubble-side);
  z-index: 199;
  width: min(var(--c-chat-panel-w), calc(100vw - 32px));
  height: min(var(--c-chat-panel-h), calc(100vh - 120px));
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--c-chat-panel-radius);
  box-shadow: var(--c-chat-panel-shadow);
  display: none; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(8px) scale(.98);
  transition: opacity .18s ease, transform .18s ease;
}
.chat-panel.open { display: flex; opacity: 1; transform: translateY(0) scale(1); }

/* Header */
.chat-header {
  display: flex; align-items: center; gap: var(--c-chat-header-gap);
  padding: var(--c-chat-header-pad-y) var(--c-chat-header-pad-x);
  background: var(--color-surface-elevated);
  border-bottom: var(--border-rule);
  flex: 0 0 auto;
  /* sit above the success overlay so the X stays clickable */
  position: relative; z-index: 10;
  /* Stops touch-drag on the header from bleeding into page scroll on
     iOS/Chrome (which would animate the URL bar and resize the panel). */
  touch-action: none;
}
.chat-header__avatar-wrap { position: relative; flex-shrink: 0; }
.chat-header__avatar {
  width: var(--c-chat-avatar-size); height: var(--c-chat-avatar-size);
  border-radius: var(--radius-pill);
  object-fit: cover; display: block;
  border: var(--border-accent);
}
/* Online indicator removed — the brand-coloured ring around the avatar
   already signals presence. Less ink, same message. */
.chat-header__meta {
  flex: 1; min-width: 0;
  /* Right-align both AR and EN consistently. text-align: end was flipping
     EN to the visual right and AR to the visual left because each span
     has its own direction. Force physical right. */
  text-align: right;
}
.chat-header__name {
  display: flex; flex-direction: column; gap: 3px;
  line-height: 1.2;
}
.chat-header__name-ar,
.chat-header__name-en,
.chat-header__status-ar,
.chat-header__status-en {
  display: block;
  width: 100%;
  text-align: right;
}
.chat-header__name-ar {
  font-size: 15px; font-weight: 600; color: var(--color-text-default);
}
.chat-header__name-en {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px; letter-spacing: .05em; color: var(--color-text-muted);
  text-transform: uppercase;
}
.chat-header__status {
  display: flex; flex-direction: column; gap: 2px; margin-top: 6px;
  font-size: 10.5px; color: var(--color-text-faint);
  font-family: 'JetBrains Mono', monospace; letter-spacing: .03em;
}
.chat-header__status-ar { font-family: inherit; }
.chat-header__status-en { font-family: 'JetBrains Mono', monospace; }
.chat-header__close {
  background: transparent; border: none; color: var(--color-text-muted);
  cursor: pointer; padding: 8px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.chat-header__close:hover { background: var(--color-surface-card); color: var(--color-text-default); }

/* Feed — the ONLY scroll region inside the panel. Header and input
   stay pinned via flex: 0 0 auto. overscroll-behavior: contain stops
   scroll chaining (no rubber-band onto the body, no URL-bar animation
   on iOS/Chrome). */
.chat-feed {
  /* LTR direction puts the scrollbar on the right (standard convention)
     even though the surrounding panel is RTL. Bubble sides are kept
     visually correct by flipping the align-self below. */
  direction: ltr;
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--c-chat-feed-pad);
  display: flex; flex-direction: column; gap: var(--c-chat-feed-gap);
  scroll-behavior: smooth;
}

/* Bubbles */
.chat-msg {
  max-width: var(--c-chat-msg-max-w);
  padding: var(--c-chat-msg-pad-y) var(--c-chat-msg-pad-x);
  border-radius: var(--c-chat-msg-radius);
  font-size: var(--c-chat-msg-font); line-height: 1.5;
  word-wrap: break-word; overflow-wrap: anywhere;
  animation: chatBubbleIn .22s ease-out both;
}
@keyframes chatBubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-msg p { margin: 0; }
.chat-msg p + p { margin-top: 4px; }
.chat-msg__en { font-size: var(--text-2xs); color: var(--color-text-muted); }
/* Feed is LTR (so scrollbar sits on the right), so bot/user align-self
   values are flipped vs. an RTL container — flex-end = right, flex-start
   = left. Bubble "tail" corner also flips to match the new visual side. */
.chat-msg--bot {
  align-self: flex-end;
  background: var(--color-surface-elevated); color: var(--color-text-default);
  border: var(--border-rule);
  border-bottom-right-radius: var(--c-chat-msg-radius-tail);
}
.chat-msg--bot p { text-align: right; }
.chat-msg--user {
  align-self: flex-start;
  background: var(--color-brand); color: var(--color-interactive-primary-text);
  border-bottom-left-radius: var(--c-chat-msg-radius-tail);
}
.chat-msg--user .chat-msg__en { color: color-mix(in srgb, var(--color-interactive-primary-text) 75%, transparent); }

/* Typing indicator */
.chat-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-text-muted);
  animation: chatDot 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatDot {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* Choice chips — align to the user's side (same edge as user bubbles).
   With the feed in LTR, that's flex-start = left. */
.chat-chips {
  align-self: flex-start; max-width: 100%;
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 2px 0; justify-content: flex-start;
}
.chat-chip {
  display: inline-flex; flex-direction: column; gap: 1px;
  padding: var(--c-chat-chip-pad-y) var(--c-chat-chip-pad-x);
  background: color-mix(in srgb, var(--color-brand) 22%, var(--color-surface-card));
  border: 1px solid color-mix(in srgb, var(--color-brand) 45%, transparent);
  border-radius: var(--c-chat-chip-radius);
  color: var(--color-text-default);
  font-family: inherit; cursor: pointer;
  transition: background .15s, transform .1s, border-color .15s;
  align-items: flex-start;
  text-align: start;
}
.chat-chip:hover {
  background: color-mix(in srgb, var(--color-brand) 40%, var(--color-surface-card));
  border-color: var(--color-brand);
}
.chat-chip:active { transform: scale(.97); }
.chat-chip:disabled { opacity: .5; cursor: default; }
.chat-chip__ar { font-size: 13.5px; font-weight: 500; line-height: 1.25; }
.chat-chip__en {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; letter-spacing: .04em; color: var(--color-text-muted);
  text-transform: uppercase; line-height: 1.2;
}

/* Bottom input bar — floating card style. Margin around the card so it
   visibly floats above the panel surface. */
.chat-input {
  flex: 0 0 auto;
  margin: var(--c-chat-input-margin-y) var(--c-chat-input-margin-x);
  margin-bottom: max(var(--c-chat-input-margin-y), env(safe-area-inset-bottom, 0));
  padding: var(--c-chat-input-pad);
  display: flex; align-items: flex-end; gap: var(--c-chat-input-gap);
  background: var(--color-surface-elevated);
  border: var(--border-rule);
  border-radius: var(--c-chat-input-radius);
  box-shadow: var(--c-chat-input-shadow);
  position: relative;
  /* Touch events on the input bar are forwarded to the feed by JS
     (see chat_bubble.dart) so finger-scrolling here scrolls the chat
     instead of escaping into the page underneath. */
  touch-action: auto;
}
.chat-input__field { flex: 1; min-width: 0; align-self: center; }
.chat-input__field textarea#chat-input-el {
  width: 100%; resize: none; overflow-y: auto;
  overscroll-behavior: contain;
  max-height: var(--c-chat-textarea-max-h);
  padding: var(--c-chat-textarea-pad-y) var(--c-chat-textarea-pad-x);
  background: transparent; border: none;
  color: var(--color-text-default);
  font-family: inherit; font-size: 16px; line-height: 1.4;
}
.chat-input__field textarea#chat-input-el:focus { outline: none; }
.chat-input__field textarea#chat-input-el::placeholder { color: var(--color-text-faint); }

.chat-input__send {
  width: var(--c-chat-send-size); height: var(--c-chat-send-size);
  flex-shrink: 0;
  background: var(--color-brand); color: var(--color-interactive-primary-text);
  border: none; border-radius: var(--c-chat-send-radius);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: filter .15s, transform .1s;
  align-self: flex-end;
}
.chat-input__send:hover { filter: brightness(1.1); }
.chat-input__send:active { transform: scale(.95); }
.chat-input__send:disabled { opacity: .4; cursor: not-allowed; }

.chat-input__skip {
  background: transparent; border: none;
  color: var(--color-text-muted);
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  letter-spacing: .04em; padding: 8px 10px;
  cursor: pointer; transition: color .15s;
  align-self: center;
}
.chat-input__skip:hover { color: var(--color-text-default); }

/* Country code chip inside input bar */
.chat-cc { position: relative; flex-shrink: 0; align-self: center; }
.chat-cc__btn {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: var(--c-chat-cc-pad-y) var(--c-chat-cc-pad-x);
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--c-chat-cc-radius); color: var(--color-text-default);
  font-family: inherit; cursor: pointer;
  transition: border-color .15s;
}
.chat-cc__btn:hover { border-color: var(--color-brand); }
.chat-cc.open .chat-cc__btn { border-color: var(--color-brand); }
.chat-cc__flag { font-size: 15px; line-height: 1; }
.chat-cc__code { font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.chat-cc__menu {
  display: none; position: absolute; bottom: calc(100% + var(--space-1-5)); left: 0;
  width: min(260px, calc(100vw - 60px));
  max-height: 240px; overflow-y: auto;
  background: var(--color-surface-card); border: var(--border-rule);
  border-radius: var(--c-chat-cc-menu-radius); box-shadow: var(--shadow-card);
  z-index: 20;
}
.chat-cc.open .chat-cc__menu { display: block; }
.chat-cc__opt {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px;
  background: transparent; border: none; cursor: pointer;
  color: var(--color-text-muted); text-align: start;
  font-family: inherit; font-size: 13px;
  transition: background .12s, color .12s;
}
.chat-cc__opt:hover { background: var(--color-surface-elevated); color: var(--color-text-default); }
.chat-cc__name { flex: 1; }
.chat-cc__opt .chat-cc__code { color: var(--color-text-faint); }

/* Success overlay — covers the feed + input, centered. Triggered on
   successful submit; "New chat" button restarts the conversation. */
.chat-success {
  position: absolute; inset: 0;
  background: var(--color-surface-card);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px; padding: 32px 24px;
  text-align: center; z-index: 5;
  animation: chatSuccessIn .35s ease-out both;
}
@keyframes chatSuccessIn {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1); }
}
.chat-success__check {
  width: 80px; height: 80px;
  display: flex; align-items: center; justify-content: center;
  color: #22c55e;
}
.chat-success__circle {
  animation: chatSuccessCircle .6s ease-out forwards;
}
.chat-success__tick {
  animation: chatSuccessTick .35s .5s ease-out forwards;
}
@keyframes chatSuccessCircle {
  to { stroke-dashoffset: 0; }
}
@keyframes chatSuccessTick {
  to { stroke-dashoffset: 0; }
}
.chat-success__title {
  display: flex; flex-direction: column; gap: 8px;
  font-size: 22px; font-weight: 600; color: var(--color-text-default);
  line-height: 1.35;
}
.chat-success__title-en {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; letter-spacing: .08em;
  color: var(--color-text-muted); text-transform: uppercase;
  font-weight: 500;
  margin-top: 2px;
}
.chat-success__sub {
  margin: 0; display: flex; flex-direction: column; gap: 8px;
  font-size: 14px; color: var(--color-text-muted);
  line-height: 1.5;
}
.chat-success__sub-en {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; letter-spacing: .04em; color: var(--color-text-faint);
  margin-top: 2px;
}
.chat-success__restart {
  margin-top: 16px;
  padding: 10px 18px;
  background: var(--color-brand); color: var(--color-interactive-primary-text);
  border: none; border-radius: 999px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: filter .15s, transform .1s;
}
.chat-success__restart:hover { filter: brightness(1.1); }
.chat-success__restart:active { transform: scale(.97); }

/* Confetti — colored shards that fall through the panel on send. */
.chat-confetti {
  position: absolute; top: -20px;
  width: 8px; height: 14px;
  border-radius: 2px;
  pointer-events: none; z-index: 70;
  opacity: 0;
  animation-name: chatConfettiFall;
  animation-timing-function: cubic-bezier(.3, .7, .6, 1);
  animation-fill-mode: forwards;
}
@keyframes chatConfettiFall {
  0%   { opacity: 0; transform: translate(0, 0) rotate(0deg); }
  10%  { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--drift, 0), 110vh) rotate(720deg); }
}

/* RTL mirror — site is lang="ar" so default positioning is fine on RTL.
   For LTR contexts the bubble already sits at right. */
[dir="rtl"] .chat-bubble,
[dir="rtl"] .chat-panel { right: auto; left: 20px; }

/* Mobile — full-screen panel; the floating bubble disappears while open. */
@media (max-width: 640px) {
  /* Plain bottom value (no env() calc) — iOS Safari's URL-bar collapse
     made the env-based calc jitter on scroll. Static gap is rock-stable. */
  .chat-bubble {
    bottom: var(--space-5-5); right: var(--space-4);
    width: var(--c-chat-bubble-size-sm); height: var(--c-chat-bubble-size-sm);
  }
  .chat-bubble.open { opacity: 0; pointer-events: none; transform: scale(.6); }

  .chat-panel {
    /* Full-screen sheet on mobile — inset:0 so it ALWAYS covers the
       whole viewport (no page content peeking under the input bar when
       the keyboard opens). padding-bottom: --chat-keyboard-h (set by JS
       from VisualViewport) shrinks the usable layout area so the input
       bar floats right above the keyboard. */
    inset: 0;
    width: auto; height: 100dvh; max-height: none;
    padding-bottom: var(--chat-keyboard-h, 0);
    border-radius: 0; border: none;
  }
  .chat-msg { max-width: 88%; font-size: var(--text-md); }
  .chat-chip__ar { font-size: var(--text-base); }

  /* Slightly bigger header on full-screen */
  .chat-header { padding: var(--space-3-5) var(--space-4); }
  .chat-header__avatar { width: var(--c-chat-avatar-size-sm); height: var(--c-chat-avatar-size-sm); }
  .chat-header__name-ar { font-size: var(--text-md); }
}
