/* =========================================================================
   Spider Solitaire — WebGL preloader
   Every asset (logo, web overlay, icon) is served from the build's Build
   folder. No TemplateData is required.
   ========================================================================= */

:root {
  --gold: #f6c445;
  --gold-bright: #ffe9a6;
  --gold-deep: #9a5c10;
  --lavender: #f2e6ff;
  --violet-ink: #160227;
  --violet-deep: #240540;
  --violet: #52127f;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-soft: cubic-bezier(0.33, 1, 0.68, 1);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--violet-ink);
}

body {
  color: var(--lavender);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

/* -------------------------------------------------------------------------
   Unity host
   ------------------------------------------------------------------------- */

#unity-container {
  position: fixed;
  inset: 0;
  background: #1a032c;
}

#unity-fullscreen-container {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: scale(1.015);
  transition: opacity 0.9s var(--ease-out), transform 1.4s var(--ease-out);
  will-change: opacity, transform;
}

body.game-ready #unity-fullscreen-container {
  opacity: 1;
  transform: none;
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #240540;
  outline: none;
}

#unity-fullscreen-button {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 5;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(246, 196, 69, 0.4);
  border-radius: 50%;
  background: linear-gradient(160deg, rgba(72, 20, 112, 0.85), rgba(26, 3, 44, 0.9));
  color: var(--gold-bright);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out),
    background 0.3s ease, border-color 0.3s ease;
}

body.game-ready #unity-fullscreen-button {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

#unity-fullscreen-button:hover {
  background: linear-gradient(160deg, rgba(104, 32, 158, 0.95), rgba(40, 6, 66, 0.95));
  border-color: rgba(246, 196, 69, 0.85);
}

#unity-fullscreen-button svg {
  width: 20px;
  height: 20px;
}

#unity-warning {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 60;
  display: none;
  width: min(92vw, 620px);
  transform: translateX(-50%);
  pointer-events: none;
}

#unity-warning > div {
  margin-bottom: 8px;
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: #fff;
  background: rgba(24, 24, 24, 0.92);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

#unity-warning > div.is-warning {
  color: #2a1400;
  background: linear-gradient(180deg, #ffe28a, #f3c44b);
}

#unity-warning > div.is-error {
  background: linear-gradient(180deg, #c0392b, #8e2318);
}

/* -------------------------------------------------------------------------
   Preloader backdrop
   ------------------------------------------------------------------------- */

#preloader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
  isolation: isolate;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.95s var(--ease-out), visibility 0.95s linear;
  --px: 0;
  --py: 0;
}

#preloader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#preloader.is-done .pl-stage {
  transform: translateY(-12px) scale(1.03);
  filter: blur(5px);
}

#preloader.is-done .pl-bg {
  transform: scale(1.06);
}

#preloader.is-done .pl-footer {
  opacity: 0;
  transform: translateY(8px);
}

.pl-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  transition: transform 1.6s var(--ease-out);
  will-change: transform;
}

.pl-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(115% 88% at 50% 38%, #7b2cb5 0%, #622096 26%, #48106f 48%, #320a52 68%, #240540 84%, #170228 100%),
    linear-gradient(180deg, #4d1278 0%, #1c0330 100%);
}

.pl-web {
  position: absolute;
  top: 0;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translateX(-50%) translate3d(calc(var(--px) * -8px), calc(var(--py) * -5px), 0);
  background: url("spider-web.png") top center / 100% auto no-repeat;
  opacity: 0.55;
  filter: drop-shadow(0 0 7px rgba(214, 178, 255, 0.22));
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 52%, transparent 76%);
  mask-image: linear-gradient(180deg, #000 0%, #000 52%, transparent 76%);
  pointer-events: none;
  transition: transform 0.9s var(--ease-soft), opacity 1.4s ease;
  will-change: transform;
}

.pl-glow {
  position: absolute;
  top: 4%;
  left: 50%;
  width: 82vw;
  height: 82vw;
  max-width: 940px;
  max-height: 940px;
  transform: translateX(-50%) translate3d(calc(var(--px) * 14px), calc(var(--py) * 11px), 0);
  background: radial-gradient(circle, rgba(255, 214, 112, 0.14) 0%, rgba(190, 110, 255, 0.12) 36%, transparent 68%);
  filter: blur(20px);
  pointer-events: none;
  transition: transform 0.6s var(--ease-soft);
  will-change: transform;
}

.pl-grain {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='150' height='150' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  opacity: 0.04;
  mix-blend-mode: overlay;
  pointer-events: none;
}

.pl-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 88% 78% at 50% 43%, transparent 42%, rgba(14, 2, 24, 0.45) 76%, rgba(10, 1, 18, 0.82) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.26) 0%, transparent 20%, transparent 80%, rgba(0, 0, 0, 0.36) 100%);
  pointer-events: none;
}

