/* The loading screen (js/ui/bootProgress.js): a picture of the game, full-bleed (assets/ui/loading-<track>.jpg,
   chosen in index.html's head, its average colour behind it until it is there), the logo where the title has it,
   and along the bottom a slim bar, the line of what is happening and one tip. The wait for a track (#track-wait)
   is the same family: that track's picture behind a small card. */

/* ---------------------------------------------------------------- the screen and its picture */
.loading {
  z-index: 10;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  padding: var(--gutter);
  overflow: hidden;
  background: var(--shot-colour, #24314f);
  transition: opacity 0.6s ease;
}

/* leaving: it fades and the title shows through (no flash: the title is already there under it) */
.loading.is-leaving {
  opacity: 0;
  pointer-events: none;
}

.loading-shot {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.loading-shot.is-in { opacity: 1; }

/* a gentle dark gradient at the bottom, for the words, and a breath of it at the top, for the logo */
.loading::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(to top, rgb(6 10 26 / 78%) 0%, rgb(6 10 26 / 46%) 15%, rgb(6 10 26 / 0%) 36%),
    linear-gradient(to bottom, rgb(6 10 26 / 26%) 0%, rgb(6 10 26 / 0%) 24%);
  content: "";
}

.loading-head {
  display: flex;
  justify-content: center;
}

.loading [data-when] { display: none; }
.loading[data-state="loading"] [data-when="loading"],
.loading[data-state="error"] [data-when="error"] { display: flex; }

/* ---------------------------------------------------------------- along the bottom: the line, the bar, a tip */
.loading-foot {
  grid-row: 3;
  flex-direction: column;
  gap: var(--s-2);
  align-items: center;
  width: min(36rem, 100%);
  padding-bottom: 1vh;
  text-align: center;
}

.loading-stage {
  margin: 0;
  font-size: var(--t-md);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgb(0 0 0 / 55%), 0 0 18px rgb(0 0 0 / 35%);
}

.loading-bar {
  position: relative;
  width: 100%;
  height: 0.375rem;
  overflow: hidden;
  background: rgb(255 255 255 / 22%);
  border-radius: var(--r-pill);
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
}

.loading-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, var(--c-gold-top), var(--c-gold-bottom));
  border-radius: inherit;
  transition: width 0.25s linear;
}

/* one tip, with its picture */
.loading-tip {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  justify-content: center;
  margin: 0;
  font-size: var(--t-sm);
  font-weight: 700;
  color: rgb(255 255 255 / 86%);
  text-shadow: 0 1px 2px rgb(0 0 0 / 60%);
}

.loading-tip .tip-icon { flex: none; color: var(--c-gold); filter: drop-shadow(0 1px 1px rgb(0 0 0 / 50%)); }
.loading-tip .tip-icon svg { width: 1.25rem; height: 1.25rem; }
.loading-tip:not(:has(.loading-tip-text:not(:empty))) { visibility: hidden; }

/* ---------------------------------------------------------------- the error state: a card on the same picture, the picture dimmed */
.loading[data-state="error"]::after { background: rgb(6 10 26 / 58%); }

.loading-error {
  grid-row: 2;
  flex-direction: column;
  gap: var(--s-3);
  align-items: center;
  align-self: center;
  width: min(34rem, 100%);
  padding: var(--s-4) var(--s-5) var(--s-5);
  text-align: center;
}

.loading-error .title { font-size: var(--t-lg); }
.loading-error .lead { color: var(--c-text-soft); }
.loading-detail { font-size: var(--t-xs); font-weight: 700; color: var(--c-text-dim); }
.loading-detail:empty { display: none; }

/* ---------------------------------------------------------------- waiting for a track: its picture behind a small card */
.track-wait {
  z-index: 25;
  overflow: hidden;
  background: rgb(6 10 26 / 40%);
  animation: tw-in 0.3s ease 0.12s both;
}

.track-wait .loading-shot { transition: none; }
.track-wait .loading-shot:not([src]) { display: none; }
.track-wait:has(.loading-shot.is-in)::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgb(6 10 26 / 30%);
  content: "";
}

/* (the layer is the picture's stacking context) */
.track-wait { isolation: isolate; }
.track-wait .sheet-message { --sheet-w: 24rem; gap: var(--s-3); }
.track-wait .loading-stage { font-size: var(--t-md); color: var(--c-text); text-shadow: none; }
.track-wait .loading-bar { width: min(16rem, 100%); background: rgb(255 255 255 / 14%); box-shadow: none; }

/* busy, with no amount to show: a stretch of gold gliding back and forth */
.loading-bar.is-busy .loading-fill {
  width: 34%;
  animation: lb-glide 1.4s ease-in-out infinite alternate;
}

@keyframes lb-glide {
  from { left: 0; }
  to { left: 66%; }
}

@keyframes tw-in {
  from { opacity: 0; }
}

/* ---------------------------------------------------------------- calm motion: nothing glides or fades in */
html.calm .loading-shot,
html.calm .track-wait { transition: none; animation: none; }
html.calm .loading-bar.is-busy .loading-fill { left: 33%; animation: none; }

@media (prefers-reduced-motion: reduce) {
  html:not(.motion-full) .loading-shot,
  html:not(.motion-full) .track-wait { transition: none; animation: none; }
  html:not(.motion-full) .loading-bar.is-busy .loading-fill { left: 33%; animation: none; }
}

/* ---------------------------------------------------------------- a low window (a phone on its side) */
@media (max-height: 520px) {
  .loading-foot { gap: var(--s-1); padding-bottom: 0; }
  .loading-stage { font-size: var(--t-sm); }
  .loading-tip { font-size: var(--t-xs); }
  .loading-tip .tip-icon svg { width: 1rem; height: 1rem; }
  .loading-error { gap: var(--s-2); padding: var(--s-3) var(--s-4); }
  .loading-error .choice-icon { display: none; }
}
