/* ==========================================================================
   Terminal theme — dark, phosphor-green on near-black, mono display type,
   a faint grid and scanlines. Loaded after every section stylesheet, so it
   wins by order and by :root:root specificity. Dark only; the theme toggle
   is hidden because one well-built dark look beats two half-built ones.
   ========================================================================== */

@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap");

:root:root, :root:root[data-theme] {
  --paper: #060809;
  --surface: #0b1110;
  --ink: #d5e6dd;
  --muted: #7f958b;
  --line: #17302a;
  --line-strong: #2a4a40;
  --spruce: #3df09a;
  --spruce-soft: #0c2a1e;
  --berry: #3df09a;
  --berry-ink: #03120b;
  --danger: #ff4d6d;
  --ok: #3df09a;
  --glow: 0 0 24px -6px rgba(61, 240, 154, .45);
  --font-display: "JetBrains Mono", "IBM Plex Sans Arabic", ui-monospace, monospace;
  --radius-m: 10px;
  --radius-s: 4px;
  color-scheme: dark;
}
:root:root:lang(ar), :root:root[data-theme]:lang(ar) { --font-display: "Readex Pro", "IBM Plex Sans Arabic", system-ui, sans-serif; }

/* Background: grid, scanlines, a green glow in the corner. */
body {
  background:
    radial-gradient(900px 500px at 85% -5%, rgba(61, 240, 154, .10), transparent 60%),
    var(--paper);
  color: var(--ink);
  position: relative;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .22) 0 1px, transparent 1px 3px),
    linear-gradient(rgba(61, 240, 154, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 240, 154, .035) 1px, transparent 1px);
  background-size: auto, 48px 48px, 48px 48px;
}
main, .site-footer { position: relative; z-index: 1; }
.site-header { position: sticky; top: 0; z-index: 50; }
::selection { background: var(--spruce); color: var(--berry-ink); }

/* Header */
.site-header {
  background: rgba(6, 8, 9, .82);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--font-display); font-weight: 700; letter-spacing: .02em; }
.brand::before { content: "> "; color: var(--spruce); }
:lang(ar) .brand::before { content: none; }
.nav a, .nav li > a {
  font-family: var(--font-display); font-size: .78rem; font-weight: 500;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted); text-decoration: none;
  transition: color .15s, text-shadow .15s;
}
:lang(ar) .nav a { letter-spacing: 0; text-transform: none; font-size: .9rem; }
.nav a:hover, .nav a:focus-visible { color: var(--spruce); text-shadow: 0 0 12px rgba(61, 240, 154, .6); }
.lang-switch {
  font-family: var(--font-display); font-size: .75rem; text-decoration: none;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 6px 10px; color: var(--ink);
}
.lang-switch:hover { border-color: var(--spruce); color: var(--spruce); }

/* Buttons */
.btn { border-radius: var(--radius-s); border-color: var(--line-strong); color: var(--ink); font-family: var(--font-display); font-size: .85rem; letter-spacing: .02em; }
.btn:hover { background: transparent; color: var(--spruce); border-color: var(--spruce); box-shadow: var(--glow); }
.btn-primary { background: var(--spruce); border-color: var(--spruce); color: var(--berry-ink); font-weight: 700; }
.btn-primary:hover { background: transparent; color: var(--spruce); border-color: var(--spruce); }
.link { color: var(--spruce); }
.link:hover { color: var(--ink); }
.tag { border-radius: var(--radius-s); border-color: var(--line-strong); font-family: var(--font-display); font-size: .72rem; color: var(--spruce); background: var(--spruce-soft); }

