/* PhysicsUK loading wheel — brand face mark whose outer ring
   fades and rotates like a spinner. CSS + one shared image asset.
   Reusable anywhere: server-render partials/loadingSpinner.ejs, or drive
   it from JS via window.PWLoader (public/js/loadingWheel.js). */

.pw-loader {
  --pw-green: #22c670;
  --pw-green-dark: #157a5c;
  --pw-track: rgba(34, 198, 112, .14);
  --pw-size: 120px;
  --pw-thick: calc(var(--pw-size) * .11);
  --pw-box-margin: max(6px, calc(var(--pw-size) * .06));
  --pw-speed: 1s;
  position: relative;
  width: var(--pw-size);
  height: var(--pw-size);
  padding: var(--pw-box-margin);
  flex: 0 0 auto;
  box-sizing: content-box;
}

.pw-loader::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 22%;
  background: #fff;
  box-shadow: 0 8px 22px rgba(21, 122, 92, .12);
  z-index: 0;
}

.pw-loader__track,
.pw-loader__spin,
.pw-loader__mark,
.pw-loader__done {
  position: absolute;
  inset: var(--pw-box-margin);
}

.pw-loader__track { z-index: 2; }
.pw-loader__spin { z-index: 3; }
.pw-loader__mark { z-index: 1; }
.pw-loader__done { z-index: 4; }

.pw-loader__track {
  border-radius: 50%;
  background: var(--pw-track);
  -webkit-mask: radial-gradient(farthest-side, #0000 calc(100% - var(--pw-thick)), #000 calc(100% - var(--pw-thick)));
          mask: radial-gradient(farthest-side, #0000 calc(100% - var(--pw-thick)), #000 calc(100% - var(--pw-thick)));
}

.pw-loader__spin {
  animation: pw-spin var(--pw-speed) linear infinite;
  transition: opacity .25s ease;
}

.pw-loader__spin::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--pw-green), rgba(34, 198, 112, 0) 300deg, rgba(34, 198, 112, 0) 360deg);
  -webkit-mask: radial-gradient(farthest-side, #0000 calc(100% - var(--pw-thick)), #000 calc(100% - var(--pw-thick)));
          mask: radial-gradient(farthest-side, #0000 calc(100% - var(--pw-thick)), #000 calc(100% - var(--pw-thick)));
}

.pw-loader__spin::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--pw-thick);
  height: var(--pw-thick);
  margin-left: calc(var(--pw-thick) / -2);
  border-radius: 50%;
  background: var(--pw-green);
}

.pw-loader__mark {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .22s ease, transform .22s ease;
}

.pw-loader__mark::before {
  content: "";
  position: absolute;
  width: 70%;
  height: 70%;
  border-radius: 18%;
  background: #fff;
}

.pw-loader__mark img {
  position: relative;
  display: block;
  width: 62%;
  height: auto;
}

.pw-loader__done {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(.78);
  pointer-events: none;
  transition: opacity .22s ease, transform .28s cubic-bezier(.2, .8, .2, 1);
}

.pw-loader__done::before {
  content: "";
  position: absolute;
  width: 55%;
  height: 55%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 8px 20px rgba(34, 198, 112, .2);
}

.pw-loader__done svg {
  position: relative;
  width: 42%;
  height: 42%;
  overflow: visible;
  stroke: var(--pw-green);
  stroke-width: 13;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.pw-loader--complete {
  animation: pw-complete-pulse .62s ease-out both;
}

.pw-loader--complete .pw-loader__spin {
  animation-play-state: paused;
  opacity: .16;
}

.pw-loader--complete .pw-loader__mark {
  opacity: .2;
  transform: scale(.88);
}

.pw-loader--complete .pw-loader__done {
  opacity: 1;
  transform: scale(1);
}

@keyframes pw-spin { to { transform: rotate(360deg); } }

@keyframes pw-complete-pulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Overlay — full-page by default; add .pw-overlay--contained to fill a
   positioned parent instead (e.g. a card waiting on an LLM response). */
.pw-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(246, 250, 248, .94);
  -webkit-backdrop-filter: blur(3px);
          backdrop-filter: blur(3px);
  opacity: 1;
  visibility: visible;
  transition: opacity .35s ease, visibility .35s ease;
  animation: pw-overlay-failsafe 0s linear 15s forwards;
}

.pw-overlay--contained { position: absolute; z-index: 20; }

.pw-overlay__msg {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: #0b3d1c;
}

.pw-overlay--hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* JS-independent backstop: never trap the user behind a stuck overlay. */
@keyframes pw-overlay-failsafe { to { opacity: 0; visibility: hidden; } }

@media (prefers-reduced-motion: reduce) {
  .pw-loader__spin { animation-duration: 2.6s; }
  .pw-loader--complete { animation: none; }
  .pw-loader__mark,
  .pw-loader__spin,
  .pw-loader__done { transition: none; }
  .pw-overlay { transition: none; }
}
