/* ============================================================
   IMPACT Learning Hub — image layer
   ------------------------------------------------------------
   LOAD THIS LAST. It owns every .photo-slot on the site and
   deliberately overrides the slot styling in home.css.

   Stacking inside a slot is positive-only now. The old version
   put the image on z-index:-1, which meant it painted *behind*
   its own container's background and broke the moment any
   parent created a stacking context. Paint order here is just
   DOM order: ::before (fallback panel) sits first, the <img>
   sits above it, captions above that.

   object-fit: cover always crops. --focus (set from
   data-focus) decides what survives the crop: "top" for
   people, "bottom" for benches and equipment, "center" when it
   does not matter. Default is a little above centre, which is
   right far more often than dead centre for photographs of
   people.
   ============================================================ */

.photo-slot{
  --focus: 50% 42%;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 0;
  outline: 0;
  border-radius: var(--radius);
  background: var(--paper-deep);
  aspect-ratio: 4 / 3;
}

/* The old build printed the expected file path inside the slot.
   Useful during design, wrong in production. */
.photo-slot > span{ display: none; }

/* ---------- the image ---------- */
.photo-slot > img.slot-img{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--focus);
  display: block;
  opacity: 0;
  transition: opacity .45s var(--ease), transform .8s var(--ease);
}
.photo-slot.has-img > img.slot-img{ opacity: 1; }

/* contain mode — for logos and certificates, where cropping
   would cut the subject */
.photo-slot.fit-contain{ background: var(--surface); }
.photo-slot.fit-contain > img.slot-img{ object-fit: contain; }

/* ---------- fallback panel ----------
   Shown whenever a slot has no image. A flat warm panel with
   the four-square mark, at full strength and properly sized.
   Reads as "image coming" rather than "broken". */
.photo-slot::before{
  content: "";
  position: absolute;
  inset: 0;
  /* A grid of identical grey panels is what a catalogue looks
     like before the thumbnails are uploaded. --tint washes each
     one with its own division colour so the row still reads as
     five different subjects. Browsers without color-mix keep
     the flat fallback on the line above. */
  background-color: var(--paper-deep);
  background-color: color-mix(in srgb, var(--tint, transparent) 9%, var(--paper-deep));
  background-image:
    linear-gradient(var(--div-data), var(--div-data)),
    linear-gradient(var(--div-tech), var(--div-tech)),
    linear-gradient(var(--div-lab),  var(--div-lab)),
    linear-gradient(var(--div-agri), var(--div-agri));
  background-size: 20px 20px;
  background-repeat: no-repeat;
  background-position:
    calc(50% - 11px) calc(50% - 11px),
    calc(50% + 11px) calc(50% - 11px),
    calc(50% - 11px) calc(50% + 11px),
    calc(50% + 11px) calc(50% + 11px);
  box-shadow: inset 0 0 0 1px var(--stone);
  opacity: 1;
  transition: opacity .3s var(--ease);
}
.photo-slot.has-img::before{ opacity: 0; }

/* ---------- aspect ratios by context ----------
   Each slot type gets one ratio and keeps it, so a grid of
   cards never goes ragged because one upload was portrait. */
.course-card .photo-slot{ aspect-ratio: 16 / 10; }
.portfolio-card .photo-slot{ aspect-ratio: 4 / 3; }
.division-card .photo-slot{ aspect-ratio: 3 / 2; }
/* The instructors photograph is portrait (960x1280). Forcing it
   into a 4/3 landscape slot threw away nearly half the frame,
   which is why this block never looked right. */
.banner .photo-slot{ aspect-ratio: 4 / 5; }
@media (max-width: 980px){
  .banner .photo-slot{ aspect-ratio: 1 / 1; }
}
.photo-slot.ratio-wide{ aspect-ratio: 16 / 9; }
.photo-slot.ratio-square{ aspect-ratio: 1 / 1; }
.photo-slot.ratio-portrait{ aspect-ratio: 3 / 4; }
.photo-slot.ratio-banner{ aspect-ratio: 21 / 9; }