/* Hero: glitch title and a terminal window instead of the phone. */
.hero-status { font-family: var(--font-display); font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
.hero-greeting { font-family: var(--font-display); color: var(--spruce); font-size: .95rem; }
:lang(ar) .hero-greeting { font-family: var(--font-body); }
.hero-title {
  position: relative; display: block; max-width: 16ch;
  font-size: clamp(2.3rem, 6vw, 4.4rem); font-weight: 700; letter-spacing: -0.02em; line-height: 1.05;
  color: var(--ink);
}
:lang(ar) .hero-title { max-width: 14ch; line-height: 1.3; letter-spacing: 0; font-family: var(--font-body); }
.hero-title[data-text]::before, .hero-title[data-text]::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none;
}
.hero-title[data-text]::before { color: var(--danger); opacity: 0; }
.hero-title[data-text]::after { color: var(--spruce); opacity: 0; }
@media (prefers-reduced-motion: no-preference) {
  .hero-title[data-text]::before { animation: glitch-a 5s infinite steps(1); }
  .hero-title[data-text]::after  { animation: glitch-b 5s infinite steps(1); }
}
@keyframes glitch-a {
  0%, 89%, 100% { opacity: 0; transform: none; clip-path: inset(0 0 100% 0); }
  90% { opacity: .8; transform: translate(-3px, 0); clip-path: inset(18% 0 58% 0); }
  92% { opacity: .8; transform: translate(3px, 0); clip-path: inset(62% 0 12% 0); }
  94% { opacity: .8; transform: translate(-2px, 0); clip-path: inset(40% 0 30% 0); }
}
@keyframes glitch-b {
  0%, 89%, 100% { opacity: 0; transform: none; clip-path: inset(0 0 100% 0); }
  90% { opacity: .6; transform: translate(3px, 0); clip-path: inset(70% 0 8% 0); }
  93% { opacity: .6; transform: translate(-3px, 0); clip-path: inset(25% 0 50% 0); }
}
.hero-subtitle { font-family: var(--font-display); color: var(--spruce); font-size: 1rem; font-weight: 500; }
:lang(ar) .hero-subtitle { font-family: var(--font-body); font-size: 1.2rem; }
.hero-bio { color: var(--muted); }
.hero-cv { color: var(--spruce); font-family: var(--font-display); font-size: .85rem; }

.hero-term {
  margin: 0; justify-self: center; width: min(100%, 480px);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; overflow: hidden;
  box-shadow: var(--glow), 0 30px 70px -30px rgba(0, 0, 0, .8);
  font-family: var(--font-display); font-size: .88rem; direction: ltr; text-align: left;
}
.term-bar {
  display: flex; align-items: center; gap: 7px; padding: 11px 14px;
  border-bottom: 1px solid var(--line); color: var(--muted); font-size: .72rem;
}
.term-bar i { width: 10px; height: 10px; border-radius: 50%; background: var(--line-strong); }
.term-bar i:nth-child(1) { background: var(--danger); }
.term-bar i:nth-child(2) { background: #f5c451; }
.term-bar i:nth-child(3) { background: var(--spruce); }
.term-bar span { margin-inline-start: 10px; }
.term-body { padding: 18px 20px 22px; line-height: 1.95; }
.term-line { white-space: pre-wrap; word-break: break-word; }
.term-prompt { color: var(--spruce); margin-inline-end: .5em; }
.term-out { color: var(--ink); padding-inline-start: 1.2em; }
.term-photo {
  width: 84px; height: 84px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;
  border: 1px solid var(--line-strong); filter: grayscale(.2) contrast(1.05);
}
.term-cursor::after { content: "▌"; color: var(--spruce); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .term-cursor::after { animation: none; } }

@media (prefers-reduced-motion: no-preference) {
  .term-static .term-line { opacity: 0; animation: type-in .4s forwards; }
  .term-static .term-line:nth-child(1) { animation-delay: .3s; }
  .term-static .term-line:nth-child(2) { animation-delay: .7s; }
  .term-static .term-line:nth-child(3) { animation-delay: 1.1s; }
  .term-static .term-line:nth-child(4) { animation-delay: 1.5s; }
  .term-static .term-line:nth-child(5) { animation-delay: 1.9s; }
  .term-static .term-line:nth-child(6) { animation-delay: 2.3s; }
  .term-static .term-line:nth-child(7) { animation-delay: 2.7s; }
}
@keyframes type-in { to { opacity: 1; } }
@media (max-width: 820px) { .hero-term { width: 100%; } }

/* Sections */
.section + .section { border-top: 1px solid var(--line); }
.section-title { font-size: clamp(1.9rem, 4vw, 2.7rem); font-weight: 700; letter-spacing: -0.01em; }
:lang(en) .section-title::before { content: "// "; color: var(--spruce); }

/* Cards: services, projects, testimonials, skills */
.service, .project, .quote, .skill-group {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.service:hover, .project:hover, .quote:hover, .skill-group:hover {
  border-color: var(--spruce); box-shadow: var(--glow);
}
.service-icon { color: var(--spruce); }
.project-media img { filter: grayscale(.5) brightness(.85); transition: filter .3s, transform .4s; }
.project:hover .project-media img { filter: none; transform: scale(1.03); }
.project-placeholder { color: var(--spruce); }
.chip { border-radius: var(--radius-s); border-color: var(--line-strong); font-family: var(--font-display); font-size: .8rem; }
.chip[aria-pressed="true"] { background: var(--spruce); color: var(--berry-ink); border-color: var(--spruce); }

/* Footer */
.site-footer { border-top: 1px solid var(--line); background: rgba(6, 8, 9, .9); color: var(--muted); font-size: .9rem; }
.site-footer .brand { font-size: 1.05rem; }
.socials a { color: var(--ink); font-family: var(--font-display); font-size: .8rem; }
.socials a:hover { color: var(--spruce); }
.to-top { color: var(--spruce); }

/* Stats band — four real figures under the hero. */
.stats-band { position: relative; border-block: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 70%, transparent); padding-block: 28px; }
.stats-band[hidden] { display: none; }
.stats-band-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px; text-align: center; }
.stats-band-item { display: grid; gap: 4px; }
.stats-band .num { font-family: var(--font-display); font-size: clamp(1.9rem, 4vw, 2.7rem); font-weight: 700; color: var(--spruce); text-shadow: 0 0 18px rgba(61, 240, 154, .35); }
.stats-band .lbl { color: var(--muted); font-size: .9rem; }

