/* =========================================================================
   Kamal Mehta — Portfolio :: Signature layer
   -------------------------------------------------------------------------
   Everything that makes this site look like nobody else's: the live
   machine-learning canvas, the inference-lock hover, the co-pilot avatar,
   and the autoplay video treatment.

   Kept in its own file on purpose — if any of it ever feels like too much,
   removing one <link> tag and two <script> tags returns the site to the
   clean, conventional version underneath. Nothing here is load-bearing.
   ========================================================================= */

/* =======================================================================
   1. ML SCENE CANVAS (hero) — see js/mlscene.js
   ======================================================================= */
#mlCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  pointer-events: none;   /* never intercepts a click */
}

/* Make sure hero copy always sits above the canvas. */
.hero-inner { position: relative; z-index: 3; }
.scroll-cue { z-index: 3; }

/* Telemetry strip — a small monospace readout that sells the "live system"
   idea without adding visual weight. */
.hero-telemetry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  margin: 26px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.hero-telemetry .tel-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.hero-telemetry .tel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(94, 230, 160, 0.55);
  animation: telPulse 2.4s ease-out infinite;
}
@keyframes telPulse {
  0%   { box-shadow: 0 0 0 0 rgba(94, 230, 160, 0.5); }
  70%  { box-shadow: 0 0 0 7px rgba(94, 230, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(94, 230, 160, 0); }
}
.hero-telemetry .tel-sep { color: var(--border); }

/* =======================================================================
   2. DETECTION LOCK — corner brackets that snap around whatever you hover
   ======================================================================= */
.det-lock {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 880;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.16s ease;
  will-change: transform;
}
.det-lock.on { opacity: 1; }

.det-lock .dl-c {
  position: absolute;
  width: 13px;
  height: 13px;
  border: 1.6px solid var(--accent);
  transition: inset 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.det-lock .dl-tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 4px 0 0 0; }
.det-lock .dl-tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 4px 0 0; }
.det-lock .dl-bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 4px; }
.det-lock .dl-br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 4px 0; }

.det-lock.on .dl-c { animation: dlSnap 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes dlSnap {
  from { opacity: 0; transform: scale(1.9); }
  to   { opacity: 1; transform: scale(1); }
}

.det-lock .dl-label {
  position: absolute;
  top: -16px;
  left: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(67, 217, 217, 0.13);
  border: 1px solid rgba(67, 217, 217, 0.22);
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

/* =======================================================================
   3. CO-PILOT AVATAR
   ======================================================================= */
#copilot {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 950;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;              /* container is transparent to clicks */
  opacity: 0;
  transform: translateY(24px) scale(0.9);
  transition: opacity 0.5s ease, transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}
#copilot.ready { opacity: 1; transform: none; }

/* ---- speech bubble ---- */
.cp-bubble {
  position: relative;
  max-width: 292px;
  padding: 13px 16px;
  background: linear-gradient(160deg, rgba(24, 32, 54, 0.97), rgba(18, 24, 40, 0.97));
  border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 18px 44px -16px rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 0.87rem;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
  /*
    The bubble stays transparent to clicks even while visible. It floats over
    real page content near the bottom-right corner, and a speech bubble that
    swallows a click meant for a project title is a genuinely annoying bug --
    the visitor just sees nothing happen. The avatar underneath keeps its own
    click target, and the bubble hides itself on a timer regardless.
  */
  pointer-events: none;
  min-height: 1.5em;
}
.cp-bubble.show {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.cp-bubble::after {
  content: "";
  position: absolute;
  right: 26px;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: rgba(20, 27, 45, 0.97);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(45deg);
}
.cp-bubble-text::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 2px;
  vertical-align: -0.14em;
  background: var(--accent);
  animation: cpCaret 1s steps(2) infinite;
}
@keyframes cpCaret { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* ---- the avatar itself ---- */
.cp-avatar {
  position: relative;
  width: 104px;
  height: 108px;
  pointer-events: auto;
  cursor: pointer;
  filter: drop-shadow(0 14px 26px rgba(0, 0, 0, 0.55));
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.cp-avatar:hover { transform: translateY(-4px) scale(1.04); }
.cp-avatar:active { transform: translateY(-1px) scale(0.99); }
.cp-svg { width: 100%; height: 100%; overflow: visible; animation: cpBob 3.8s ease-in-out infinite; }
@keyframes cpBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4.5px); }
}

/* soft pulse ring behind the avatar so the eye finds it */
.cp-pulse {
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 62px;
  height: 62px;
  margin-left: -31px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(67, 217, 217, 0.22) 0%, transparent 68%);
  animation: cpPulse 3.4s ease-in-out infinite;
  z-index: -1;
}
@keyframes cpPulse {
  0%, 100% { transform: scale(1); opacity: 0.55; }
  50%      { transform: scale(1.28); opacity: 0.95; }
}

