/* ============================================================================
   musaahmed.uk — shared site layer
   Loaded by every page. Owns: design tokens, black-first preloader,
   the desktop-only panel glide, mobile scroll normalisation, the social
   rail, the LinkedIn blue tile, and the per-page chat widget.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens -- */
:root, html.dark {
  --bg-base: #07080a;
  --bg-surface: #0e1017;
  --bg-card: rgba(14, 16, 23, 0.88);
  --bg-card-hover: rgba(22, 25, 36, 0.96);
  --border-card: rgba(255, 255, 255, 0.14);
  --border-card-hover: rgba(239, 68, 68, 0.55);
  --metallic-rim: inset 0 1px 0 0 rgba(255, 255, 255, 0.25), inset 0 0 16px 0 rgba(255, 255, 255, 0.03);
  --metallic-bevel: inset 0 1.5px 0 0 rgba(255, 255, 255, 0.45), inset 0 -1.5px 0 0 rgba(0, 0, 0, 0.6);
  --accent-primary: #dc2626;
  --accent-glow: rgba(220, 38, 38, 0.35);
  --accent-gradient: linear-gradient(135deg, #f87171 0%, #dc2626 50%, #991b1b 100%);
  --text-heading: #ffffff;
  --text-body: #cbd5e1;
  --text-muted: #94a3b8;
  --nav-bg: rgba(7, 8, 10, 0.94);
  --nav-border: rgba(255, 255, 255, 0.12);
  --sub-card-bg: rgba(255, 255, 255, 0.04);
  --sub-card-border: rgba(255, 255, 255, 0.09);
  --pill-bg: rgba(220, 38, 38, 0.18);
  --pill-border: rgba(239, 68, 68, 0.8);
  --pill-text: #ffffff;
  --chat-bg: rgba(13, 14, 20, 0.98);
  --chat-header-bg: rgba(7, 8, 10, 0.85);
  --chat-msg-bg: rgba(255, 255, 255, 0.08);
  --chat-msg-text: #e2e8f0;
  --chat-opt-bg: rgba(220, 38, 38, 0.09);
  --chat-opt-border: rgba(220, 38, 38, 0.32);
  --chat-opt-text: #fca5a5;
  --chat-opt-hover: rgba(220, 38, 38, 0.22);
  --chat-back-bg: rgba(255, 255, 255, 0.05);
  --chat-back-border: rgba(255, 255, 255, 0.12);
  --chat-back-text: #94a3b8;
  --li-blue: #0a66c2;
  --li-blue-soft: rgba(10, 102, 194, 0.14);
  --ai-blue: #2d7cff;
}

html.light {
  --bg-base: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.94);
  --bg-card-hover: rgba(255, 255, 255, 1);
  --border-card: rgba(15, 23, 42, 0.12);
  --border-card-hover: rgba(220, 38, 38, 0.55);
  --metallic-rim: inset 0 1px 0 0 rgba(255, 255, 255, 0.9), inset 0 0 16px 0 rgba(0, 0, 0, 0.03);
  --metallic-bevel: inset 0 1.5px 0 0 rgba(255, 255, 255, 0.9), inset 0 -1.5px 0 0 rgba(15, 23, 42, 0.15);
  --accent-primary: #dc2626;
  --accent-glow: rgba(220, 38, 38, 0.20);
  --accent-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  --text-heading: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --nav-bg: rgba(255, 255, 255, 0.96);
  --nav-border: rgba(15, 23, 42, 0.10);
  --sub-card-bg: #f8fafc;
  --sub-card-border: #e2e8f0;
  --pill-bg: #fee2e2;
  --pill-border: #ef4444;
  --pill-text: #991b1b;
  --chat-bg: rgba(255, 255, 255, 0.98);
  --chat-header-bg: rgba(248, 250, 252, 0.95);
  --chat-msg-bg: #f1f5f9;
  --chat-msg-text: #1e293b;
  --chat-opt-bg: #fef2f2;
  --chat-opt-border: #fecaca;
  --chat-opt-text: #b91c1c;
  --chat-opt-hover: #fee2e2;
  --chat-back-bg: #f8fafc;
  --chat-back-border: #e2e8f0;
  --chat-back-text: #475569;
  --li-blue: #0a66c2;
  --li-blue-soft: rgba(10, 102, 194, 0.1);
  --ai-blue: #1d4ed8;
}

