/* =========================================================================
   Oleaf — UI polish layer
   -------------------------------------------------------------------------
   A progressive-enhancement stylesheet loaded *after* the page's own CSS.
   It only refines what already exists — micro-interactions, focus states,
   loading/hover feedback and typographic finish — using the site's own
   design tokens (--ink / --olive / --orange / --line). Nothing here changes
   layout, so it layers cleanly over both index.html's inline styles and the
   shared pages.css. Everything degrades gracefully and honours
   prefers-reduced-motion.
   ========================================================================= */

:where(:root) {
  --focus-ring: #ff8500;
  --lift-shadow: 0 18px 44px rgba(5, 5, 5, 0.14);
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* --- Text selection + caret in brand colour ------------------------------ */
::selection {
  background: rgba(255, 133, 0, 0.22);
  color: inherit;
}

/* --- Keyboard focus: a clear, on-brand ring (never on mouse click) ------- */
:where(a, button, input, select, textarea, [tabindex], summary):focus-visible {
  outline: 2px solid var(--focus-ring, #ff8500);
  outline-offset: 3px;
  border-radius: 4px;
}

/* --- Buttons: tactile hover + press --------------------------------------- */
:where(.button) {
  transition:
    transform 0.16s var(--ease-out),
    box-shadow 0.22s var(--ease-out),
    background-color 0.2s var(--ease-out),
    color 0.2s var(--ease-out),
    filter 0.2s var(--ease-out);
  will-change: transform;
}

:where(.button):hover {
  transform: translateY(-2px);
  box-shadow: var(--lift-shadow);
}

:where(.button):active {
  transform: translateY(0);
  box-shadow: 0 6px 16px rgba(5, 5, 5, 0.14);
}

:where(.button.secondary):hover {
  background: rgba(5, 5, 5, 0.04);
}

/* --- Animated underline for inline nav / footer links -------------------- */
:where(.nav-cell a, .page-footer nav a) {
  position: relative;
  transition: color 0.2s var(--ease-out);
}

:where(.nav-cell a)::after,
:where(.page-footer nav a)::after {
  content: "";
  position: absolute;
  left: 0;
  right: 100%;
  bottom: -4px;
  height: 1.5px;
  background: currentColor;
  opacity: 0.85;
  transition: right 0.28s var(--ease-out);
}

:where(.nav-cell a:hover)::after,
:where(.page-footer nav a:hover)::after {
  right: 0;
}

:where(.page-footer nav a):hover {
  color: var(--ink, #050505);
}

/* --- Cards / tiles: gentle lift + image zoom on hover -------------------- */
:where(.tile) {
  transition:
    transform 0.3s var(--ease-out),
    box-shadow 0.3s var(--ease-out);
}

:where(.tile):hover {
  transform: translateY(-4px);
  box-shadow: var(--lift-shadow);
  z-index: 1;
}

:where(.tile) > img,
:where(.tile) > video {
  transition: transform 0.5s var(--ease-out);
}

:where(.tile):hover > img,
:where(.tile):hover > video {
  transform: scale(1.035);
}

/* --- Stat cells: quiet hover wash to reward the eye ---------------------- */
:where(.stat) {
  transition: background-color 0.25s var(--ease-out);
}

:where(.stat):hover {
  background: rgba(255, 255, 255, 0.7);
}

/* --- Loading state: lazy images fade + rise in once decoded -------------- */
@media (prefers-reduced-motion: no-preference) {
  img[loading="lazy"] {
    opacity: 0;
    transform: translateY(8px) scale(1.005);
    transition:
      opacity 0.6s var(--ease-out),
      transform 0.6s var(--ease-out);
  }

  /* Once the browser has painted the image, `complete` flips true. The rule
     below reveals it; a tiny inline helper (ui-polish.js) also toggles a
     class for images that finish before this CSS applies. */
  img[loading="lazy"].is-loaded,
  img[loading="lazy"][data-loaded] {
    opacity: 1;
    transform: none;
  }
}

/* Skeleton shimmer — add class="skeleton" to any placeholder box ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: rgba(5, 5, 5, 0.06);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.55),
    transparent
  );
  animation: oleaf-shimmer 1.4s infinite;
}

@keyframes oleaf-shimmer {
  100% {
    transform: translateX(100%);
  }
}

/* --- Prettier scrollbar (WebKit) ---------------------------------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(32, 61, 29, 0.45) transparent;
}

*::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

*::-webkit-scrollbar-thumb {
  background: rgba(32, 61, 29, 0.4);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(32, 61, 29, 0.62);
  background-clip: content-box;
}

/* --- Respect users who prefer less motion -------------------------------- */
@media (prefers-reduced-motion: reduce) {
  :where(.button, .tile, .tile > img, .tile > video, .stat),
  img[loading="lazy"] {
    transition: none !important;
    transform: none !important;
    opacity: 1 !important;
  }

  .skeleton::after {
    animation: none;
  }
}