.pl-dust {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.pl-dust-dot {
  position: absolute;
  bottom: -12px;
  width: var(--s, 3px);
  height: var(--s, 3px);
  border-radius: 50%;
  background: #f3dcff;
  box-shadow: 0 0 8px 1px rgba(212, 160, 255, 0.65);
  opacity: 0;
  animation: plDrift var(--d, 12s) linear var(--delay, 0s) infinite;
}

@keyframes plDrift {
  0% { opacity: 0; transform: translate3d(0, 0, 0) scale(0.7); }
  12% { opacity: 0.7; }
  70% { opacity: 0.4; }
  100% { opacity: 0; transform: translate3d(var(--dx, 20px), -80vh, 0) scale(1.1); }
}

/* -------------------------------------------------------------------------
   Stage
   ------------------------------------------------------------------------- */

.pl-stage {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.2vh, 24px);
  min-height: 0;
  padding: clamp(16px, 3.5vh, 46px) 20px clamp(8px, 1.6vh, 18px);
  transition: transform 0.95s var(--ease-out), filter 0.95s var(--ease-out);
}

/* Brand ------------------------------------------------------------------ */

.pl-brand {
  position: relative;
  display: grid;
  place-items: center;
  animation: plBrandIn 1.15s var(--ease-out) 0.08s both;
}

.pl-halo {
  position: absolute;
  width: 118%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 212, 108, 0.2) 0%, rgba(186, 104, 255, 0.16) 44%, transparent 70%);
  filter: blur(18px);
  animation: plHalo 5.5s var(--ease-soft) infinite;
  pointer-events: none;
}

.pl-logo {
  position: relative;
  display: block;
  height: clamp(180px, 46vh, 430px);
  width: auto;
  max-width: min(46vw, 430px);
  object-fit: contain;
  filter:
    drop-shadow(0 22px 34px rgba(0, 0, 0, 0.52))
    drop-shadow(0 0 30px rgba(198, 128, 255, 0.22));
  animation: plFloat 7s var(--ease-soft) infinite;
  transition: filter 0.45s ease;
  will-change: transform;
  cursor: pointer;
}

.pl-brand:hover .pl-logo,
.pl-brand.is-pulsing .pl-logo {
  filter:
    drop-shadow(0 24px 38px rgba(0, 0, 0, 0.56))
    drop-shadow(0 0 44px rgba(255, 203, 84, 0.32));
}

.pl-ripple {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58%;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 222, 138, 0.7);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
}

.pl-brand.is-pulsing .pl-ripple {
  animation: plRipple 0.9s var(--ease-out);
}

@keyframes plBrandIn {
  from { opacity: 0; transform: translateY(18px) scale(0.94); }
  to { opacity: 1; transform: none; }
}

@keyframes plFloat {
  0%, 100% { transform: translateY(-5px); }
  50% { transform: translateY(6px); }
}

@keyframes plHalo {
  0%, 100% { opacity: 0.68; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1.05); }
}

@keyframes plRipple {
  0% { opacity: 0.85; transform: translate(-50%, -50%) scale(0.62); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.25); }
}

/* Loading readout --------------------------------------------------------- */

.pl-loader {
  display: flex;
  flex-direction: column;
  gap: clamp(7px, 1.3vh, 11px);
  width: clamp(240px, 34vw, 400px);
  animation: plLoaderIn 0.9s var(--ease-out) 0.45s backwards;
}

@keyframes plLoaderIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.pl-track {
  position: relative;
  height: clamp(26px, 3.8vh, 34px);
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 999px;
  background:
    linear-gradient(180deg, #320a52 0%, #1d0333 100%) padding-box,
    linear-gradient(160deg, #ffe9a6 0%, #f3b93a 26%, #b06d12 52%, #ffe08a 76%, #efb42d 100%) border-box;
  box-shadow:
    0 0 22px rgba(240, 175, 45, 0.24),
    0 12px 26px rgba(0, 0, 0, 0.42),
    inset 0 2px 7px rgba(0, 0, 0, 0.72);
}

.pl-track::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(22, 2, 39, 0.6);
  pointer-events: none;
}

.pl-fill {
  position: relative;
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #9a5c10 0%, #e1a326 20%, #ffe89a 50%, #f3c13b 76%, #b9781d 100%);
  box-shadow:
    0 0 14px rgba(255, 198, 58, 0.6),
    0 0 34px rgba(255, 198, 58, 0.26),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  will-change: width;
}

.pl-shine {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    112deg,
    transparent 18%,
    rgba(255, 255, 255, 0.8) 42%,
    rgba(255, 255, 255, 0.16) 54%,
    transparent 74%
  );
  background-size: 220% 100%;
  animation: plShine 1.9s linear infinite;
  mix-blend-mode: screen;
  pointer-events: none;
  overflow: hidden;
}