/* ---- SVG part colours ---- */
.cp-skin   { fill: #dda57d; }
.cp-hair   { fill: #241c1a; }
.cp-torso  { fill: url(#cpShirt); }
.cp-collar { fill: url(#cpGlow); opacity: 0.9; }
.cp-glow   { fill: rgba(67, 217, 217, 0.16); }
.cp-sleeve { stroke: #223052; stroke-width: 9.5; stroke-linecap: round; fill: none; }
.cp-hand   { fill: #dda57d; }
.cp-sclera { fill: #ffffff; }
.cp-pupil  { fill: #1c1512; }
.cp-spark  { fill: #ffffff; }
.cp-brow   { stroke: #241c1a; stroke-width: 2.6; fill: none; stroke-linecap: round; }
.cp-mouth  { stroke: #9a4f3c; stroke-width: 2.5; fill: none; stroke-linecap: round; }
.cp-glasses rect { fill: rgba(200, 235, 255, 0.09); stroke: #0f1524; stroke-width: 2.3; }
.cp-glasses path { stroke: #0f1524; stroke-width: 2.3; fill: none; stroke-linecap: round; }
.cp-band   { stroke: #33415f; stroke-width: 4.6; fill: none; stroke-linecap: round; }
.cp-cup    { fill: #33415f; }
.cp-boom   { stroke: #33415f; stroke-width: 2.5; fill: none; stroke-linecap: round; }
.cp-mic    { fill: #43d9d9; }

/* ---- blink ---- */
.cp-eye {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.07s ease;
}
.cp-eye.blinking { transform: scaleY(0.08); }

/* ---- wave ---- */
.cp-arm {
  transform-box: view-box;
  transform-origin: 88px 92px;
}
.cp-arm.waving { animation: cpWave 1.15s ease-in-out; }
@keyframes cpWave {
  0%, 100% { transform: rotate(0deg); }
  14%      { transform: rotate(-18deg); }
  30%      { transform: rotate(10deg); }
  46%      { transform: rotate(-15deg); }
  62%      { transform: rotate(8deg); }
  80%      { transform: rotate(-5deg); }
}

/* ---- dismiss / recall ---- */
.cp-dismiss {
  position: absolute;
  top: 0;
  right: -2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.68rem;
  line-height: 1;
  display: grid;
  place-items: center;
  pointer-events: auto;
  opacity: 0;
  transform: scale(0.7);
  transition: all 0.2s ease;
}
#copilot:hover .cp-dismiss { opacity: 1; transform: none; }
.cp-dismiss:hover { color: var(--text); border-color: var(--accent); background: var(--surface); }

.cp-recall {
  display: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 1.2rem;
  line-height: 1;
  pointer-events: auto;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}
.cp-recall:hover { border-color: var(--accent); transform: scale(1.08); }

#copilot.dismissed .cp-avatar,
#copilot.dismissed .cp-bubble,
#copilot.dismissed .cp-dismiss { display: none; }
#copilot.dismissed .cp-recall { display: grid; place-items: center; }

/* =======================================================================
   4. AUTOPLAY VIDEO
   ======================================================================= */
.project-media video.project-video {
  width: 100%;
  display: block;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #05080f;
}

/*
  Graceful failure. If a clip can't load (bad path, 404, codec the browser
  won't decode) main.js tags it and we get out of the way rather than leaving
  a black rectangle sitting in the middle of a project card. With a poster the
  video element stays and simply shows the still frame plus controls; with no
  poster at all it is hidden entirely and the card falls back to text.
*/
.project-media video.video-fallback {
  aspect-ratio: 16 / 9;
  background: #05080f;
}
.project-media.media-no-video video.video-fallback { display: none; }
.project-media.media-no-video {
  min-height: 132px;
  background: linear-gradient(135deg, rgba(67, 217, 217, 0.08), rgba(124, 140, 255, 0.08));
}

/* "LIVE" pill so visitors register that the tile is really playing */
.video-live-pill {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(5, 8, 15, 0.72);
  border: 1px solid rgba(67, 217, 217, 0.32);
  backdrop-filter: blur(6px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  pointer-events: none;
}
.video-live-pill .lp-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: lpBlink 1.6s ease-in-out infinite;
}
@keyframes lpBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* video inside the project modal */
.modal-video-wrap { position: relative; margin: 0 0 6px; }
.modal-video {
  width: 100%;
  display: block;
  border-radius: 12px;
  background: #000;
  max-height: 68vh;
}
.video-sound-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(67, 217, 217, 0.4);
  background: rgba(5, 8, 15, 0.78);
  backdrop-filter: blur(8px);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  transition: all 0.2s ease;
}
.video-sound-btn:hover { background: rgba(67, 217, 217, 0.16); color: var(--text); }

/* =======================================================================
   5. RESPONSIVE
   ======================================================================= */
@media (max-width: 760px) {
  #copilot { right: 14px; bottom: 14px; gap: 8px; }
  .cp-avatar { width: 74px; height: 78px; }
  .cp-pulse { width: 46px; height: 46px; margin-left: -23px; }
  .cp-bubble { max-width: min(72vw, 260px); font-size: 0.8rem; padding: 11px 13px; }
  /* On touch there's no hover, so the dismiss control is always visible. */
  .cp-dismiss { opacity: 1; transform: none; width: 22px; height: 22px; }
  .hero-telemetry { font-size: 0.62rem; gap: 6px 12px; }
  .hero-telemetry .tel-sep { display: none; }
}

@media (max-width: 480px) {
  .cp-avatar { width: 62px; height: 66px; }
  .cp-bubble { max-width: min(74vw, 220px); }
}

/* =======================================================================
   6. REDUCED MOTION — strip every looping animation, keep the layout.
   ======================================================================= */
@media (prefers-reduced-motion: reduce) {
  .cp-svg,
  .cp-pulse,
  .hero-telemetry .tel-dot,
  .video-live-pill .lp-dot,
  .cp-bubble-text::after,
  .det-lock.on .dl-c {
    animation: none !important;
  }
  .cp-bubble-text::after { display: none; }
  #copilot { transition: opacity 0.2s ease; transform: none; }
  .cp-avatar:hover { transform: none; }
}