/* Chat accent is page-scoped: --chat-accent / --chat-accent-rgb get set inline. */
:root {
  --chat-accent: #dc2626;
  --chat-accent-rgb: 220, 38, 38;
  --header-height: 3.75rem;
}

/* --------------------------------------------------------- base reset ---- */
*, *::before, *::after { box-sizing: border-box; }

html {
  background-color: var(--bg-base);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-base);
  color: var(--text-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar, html::-webkit-scrollbar, body::-webkit-scrollbar,
#chatMessages::-webkit-scrollbar, #chatScroll::-webkit-scrollbar {
  display: none !important;
  width: 0 !important; height: 0 !important; background: transparent !important;
}
* { scrollbar-width: none !important; -ms-overflow-style: none !important; }

.font-mono { font-family: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Generic focus ring — keyboard only, never on mouse click. */
:where(a, button, input, textarea, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ==========================================================================
   BLACK-FIRST
   Pages that ship a brand intro set <html class="has-intro">. The document
   stays hidden behind an opaque black curtain until the intro hands off, so
   the page content can never flash before the animation plays.
   ========================================================================== */
html.has-intro body { visibility: hidden; }

/* `visibility` is inherited, so the intro and its curtain must opt back in
   explicitly or the page would sit permanently black. */
html.has-intro #introCurtain,
html.has-intro #brandSplashIntro { visibility: visible; }

#introCurtain {
  position: fixed;
  inset: 0;
  z-index: 9990;
  background: #000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.45s ease, visibility 0s linear 0.45s;
}
html.has-intro #introCurtain { opacity: 1; visibility: visible; transition-delay: 0s; }
html.has-intro.intro-handoff #introCurtain { opacity: 0; visibility: hidden; transition-delay: 0s; }
html.has-intro.intro-handoff body { visibility: visible; }

/* Safety net: if an intro script never fires, reveal anyway. */
html.has-intro.intro-timeout #introCurtain { opacity: 0; visibility: hidden; }
html.has-intro.intro-timeout body { visibility: visible; }

/* ==========================================================================
   PANEL DECK  (laptops / desktop / horizontal screens)
   Each panel is exactly one viewport and one wheel tick glides one panel.
   ========================================================================== */
html.deck, body.deck {
  height: 100%;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  overscroll-behavior: none;
}

.panel-section {
  scroll-snap-align: start;
  scroll-snap-stop: always;
  box-sizing: border-box;
  position: relative;
  width: 100%;
  padding-top: var(--panel-pad-top, calc(var(--header-height) + 0.5rem));
  padding-bottom: 0.75rem;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tile-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-top: auto;
  margin-bottom: auto;
  transform-origin: center center;
}

/* Laptops / desktop: each panel is exactly one viewport. Tile fitting is done
   in script (site.js → fitTiles) with a transform, because `zoom` changes
   layout size and cannot shrink content that overflows its own box. */
@media (min-width: 769px) and (pointer: fine) {
  html.has-intro .panel-section { height: 100dvh; min-height: 100dvh; max-height: 100dvh; }
  html.has-intro .tile-inner { max-height: none; }
}

/* A phone-sized window on a desktop gets the same treatment as a real phone. */
@media (max-width: 768px) and (pointer: fine) {
  .tile-inner { max-height: none; }
}

/* ==========================================================================
   PHONE / TOUCH  —  normal document scrolling, no snap, no zoom shrink
   Panels become ordinary stacked sections. Nothing is scaled to fit a
   viewport, so type renders at its real size and long panels simply scroll.
   ========================================================================== */
@media (max-width: 768px), (pointer: coarse) {
  :root { --header-height: 4.25rem; }

  html.deck, body.deck {
    height: auto;
    scroll-snap-type: none;
    scroll-behavior: auto;
    overscroll-behavior-y: auto;
  }

  .panel-section {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    scroll-snap-align: none;
    scroll-snap-stop: normal;
    padding-top: calc(var(--header-height) + 1.5rem);
    padding-bottom: 2.75rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .tile-inner {
    max-height: none;
    margin-top: 0;
    margin-bottom: 0;
    zoom: 1 !important;
    transform: none !important;
  }
  /* Real breathing room between stacked sections on a phone. */
  .panel-section + .panel-section { border-top: 1px solid var(--border-card); }
}

/* A phone-sized browser window on a desktop should behave like a phone. */
@media (max-width: 768px) and (pointer: fine) {
  html.deck, body.deck { height: auto; scroll-snap-type: none; scroll-behavior: auto; }
  .panel-section { height: auto; min-height: 0; max-height: none; overflow: visible; }
  .tile-inner { max-height: none; zoom: 1 !important; }
}

/* Landscape phone: very short. Never lock to a viewport. */
@media (max-height: 560px) and (max-width: 900px) {
  .panel-section { min-height: 0; height: auto; }
  .tile-inner { zoom: 1 !important; }
}

/* ------------------------------------------------------------ surfaces --- */

/* PanelMotion injects one canvas per panel. It must be taken out of flow —
   left in flow it becomes a full-viewport flex item and shoves the panel's
   real content clean off the screen. */
.panel-motion-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.7;
  mix-blend-mode: screen;
}
.panel-section > .tile-inner { position: relative; z-index: 1; }

.glass-panel {
  background-color: var(--bg-card);
  background-image: linear-gradient(145deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.01) 40%, rgba(0,0,0,0.35) 100%);
  border: 1px solid var(--border-card);
  box-shadow: var(--metallic-rim), 0 14px 36px -4px rgba(0,0,0,0.7);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  transition: border-color 0.3s cubic-bezier(0.16,1,0.3,1), box-shadow 0.3s cubic-bezier(0.16,1,0.3,1);
}
html.light .glass-panel {
  background-image: linear-gradient(145deg, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.6) 40%, rgba(15,23,42,0.05) 100%);
}
.glass-panel:hover { border-color: var(--border-card-hover); }

