/* Portfolio — Mamdouh Mahmoud
   Direction: a backend developer's page that reads like an API response.
   Light "paper" page, one dark JSON panel as the signature, cobalt as the only accent. */

:root {
  --paper: #f4f6f9;
  --card: #ffffff;
  --ink: #0b1b33;
  --ink-2: #44546b;
  --line: #dce2ea;
  --cobalt: #2347e8;
  --cobalt-soft: #e8edfd;
  --ok: #14835f;
  --code-bg: #0b1b33;
  --code-ink: #c9d6ee;
  --code-key: #8fb0ff;
  --code-str: #7fe0b8;
  --code-dim: #6f84a8;

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  --wrap: 1120px;
  --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: clip; scroll-behavior: smooth; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; border-radius: 4px; }

.wrap { width: min(var(--wrap), 100% - 40px); margin-inline: auto; }
.skip {
  position: absolute; left: 12px; top: -48px; background: var(--ink); color: #fff;
  padding: 8px 14px; border-radius: 8px; z-index: 200; transition: top .2s;
}
.skip:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.mono { font-family: var(--font-mono); }
.eyebrow {
  font-family: var(--font-mono); font-size: .8rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-2); margin: 0 0 14px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  font-family: var(--font-body); font-weight: 600; font-size: .98rem;
  padding: 12px 20px; border-radius: 10px; border: 1.5px solid var(--ink);
  background: transparent; color: var(--ink); cursor: pointer;
  transition: background .18s, color .18s, transform .18s;
}
.btn:hover { background: var(--ink); color: #fff; }
.btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.btn.primary:hover { background: #1a39c0; border-color: #1a39c0; }
.btn.small { padding: 8px 14px; font-size: .9rem; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(244, 246, 249, .88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; flex-wrap: wrap; }
.brand { text-decoration: none; font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; letter-spacing: -.01em; }
.brand span { font-family: var(--font-mono); font-weight: 500; font-size: .78rem; color: var(--cobalt); margin-left: 8px; }
.nav { display: flex; gap: 26px; }
.nav a { text-decoration: none; font-weight: 500; font-size: .98rem; color: var(--ink-2); padding: 4px 0; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--ink); border-bottom-color: var(--cobalt); }
.nav-cv, .menu-btn { display: none; }
.menu-btn { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; padding: 0; flex-direction: column; align-items: center; justify-content: center; gap: 5px; }
.menu-btn span { display: block; width: 20px; height: 2px; background: var(--ink); border-radius: 2px; transition: transform .2s, opacity .2s; }
.menu-btn:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.menu-open .menu-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-open .menu-btn span:nth-child(2) { opacity: 0; }
.menu-open .menu-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Hero */
.hero { padding: clamp(48px, 8vw, 104px) 0 clamp(56px, 8vw, 96px); }
.hero .wrap { display: grid; grid-template-columns: 1.1fr .9fr; gap: clamp(32px, 5vw, 72px); align-items: center; }
.status {
  display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: .82rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 12px; margin-bottom: 26px;
}
.status i { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(20, 131, 95, .16); }
h1 {
  font-family: var(--font-display); font-weight: 800; letter-spacing: -.035em; line-height: 1.02;
  font-size: clamp(2.5rem, 6vw, 4.6rem); margin: 0 0 24px;
}
h1 em { font-style: normal; color: var(--cobalt); }
.lede { font-size: clamp(1.05rem, 1.6vw, 1.22rem); color: var(--ink-2); max-width: 34em; margin: 0 0 32px; }
.cta { display: flex; flex-wrap: wrap; gap: 12px; }

/* Signature: the JSON response */
.panel {
  background: var(--code-bg); color: var(--code-ink); border-radius: 16px; overflow: hidden;
  box-shadow: 0 30px 60px -28px rgba(11, 27, 51, .55), 0 0 0 1px rgba(255, 255, 255, .04) inset;
  font-family: var(--font-mono); font-size: .9rem; line-height: 1.75;
}
.panel-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid rgba(255, 255, 255, .09); }
.panel-bar .req b { color: var(--code-key); font-weight: 600; margin-right: 8px; }
.panel-bar .ok { color: #0b1b33; background: var(--code-str); padding: 2px 10px; border-radius: 6px; font-weight: 700; font-size: .78rem; white-space: nowrap; }
.panel pre { margin: 0; padding: 20px 22px 24px; white-space: pre-wrap; word-break: break-word; }
.k { color: var(--code-key); }
.s { color: var(--code-str); }
.d { color: var(--code-dim); }
.panel .ln { display: block; opacity: 0; transform: translateY(4px); animation: lineIn .45s ease forwards; }
@keyframes lineIn { to { opacity: 1; transform: none; } }

/* Sections */
section { padding: clamp(56px, 8vw, 104px) 0; }
.section-head { max-width: 40em; margin-bottom: 36px; }
h2 { font-family: var(--font-display); font-weight: 700; letter-spacing: -.025em; line-height: 1.1; font-size: clamp(1.9rem, 3.6vw, 2.8rem); margin: 0 0 12px; }
.section-head p { color: var(--ink-2); margin: 0; }

/* Work */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 28px; }
.filters button {
  font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; padding: 8px 18px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink-2); transition: all .18s;
}
.filters button:hover { border-color: var(--ink); color: var(--ink); }
.filters button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 22px; }
.card {
  grid-column: span 4; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; transition: transform .22s, box-shadow .22s, border-color .22s;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 22px 40px -26px rgba(11, 27, 51, .5); border-color: #c4cddb; }
.card.featured { grid-column: span 6; }
.card[hidden] { display: none; }
.shot { aspect-ratio: 1.9 / 1; overflow: hidden; background: #e9edf3; border-bottom: 1px solid var(--line); }
.shot img { width: 100%; height: 100%; object-fit: cover; object-position: top center; transition: transform .5s; }
.card:hover .shot img { transform: scale(1.035); }
.card-body { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.tags { font-family: var(--font-mono); font-size: .76rem; color: var(--cobalt); letter-spacing: .02em; margin: 0; }
.card h3 { font-family: var(--font-display); font-size: 1.32rem; letter-spacing: -.015em; line-height: 1.2; margin: 0; }
.card p.desc { margin: 0; color: var(--ink-2); font-size: .98rem; line-height: 1.55; }
.links { margin-top: auto; padding-top: 10px; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.links a { font-weight: 600; font-size: .92rem; text-decoration: none; color: var(--ink); border-bottom: 2px solid var(--cobalt-soft); padding-bottom: 1px; }
.links a:hover { border-bottom-color: var(--cobalt); color: var(--cobalt); }

/* AI */
.ai { background: var(--ink); color: #e6ecf7; }
.ai h2 { color: #fff; }
.ai .section-head p, .ai .eyebrow { color: #9fb1cf; }
.ai-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 36px; margin-bottom: 40px; }
.ai-grid h3 { font-family: var(--font-display); font-size: 1.25rem; margin: 0 0 10px; color: #fff; letter-spacing: -.01em; }
.ai-grid p { margin: 0; color: #b9c6dd; font-size: 1rem; }
.ai-grid code { font-family: var(--font-mono); font-size: .88em; background: rgba(255, 255, 255, .09); padding: 1px 6px; border-radius: 5px; color: #dfe8ff; }
.ai-grid a { color: #fff; text-decoration-color: #5b78f0; text-underline-offset: 3px; }
.ai .btn { color: #fff; border-color: #fff; }
.ai .btn:hover { background: #fff; color: var(--ink); }
.ai .note { color: #9fb1cf; margin: 0 0 22px; max-width: 40em; }

/* Stack */
.stack { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border-top: 1px solid var(--line); }
.stack div { padding: 26px 24px 8px 0; }
.stack h3 { font-family: var(--font-mono); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 0 0 12px; font-weight: 500; }
.stack ul { list-style: none; padding: 0; margin: 0; }
.stack li { padding: 5px 0; font-weight: 500; }

/* Courses */
.certs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.cert { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 0; }
.cert img { width: 100%; aspect-ratio: 1.38 / 1; object-fit: contain; background: #fff; border-bottom: 1px solid var(--line); }
.cert figcaption { padding: 14px 18px 18px; }
.cert strong { display: block; font-family: var(--font-display); font-size: 1.05rem; line-height: 1.25; margin-bottom: 4px; }
.cert span { color: var(--ink-2); font-size: .9rem; }

/* About */
.about .wrap { display: grid; grid-template-columns: 220px 1fr; gap: clamp(28px, 5vw, 64px); align-items: start; }
.avatar { width: 220px; aspect-ratio: 1; border-radius: 22px; object-fit: cover; border: 1px solid var(--line); }
.about p { color: var(--ink-2); margin: 0 0 14px; max-width: 38em; }
.about p strong { color: var(--ink); }

/* Contact */
.contact { border-top: 1px solid var(--line); }
.mail { font-family: var(--font-display); font-weight: 700; letter-spacing: -.02em; font-size: clamp(1.5rem, 4.2vw, 3rem); text-decoration: none; border-bottom: 3px solid var(--cobalt); word-break: break-all; }
.mail:hover { color: var(--cobalt); }
.contact-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
footer { padding: 28px 0 40px; color: var(--ink-2); font-size: .9rem; border-top: 1px solid var(--line); }

/* Reveal */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .6s ease, transform .6s ease; }
.reveal.in { opacity: 1; transform: none; }

/* Digital Twin chat */
.dt-toggle {
  position: fixed; right: 20px; bottom: 20px; z-index: 150; width: 56px; height: 56px; border-radius: 50%;
  border: none; background: var(--cobalt); color: #fff; display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 10px 24px -8px rgba(35, 71, 232, .7); transition: transform .2s, background .2s;
}
.dt-toggle:hover { transform: scale(1.06); background: #1a39c0; }
.dt-toggle svg { width: 24px; height: 24px; }
.dt-toggle .ic-close { display: none; }
.dt-toggle.dt-open .ic-chat { display: none; }
.dt-toggle.dt-open .ic-close { display: block; }
.dt-panel {
  position: fixed; right: 20px; bottom: 90px; z-index: 150; width: 350px; max-width: calc(100vw - 40px);
  height: 520px; max-height: calc(100dvh - 120px); padding: 0; background: var(--card); border-radius: 16px; border: 1px solid var(--line);
  box-shadow: 0 30px 60px -20px rgba(11, 27, 51, .5); display: none; flex-direction: column; overflow: hidden;
}
.dt-panel.dt-open { display: flex; }
.dt-header { background: var(--ink); color: #fff; padding: 10px 14px; gap: 10px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.dt-header strong { font-family: var(--font-display); font-size: .95rem; line-height: 1.2; }
.dt-header span { display: block; font-size: .72rem; opacity: .75; }
.dt-close { background: transparent; border: none; color: #fff; cursor: pointer; padding: 4px; line-height: 0; opacity: .85; }
.dt-close:hover { opacity: 1; }
.dt-close svg { width: 20px; height: 20px; }
.dt-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--paper); }
.dt-msg { max-width: 86%; padding: 9px 13px; border-radius: 14px; font-size: .92rem; line-height: 1.45; word-wrap: break-word; }
.dt-msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.dt-msg.user { align-self: flex-end; background: var(--cobalt); color: #fff; border-bottom-right-radius: 4px; }
.dt-msg.error { align-self: flex-start; background: #fdecea; color: #7a1f1f; border: 1px solid #f3c2bd; }
.dt-typing { align-self: flex-start; display: flex; gap: 4px; padding: 10px 12px; }
.dt-typing span { width: 6px; height: 6px; border-radius: 50%; background: #8a98ad; animation: dtBlink 1.2s infinite ease-in-out; }
.dt-typing span:nth-child(2) { animation-delay: .2s; }
.dt-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes dtBlink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.dt-form { display: flex; gap: 8px; padding: 8px 10px 6px; border-top: 1px solid var(--line); background: var(--card); flex-shrink: 0; }
.dt-contact { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; padding: 0 10px 8px; background: var(--card); font-size: .74rem; color: var(--ink-2); flex-shrink: 0; }
.dt-contact a { color: var(--cobalt); font-weight: 600; text-decoration: none; }
.dt-contact a:hover { text-decoration: underline; }
.dt-input { flex: 1; min-width: 0; border: 1.5px solid var(--line); border-radius: 22px; padding: 9px 15px; font: inherit; font-size: 16px; background: var(--paper); }
.dt-input:focus { outline: none; border-color: var(--cobalt); }
.dt-send { width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%; border: none; background: var(--cobalt); color: #fff; cursor: pointer; display: grid; place-items: center; }
.dt-send svg { width: 18px; height: 18px; }
.dt-send:disabled { opacity: .5; cursor: not-allowed; }

/* Responsive */
@media (max-width: 960px) {
  .hero .wrap { grid-template-columns: 1fr; }
  .card, .card.featured { grid-column: span 6; }
  .ai-grid { grid-template-columns: 1fr; gap: 26px; }
  .stack { grid-template-columns: repeat(2, 1fr); }
  .certs { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 960px) {
  html { scroll-padding-top: 80px; }
  .site-header .btn { display: none; }
  .site-header .wrap { flex-wrap: nowrap; }
  .menu-btn { display: inline-flex; }
  .nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; gap: 0; background: var(--paper); border-bottom: 1px solid var(--line); padding: 8px 20px 16px; box-shadow: 0 14px 30px rgba(11,27,51,.10); }
  .menu-open .nav { display: flex; }
  .nav a { padding: 14px 0; font-size: 1.05rem; border-bottom: 1px solid var(--line); }
  .nav a:last-child { border-bottom: 0; }
  .nav .nav-cv { display: block; margin-top: 12px; text-align: center; background: var(--cobalt); color: #fff; border-radius: 10px; padding: 12px; border: 0; }
}
@media (max-width: 720px) {
  html { scroll-padding-top: 80px; }
  .panel { font-size: .76rem; }
  .panel pre { padding: 16px 16px 20px; }
  .card, .card.featured { grid-column: 1 / -1; }
  .about .wrap { grid-template-columns: 1fr; }
  .avatar { width: 140px; }
  .certs { grid-template-columns: 1fr; }
  .stack { grid-template-columns: 1fr 1fr; }
  .dt-panel { left: 12px; right: 12px; width: auto; max-width: none; bottom: 88px; height: calc(100dvh - 170px); max-height: 600px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .panel .ln { opacity: 1; transform: none; animation: none; }
  .card, .card:hover, .shot img, .dt-toggle { transition: none; transform: none; }
}

/* Overflow safety: grid/flex children may shrink, long words may wrap */
.hero .wrap > *, .about .wrap > *, .grid > *, .stack > *, .certs > *, .ai-grid > * { min-width: 0; }
h1, h2, h3, p, li, a { overflow-wrap: anywhere; }
img, svg, video { max-width: 100%; }
