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

:root {
  --bg:      #F5F3EF;
  --fg:      #1A1A1A;
  --mid:     #888888;
  --t:       0.35s ease;

  --en:      'JetBrains Mono', monospace;
  --ar:      'Tajawal', sans-serif;
  --ar-h:    'Alyamama', serif;

  --fs-back:        0.8125rem;
  --fs-home:        1.875rem;
  --fs-about-big:   4.5rem;
  --fs-label:       0.75rem;
  --fs-body:        0.9375rem;
  --fs-proj-name:   0.875rem;
  --fs-proj-desc:   0.8125rem;
  --fs-proj-title:  1.625rem;
  --fs-meta:        0.8125rem;
  --fs-cell:        0.8125rem;
  --fs-cell-sub:    0.75rem;
  --fs-more:        0.8125rem;

  --fs-ar-logo:       1.0625rem;
  --fs-ar-back:       0.9375rem;
  --fs-ar-home:       1.875rem;
  --fs-ar-label:      0.8125rem;
  --fs-ar-body:       1rem;
  --fs-ar-proj-name:  0.9375rem;
  --fs-ar-proj-desc:  0.875rem;
  --fs-ar-proj-title: 1.625rem;
  --fs-ar-cell:       0.875rem;
  --fs-ar-cell-sub:   0.8125rem;
  --fs-ar-more:       0.875rem;
}

[data-theme="dark"] {
  --bg:  #161616;
  --fg:  #E2E2E2;
  --mid: #606060;
}

html { transition: background var(--t), color var(--t); }
html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--en);
}
body.loading { visibility: hidden; }

/* ─── HEADER ─── */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--bg);
  direction: ltr;
  z-index: 300;
}

.logo {
  font-family: var(--ar-h);
  font-size: var(--fs-ar-logo);
  font-weight: 900;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
}
.logo:hover { opacity: 0.35; }

.logo-img { display: block; height: 25px; width: auto; transition: opacity 0.2s; }
[data-theme="dark"] .logo-img { filter: invert(1); }

.logo-text { font-family: var(--ar-h); font-size: var(--fs-ar-logo); font-weight: 900; }

.hdr-left { display: flex; flex-direction: row; gap: 12px; }

.hdr-btn {
  background: none;
  border: none;
  color: var(--mid);
  width: 28px; height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: color 0.15s;
  user-select: none;
  padding: 0;
}
.hdr-btn:hover { color: var(--fg); }

/* ─── PAGES ─── */
.page {
  position: fixed;
  top: 52px; bottom: 62px;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.page.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}

:focus-visible { outline: 1px solid var(--fg); outline-offset: 3px; }

.inner {
  width: 100%;
  max-width: 460px;
  max-height: 100%;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  overscroll-behavior: contain;
}
.inner::-webkit-scrollbar { display: none; }