/* People are photographed head-up: default to keeping the top. */
.team-photo .photo-slot,
.photo-slot.is-person{ --focus: 50% 28%; }

/* Avatars */
.photo-slot.avatar{
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  width: 96px;
  flex: none;
}
.photo-slot.avatar::before{
  background-size: 13px 13px;
  background-position:
    calc(50% - 7px) calc(50% - 7px),
    calc(50% + 7px) calc(50% - 7px),
    calc(50% - 7px) calc(50% + 7px),
    calc(50% + 7px) calc(50% + 7px);
}

/* Card images sit flush against the card edge */
.course-card .photo-slot,
.portfolio-card .photo-slot{ border-radius: var(--radius) var(--radius) 0 0; }

/* Compact horizontal course card on phones (layout in home.css).
   aspect-ratio has to be cleared here or the slot sizes itself
   from its own height and overflows the 108px grid column. */
@media (max-width: 560px){
  .course-card .photo-slot{
    aspect-ratio: auto;
    width: 100%;
    height: 100%;
    min-height: 118px;
    border-radius: var(--radius) 0 0 var(--radius);
  }
}

/* Slow, small zoom on hover. Deliberately subtle — a 6% jump
   reads as a glitch on a trackpad. */
@media (hover: hover){
  .course-card:hover .photo-slot > img.slot-img,
  .portfolio-card:hover .photo-slot > img.slot-img{ transform: scale(1.03); }
}

/* ---------- hero ----------
   Three layers: image, scrim, content. All positive z-index. */
.hero-full{ position: relative; overflow: hidden; isolation: isolate; }
.hero-full .hero-bg.photo-slot{
  position: absolute;
  inset: 0;
  z-index: 0;
  aspect-ratio: auto;
  border-radius: 0;
  background: var(--ink);
  --focus: 50% 45%;
}
/* No four-square mark behind the hero — the gradient scrim
   handles an empty hero on its own. */
.hero-full .hero-bg.photo-slot::before{
  background: linear-gradient(135deg, #0F1B3C 0%, #16306E 55%, #103E9E 100%);
  box-shadow: none;
}
.hero-full .hero-bg.photo-slot.has-img::before{ opacity: 0; }
.hero-full .hero-in{ position: relative; z-index: 2; }

/* ---------- course page preview screen ---------- */
.course-screen{ position: relative; }
.course-screen.has-img::after{
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 40%, rgba(15,27,60,.62));
  pointer-events: none;
}
.course-screen video{ position: relative; z-index: 3; width: 100%; height: 100%; object-fit: contain; background: #000; }

/* ---------- caption ---------- */
.photo-caption{
  margin-top: 8px;
  font-size: var(--step--1);
  color: var(--ink-faint);
  max-width: 54ch;
}

/* ---------- zoom ---------- */
.portfolio-card .photo-slot.has-img,
.team-photo img,
.zoomable{ cursor: zoom-in; }

.lightbox{
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(8,13,30,.94);
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 48px);
  cursor: zoom-out;
  animation: lbIn .2s var(--ease);
  backdrop-filter: blur(2px);
}
.lightbox img{
  max-width: 100%;
  max-height: 100%;
  width: auto;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--lift-3);
  cursor: default;
  animation: lbImg .28s var(--ease);
}
.lightbox button{
  position: absolute;
  top: clamp(10px, 2vw, 20px);
  right: clamp(10px, 2vw, 20px);
  width: 46px; height: 46px;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 26px; line-height: 1;
  cursor: pointer;
  transition: background-color .15s var(--ease);
}
.lightbox button:hover{ background: rgba(255,255,255,.22); }

@keyframes lbIn{ from{ opacity: 0; } }
@keyframes lbImg{ from{ opacity: 0; transform: scale(.97); } }

/* ---------- logo override image ---------- */
.logo-img{ height: 44px; width: auto; display: block; flex: none; }
@media (max-width: 560px){ .logo-img{ height: 36px; } }

@media (prefers-reduced-motion: reduce){
  .photo-slot > img.slot-img{ transition: opacity .01ms; transform: none !important; }
  .lightbox, .lightbox img{ animation: none; }
}