.accent-btn {
  background: var(--accent-gradient);
  box-shadow: var(--metallic-bevel), 0 4px 22px var(--accent-glow);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.accent-btn:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.55); }

.accent-pill {
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  color: var(--pill-text);
  box-shadow: inset 0 1px 0 0 rgba(255,255,255,0.35), 0 4px 16px rgba(0,0,0,0.5);
}

.metallic-heading {
  background: linear-gradient(180deg, #FFFFFF 0%, #E2E8F0 50%, #94A3B8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
html.light .metallic-heading {
  background: linear-gradient(180deg, #0F172A 0%, #1E293B 55%, #475569 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-link { color: var(--text-muted); transition: color 0.2s ease; }
.nav-link:hover, .nav-link.active { color: var(--text-heading); }
.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--accent-primary);
  box-shadow: 0 0 10px var(--accent-primary);
}
.nav-link { position: relative; }

.social-icon-btn { color: var(--text-muted); transition: color 0.2s ease, background-color 0.2s ease; }
.social-icon-btn:hover { color: var(--text-heading); background-color: rgba(255,255,255,0.07); }
.social-icon-btn.li:hover { color: var(--li-blue); background-color: var(--li-blue-soft); }

/* ==========================================================================
   LINKEDIN TILE  —  always brand blue, everywhere it appears.
   ========================================================================== */
.tile-linkedin {
  background-color: var(--li-blue) !important;
  background-image: linear-gradient(140deg, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 55%) !important;
  border: 1px solid rgba(255,255,255,0.35) !important;
  color: #fff !important;
  box-shadow: inset 0 1px 0 0 rgba(255,255,255,0.4), 0 10px 28px -8px rgba(10,102,194,0.75) !important;
}
.tile-linkedin:hover {
  background-image: linear-gradient(140deg, rgba(255,255,255,0.32) 0%, rgba(255,255,255,0) 60%) !important;
  box-shadow: inset 0 1px 0 0 rgba(255,255,255,0.55), 0 14px 34px -8px rgba(10,102,194,0.9) !important;
}
html.light .tile-linkedin { color: #fff !important; }
.tile-linkedin .tile-kicker { color: rgba(255,255,255,0.82) !important; }
.tile-linkedin .tile-body   { color: rgba(255,255,255,0.86) !important; }
.tile-linkedin .tile-title  { color: #fff !important; }
.tile-linkedin:hover .tile-title { color: #fff !important; }

/* Generic channel tile bits (email / github / book-a-call) */
.tile-kicker { font-family: 'Geist Mono', monospace; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.tile-title { font-weight: 700; color: var(--text-heading); }
.tile-body { color: var(--text-muted); font-size: 12px; margin-top: 4px; line-height: 1.5; }
.tile-linkedin svg { fill: #fff; }

/* ==========================================================================
   CHAT WIDGET  —  mounted on Home, Academy and Intelligence (never Contact)
   ========================================================================== */
.aa-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, sans-serif;
  /* The closed window still occupies layout space, so this container's box is
     nearly full-screen on a phone. Without this it swallows every tap on the
     page underneath. Only the launcher and an open window take pointers. */
  pointer-events: none;
}
.aa-chat__launch { pointer-events: auto; }
.aa-chat__window.is-open { pointer-events: auto; }
.aa-chat__window {
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100dvh - 120px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-card);
  border-radius: 18px;
  background: var(--chat-bg);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  box-shadow: 0 24px 60px -18px rgba(0,0,0,0.85);
  transform-origin: bottom right;
  transition: opacity 0.3s cubic-bezier(0.16,1,0.3,1), transform 0.3s cubic-bezier(0.16,1,0.3,1), visibility 0s linear 0.3s;
  visibility: hidden;
  opacity: 0;
  transform: scale(0.94) translateY(14px);
}
.aa-chat__window.is-open { visibility: visible; opacity: 1; transform: none; transition-delay: 0s; }

.aa-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-card);
  background: var(--chat-header-bg);
  flex: 0 0 auto;
}
.aa-chat__id { display: flex; align-items: center; gap: 9px; min-width: 0; }
.aa-chat__dot { width: 8px; height: 8px; border-radius: 50%; background: #10b981; flex: 0 0 auto; animation: aa-pulse 2.4s ease-in-out infinite; }
@keyframes aa-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.aa-chat__title {
  font-family: 'Geist Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.aa-chat__close {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 5px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.aa-chat__close:hover { color: var(--text-heading); background: rgba(255,255,255,0.08); }
.aa-chat__close svg { width: 18px; height: 18px; }

.aa-chat__body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
}
.aa-chat__msg {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border-card);
  background: var(--chat-msg-bg);
  color: var(--chat-msg-text);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-line;
}
.aa-chat__opts { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }
.aa-chat__opt {
  text-align: left;
  width: 100%;
  font: 500 13px/1.4 'Geist', sans-serif;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(var(--chat-accent-rgb), 0.32);
  background: rgba(var(--chat-accent-rgb), 0.09);
  color: var(--chat-accent);
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.aa-chat__opt:hover { background: rgba(var(--chat-accent-rgb), 0.2); transform: translateX(2px); }
.aa-chat__opt span:last-child { opacity: 0.55; flex: 0 0 auto; }
.aa-chat__back {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-card);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.aa-chat__back button {
  text-align: left;
  font: 500 12px 'Geist', sans-serif;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--chat-back-border);
  background: var(--chat-back-bg);
  color: var(--chat-back-text);
}
.aa-chat__back button:hover { color: var(--text-heading); }
.aa-chat__foot {
  flex: 0 0 auto;
  padding: 10px 14px;
  text-align: center;
  border-top: 1px solid var(--border-card);
  background: var(--chat-header-bg);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.aa-chat__foot a { color: var(--chat-accent); text-decoration: none; }
.aa-chat__foot a:hover { text-decoration: underline; }

.aa-chat__launch {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.22);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--chat-accent) 0%, rgba(var(--chat-accent-rgb), 1) 100%);
  box-shadow: 0 12px 30px -8px rgba(var(--chat-accent-rgb), 0.85), inset 0 1px 0 0 rgba(255,255,255,0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.aa-chat__launch:hover { transform: translateY(-2px) scale(1.04); }
.aa-chat__launch svg { width: 25px; height: 25px; fill: currentColor; }

@media (max-width: 768px) {
  .aa-chat { right: 14px; bottom: 14px; }
  .aa-chat__window { width: calc(100vw - 28px); max-width: calc(100vw - 28px); height: min(72dvh, 520px); max-height: min(72dvh, 520px); border-radius: 16px; }
  .aa-chat__launch { width: 52px; height: 52px; }
  .aa-chat__launch svg { width: 22px; height: 22px; }
}

/* Keep the launch button clear of the notch on notched phones. */
@supports (padding: max(0px)) {
  .aa-chat { bottom: max(20px, env(safe-area-inset-bottom)); }
  @media (max-width: 768px) { .aa-chat { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); } }
}

/* ==========================================================================
   MISC PAGE FURNITURE
   ========================================================================== */

/* Small-caps eyebrow used across panels */
.eyebrow {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-primary);
}
@media (min-width: 640px) { .eyebrow { font-size: 12px; } }

/* Brand mark plate — used for the big centred Academy lockup */
.brand-plate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
}

/* Visible only to screen readers */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print — never print the chrome */
@media print {
  .aa-chat, #introCurtain, header, nav, .panel-motion-canvas { display: none !important; }
}