/* Process — four numbered steps. */
.process { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.process-step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 24px; transition: border-color .2s, box-shadow .2s; }
.process-step:hover { border-color: var(--spruce); box-shadow: var(--glow); }
.process-step h3 { margin-top: 10px; font-size: 1.15rem; }
.process-step p { margin-top: 8px; color: var(--muted); font-size: .95rem; }
.step-num { font-family: var(--font-display); color: var(--spruce); font-size: .85rem; letter-spacing: .08em; }

/* Card spacing — base.css sets vertical padding only (0 sides), so the
   icons and labels sat on the border. Give every card real inner padding. */
.services { row-gap: 16px; }
.service { padding: 24px; }
.skill-group { padding: 22px 26px; }
.skill-groups { gap: 14px; }
@media (max-width: 720px) {
  .service, .skill-group { padding: 20px; }
}

/* ── Hero extras ─────────────────────────────────────────────────────── */
.hero-now { margin-top: 14px; font-family: var(--font-display); font-size: .92rem; color: var(--ink); }
.hero-now-label { color: var(--spruce); margin-inline-end: .4em; }
:lang(ar) .hero-now-label { font-family: var(--font-body); }

/* Terminal: history, input line */
.term-hint { color: var(--muted); font-size: .8rem; }
.term-history:empty { display: none; }
.term-history { margin-top: 6px; max-height: 180px; overflow-y: auto; scrollbar-width: thin; }
.term-history .term-line { opacity: 1; animation: none; }
.term-form { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.term-form .term-prompt { margin: 0; }
.term-input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: var(--ink); font: inherit; caret-color: var(--spruce); padding: 0; }
.term-body { cursor: text; }

/* Command-palette button and key caps */
kbd { font-family: var(--font-display); font-size: .7rem; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--ink); }
.cmd-btn { display: inline-flex; gap: 4px; align-items: center; background: transparent; border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 5px 8px; cursor: pointer; color: var(--muted); }
.cmd-btn:hover { border-color: var(--spruce); color: var(--spruce); }
@media (max-width: 720px) { .cmd-btn { display: none; } }