.hdr-back-sort{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.hdr-back-sort .back {
  margin-bottom: 0;
}

.proj-date{
  font-size: var(--fs-meta);
  color: var(--mid);
  margin-bottom: 8px;
}


/* ─── BACK ─── */
.back {
  background: none;
  border: none;
  color: var(--mid);
  font-family: var(--en);
  font-size: var(--fs-back);
  letter-spacing: 0.06em;
  cursor: pointer;
  padding: 0;
  margin-bottom: 32px;
  display: block;
  transition: color 0.2s;
  text-align: start;
}
html[lang="ar"] .back { font-family: var(--ar); font-size: var(--fs-ar-back); letter-spacing: 0; }
.back:hover { color: var(--fg); }

/* ══════════════════════════════
   HOME
══════════════════════════════ */
#page-home { align-items: center; justify-content: center; }

.home-nav { display: flex; flex-direction: column; align-items: center; }

.home-nav button {
  background: none;
  border: none;
  color: var(--fg);
  font-family: var(--en);
  font-size: var(--fs-home);
  font-weight: 400;
  letter-spacing: 0.04em;
  padding: 10px 0;
  cursor: pointer;
  display: block;
  transition: opacity 0.18s, color var(--t);
}
html[lang="ar"] .home-nav button { font-family: var(--ar-h); font-size: var(--fs-ar-home); letter-spacing: 0; }
.home-nav button:hover { opacity: 0.25; }

.home-nav-link {
  color: var(--fg);
  font-family: var(--en);
  font-size: var(--fs-home);
  font-weight: 400;
  letter-spacing: 0.04em;
  padding: 10px 0;
  cursor: pointer;
  display: block;
  transition: opacity 0.18s, color var(--t);
  text-decoration: none;
}
html[lang="ar"] .home-nav-link { font-family: var(--ar-h); font-size: var(--fs-ar-home); letter-spacing: 0; }
.home-nav-link:hover { opacity: 0.25; }

/* ══════════════════════════════
   ABOUT
══════════════════════════════ */
.about-letter {
  font-family: var(--en);
  font-size: var(--fs-about-big);
  font-weight: 700;
  line-height: 1;
  margin-bottom: 12px;
}
html[lang="ar"] .about-letter { font-family: var(--ar-h); }

.about-text { font-size: var(--fs-body); line-height: 1.9; color: var(--mid); }
html[lang="ar"] .about-text { font-family: var(--ar); font-size: var(--fs-ar-body); line-height: 2; }

/* ══════════════════════════════
   WORKS LIST
══════════════════════════════ */
.works-list {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.proj-item {
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.proj-name {
  font-size: var(--fs-proj-name);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
html[lang="ar"] .proj-name { font-family: var(--ar-h); letter-spacing: 0; font-size: var(--fs-ar-proj-name); }

.proj-desc { font-size: var(--fs-proj-desc); color: var(--mid); line-height: 1.5; }
html[lang="ar"] .proj-desc { font-family: var(--ar); font-size: var(--fs-ar-proj-desc); }

.proj-tags-date {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0;
  font-size: var(--fs-proj-desc);
  color: var(--mid);
  margin-bottom: 12px;
  line-height: 1.5;
}
html[lang="ar"] .proj-tags-date { font-family: var(--ar); font-size: var(--fs-ar-proj-desc); }

.proj-sep {
  margin: 0 6px;
}

.proj-date {
  font-size: inherit;
  color: inherit;
}

.proj-excerpt { font-size: var(--fs-proj-desc); color: var(--mid); line-height: 1.85; margin-bottom: 10px; }
html[lang="ar"] .proj-excerpt { font-family: var(--ar); font-size: var(--fs-ar-proj-desc); line-height: 2; }

.proj-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  margin-bottom: 12px;
}
.proj-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.proj-item:hover .proj-thumb img {
  transform: scale(1.04);
}
.proj-thumb svg {
  width: 42px; height: 42px;
  stroke: var(--mid); fill: none; stroke-width: 1.2;
  transition: stroke 0.2s;
}
.proj-item:hover .proj-thumb svg { stroke: var(--fg); }

/* hover overlay */
.proj-thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.proj-thumb-overlay span {
  font-family: var(--en);
  font-size: var(--fs-label);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #fff;
}
html[lang="ar"] .proj-thumb-overlay span { font-family: var(--ar); letter-spacing: 0; font-size: var(--fs-ar-label); }
.proj-item:hover .proj-thumb-overlay { opacity: 1; }

.proj-meta {
  display: flex;
  align-items: center;
}

.proj-arrow {
  font-family: var(--en);
  font-size: var(--fs-more);
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: opacity 0.2s;
}
html[lang="ar"] .proj-arrow { font-family: var(--ar); font-size: var(--fs-ar-more); }
.proj-item:hover .proj-arrow { opacity: 0.35; }

/* ══════════════════════════════
   WORKS DETAIL
══════════════════════════════ */
.detail-hero {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}
.detail-hero img {
  width: 100%; height: 100%;
  object-fit: cover;
  position: relative; z-index: 1;
}
.detail-hero svg.placeholder-icon {
  width: 42px; height: 42px;
  stroke: var(--mid); fill: none; stroke-width: 1.2;
  position: relative; z-index: 1;
}
.detail-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, var(--mid) 1px, transparent 1px);
  background-size: 18px 18px;
  opacity: 0.18;
}
.detail-hero.has-img::before { display: none; }

.detail-header { margin-bottom: 0; }

.proj-title { font-size: var(--fs-proj-title); font-weight: 700; line-height: 1.3; margin-bottom: 8px; }
html[lang="ar"] .proj-title { font-family: var(--ar-h); font-size: var(--fs-ar-proj-title); }

.detail-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.detail-tags {
  font-size: var(--fs-proj-desc);
  color: var(--mid);
  line-height: 1.5;
}
html[lang="ar"] .detail-tags { font-family: var(--ar); font-size: var(--fs-ar-proj-desc); }

.detail-date {
  font-size: var(--fs-meta);
  color: var(--mid);
  flex-shrink: 0;
}

.detail-divider {
  width: 100%;
  height: 1px;
  background: var(--fg);
  margin: 18px 0;
  opacity: 0.2;
  transition: background var(--t);
}

/* ══════════════════════════════
   FOOTER
══════════════════════════════ */
footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 62px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-bottom: 5px;
  padding-bottom: 10px;
  z-index: 300;
}