@keyframes plShine {
  from { background-position: 180% 0; }
  to { background-position: -80% 0; }
}

/* The little spider rides the leading edge of the gold fill. */
.pl-crawler {
  position: absolute;
  top: 50%;
  right: -10px;
  width: 22px;
  height: 18px;
  color: #2b063f;
  transform: translateY(-50%) scale(0);
  filter: drop-shadow(0 0 6px rgba(255, 207, 85, 0.8));
  transition: transform 0.35s var(--ease-out);
  pointer-events: none;
}

.pl-fill.is-started .pl-crawler {
  transform: translateY(-50%) scale(1);
}

.pl-crawler svg {
  display: block;
  width: 100%;
  height: 100%;
}

.pl-fill.is-crawling .pl-crawler svg {
  animation: plCrawler 0.9s var(--ease-soft);
}

@keyframes plCrawler {
  0%, 100% { transform: none; }
  30% { transform: translateY(-2px) rotate(-7deg); }
  65% { transform: translateY(1px) rotate(5deg); }
}

.pl-readout {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding: 0 4px;
}

.pl-status {
  font-size: clamp(9px, 1.25vh, 12px);
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgba(242, 230, 255, 0.68);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.pl-status.is-swapping {
  animation: plStatusIn 0.32s var(--ease-out);
}

@keyframes plStatusIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}

.pl-percent {
  position: absolute;
  right: 4px;
  top: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(12px, 1.7vh, 16px);
  font-weight: 700;
  line-height: 1;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 14px rgba(255, 202, 74, 0.38);
}

.pl-percent span {
  margin-left: 1px;
  font-size: 0.7em;
  font-weight: 400;
  opacity: 0.68;
}

/* Hint / retry (error-only) ----------------------------------------------- */

.pl-meta {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: clamp(15px, 2.2vh, 22px);
  padding: 0 3px;
}

.pl-hint {
  display: none;
  align-items: center;
  gap: 7px;
  font-size: clamp(9px, 1.25vh, 11px);
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: rgba(255, 190, 168, 0.88);
}

.pl-hint svg {
  width: 14px;
  height: 14px;
  color: #ffb59c;
  flex: none;
}

.pl-retry {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 16px;
  border: 1px solid rgba(246, 196, 69, 0.55);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(246, 196, 69, 0.16), rgba(246, 196, 69, 0.06));
  color: var(--gold-bright);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease;
}

.pl-retry:hover {
  background: rgba(246, 196, 69, 0.26);
  border-color: var(--gold);
}

#preloader.is-error .pl-meta { display: flex; }
#preloader.is-error .pl-hint { display: inline-flex; }
#preloader.is-error .pl-retry { display: inline-flex; }
#preloader.is-error .pl-status { color: #ffc2ae; }
#preloader.is-error .pl-fill {
  background: linear-gradient(90deg, #7d2418, #c04a33 55%, #e4775f);
  box-shadow: 0 0 14px rgba(220, 90, 60, 0.48);
}
#preloader.is-error .pl-crawler { filter: drop-shadow(0 0 6px rgba(232, 96, 70, 0.75)); }
#preloader.is-error .pl-shine { animation: none; opacity: 0.15; }

/* -------------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------------- */

.pl-footer {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  padding: 0 24px max(18px, env(safe-area-inset-bottom));
  transition: opacity 0.6s ease, transform 0.6s var(--ease-out);
  animation: plFooterIn 1s var(--ease-out) 1s backwards;
}

.pl-version {
  padding-left: 2px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(242, 230, 255, 0.34);
}

@keyframes plFooterIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* -------------------------------------------------------------------------
   Responsive tuning
   ------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .pl-logo {
    height: clamp(140px, 32vh, 240px);
    max-width: min(78vw, 240px);
  }

  .pl-loader { width: min(78vw, 360px); }

  .pl-readout { padding: 0 2px; }

  .pl-web {
    background-size: 160% auto;
    opacity: 0.48;
  }

  .pl-footer { padding-inline: 18px; }
}

@media (max-height: 430px) and (orientation: landscape) {
  .pl-stage {
    gap: 8px;
    padding-top: 8px;
  }

  .pl-logo { height: clamp(96px, 27vh, 160px); }
  .pl-loader { gap: 6px; }
  .pl-meta { display: none; }
  .pl-track { height: 24px; }
  .pl-footer { padding-bottom: 8px; }
}

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