/* Command palette */
.palette { position: fixed; inset: 0; z-index: 200; background: rgba(3, 5, 6, .72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; }
.palette[hidden] { display: none; }
.palette-box { width: min(620px, 100%); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); box-shadow: var(--glow), 0 40px 80px -30px #000; overflow: hidden; }
.palette-input { width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 16px 18px; color: var(--ink); font-family: var(--font-display); font-size: 1rem; outline: none; }
:lang(ar) .palette-input { font-family: var(--font-body); }
.palette-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.palette-item { width: 100%; display: flex; justify-content: space-between; gap: 12px; align-items: center; background: transparent; border: 0; border-radius: var(--radius-s); padding: 10px 12px; color: var(--ink); cursor: pointer; text-align: start; font-size: .95rem; }
.palette-item.is-active, .palette-item:hover { background: var(--spruce-soft); color: var(--spruce); }
.palette-kind { font-family: var(--font-display); font-size: .72rem; color: var(--muted); white-space: nowrap; }
.palette-empty { padding: 14px 12px; color: var(--muted); }
.palette-hint { margin: 0; padding: 10px 16px; border-top: 1px solid var(--line); font-family: var(--font-display); font-size: .72rem; color: var(--muted); }

/* GitHub repositories */
.repos { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.repo { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 22px 24px; transition: border-color .2s, box-shadow .2s; }
.repo:hover { border-color: var(--spruce); box-shadow: var(--glow); }
.repo-name { font-family: var(--font-display); font-weight: 700; color: var(--spruce); text-decoration: none; overflow-wrap: anywhere; }
.repo-name:hover { text-decoration: underline; }
.repo-desc { color: var(--muted); font-size: .95rem; margin-top: 8px; }
.repo-meta { display: flex; gap: 14px; margin-top: 12px; font-family: var(--font-display); font-size: .78rem; color: var(--muted); }

/* Certificates */
.certs { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.cert { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 22px 24px; display: grid; gap: 10px; align-content: start; transition: border-color .2s, box-shadow .2s; }
.cert:hover { border-color: var(--spruce); box-shadow: var(--glow); }
.cert h3 { font-size: 1.05rem; }
.cert-img { width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: cover; border-radius: var(--radius-s); border: 1px solid var(--line); }
.cert-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: .85rem; }

/* Blog cards */
.posts { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.post-link { display: grid; gap: 10px; align-content: start; height: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding-bottom: 22px; text-decoration: none; overflow: hidden; transition: border-color .2s, box-shadow .2s; }
.post-link:hover { border-color: var(--spruce); box-shadow: var(--glow); }
.post-link img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; filter: grayscale(.4); transition: filter .3s; }
.post-link:hover img { filter: none; }
.post-link h3 { padding: 0 22px; font-size: 1.1rem; }
.post-link p { padding: 0 22px; color: var(--muted); font-size: .95rem; }
.post-link .link { padding: 0 22px; }
.post-link .post-date { padding: 16px 22px 0; }
.post-date { font-family: var(--font-display); font-size: .75rem; color: var(--spruce); letter-spacing: .04em; }

/* Sub-pages: project and post */
.page { position: relative; z-index: 1; padding-block: clamp(40px, 7vw, 80px) clamp(64px, 10vw, 110px); }
.page-narrow { max-width: 760px; }
.page-crumb { font-family: var(--font-display); font-size: .85rem; margin-bottom: 24px; }
.page-head { display: grid; gap: 14px; margin-bottom: 28px; }
.page-head .post-date { padding: 0; }
.page-title { font-family: var(--font-display); font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; }
:lang(ar) .page-title { font-family: var(--font-body); line-height: 1.35; }
.page-lead { color: var(--muted); font-size: 1.1rem; max-width: 60ch; }
.page-cover { width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-m); border: 1px solid var(--line); margin-block: 24px; }
.page-empty { font-size: 1.1rem; color: var(--muted); }
.prose { font-size: 1.05rem; line-height: 1.85; }
.prose p { margin: 0 0 1.2em; }
.demo-video { width: 100%; border-radius: var(--radius-m); border: 1px solid var(--line); margin-block: 24px; background: #000; }
.shots { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.shots img { width: 100%; height: auto; border-radius: 18px; border: 1px solid var(--line); }

/* Project cards — the border needs room inside it, or the text touches it. */
.project { padding: clamp(20px, 3vw, 36px); }
.projects { gap: clamp(28px, 4vw, 44px); }
@media (max-width: 820px) {
  .project { padding: 20px; gap: 20px; }
}

/* ── Light theme (the toggle in the header switches to it) ───────────── */
:root:root:root[data-theme="light"] {
  --paper: #f5f8f6;
  --surface: #ffffff;
  --ink: #0c1a14;
  --muted: #56695f;
  --line: #d6e3dd;
  --line-strong: #b3c8be;
  --spruce: #0b7a4c;
  --spruce-soft: #e2f3eb;
  --berry: #0b7a4c;
  --berry-ink: #ffffff;
  --danger: #c4283f;
  --ok: #0b7a4c;
  --glow: 0 0 22px -8px rgba(11, 122, 76, .35);
  color-scheme: light;
}
:root[data-theme="light"] body::before { opacity: .35; }
:root[data-theme="light"] .site-header { background: rgba(245, 248, 246, .88); }
:root[data-theme="light"] .site-footer { background: rgba(245, 248, 246, .95); }
:root[data-theme="light"] .palette { background: rgba(12, 26, 20, .35); }
:root[data-theme="light"] .term-body { color: var(--ink); }
:root[data-theme="light"] .hero-term { box-shadow: var(--glow), 0 30px 60px -34px rgba(12, 26, 20, .35); }

/* Reading progress, copy-link, article meta */
.read-progress { position: fixed; top: 0; inset-inline: 0; height: 2px; z-index: 60; background: var(--spruce); transform: scaleX(0); transform-origin: 0 50%; box-shadow: var(--glow); pointer-events: none; }
[dir="rtl"] .read-progress { transform-origin: 100% 50%; }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; font-family: var(--font-display); font-size: .82rem; color: var(--muted); margin: 0 0 20px; }
.copy-link { background: transparent; border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 4px 10px; color: var(--spruce); cursor: pointer; font: inherit; font-size: .78rem; }
.copy-link:hover { border-color: var(--spruce); }

/* WhatsApp floating button */
.wa-fab { position: fixed; inset-inline-end: 18px; bottom: 18px; z-index: 90; display: inline-flex; align-items: center; gap: 8px; background: #25d366; color: #06240f; text-decoration: none; font-family: var(--font-display); font-weight: 700; font-size: .85rem; padding: 12px 16px; border-radius: 999px; box-shadow: 0 12px 30px -10px rgba(37, 211, 102, .6); transition: transform .15s; }
.wa-fab:hover { transform: translateY(-2px); }
.wa-fab span { font-size: .6rem; }

/* Newsletter */
.subscribe-row { display: grid; gap: 14px 40px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: center; padding-block: 36px; border-bottom: 1px solid var(--line); }
.subscribe-row h3 { font-family: var(--font-display); font-size: 1.1rem; }
.subscribe-row p { color: var(--muted); margin-top: 6px; font-size: .95rem; }
.subscribe { display: flex; flex-wrap: wrap; gap: 8px; }
.subscribe input[type="email"] { flex: 1 1 220px; min-height: 46px; padding: 0 14px; border-radius: var(--radius-s); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; }
.subscribe input[type="email"]:focus-visible { outline: 2px solid var(--spruce); outline-offset: 2px; }
.subscribe .btn { min-height: 46px; }
.subscribe-status { width: 100%; margin: 0; font-size: .88rem; color: var(--muted); min-height: 1.2em; }
.hp-field { position: absolute; inset-inline-start: -9999px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 820px) { .subscribe-row { grid-template-columns: 1fr; } }