.footer-links { display: flex; flex-direction: row; gap: 24px; }

.f-link {
  color: var(--mid);
  text-decoration: none;
  font-family: var(--en);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  transition: color 0.2s;
}
html[lang="ar"] .f-link { font-family: var(--ar); font-size: 1rem; letter-spacing: 0; }
.f-link:hover { color: var(--fg); }

.footer-credit {
  font-family: var(--en);
  font-size: 0.9rem;
  letter-spacing: 0;
  color: var(--mid);
}

/* ══════════════════════════════
   DETAIL BODY (markdown)
══════════════════════════════ */
.detail-body {
  color: var(--fg);
  font-family: var(--en);
  font-size: var(--fs-body);
  line-height: 1.9;
  margin-top: 8px;
}
.detail-body[data-lang="ar"] {
  font-family: var(--ar);
  font-size: var(--fs-ar-body);
  line-height: 2;
  direction: rtl;
  text-align: start;
}

.detail-body h1, .detail-body h2, .detail-body h3,
.detail-body h4, .detail-body h5, .detail-body h6 {
  font-family: var(--en);
  font-weight: 700;
  font-size: var(--fs-label);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--mid);
  margin-top: 28px;
  margin-bottom: 10px;
  line-height: 1.3;
}
.detail-body[data-lang="ar"] h1, .detail-body[data-lang="ar"] h2,
.detail-body[data-lang="ar"] h3, .detail-body[data-lang="ar"] h4 {
  font-family: var(--ar); font-size: var(--fs-ar-label); letter-spacing: 0;
}

.detail-body p { margin-bottom: 14px; }

.detail-body a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: opacity 0.2s;
}
.detail-body a:hover { opacity: 0.45; }

.detail-body img {
  display: block;
  width: 100%; max-width: 100%; height: auto;
  object-fit: cover;
  border: 1px solid var(--fg);
  margin: 18px 0;
  transition: border-color var(--t);
}

.detail-body table {
  display: table;
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-cell);
  margin: 16px 0;
}
.detail-body[data-lang="ar"] table { font-family: var(--ar); font-size: var(--fs-ar-cell); }
.detail-body th, .detail-body td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--mid);
  text-align: start;
  white-space: normal;
  transition: border-color var(--t);
}
.detail-body thead tr { border-bottom: 1px solid var(--fg); }
.detail-body th {
  font-size: var(--fs-label); letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--mid);
}
.detail-body[data-lang="ar"] th { font-family: var(--ar); letter-spacing: 0; font-size: var(--fs-ar-label); }
.detail-body tr:last-child td { border-bottom: none; }

.detail-body pre {
  border: 1px solid var(--fg);
  padding: 14px 16px;
  margin: 14px 0;
  overflow-x: auto;
  font-family: var(--en);
  font-size: 0.82rem;
  line-height: 1.65;
  background: none;
  transition: border-color var(--t);
}
.detail-body code { font-family: var(--en); font-size: 0.88em; }
.detail-body pre code { font-size: inherit; }

.detail-body ul, .detail-body ol { padding-inline-start: 1.4em; margin-bottom: 14px; }
.detail-body li { line-height: 1.85; margin-bottom: 5px; }

.detail-body blockquote {
  border-inline-start: 2px solid var(--mid);
  padding-inline-start: 16px;
  color: var(--mid);
  margin: 16px 0;
}
.detail-body blockquote p { margin-bottom: 0; }

.detail-body strong { font-weight: 700; }
.detail-body em { font-style: italic; }

.detail-body hr {
  border: none;
  border-top: 1px solid var(--fg);
  margin: 24px 0;
  transition: border-color var(--t);
}

/* ══════════════════════════════
   MOBILE (≤ 600px)
══════════════════════════════ */
@media (max-width: 600px) {
  header { padding: 0 18px; }
  .page  { padding: 20px 18px; bottom: 54px; }
  footer { height: 54px; margin-bottom: 18px;}

  .home-nav button { font-size: 1.55rem; padding: 8px 0; }
  html[lang="ar"] .home-nav button { font-size: 1.55rem; }
  .home-nav-link { font-size: 1.55rem; padding: 8px 0; }
  html[lang="ar"] .home-nav-link { font-size: 1.55rem; }

  .about-letter { font-size: 3.6rem; }

  .detail-body pre   { overflow-x: auto; }
  .detail-body table { overflow-x: auto; }

  .footer-links { gap: 14px; flex-wrap: wrap; justify-content: center; }
}
