/* POVPAD's share (share.js): the Share button on the last step, and the page a shared link opens. While it loads, the
   stage's reticle seeks; in the replay its ring fills as the angle is aimed and locks in lava; then it fades and the
   sheet offers Order this and Make your own. #app's data-share says where it is: loading, replay, done or broken. */

/* ---- the last step's buttons: On my desk (once measured) and Share, side by side */
.see-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}
.see-buttons .btn {
  padding-inline: 14px;
  font-size: 15px;
}
.share-said {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin: 0;
  color: var(--lamp);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}
.share-said input {
  flex: 1 1 14em;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--night);
  color: var(--paper);
  font:
    400 13px A,
    sans-serif;
}

/* ---- the stage's reticle */
.hud {
  --hud-size: min(42vmin, 210px);
  --hud-lava: #ff7a3d;
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  display: none;
  justify-items: center;
  gap: 2px;
  width: max-content;
  transform: translate(-50%, calc(-1 * var(--hud-size) / 2));
  pointer-events: none;
  /* a shadow without a filter, which a phone would paint again on every frame of the aim */
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.8);
}
#app:is([data-share='loading'], [data-share='replay']) .hud:not([data-phase='off']) {
  display: grid;
}
.hud svg {
  width: var(--hud-size);
  height: var(--hud-size);
  overflow: visible;
}
.hud-shade {
  fill: none;
  stroke: rgb(0 0 0 / 0.4);
  stroke-width: 10;
}
.hud-ring {
  fill: none;
  stroke: rgb(255 250 240 / 0.5);
  stroke-width: 2.5;
}
.hud-fill,
.hud-seek {
  fill: none;
  stroke: var(--lamp);
  stroke-width: 5;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}
.hud-fill {
  stroke-dasharray: 0 100;
}
/* loading: an arc going round the ring, the reticle seeking */
.hud-seek {
  display: none;
  stroke-dasharray: 18 82;
  animation: hud-seek 0.9s linear infinite;
}
#app[data-share='loading'] .hud-seek {
  display: block;
}
#app[data-share='loading'] .hud-cross {
  animation: hud-breathe 1.2s ease-in-out infinite;
}
.hud-cross {
  stroke: var(--paper);
  stroke-width: 2.5;
  stroke-linecap: round;
  transform-origin: 50% 50%;
}
.hud-tick {
  fill: none;
  stroke: var(--hud-lava);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 0 100;
  opacity: 0;
}
.hud-angle {
  min-height: 1.15em;
  color: var(--paper);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.hud-word {
  min-height: 1.2em;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--night);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.5;
}
.hud-word:empty {
  visibility: hidden;
}
/* the lock: the ring flashes lava, the tick draws itself, the words stamp in */
.hud[data-phase='locked'] svg {
  animation: hud-lock 0.6s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.hud[data-phase='locked'] .hud-fill {
  stroke: var(--hud-lava);
  stroke-width: 7;
}
.hud[data-phase='locked'] .hud-tick {
  opacity: 1;
  stroke-dasharray: 100 100;
  transition: stroke-dasharray 0.35s cubic-bezier(0.3, 1.2, 0.5, 1);
}
.hud[data-phase='locked'] .hud-cross {
  stroke: var(--hud-lava);
}
.hud[data-phase='locked'] .hud-word {
  background: var(--hud-lava);
  animation: hud-lock 0.6s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes hud-seek {
  to {
    transform: rotate(270deg);
  }
}
@keyframes hud-breathe {
  50% {
    transform: scale(0.9);
    opacity: 0.6;
  }
}
@keyframes hud-lock {
  40% {
    transform: scale(1.12);
  }
}

/* ---- the sheet: a word while it loads and plays, then what it is and the two ways on */
.shared {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-xs);
  max-width: 520px;
  min-height: 100%;
  margin-inline: auto;
  padding: 4px var(--space-s) calc(10px + env(safe-area-inset-bottom));
}
.shared .steps-head {
  grid-template-columns: minmax(0, 1fr);
}
.shared-done,
.shared-buttons,
.shared-broken {
  display: none;
}
#app[data-share='done'] .shared-done {
  display: grid;
  gap: var(--space-xs);
  animation: step-in 0.28s ease-out;
}
#app:is([data-share='done'], [data-share='broken']) .shared-buttons {
  display: grid;
  grid-row: 5;
  animation: step-in 0.28s ease-out;
}
#app[data-share='broken'] .shared-broken {
  display: block;
}
#app[data-share='broken'] #orderThis,
#app:is([data-share='done'], [data-share='broken']) .shared-wait {
  display: none;
}
/* while it loads and plays, the stage is the page: its chips show the making, a tap anywhere skips */
#app:is([data-share='loading'], [data-share='replay']) {
  cursor: pointer;
}
#app[data-share] .shows button {
  cursor: default;
}

@media (min-width: 860px) and (min-aspect-ratio: 1/1) {
  .shared {
    flex: 1 0 auto;
    width: 100%;
    gap: var(--space-s);
    min-height: 0;
    padding: var(--space-m) var(--space-l);
  }
  .shared .steps-head h1 {
    font-size: 26px;
  }
  .hud {
    --hud-size: min(30vmin, 240px);
  }
  .hud-angle {
    font-size: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hud *,
  .hud,
  .shared-done,
  .shared-buttons {
    animation: none !important;
    transition: none !important;
  }
}
